Skip to content

Commit 5be5cef

Browse files
authored
Merge pull request #673 from Xian55/feature/addon/1.7.64
Addon: [1.7.64] - Improved LootGoal state - many small fixes and optimizations
2 parents f1a629c + 6beef43 commit 5be5cef

28 files changed

+382
-274
lines changed

Addons/DataToColor/DataToColor.lua

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ local GetItemInfo = GetItemInfo
9595
local GetCoinTextureString = GetCoinTextureString
9696
local UseContainerItem = DataToColor.UseContainerItem
9797

98+
local GetNumLootItems = GetNumLootItems
99+
98100
-- initialization
99101
local globalTick = 0
100102
local initPhase = 10
@@ -254,6 +256,7 @@ end
254256
function DataToColor:Reset()
255257
DataToColor.S.playerSpellBookName = {}
256258
DataToColor.S.playerSpellBookId = {}
259+
DataToColor.S.playerSpellBookIdHighest = {}
257260
DataToColor.S.playerSpellBookIconId = {}
258261

259262
DataToColor.playerGUID = UnitGUID(DataToColor.C.unitPlayer)
@@ -408,6 +411,10 @@ function DataToColor:PopulateSpellBookInfo()
408411
DataToColor.S.playerSpellBookName[texture] = name
409412
DataToColor.S.playerSpellBookIconToId[texture] = id
410413

414+
if not DataToColor.S.playerSpellBookIdHighest[texture] or id > DataToColor.S.playerSpellBookIdHighest[texture] then
415+
DataToColor.S.playerSpellBookIdHighest[texture] = id
416+
end
417+
411418
num = num + 1
412419
end
413420
end
@@ -426,6 +433,10 @@ function DataToColor:PopulateSpellBookInfo()
426433
DataToColor.S.playerSpellBookName[texture] = name
427434
DataToColor.S.playerSpellBookIconToId[texture] = id
428435

436+
if not DataToColor.S.playerSpellBookIdHighest[texture] or id > DataToColor.S.playerSpellBookIdHighest[texture] then
437+
DataToColor.S.playerSpellBookIdHighest[texture] = id
438+
end
439+
429440
num = num + 1
430441
end
431442
end
@@ -434,7 +445,7 @@ function DataToColor:PopulateSpellBookInfo()
434445
end
435446

436447
function DataToColor:InitSpellBookQueue()
437-
for id, _ in pairs(DataToColor.S.playerSpellBookId) do
448+
for _, id in pairs(DataToColor.S.playerSpellBookIdHighest) do
438449
DataToColor.spellBookQueue:push(id)
439450
end
440451
end
@@ -877,10 +888,11 @@ function DataToColor:CreateFrames()
877888

878889
-- Timers
879890
if DataToColor.lastLoot == DataToColor.C.Loot.Closed and
880-
DataToColor.globalTime - DataToColor.lastLootResetStart > LOOT_RESET_RATE then
891+
DataToColor.globalTime - DataToColor.lastLootResetStart >= LOOT_RESET_RATE then
881892
DataToColor.lastLoot = DataToColor.C.Loot.Corpse
882893
end
883-
Pixel(int, DataToColor.lastLoot, 97)
894+
local lootItemCount = GetNumLootItems()
895+
Pixel(int, lootItemCount * 10 + DataToColor.lastLoot, 97)
884896

885897
local e = DataToColor.ChatQueue:peek()
886898
if e == nil then

Addons/DataToColor/DataToColor.toc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Title: DataToColor
44
## Author: FreeHongKongMMO
55
## Notes: Displays data as colors
6-
## Version: 1.7.63
6+
## Version: 1.7.64
77
## RequiredDeps:
88
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
99
## SavedVariables:

Addons/DataToColor/EventHandlers.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,23 @@ end
167167

168168
function DataToColor:OnUIErrorMessage(_, _, message)
169169
if ignoreErrorListMessages[message] then
170-
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey messasge
170+
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey message
171171
return
172172
end
173173

174174
local code = errorListMessages[message] or 0
175175
if code > 0 then
176176
DataToColor.uiErrorMessage = code
177177
DataToColor.uiErrorMessageTime = DataToColor.globalTime
178-
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
178+
--UIErrorsFrame:AddMessage(code .. " " .. message, 0, 1, 0) -- show as green message
179+
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green message
179180
return
180181
else
181182
for i, v in pairs(specialErrorS) do
182183
if string.find(message, i) then
183184
DataToColor.uiErrorMessage = v
184185
DataToColor.uiErrorMessageTime = DataToColor.globalTime
185-
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
186+
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green message
186187
return
187188
end
188189
end

Addons/DataToColor/Query.lua

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ local UnitAttackSpeed = UnitAttackSpeed
5151
local UnitRangedDamage = UnitRangedDamage
5252

5353
local GameMenuFrame = GameMenuFrame
54+
local LootFrame = LootFrame
55+
local ChatFrame1EditBox = ChatFrame1EditBox
5456

5557
local HasPetUI = HasPetUI
5658

@@ -124,11 +126,11 @@ function DataToColor:Bits1()
124126
(UnitIsVisible(DataToColor.C.unitPet) and not UnitIsDead(DataToColor.C.unitPet) and 2 or 0) ^ 6 +
125127
(mainHandEnchant and 2 or 0) ^ 7 +
126128
(offHandEnchant and 2 or 0) ^ 8 +
127-
DataToColor:GetInventoryBroken() ^ 9 +
129+
(DataToColor:GetInventoryBroken() ^ 9) +
128130
(UnitOnTaxi(DataToColor.C.unitPlayer) and 2 or 0) ^ 10 +
129131
(IsSwimming() and 2 or 0) ^ 11 +
130-
(GetPetHappiness() == 3 and 2 or 0) ^ 12 +
131-
(GetInventoryItemCount(DataToColor.C.unitPlayer, ammoSlot) > 0 and 2 or 0) ^ 13 +
132+
(DataToColor:PetHappy() and 2 or 0) ^ 12 +
133+
(DataToColor:HasAmmo() and 2 or 0) ^ 13 +
132134
(UnitAffectingCombat(DataToColor.C.unitPlayer) and 2 or 0) ^ 14 +
133135
(DataToColor:IsUnitsTargetIsPlayerOrPet(DataToColor.C.unitTarget, DataToColor.C.unitTargetTarget) and 2 or 0) ^ 15 +
134136
(IsAutoRepeatSpell(DataToColor.C.Spell.AutoShotId) and 2 or 0) ^ 16 +
@@ -163,11 +165,11 @@ function DataToColor:Bits2()
163165
(DataToColor:IsUnitsTargetIsPlayerOrPet(DataToColor.C.unitmouseover, DataToColor.C.unitmouseovertarget) and 2 or 0) ^ 16 +
164166
(UnitPlayerControlled(DataToColor.C.unitmouseover) and 2 or 0) ^ 17 +
165167
(UnitPlayerControlled(DataToColor.C.unitTarget) and 2 or 0) ^ 18 +
166-
((DataToColor.autoFollow) and 2 or 0) ^ 19 +
167-
((GameMenuFrame:IsShown() and 2 or 0)) ^ 20 +
168-
((IsFlying() and 2 or 0)) ^ 21 +
169-
((DataToColor.moving and 2 or 0)) ^ 22 +
170-
((DataToColor:PetIsDefensive() and 2 or 0)) ^ 23
168+
(DataToColor.autoFollow and 2 or 0) ^ 19 +
169+
(GameMenuFrame:IsShown() and 2 or 0) ^ 20 +
170+
(IsFlying() and 2 or 0) ^ 21 +
171+
(DataToColor.moving and 2 or 0) ^ 22 +
172+
(DataToColor:PetIsDefensive() and 2 or 0) ^ 23
171173
end
172174

173175
function DataToColor:Bits3()
@@ -180,7 +182,9 @@ function DataToColor:Bits3()
180182
(UnitIsTapDenied(DataToColor.C.unitSoftInteract) and 2 or 0) ^ 4 +
181183
(UnitAffectingCombat(DataToColor.C.unitSoftInteract) and 2 or 0) ^ 5 +
182184
(DataToColor:IsUnitHostile(DataToColor.C.unitPlayer, DataToColor.C.unitSoftInteract) and 2 or 0) ^ 6 +
183-
((DataToColor.channeling and 2 or 0)) ^ 7
185+
(DataToColor.channeling and 2 or 0) ^ 7 +
186+
(LootFrame:IsShown() and 2 or 0) ^ 8 +
187+
(ChatFrame1EditBox:IsVisible() and 2 or 0) ^ 9
184188
)
185189
end
186190

@@ -602,6 +606,25 @@ function DataToColor:UnitTargetsPartyOrPet(unittarget)
602606
return false
603607
end
604608

609+
function DataToColor:HasAmmo()
610+
-- After Cataclysm, ammo slot was removed
611+
if DataToColor:IsClassicPreCata() == false then
612+
return true
613+
end
614+
615+
local count = GetInventoryItemCount(DataToColor.C.unitPlayer, ammoSlot)
616+
return count > 0
617+
end
618+
619+
function DataToColor:PetHappy()
620+
-- After Cataclysm, pet always happy :)
621+
if DataToColor:IsClassicPreCata() == false then
622+
return true
623+
end
624+
625+
return GetPetHappiness() == 3
626+
end
627+
605628
-- Returns true if target of our target is us
606629
function DataToColor:IsUnitsTargetIsPlayerOrPet(unit, unittarget)
607630
local x = DataToColor:UnitsTargetAsNumber(unit, unittarget)

Addons/DataToColor/Storage.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ DataToColor.S.playerAuraMap = {}
1212

1313
DataToColor.S.playerSpellBookName = {}
1414
DataToColor.S.playerSpellBookId = {}
15+
DataToColor.S.playerSpellBookIdHighest = {}
1516
DataToColor.S.playerSpellBookIconToId = {}
1617

1718
function DataToColor:InitStorage()

Addons/DataToColor/Versions.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ function DataToColor.IsRetail()
4040
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
4141
end
4242

43+
function DataToColor.IsClassicPreCata()
44+
return DataToColor.IsClassic() or DataToColor.IsClassic_BCC() or DataToColor.IsClassic_Wrath()
45+
end
46+
47+
4348
local LibClassicCasterino
4449
if DataToColor.IsClassic() then
4550
LibClassicCasterino = _G.LibStub("LibClassicCasterino")

Core/Actionbar/ActionBarCooldownReader.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22

33
using static Core.ActionBar;
4-
using static System.DateTime;
4+
using static System.Diagnostics.Stopwatch;
55
using static System.Math;
66

77
namespace Core;
@@ -11,11 +11,11 @@ public sealed class ActionBarCooldownReader : IReader
1111
private readonly struct Data
1212
{
1313
private readonly float durationSec;
14-
private readonly DateTime start;
14+
private readonly long start;
1515

16-
public DateTime End => start.AddSeconds(durationSec);
16+
public long End => start + (long)(durationSec * TimeSpan.TicksPerSecond);
1717

18-
public Data(float durationSec, DateTime start)
18+
public Data(float durationSec, long start)
1919
{
2020
this.durationSec = durationSec;
2121
this.start = start;
@@ -43,13 +43,13 @@ public void Update(IAddonDataProvider reader)
4343
int slotIdx = (value / ACTION_SLOT_MUL) - 1;
4444
float durationSec = value % ACTION_SLOT_MUL / FRACTION_PART;
4545

46-
data[slotIdx] = new(durationSec, UtcNow);
46+
data[slotIdx] = new(durationSec, GetTimestamp());
4747
}
4848

4949
public void Reset()
5050
{
5151
var span = data.AsSpan();
52-
span.Fill(new(0, UtcNow));
52+
span.Fill(new(0, GetTimestamp()));
5353
}
5454

5555
public int Get(KeyAction keyAction)
@@ -58,6 +58,6 @@ public int Get(KeyAction keyAction)
5858

5959
ref readonly Data d = ref data[index];
6060

61-
return Max((int)(d.End - UtcNow).TotalMilliseconds, 0);
61+
return Max((int)((d.End - GetTimestamp()) / TimeSpan.TicksPerMillisecond), 0);
6262
}
6363
}

Core/Addon/AuraTimeReader.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34

5+
using static System.Diagnostics.Stopwatch;
6+
47
namespace Core;
58

69
public interface IAuraTimeReader
@@ -22,10 +25,13 @@ public sealed class AuraTimeReader<T> : IAuraTimeReader, IReader
2225
{
2326
public readonly struct Data
2427
{
28+
private long StartTime { get; }
29+
2530
public int DurationSec { get; }
26-
public DateTime StartTime { get; }
2731

28-
public Data(int duration, DateTime startTime)
32+
public long End => StartTime + (DurationSec * TimeSpan.TicksPerSecond);
33+
34+
public Data(int duration, long startTime)
2935
{
3036
DurationSec = duration;
3137
StartTime = startTime;
@@ -37,7 +43,7 @@ public Data(int duration, DateTime startTime)
3743
private readonly int cTextureId;
3844
private readonly int cDurationSec;
3945

40-
private readonly Dictionary<int, Data> data = new();
46+
private readonly Dictionary<int, Data> data = [];
4147

4248
public AuraTimeReader(int cTextureId, int cDurationSec)
4349
{
@@ -52,7 +58,7 @@ public void Update(IAddonDataProvider reader)
5258
if (textureId == 0) return;
5359

5460
int durationSec = reader.GetInt(cDurationSec);
55-
data[textureId] = new(durationSec, DateTime.UtcNow);
61+
data[textureId] = new(durationSec, GetTimestamp());
5662
}
5763

5864
public void Reset()
@@ -63,7 +69,7 @@ public void Reset()
6369
public int GetRemainingTimeMs(int textureId)
6470
{
6571
return data.TryGetValue(textureId, out Data d) ?
66-
Math.Max(0, d.DurationSec >= UNLIMITED ? 1 : (int)(d.StartTime.AddSeconds(d.DurationSec) - DateTime.UtcNow).TotalMilliseconds)
72+
Math.Max(0, d.DurationSec >= UNLIMITED ? 1 : (int)((d.End - GetTimestamp()) / TimeSpan.TicksPerMillisecond))
6773
: 0;
6874
}
6975

Core/Addon/Loot.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public static class Loot_Extensions
2020

2121
public static class Loot
2222
{
23-
public const int LOOTFRAME_AUTOLOOT_DELAY = 300;
23+
public const int LOOTFRAME_AUTOLOOT_DELAY_MS = 300;
2424

25-
public const int LOOT_RESET_UPDATE_COUNT = 5;
25+
public const int LOOTFRAME_OPEN_TIME_MS = 2000;
26+
27+
public const int LOOT_PER_ITEM_TIME_MS = 1000;
28+
29+
public const int RESET_UPDATE_COUNT = 5;
2630
}

Core/Addon/PlayerReader.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Core.AddonComponent;
2-
using Core.Database;
1+
using Core.Database;
32

43
using SharedLib;
54

0 commit comments

Comments
 (0)