From 5f1e1da895489a9cac5d5a56c1dba67515e6c2ab Mon Sep 17 00:00:00 2001 From: Sumsebrum Date: Sun, 31 Jul 2022 18:17:49 +0200 Subject: [PATCH] fix racial/trinket usage tracking --- EventListener.lua | 27 ++++++++++++++++++++------- Modules/Racial.lua | 2 +- Modules/Trinket.lua | 30 +++++++++++------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/EventListener.lua b/EventListener.lua index 52560f0..a3c43af 100644 --- a/EventListener.lua +++ b/EventListener.lua @@ -157,7 +157,6 @@ function EventListener:COMBAT_LOG_EVENT_UNFILTERED() self:DetectSpec(srcUnit, Gladdy.specSpells[spellName]) end if (eventType == "SPELL_CAST_SUCCESS" or eventType == "SPELL_AURA_APPLIED" or eventType == "SPELL_MISSED") then - local unitRace = Gladdy.buttons[srcUnit].race self:DetectSpec(srcUnit, Gladdy.specSpells[spellName]) -- cooldown tracker if Gladdy.db.cooldown and Cooldowns.cooldownSpellIds[spellName] then @@ -177,10 +176,6 @@ function EventListener:COMBAT_LOG_EVENT_UNFILTERED() end end end - - if Gladdy.db.racialEnabled and Gladdy:Racials()[unitRace].spellName == spellName and Gladdy:Racials()[unitRace][spellID] then - Gladdy:SendMessage("RACIAL_USED", srcUnit) - end end if (eventType == "SPELL_AURA_REMOVED" and (spellID == 16188 or spellID == 17116) and Gladdy.buttons[srcUnit].class) then Cooldowns:CooldownUsed(srcUnit, Gladdy.buttons[srcUnit].class, spellID) @@ -191,6 +186,7 @@ end function EventListener:ARENA_OPPONENT_UPDATE(unit, updateReason) --[[ updateReason: seen, unseen, destroyed, cleared ]] + unit = Gladdy:GetArenaUnit(unit) local button = Gladdy.buttons[unit] local pet = Gladdy.modules["Pets"].frames[unit] if button or pet then @@ -332,12 +328,29 @@ function EventListener:UNIT_SPELLCAST_CHANNEL_START(unit) end end -function EventListener:UNIT_SPELLCAST_SUCCEEDED(unit) +function EventListener:UNIT_SPELLCAST_SUCCEEDED(...) + local unit, castGUID, spellID = ... + unit = Gladdy:GetArenaUnit(unit, true) if Gladdy.buttons[unit] then - local spellName = UnitCastingInfo(unit) + local unitRace = Gladdy.buttons[unit].race + local spellName = GetSpellInfo(spellID) + + -- spec detection if Gladdy.specSpells[spellName] and not Gladdy.buttons[unit].spec then self:DetectSpec(unit, Gladdy.specSpells[spellName]) end + + -- trinket + if spellID == 42292 or spellID == 59752 then + Gladdy:Debug("INFO", "UNIT_SPELLCAST_SUCCEEDED - TRINKET_USED", unit, spellID) + Gladdy:SendMessage("TRINKET_USED", unit) + end + + -- racial + if Gladdy:Racials()[unitRace].spellName == spellName and Gladdy:Racials()[unitRace][spellID] then + Gladdy:Debug("INFO", "UNIT_SPELLCAST_SUCCEEDED - RACIAL_USED", unit, spellID) + Gladdy:SendMessage("RACIAL_USED", unit) + end end end diff --git a/Modules/Racial.lua b/Modules/Racial.lua index 3bba10c..18837e7 100644 --- a/Modules/Racial.lua +++ b/Modules/Racial.lua @@ -203,7 +203,7 @@ end function Racial:RACIAL_USED(unit, expirationTime, spellName) local racial = self.frames[unit] local button = Gladdy.buttons[unit] - if (not racial or not button or not button.race) then + if (not racial or not button or not button.race or not Gladdy.db.racialEnabled) then return end if expirationTime and Gladdy:Racials()[button.race].spellName ~= spellName then diff --git a/Modules/Trinket.lua b/Modules/Trinket.lua index 6276f9b..b8ffa61 100644 --- a/Modules/Trinket.lua +++ b/Modules/Trinket.lua @@ -247,14 +247,13 @@ function Trinket:Test(unit) return end if (unit == "arena1" or unit == "arena2") then - self:Used(unit, GetTime() * 1000, 120000) + Gladdy:SendMessage("TRINKET_USED", unit) end end function Trinket:JOINED_ARENA() self:RegisterEvent("ARENA_COOLDOWNS_UPDATE") self:RegisterEvent("ARENA_CROWD_CONTROL_SPELL_UPDATE") - self:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "arena1", "arena2", "arena3", "arena4", "arena5") self:SetScript("OnEvent", function(self, event, ...) if self[event] then self[event](self, ...) @@ -273,15 +272,11 @@ function Trinket:ARENA_CROWD_CONTROL_SPELL_UPDATE(...) end end -function Trinket:UNIT_SPELLCAST_SUCCEEDED(...) - local unitID, castGUID, spellID = ... - if Gladdy.buttons[unitID] then - if spellID == 42292 or spellID == 59752 then - Gladdy:Debug("INFO", "Trinket:UNIT_SPELLCAST_SUCCEEDED", unitID, spellID) - self:Used(unitID, GetTime() * 1000, - Gladdy.buttons[unitID].trinket.itemID and Gladdy:GetPvpTrinkets()[Gladdy.buttons[unitID].trinket.itemID] - or 120000) - end +function Trinket:TRINKET_USED(unit) + if Gladdy.buttons[unit] then + self:Used(unit, GetTime() * 1000, + Gladdy.buttons[unit].trinket.itemID and Gladdy:GetPvpTrinkets()[Gladdy.buttons[unit].trinket.itemID] + or 120000) end end @@ -291,11 +286,11 @@ function Trinket:RACIAL_USED(unit) -- Wrath only return end if Gladdy.buttons[unit].race == "Scourge" then - if trinket.active and trinket.timeLeft >= 44 then + if trinket.active and trinket.timeLeft >= 45 then -- do nothing else trinket.active = false - self:Used(unit, GetTime() * 1000, 45000, true) + self:Used(unit, GetTime() * 1000, 45000) end elseif Gladdy.buttons[unit].race == "Human" then trinket.active = false @@ -307,8 +302,8 @@ function Trinket:ARENA_COOLDOWNS_UPDATE() for i=1, Gladdy.curBracket do local unitID = "arena" .. i local spellID, itemID, startTime, duration = C_PvP.GetArenaCrowdControlInfo(unitID) - Gladdy:Debug("INFO", "Trinket:ARENA_COOLDOWNS_UPDATE", spellID, itemID, startTime, duration) if (spellID) then + Gladdy:Debug("INFO", "Trinket:ARENA_COOLDOWNS_UPDATE", spellID, itemID, startTime, duration) if not Gladdy.db.trinketColored and Gladdy:GetPvpTrinkets()[itemID] then self.frames[unitID].texture:SetTexture(GetItemIcon(itemID)) end @@ -319,9 +314,9 @@ function Trinket:ARENA_COOLDOWNS_UPDATE() end end -function Trinket:Used(unit, startTime, duration, passive) +function Trinket:Used(unit, startTime, duration) local trinket = self.frames[unit] - if (not trinket) then + if (not trinket or not Gladdy.db.trinketEnabled) then return end if not trinket.active then @@ -331,9 +326,6 @@ function Trinket:Used(unit, startTime, duration, passive) if Gladdy.db.trinketColored then trinket:SetBackdropColor(Gladdy:SetColor(Gladdy.db.trinketColoredCd)) end - if not passive then - Gladdy:SendMessage("TRINKET_USED", unit) - end end end