Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon: [1.7.64] - Improved LootGoal state - many small fixes and optimizations #673

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ local GetItemInfo = GetItemInfo
local GetCoinTextureString = GetCoinTextureString
local UseContainerItem = DataToColor.UseContainerItem

local GetNumLootItems = GetNumLootItems

-- initialization
local globalTick = 0
local initPhase = 10
Expand Down Expand Up @@ -254,6 +256,7 @@ end
function DataToColor:Reset()
DataToColor.S.playerSpellBookName = {}
DataToColor.S.playerSpellBookId = {}
DataToColor.S.playerSpellBookIdHighest = {}
DataToColor.S.playerSpellBookIconId = {}

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

if not DataToColor.S.playerSpellBookIdHighest[texture] or id > DataToColor.S.playerSpellBookIdHighest[texture] then
DataToColor.S.playerSpellBookIdHighest[texture] = id
end

num = num + 1
end
end
Expand All @@ -426,6 +433,10 @@ function DataToColor:PopulateSpellBookInfo()
DataToColor.S.playerSpellBookName[texture] = name
DataToColor.S.playerSpellBookIconToId[texture] = id

if not DataToColor.S.playerSpellBookIdHighest[texture] or id > DataToColor.S.playerSpellBookIdHighest[texture] then
DataToColor.S.playerSpellBookIdHighest[texture] = id
end

num = num + 1
end
end
Expand All @@ -434,7 +445,7 @@ function DataToColor:PopulateSpellBookInfo()
end

function DataToColor:InitSpellBookQueue()
for id, _ in pairs(DataToColor.S.playerSpellBookId) do
for _, id in pairs(DataToColor.S.playerSpellBookIdHighest) do
DataToColor.spellBookQueue:push(id)
end
end
Expand Down Expand Up @@ -877,10 +888,11 @@ function DataToColor:CreateFrames()

-- Timers
if DataToColor.lastLoot == DataToColor.C.Loot.Closed and
DataToColor.globalTime - DataToColor.lastLootResetStart > LOOT_RESET_RATE then
DataToColor.globalTime - DataToColor.lastLootResetStart >= LOOT_RESET_RATE then
DataToColor.lastLoot = DataToColor.C.Loot.Corpse
end
Pixel(int, DataToColor.lastLoot, 97)
local lootItemCount = GetNumLootItems()
Pixel(int, lootItemCount * 10 + DataToColor.lastLoot, 97)

local e = DataToColor.ChatQueue:peek()
if e == nil then
Expand Down
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Title: DataToColor
## Author: FreeHongKongMMO
## Notes: Displays data as colors
## Version: 1.7.63
## Version: 1.7.64
## RequiredDeps:
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
## SavedVariables:
Expand Down
7 changes: 4 additions & 3 deletions Addons/DataToColor/EventHandlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,23 @@ end

function DataToColor:OnUIErrorMessage(_, _, message)
if ignoreErrorListMessages[message] then
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey messasge
UIErrorsFrame:AddMessage(message, 0.7, 0.7, 0.7) -- show as grey message
return
end

local code = errorListMessages[message] or 0
if code > 0 then
DataToColor.uiErrorMessage = code
DataToColor.uiErrorMessageTime = DataToColor.globalTime
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
--UIErrorsFrame:AddMessage(code .. " " .. message, 0, 1, 0) -- show as green message
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green message
return
else
for i, v in pairs(specialErrorS) do
if string.find(message, i) then
DataToColor.uiErrorMessage = v
DataToColor.uiErrorMessageTime = DataToColor.globalTime
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green messasge
UIErrorsFrame:AddMessage(message, 0, 1, 0) -- show as green message
return
end
end
Expand Down
41 changes: 32 additions & 9 deletions Addons/DataToColor/Query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ local UnitAttackSpeed = UnitAttackSpeed
local UnitRangedDamage = UnitRangedDamage

local GameMenuFrame = GameMenuFrame
local LootFrame = LootFrame
local ChatFrame1EditBox = ChatFrame1EditBox

local HasPetUI = HasPetUI

Expand Down Expand Up @@ -124,11 +126,11 @@ function DataToColor:Bits1()
(UnitIsVisible(DataToColor.C.unitPet) and not UnitIsDead(DataToColor.C.unitPet) and 2 or 0) ^ 6 +
(mainHandEnchant and 2 or 0) ^ 7 +
(offHandEnchant and 2 or 0) ^ 8 +
DataToColor:GetInventoryBroken() ^ 9 +
(DataToColor:GetInventoryBroken() ^ 9) +
(UnitOnTaxi(DataToColor.C.unitPlayer) and 2 or 0) ^ 10 +
(IsSwimming() and 2 or 0) ^ 11 +
(GetPetHappiness() == 3 and 2 or 0) ^ 12 +
(GetInventoryItemCount(DataToColor.C.unitPlayer, ammoSlot) > 0 and 2 or 0) ^ 13 +
(DataToColor:PetHappy() and 2 or 0) ^ 12 +
(DataToColor:HasAmmo() and 2 or 0) ^ 13 +
(UnitAffectingCombat(DataToColor.C.unitPlayer) and 2 or 0) ^ 14 +
(DataToColor:IsUnitsTargetIsPlayerOrPet(DataToColor.C.unitTarget, DataToColor.C.unitTargetTarget) and 2 or 0) ^ 15 +
(IsAutoRepeatSpell(DataToColor.C.Spell.AutoShotId) and 2 or 0) ^ 16 +
Expand Down Expand Up @@ -163,11 +165,11 @@ function DataToColor:Bits2()
(DataToColor:IsUnitsTargetIsPlayerOrPet(DataToColor.C.unitmouseover, DataToColor.C.unitmouseovertarget) and 2 or 0) ^ 16 +
(UnitPlayerControlled(DataToColor.C.unitmouseover) and 2 or 0) ^ 17 +
(UnitPlayerControlled(DataToColor.C.unitTarget) and 2 or 0) ^ 18 +
((DataToColor.autoFollow) and 2 or 0) ^ 19 +
((GameMenuFrame:IsShown() and 2 or 0)) ^ 20 +
((IsFlying() and 2 or 0)) ^ 21 +
((DataToColor.moving and 2 or 0)) ^ 22 +
((DataToColor:PetIsDefensive() and 2 or 0)) ^ 23
(DataToColor.autoFollow and 2 or 0) ^ 19 +
(GameMenuFrame:IsShown() and 2 or 0) ^ 20 +
(IsFlying() and 2 or 0) ^ 21 +
(DataToColor.moving and 2 or 0) ^ 22 +
(DataToColor:PetIsDefensive() and 2 or 0) ^ 23
end

function DataToColor:Bits3()
Expand All @@ -180,7 +182,9 @@ function DataToColor:Bits3()
(UnitIsTapDenied(DataToColor.C.unitSoftInteract) and 2 or 0) ^ 4 +
(UnitAffectingCombat(DataToColor.C.unitSoftInteract) and 2 or 0) ^ 5 +
(DataToColor:IsUnitHostile(DataToColor.C.unitPlayer, DataToColor.C.unitSoftInteract) and 2 or 0) ^ 6 +
((DataToColor.channeling and 2 or 0)) ^ 7
(DataToColor.channeling and 2 or 0) ^ 7 +
(LootFrame:IsShown() and 2 or 0) ^ 8 +
(ChatFrame1EditBox:IsVisible() and 2 or 0) ^ 9
)
end

Expand Down Expand Up @@ -602,6 +606,25 @@ function DataToColor:UnitTargetsPartyOrPet(unittarget)
return false
end

function DataToColor:HasAmmo()
-- After Cataclysm, ammo slot was removed
if DataToColor:IsClassicPreCata() == false then
return true
end

local count = GetInventoryItemCount(DataToColor.C.unitPlayer, ammoSlot)
return count > 0
end

function DataToColor:PetHappy()
-- After Cataclysm, pet always happy :)
if DataToColor:IsClassicPreCata() == false then
return true
end

return GetPetHappiness() == 3
end

-- Returns true if target of our target is us
function DataToColor:IsUnitsTargetIsPlayerOrPet(unit, unittarget)
local x = DataToColor:UnitsTargetAsNumber(unit, unittarget)
Expand Down
1 change: 1 addition & 0 deletions Addons/DataToColor/Storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DataToColor.S.playerAuraMap = {}

DataToColor.S.playerSpellBookName = {}
DataToColor.S.playerSpellBookId = {}
DataToColor.S.playerSpellBookIdHighest = {}
DataToColor.S.playerSpellBookIconToId = {}

function DataToColor:InitStorage()
Expand Down
5 changes: 5 additions & 0 deletions Addons/DataToColor/Versions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ function DataToColor.IsRetail()
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
end

function DataToColor.IsClassicPreCata()
return DataToColor.IsClassic() or DataToColor.IsClassic_BCC() or DataToColor.IsClassic_Wrath()
end


local LibClassicCasterino
if DataToColor.IsClassic() then
LibClassicCasterino = _G.LibStub("LibClassicCasterino")
Expand Down
14 changes: 7 additions & 7 deletions Core/Actionbar/ActionBarCooldownReader.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;

using static Core.ActionBar;
using static System.DateTime;
using static System.Diagnostics.Stopwatch;
using static System.Math;

namespace Core;
Expand All @@ -11,11 +11,11 @@ public sealed class ActionBarCooldownReader : IReader
private readonly struct Data
{
private readonly float durationSec;
private readonly DateTime start;
private readonly long start;

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

public Data(float durationSec, DateTime start)
public Data(float durationSec, long start)
{
this.durationSec = durationSec;
this.start = start;
Expand Down Expand Up @@ -43,13 +43,13 @@ public void Update(IAddonDataProvider reader)
int slotIdx = (value / ACTION_SLOT_MUL) - 1;
float durationSec = value % ACTION_SLOT_MUL / FRACTION_PART;

data[slotIdx] = new(durationSec, UtcNow);
data[slotIdx] = new(durationSec, GetTimestamp());
}

public void Reset()
{
var span = data.AsSpan();
span.Fill(new(0, UtcNow));
span.Fill(new(0, GetTimestamp()));
}

public int Get(KeyAction keyAction)
Expand All @@ -58,6 +58,6 @@ public int Get(KeyAction keyAction)

ref readonly Data d = ref data[index];

return Max((int)(d.End - UtcNow).TotalMilliseconds, 0);
return Max((int)((d.End - GetTimestamp()) / TimeSpan.TicksPerMillisecond), 0);
}
}
16 changes: 11 additions & 5 deletions Core/Addon/AuraTimeReader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;

using static System.Diagnostics.Stopwatch;

namespace Core;

public interface IAuraTimeReader
Expand All @@ -22,10 +25,13 @@ public sealed class AuraTimeReader<T> : IAuraTimeReader, IReader
{
public readonly struct Data
{
private long StartTime { get; }

public int DurationSec { get; }
public DateTime StartTime { get; }

public Data(int duration, DateTime startTime)
public long End => StartTime + (DurationSec * TimeSpan.TicksPerSecond);

public Data(int duration, long startTime)
{
DurationSec = duration;
StartTime = startTime;
Expand All @@ -37,7 +43,7 @@ public Data(int duration, DateTime startTime)
private readonly int cTextureId;
private readonly int cDurationSec;

private readonly Dictionary<int, Data> data = new();
private readonly Dictionary<int, Data> data = [];

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

int durationSec = reader.GetInt(cDurationSec);
data[textureId] = new(durationSec, DateTime.UtcNow);
data[textureId] = new(durationSec, GetTimestamp());
}

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

Expand Down
8 changes: 6 additions & 2 deletions Core/Addon/Loot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public static class Loot_Extensions

public static class Loot
{
public const int LOOTFRAME_AUTOLOOT_DELAY = 300;
public const int LOOTFRAME_AUTOLOOT_DELAY_MS = 300;

public const int LOOT_RESET_UPDATE_COUNT = 5;
public const int LOOTFRAME_OPEN_TIME_MS = 2000;

public const int LOOT_PER_ITEM_TIME_MS = 1000;

public const int RESET_UPDATE_COUNT = 5;
}
3 changes: 1 addition & 2 deletions Core/Addon/PlayerReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Core.AddonComponent;
using Core.Database;
using Core.Database;

using SharedLib;

Expand Down
4 changes: 4 additions & 0 deletions Core/AddonComponent/AddonBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,8 @@ public void Update(IAddonDataProvider reader)
public bool SoftInteract_Hostile() => v3[Mask._6];

public bool Channeling() => v3[Mask._7];

public bool LootFrameShown() => v3[Mask._8];

public bool ChatInputIsVisible() => v3[Mask._9];
}
6 changes: 6 additions & 0 deletions Core/AddonComponent/CombatLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ public sealed class CombatLog : IReader
public HashSet<int> DamageTaken { get; } = [];
public HashSet<int> EvadeMobs { get; } = [];

public HashSet<int> ToPull { get; } = [];

public int DamageTakenCount() => DamageTaken.Count;
public int DamageDoneCount() => DamageDone.Count;

public int ToPullCount() => ToPull.Count;

public RecordInt DamageDoneGuid { get; }
public RecordInt DamageTakenGuid { get; }
public RecordInt DeadGuid { get; }
Expand Down Expand Up @@ -92,6 +96,7 @@ public void Update(IAddonDataProvider reader)
int deadGuid = DeadGuid.Value;
DamageDone.Remove(deadGuid);
DamageTaken.Remove(deadGuid);
ToPull.Remove(deadGuid);

if (deadGuid == PLAYER_DEATH_EVENT)
{
Expand All @@ -108,6 +113,7 @@ public void Update(IAddonDataProvider reader)
// left combat
DamageTaken.Clear();
DamageDone.Clear();
ToPull.Clear();
}

wasInCombat = combat;
Expand Down
2 changes: 1 addition & 1 deletion Core/AddonComponent/GuidType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Core.AddonComponent;
namespace Core;

public enum GuidType
{
Expand Down
Loading