From 490641736b9e4e14ac9b8c06be800acfa0d55269 Mon Sep 17 00:00:00 2001 From: pepopo978 Date: Wed, 6 Nov 2024 21:23:55 -0800 Subject: [PATCH] read curse durations from spellbook for warlocks --- Localization.lua | 2 ++ core.lua | 3 ++ curses.lua | 72 ++++++++++++++++++++++++++++++++++++++++------ spells/warlock.lua | 34 +++++++++++----------- 4 files changed, 86 insertions(+), 25 deletions(-) diff --git a/Localization.lua b/Localization.lua index 98c81a8..73a9a5b 100644 --- a/Localization.lua +++ b/Localization.lua @@ -22,6 +22,7 @@ L:RegisterTranslations("enUS", function() ["Same as HIGHEST_HP_RAID_MARK but with RAID_MARK_SQUARE mark prio."] = true, ["Same as HIGHEST_HP_RAID_MARK but with INVERSE_RAID_MARK mark prio."] = true, ["|cffffcc00Cursive:|cffffaaaa Couldn't find a target to curse."] = true, + ["curse_duration_format"] = ".*over ([%d.]+) sec.", -- curses ["(.+) fades from (.+)"] = true, @@ -164,6 +165,7 @@ L:RegisterTranslations("zhCN", function() ["Same as HIGHEST_HP_RAID_MARK but with RAID_MARK_SQUARE mark prio."] = "与HIGHEST_HP_RAID_MARK相同,但是RAID_MARK_SQUARE标记优先.", ["Same as HIGHEST_HP_RAID_MARK but with INVERSE_RAID_MARK mark prio."] = "与HIGHEST_HP_RAID_MARK相同,但是INVERSE_RAID_MARK标记优先.", ["|cffffcc00Cursive:|cffffaaaa Couldn't find a target to curse."] = "|cffffcc00Cursive:|cffffaaaa 找不到要诅咒的目标.", + ["curse_duration_format"] = ".*持续([%d.]+)秒.", -- no idea if this is right -- curses ["(.+) fades from (.+)"] = "(.+)效果从(.+)身上消失", diff --git a/core.lua b/core.lua index 3360e49..07d9918 100644 --- a/core.lua +++ b/core.lua @@ -10,6 +10,9 @@ AURAADDEDSELFHARMFUL = "You are afflicted by %s (1)." AURAADDEDSELFHELPFUL = "You gain %s (1)." Cursive.core = CreateFrame("Frame", "Cursive", UIParent) + +Cursive.core.tooltipScan = CreateFrame("GameTooltip", "CursiveTooltipScan", UIParent, "GameTooltipTemplate") + Cursive.core.guids = {} Cursive.core.add = function(unit) diff --git a/curses.lua b/curses.lua index 6a65d3e..9da6cc7 100644 --- a/curses.lua +++ b/curses.lua @@ -2,9 +2,13 @@ if not Cursive.superwow then return end local L = AceLibrary("AceLocale-2.2"):new("Cursive") + +local _, playerClassName = UnitClass("player") + local curses = { trackedCurseIds = {}, trackedCurseNamesToTextures = {}, + trackedCurseNameRanksToSpellSlots = {}, guids = {}, resistSoundGuids = {}, expiringSoundGuids = {}, @@ -20,22 +24,42 @@ local resist_test = L["Your (.+) was resisted by (.+)"] local lastGuid = nil function curses:LoadCurses() + -- reset dicts + curses.trackedCurseIds = {} + curses.trackedCurseNamesToTextures = {} + curses.trackedCurseNameRanksToSpellSlots = {} + -- curses to track - local _, className = UnitClass("player") - if className == "WARLOCK" then + if playerClassName == "WARLOCK" then curses.trackedCurseIds = getWarlockSpells() - elseif className == "PRIEST" then + elseif playerClassName == "PRIEST" then curses.trackedCurseIds = getPriestSpells() - elseif className == "MAGE" then + elseif playerClassName == "MAGE" then curses.trackedCurseIds = getMageSpells() - elseif className == "DRUID" then + elseif playerClassName == "DRUID" then curses.trackedCurseIds = getDruidSpells() - elseif className == "HUNTER" then + elseif playerClassName == "HUNTER" then curses.trackedCurseIds = getHunterSpells() - elseif className == "ROGUE" then + elseif playerClassName == "ROGUE" then curses.trackedCurseIds = getRogueSpells() end + -- go through spell slots and + local i = 1 + while true do + local spellname, spellrank = GetSpellName(i, BOOKTYPE_SPELL) + if not spellname then + break + end + + if spellrank == "" then + spellrank = "Rank 1" + end + + curses.trackedCurseNameRanksToSpellSlots[spellname .. spellrank] = i + i = i + 1 + end + for id, data in pairs(curses.trackedCurseIds) do -- get the texture local name, rank, texture = SpellInfo(id) @@ -46,6 +70,33 @@ function curses:LoadCurses() end end +function curses:GetCurseDuration(curseSpellID) + if playerClassName == "WARLOCK" and curses.trackedCurseIds[curseSpellID].rapid_deterioration then + -- scan spellbook for duration in case they have haste talent + local nameRank = curses.trackedCurseIds[curseSpellID].name .. "Rank " .. curses.trackedCurseIds[curseSpellID].rank + local spellSlot = curses.trackedCurseNameRanksToSpellSlots[nameRank] + + if spellSlot then + Cursive.core.tooltipScan:SetOwner(Cursive.core.tooltipScan, "ANCHOR_NONE") + Cursive.core.tooltipScan:ClearLines() + Cursive.core.tooltipScan:SetSpell(spellSlot, BOOKTYPE_SPELL) + local numLines = Cursive.core.tooltipScan:NumLines() + if numLines and numLines > 0 then + -- get the last line + local text = getglobal("CursiveTooltipScan" .. "TextLeft" .. numLines):GetText() + if text then + local _, _, duration = string.find(text, L["curse_duration_format"]) + if duration then + return tonumber(duration) + end + end + end + end + end + + return curses.trackedCurseIds[curseSpellID].duration +end + function curses:ScanGuidForCurse(guid, curseSpellID) for i = 1, 16 do local _, _, _, spellID = UnitDebuff(guid, i) @@ -71,6 +122,11 @@ function curses:ScanGuidForCurse(guid, curseSpellID) return nil end +Cursive:RegisterEvent("LEARNED_SPELL_IN_TAB", function() + -- reload curses in case spell slots changed + curses:LoadCurses() +end) + Cursive:RegisterEvent("UNIT_CASTEVENT", function(casterGuid, targetGuid, event, spellID, castDuration) -- immolate will fire both start and cast if event == "CAST" then @@ -196,7 +252,7 @@ end function curses:ApplyCurse(spellID, targetGuid, startTime) local name = curses.trackedCurseIds[spellID].name local rank = curses.trackedCurseIds[spellID].rank - local duration = curses.trackedCurseIds[spellID].duration + local duration = curses:GetCurseDuration(spellID) if not curses.guids[targetGuid] then curses.guids[targetGuid] = {} diff --git a/spells/warlock.lua b/spells/warlock.lua index b091f0a..2f0fce0 100644 --- a/spells/warlock.lua +++ b/spells/warlock.lua @@ -1,20 +1,20 @@ local L = AceLibrary("AceLocale-2.2"):new("Cursive") function getWarlockSpells() return { - [172] = { name = L["Corruption"], rank = 1, duration = 12 }, - [6222] = { name = L["Corruption"], rank = 2, duration = 15 }, - [6223] = { name = L["Corruption"], rank = 3, duration = 18 }, - [7648] = { name = L["Corruption"], rank = 4, duration = 18 }, - [11671] = { name = L["Corruption"], rank = 5, duration = 18 }, - [11672] = { name = L["Corruption"], rank = 6, duration = 18 }, - [25311] = { name = L["Corruption"], rank = 7, duration = 18 }, + [172] = { name = L["Corruption"], rank = 1, duration = 12, rapid_deterioration = true }, + [6222] = { name = L["Corruption"], rank = 2, duration = 15, rapid_deterioration = true }, + [6223] = { name = L["Corruption"], rank = 3, duration = 18, rapid_deterioration = true }, + [7648] = { name = L["Corruption"], rank = 4, duration = 18, rapid_deterioration = true }, + [11671] = { name = L["Corruption"], rank = 5, duration = 18, rapid_deterioration = true }, + [11672] = { name = L["Corruption"], rank = 6, duration = 18, rapid_deterioration = true }, + [25311] = { name = L["Corruption"], rank = 7, duration = 18, rapid_deterioration = true }, - [980] = { name = L["Curse of Agony"], rank = 1, duration = 24 }, - [1014] = { name = L["Curse of Agony"], rank = 2, duration = 24 }, - [6217] = { name = L["Curse of Agony"], rank = 3, duration = 24 }, - [11711] = { name = L["Curse of Agony"], rank = 4, duration = 24 }, - [11712] = { name = L["Curse of Agony"], rank = 5, duration = 24 }, - [11713] = { name = L["Curse of Agony"], rank = 6, duration = 24 }, + [980] = { name = L["Curse of Agony"], rank = 1, duration = 24, rapid_deterioration = true }, + [1014] = { name = L["Curse of Agony"], rank = 2, duration = 24, rapid_deterioration = true }, + [6217] = { name = L["Curse of Agony"], rank = 3, duration = 24, rapid_deterioration = true }, + [11711] = { name = L["Curse of Agony"], rank = 4, duration = 24, rapid_deterioration = true }, + [11712] = { name = L["Curse of Agony"], rank = 5, duration = 24, rapid_deterioration = true }, + [11713] = { name = L["Curse of Agony"], rank = 6, duration = 24, rapid_deterioration = true }, [603] = { name = L["Curse of Doom"], rank = 1, duration = 60 }, @@ -58,10 +58,10 @@ function getWarlockSpells() [710] = { name = L["Banish"], rank = 1, duration = 20 }, [18647] = { name = L["Banish"], rank = 2, duration = 30 }, - [18265] = { name = L["Siphon Life"], rank = 1, duration = 30 }, - [18879] = { name = L["Siphon Life"], rank = 2, duration = 30 }, - [18880] = { name = L["Siphon Life"], rank = 3, duration = 30 }, - [18881] = { name = L["Siphon Life"], rank = 4, duration = 30 }, + [18265] = { name = L["Siphon Life"], rank = 1, duration = 30, rapid_deterioration = true }, + [18879] = { name = L["Siphon Life"], rank = 2, duration = 30, rapid_deterioration = true }, + [18880] = { name = L["Siphon Life"], rank = 3, duration = 30, rapid_deterioration = true }, + [18881] = { name = L["Siphon Life"], rank = 4, duration = 30, rapid_deterioration = true }, [5782] = { name = L["Fear"], rank = 1, duration = 10 }, [6213] = { name = L["Fear"], rank = 2, duration = 15 },