Skip to content

Commit

Permalink
fix: #2215 charges condition not reactive to changes in GetSpellCount
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Sep 7, 2024
1 parent 0c83604 commit 50c1f59
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## v11.0.7
* Fix: #2217 error in item cooldown conditions
* Fix: #2215 - Spell Charges condition not updating for countable spells without true charges.
* Fix: #2217 - Error in item cooldown conditions

## v11.0.6
* #2190: Added options to Buff/Debuff icons to source stack count from tooltip numbers.
Expand Down
43 changes: 41 additions & 2 deletions Components/Core/Common/Cooldowns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ local L = TMW.L
local print = TMW.print
local strlowerCache = TMW.strlowerCache

local select, wipe, setmetatable
= select, wipe, setmetatable
local select, wipe, next, setmetatable
= select, wipe, next, setmetatable

TMW.COMMON.Cooldowns = CreateFrame("Frame")
local Cooldowns = TMW.COMMON.Cooldowns

local emptyCooldown = {}
local CachedCooldowns = {}
local CachedCharges = {}
local CachedCounts = {}

if C_Spell.GetSpellCooldown then
local C_Spell_GetSpellCooldown = C_Spell.GetSpellCooldown
Expand Down Expand Up @@ -105,6 +106,35 @@ else
end




if C_Spell.GetSpellCastCount then
local C_Spell_GetSpellCastCount = C_Spell.GetSpellCastCount

function Cooldowns.GetSpellCastCount(spell)
local cached = CachedCounts[spell]
if cached then return cached ~= false and cached or nil end

cached = C_Spell_GetSpellCastCount(spell) or false
CachedCounts[spell] = cached
return cached
end
else
local GetSpellCount = _G.GetSpellCount

function Cooldowns.GetSpellCastCount(spell)
local cached = CachedCounts[spell]
if cached then return cached ~= false and cached or nil end

local count = GetSpellCount(spell)
cached = count or false
CachedCounts[spell] = cached
return cached
end
end



---------------------------------
-- Global Cooldown Data
---------------------------------
Expand Down Expand Up @@ -144,6 +174,13 @@ Cooldowns:SetScript("OnEvent", function(self, event, action, inRange, checksRang
if event == "SPELL_UPDATE_COOLDOWN" then
wipe(CachedCooldowns)
GCD = nil

if next(CachedCounts) then
-- There's not a great event for GetSpellCastCount. Cooldown is the closest we can get.
wipe(CachedCounts)
TMW:Fire("TMW_SPELL_UPDATE_COUNT")
end

TMW:Fire("TMW_SPELL_UPDATE_COOLDOWN")

elseif event == "SPELL_UPDATE_CHARGES" then
Expand All @@ -154,7 +191,9 @@ Cooldowns:SetScript("OnEvent", function(self, event, action, inRange, checksRang
-- Spells may have been learned/unlearned (e.g. pvp talents activating/deactivating)
wipe(CachedCooldowns)
wipe(CachedCharges)
wipe(CachedCounts)
TMW:Fire("TMW_SPELL_UPDATE_COOLDOWN")
TMW:Fire("TMW_SPELL_UPDATE_CHARGES")
TMW:Fire("TMW_SPELL_UPDATE_COUNT")
end
end)
32 changes: 19 additions & 13 deletions Components/Core/Conditions/Categories/Spells.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ local bit_band = bit.band
local COMBATLOG_OBJECT_TYPE_PLAYER = COMBATLOG_OBJECT_TYPE_PLAYER

local GetSpellCooldown = TMW.COMMON.Cooldowns.GetSpellCooldown
local GetSpellCharges = TMW.COMMON.Cooldowns.GetSpellCharges
local GetSpellCastCount = TMW.COMMON.Cooldowns.GetSpellCastCount
Env.GetSpellCooldown = GetSpellCooldown
Env.GetSpellCharges = GetSpellCharges
Env.GetSpellCastCount = GetSpellCastCount

local GetSpellName = TMW.GetSpellName
local GetSpellInfo = TMW.GetSpellInfo

Expand All @@ -56,11 +61,11 @@ function Env.CooldownDuration(spell, gcdAsUnusable)
return 0
end

local GetSpellCharges = TMW.GetSpellCharges
function Env.RechargeDuration(spell)
local charges, maxCharges, start, duration = GetSpellCharges(spell)
if charges and charges ~= maxCharges then
return (duration == 0 and 0) or (duration - (TMW.time - start))
local charges = GetSpellCharges(spell)
if charges and charges.currentCharges ~= charges.maxCharges then
local duration = charges.cooldownDuration
return (duration == 0 and 0) or (duration - (TMW.time - charges.cooldownStartTime))
end
return 0
end
Expand Down Expand Up @@ -184,13 +189,17 @@ if TMW.isRetail then
icon = "Interface\\Icons\\ability_monk_roll",
tcoords = CNDT.COMMON.standardtcoords,
Env = {
GetSpellCharges = TMW.GetSpellCharges,
GetSpellCount = C_Spell.GetSpellCastCount or _G.GetSpellCount
GetSpellChargesOrCount = function(spell)
local charges = GetSpellCharges(spell)
if charges then return charges.currentCharges end
return GetSpellCastCount(spell)
end,
},
funcstr = [[(GetSpellCharges(c.OwnSpells.First) or GetSpellCount(c.OwnSpells.First)) c.Operator c.Level]],
funcstr = [[(GetSpellChargesOrCount(c.OwnSpells.First)) c.Operator c.Level]],
events = function(ConditionObject, c)
return
ConditionObject:GenerateNormalEventString("TMW_SPELL_UPDATE_CHARGES")
ConditionObject:GenerateNormalEventString("TMW_SPELL_UPDATE_CHARGES"),
ConditionObject:GenerateNormalEventString("TMW_SPELL_UPDATE_COUNT")
end,
})
ConditionCategory:RegisterCondition(2.6, "SPELLCHARGETIME", {
Expand All @@ -213,17 +222,14 @@ if TMW.isRetail then
end),
icon = "Interface\\Icons\\ability_warlock_handofguldan",
tcoords = CNDT.COMMON.standardtcoords,
Env = {
GetSpellCharges = TMW.GetSpellCharges,
},
funcstr = [[RechargeDuration(c.OwnSpells.First) c.Operator c.Level]],
events = function(ConditionObject, c)
return
ConditionObject:GenerateNormalEventString("TMW_SPELL_UPDATE_CHARGES")
end,
anticipate = [[
local _, _, start, duration = GetSpellCharges(c.OwnSpells.First)
local VALUE = duration and start + (duration - c.Level) or huge
local data = GetSpellCharges(c.OwnSpells.First)
local VALUE = data and data.cooldownDuration and data.cooldownStartTime + (data.cooldownDuration - c.Level) or huge
]],
})
end
Expand Down
12 changes: 0 additions & 12 deletions Components/Core/Utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1360,18 +1360,6 @@ function TMW.GetRuneCooldownDuration()
return floor(duration * 1e3 + 0.5) / 1e3
end

if C_Spell.GetSpellCharges then
local GetSpellCharges = C_Spell.GetSpellCharges
TMW.GetSpellCharges = function(spell)
local data = GetSpellCharges(spell)
if not data then return end

return data.currentCharges, data.maxCharges, data.cooldownStartTime, data.cooldownDuration
end
else
TMW.GetSpellCharges = GetSpellCharges
end

if C_SpellBook and C_SpellBook.GetSpellBookItemType then
TMW.GetSpellBookItemInfo = function(index, book)
if book == "pet" then
Expand Down
4 changes: 2 additions & 2 deletions Components/IconTypes/IconType_cooldown/cooldown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local spellTextureCache = TMW.spellTextureCache
local IsUsableSpell = TMW.COMMON.SpellUsable.IsUsableSpell
local GetSpellCharges = TMW.COMMON.Cooldowns.GetSpellCharges
local GetSpellCooldown = TMW.COMMON.Cooldowns.GetSpellCooldown
local GetSpellCount = C_Spell.GetSpellCastCount or _G.GetSpellCount
local GetSpellCastCount = TMW.COMMON.Cooldowns.GetSpellCastCount
local GetRuneCooldownDuration = TMW.GetRuneCooldownDuration

local _, pclass = UnitClass("Player")
Expand Down Expand Up @@ -208,7 +208,7 @@ local function SpellCooldown_OnUpdate(icon, time)

local cooldown = GetSpellCooldown(iName)
local charges = GetSpellCharges(iName)
local stack = charges and charges.currentCharges or GetSpellCount(iName)
local stack = charges and charges.currentCharges or GetSpellCastCount(iName)


if cooldown then
Expand Down
4 changes: 2 additions & 2 deletions Components/IconTypes/IconType_reactive/reactive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ local GetSpellName = TMW.GetSpellName
local GetSpellTexture = TMW.GetSpellTexture
local GetSpellCharges = TMW.COMMON.Cooldowns.GetSpellCharges
local GetSpellCooldown = TMW.COMMON.Cooldowns.GetSpellCooldown
local GetSpellCastCount = TMW.COMMON.Cooldowns.GetSpellCastCount
local IsUsableSpell = TMW.COMMON.SpellUsable.IsUsableSpell
local GetSpellCount = C_Spell.GetSpellCastCount or _G.GetSpellCount

local spellTextureCache = TMW.spellTextureCache
local strlowerCache = TMW.strlowerCache
Expand Down Expand Up @@ -190,7 +190,7 @@ local function Reactive_OnUpdate(icon, time)

cooldown = GetSpellCooldown(iName)
charges = GetSpellCharges(iName) or emptyTable
stack = charges and charges.currentCharges or GetSpellCount(iName)
stack = charges and charges.currentCharges or GetSpellCastCount(iName)

if cooldown then
local duration = cooldown.duration
Expand Down
3 changes: 2 additions & 1 deletion Options/CHANGELOG.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ TMW.CHANGELOG_LASTVER="10.0.0"

TMW.CHANGELOG = [==[
## v11.0.7
* Fix: #2217 error in item cooldown conditions
* Fix: #2215 - Spell Charges condition not updating for countable spells without true charges.
* Fix: #2217 - Error in item cooldown conditions
## v11.0.6
* #2190: Added options to Buff/Debuff icons to source stack count from tooltip numbers.
Expand Down

0 comments on commit 50c1f59

Please sign in to comment.