From 2413d15d395a669d6c19ea3b05a98c15cd732641 Mon Sep 17 00:00:00 2001 From: 4n0n <4n0n@tinkr.site> Date: Sun, 29 Jan 2023 17:42:47 -0600 Subject: [PATCH] Enable classic aura support --- src/Aura/Aura.lua | 9 ++++- src/AuraTable/AuraTable.lua | 75 ++++++++++++++++++++++++++++++++++--- src/List/List.lua | 20 +++++++++- 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/src/Aura/Aura.lua b/src/Aura/Aura.lua index 7734694..3a276dc 100644 --- a/src/Aura/Aura.lua +++ b/src/Aura/Aura.lua @@ -60,7 +60,10 @@ function Aura:New(unit, index, type) type = nil, } - Bastion.SpellBook:GetSpell(self.aura.spellId) + + if self.aura.spellId then + Bastion.SpellBook:GetSpell(self.aura.spellId) + end return self end @@ -89,7 +92,9 @@ function Aura:New(unit, index, type) index = index, type = type, } - Bastion.SpellBook:GetSpell(self.aura.spellId) + if self.aura.spellId then + Bastion.SpellBook:GetSpell(self.aura.spellId) + end return self end diff --git a/src/AuraTable/AuraTable.lua b/src/AuraTable/AuraTable.lua index 577208b..b62f95c 100644 --- a/src/AuraTable/AuraTable.lua +++ b/src/AuraTable/AuraTable.lua @@ -18,16 +18,21 @@ function AuraTable:New(unit) local self = setmetatable({}, AuraTable) self.unit = unit - self.auras = {} + self.auras = {} self.playerAuras = {} + self.guid = unit:GetGUID() self.instanceIDLookup = {} return self end -function AuraTable:OnUpdate(auras) +function AuraTable:OnUpdate(a) + if not a then + self:Update() + return + end local isFullUpdate = auras.isFullUpdate if isFullUpdate then @@ -110,6 +115,33 @@ end -- Get a units buffs function AuraTable:GetUnitBuffs() + if Tinkr.classic then + for i = 1, 40 do + local aura = Bastion.Aura:New(self.unit, i, 'HELPFUL') + + if not aura:IsValid() then + break + end + + local spellId = aura:GetSpell():GetID() + + if Bastion.UnitManager['player']:IsUnit(aura:GetSource()) then + if not self.playerAuras[spellId] then + self.playerAuras[spellId] = {} + end + + table.insert(self.playerAuras[spellId], aura) + else + if not self.auras[spellId] then + self.auras[spellId] = {} + end + + table.insert(self.auras[spellId], aura) + end + end + return + end + AuraUtil_ForEachAura(self.unit.unit, 'HELPFUL', nil, function(a) local aura = Bastion.Aura:CreateFromUnitAuraInfo(a) @@ -121,6 +153,33 @@ end -- Get a units debuffs function AuraTable:GetUnitDebuffs() + if Tinkr.classic then + for i = 1, 40 do + local aura = Bastion.Aura:New(self.unit, i, 'HARMFUL') + + if not aura:IsValid() then + break + end + + local spellId = aura:GetSpell():GetID() + + if Bastion.UnitManager['player']:IsUnit(aura:GetSource()) then + if not self.playerAuras[spellId] then + self.playerAuras[spellId] = {} + end + + table.insert(self.playerAuras[spellId], aura) + else + if not self.auras[spellId] then + self.auras[spellId] = {} + end + + table.insert(self.auras[spellId], aura) + end + end + return + end + AuraUtil_ForEachAura(self.unit.unit, 'HARMFUL', nil, function(a) local aura = Bastion.Aura:CreateFromUnitAuraInfo(a) @@ -207,11 +266,14 @@ function AuraTable:Find(spell) end for k, a in pairs(aurasub) do + print(a) if a ~= nil then if a:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA return a else - self:RemoveInstanceID(a:GetAuraInstanceID()) + if not Tinkr.classic then + self:RemoveInstanceID(a:GetAuraInstanceID()) + end end end end @@ -221,7 +283,8 @@ end ---@return Aura function AuraTable:FindMy(spell) - local aurasub = self.playerAuras[spell:GetID()] + local auras = self:GetMyUnitAuras() + local aurasub = auras[spell:GetID()] if not aurasub then return Bastion.Aura:New() @@ -232,7 +295,9 @@ function AuraTable:FindMy(spell) if a:IsUp() then -- Handle expired and non refreshed dropoffs not coming in UNIT_AURA return a else - self:RemoveInstanceID(a:GetAuraInstanceID()) + if not Tinkr.classic then + self:RemoveInstanceID(a:GetAuraInstanceID()) + end end end end diff --git a/src/List/List.lua b/src/List/List.lua index 95c4f47..f26a86b 100644 --- a/src/List/List.lua +++ b/src/List/List.lua @@ -1,7 +1,25 @@ local Tinkr, Bastion = ... ---@class List -local List = {} +local List = { + -- Add overload + ---@param self List + ---@param value any + ---@return List + __add = function(self, value) + self:push(value) + return self + end, + + -- Subtract overload + ---@param self List + ---@param value any + ---@return List + __sub = function(self, value) + self:remove(value) + return self + end, +} List.__index = List function List:New(from)