From efb73988ab5ed1d721f6ad3e1f1cc23338029112 Mon Sep 17 00:00:00 2001 From: pepopo978 Date: Wed, 5 Jun 2024 22:13:15 -0700 Subject: [PATCH] add handling for spells that get dispelled --- curses.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++- ui.lua | 10 +++++++--- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/curses.lua b/curses.lua index 4480131..54f32e4 100644 --- a/curses.lua +++ b/curses.lua @@ -14,7 +14,7 @@ local curses = { -- combat events for curses local afflict_test = "^(.+) is afflicted by (.+) %((%d+)%)" -- for stacks 2-5 will be "Fire Vulnerability (2)". local gains_test = "^(.+) gains (.+) %((%d+)%)" -- for stacks 2-5 will be "Fire Vulnerability (2)". -local fades_test = "(.+) fades from (.+)." +local fades_test = "(.+) fades from (.+)" local resist_test = "Your (.+) was resisted by (.+)" local lastGuid = nil @@ -46,6 +46,31 @@ function curses:LoadCurses() end end +function curses:ScanGuidForCurse(guid, curseSpellID) + for i = 1, 16 do + local _, _, _, spellID = UnitDebuff(guid, i) + if spellID then + if spellID == curseSpellID then + return true + end + else + break + end + end + for i = 1, 32 do + local _, _, spellID = UnitBuff(guid, i) + if spellID then + if spellID == curseSpellID then + return true + end + else + break + end + end + + return nil +end + Cursive:RegisterEvent("UNIT_CASTEVENT", function(casterGuid, targetGuid, event, spellID, castDuration) -- immolate will fire both start and cast if event == "CAST" then @@ -77,6 +102,28 @@ Cursive:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE", end ) -- resists +Cursive:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_OTHER", function(message) + -- check if spell that faded is relevant + local _, _, spell, target = string.find(message, fades_test) + if spell and target then + if curses.trackedCurseNamesToTextures[spell] then + -- loop through targets with active curses + for guid, data in pairs(curses.guids) do + for curseName, curseData in pairs(data) do + if curseName == spell then + -- see if target still has that curse + if not curses:ScanGuidForCurse(guid, curseData.spellID) then + -- remove curse + curses:RemoveCurse(guid, curseName) + end + end + end + end + end + end +end +) + function curses:TimeRemaining(curseData) return math.ceil(curseData.duration - (GetTime() - curseData.start)) end @@ -150,6 +197,15 @@ function curses:ApplyCurse(spellID, targetGuid, startTime) } end +function curses:RemoveCurse(guid, curseName) + if curses.guids[guid] and curses.guids[guid][curseName] then + curses.guids[guid][curseName] = nil + end + if curses.expiringSoundGuids[guid] and curses.expiringSoundGuids[guid][curseName] then + curses.expiringSoundGuids[guid][curseName] = nil + end +end + function curses:RemoveGuid(guid) curses.guids[guid] = nil curses.resistSoundGuids[guid] = nil diff --git a/ui.lua b/ui.lua index 6a1838b..c305f20 100644 --- a/ui.lua +++ b/ui.lua @@ -312,6 +312,13 @@ local function DisplayGuid(guid, row, col) -- update curses local curseNumber = 1 + -- make sure old curses are hidden + for i = 1, Cursive.db.profile.maxcurses do + local curse = barFrame["curse" .. i] + curse:Hide() + curse.timer:Hide() + end + local guidCurses = Cursive.curses.guids[guid] if guidCurses then for curseName, curseData in pairs(guidCurses) do @@ -334,9 +341,6 @@ local function DisplayGuid(guid, row, col) elseif Cursive.curses:HasRequestedExpiringSound(curseName, guid) then Cursive.curses:EnableExpiringSound(curseName, guid) end - else - curse.timer:Hide() - curse:Hide() end curseNumber = curseNumber + 1 end