Skip to content

Commit

Permalink
Merge pull request #193 from JerichoR/RaidDebuffs
Browse files Browse the repository at this point in the history
RaidDebuffs #192
  • Loading branch information
tukz authored Sep 17, 2024
2 parents 9da0f73 + 26a8631 commit 7c21f56
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions Tukui/Libs/oUF_RaidDebuffs/oUF_RaidDebuffs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ local canDispel = {
}
}

--[[ Event handler for PLAYER_LOGIN.
* self - oUF UnitFrame
* event - PLAYER_LOGIN
]]
local function ResetDispelList(self, event)
if event == "PLAYER_LOGIN" then
dispelList["Magic"] = false
dispelList["Poison"] = false
dispelList["Disease"] = false
dispelList["Curse"] = false
end
end

--[[ Event handler for SPELLS_CHANGED.
* self - oUF UnitFrame
Expand Down Expand Up @@ -222,7 +236,8 @@ end
]]
local function ShowElement(self, unit, auraInstanceID)
local element = self.RaidDebuffs
local AuraData = element.debuffCache[auraInstanceID].AuraData
local debuffCache = element.debuffCache
local AuraData = debuffCache[auraInstanceID].AuraData
local count = AuraData.applications
local duration = AuraData.duration
local expirationTime = AuraData.expirationTime
Expand All @@ -237,9 +252,16 @@ local function ShowElement(self, unit, auraInstanceID)
element.cd:SetCooldown(start, duration)

if element.ticker then element.ticker:Cancel() end
element.ticker = NewTicker(.1, function()
element.ticker = NewTicker(.1, function(ticker)
local remaining = expirationTime - GetTime()
element.timer:SetFormattedText(timeFormat(remaining), remaining)
if remaining > 0 then
element.timer:SetFormattedText(timeFormat(remaining), remaining)
else
-- aura expired but we got no event for it
ticker:Cancel()
debuffCache[auraInstanceID] = nil
element.SelectPrioDebuff(self, unit)
end
end)
end

Expand Down Expand Up @@ -299,7 +321,7 @@ end
* AuraData - (optional) UNIT_AURA event payload
]]
local function FilterAura(self, unit, AuraData)
if AuraData then
if AuraData and AuraData.isHarmful then
local debuffCache = self.RaidDebuffs.debuffCache
local dispelName = AuraData.dispelName

Expand All @@ -313,12 +335,14 @@ local function FilterAura(self, unit, AuraData)
end
end

--[[ Aura scan when isFullUpdate.
--[[ Reset cache and full scan when isFullUpdate.
* self - oUF UnitFrame
* unit - Tracked unit
]]
local function FullUpdate(self, unit)
table.wipe(self.element.debuffCache)

if ForEachAura then
-- Mainline iteration-style.
ForEachAura(unit, "HARMFUL", nil,
Expand Down Expand Up @@ -349,9 +373,9 @@ end
]]
local function Update(self, event, unit, updateInfo)
-- Exit when unit doesn't match or no updateInfo provided or target can't be assisted
if event ~= "UNIT_AURA" or self.unit ~= unit or not updateInfo or not UnitCanAssist("player", unit) then return end
if event ~= "UNIT_AURA" or self.unit ~= unit or not UnitCanAssist("player", unit) then return end

if updateInfo.isFullUpdate then
if not updateInfo or updateInfo.isFullUpdate then
FullUpdate(self, unit)
return
end
Expand Down Expand Up @@ -393,6 +417,7 @@ local function Enable(self)
.AuraData - See UNIT_AURA event payload
}]]
element.debuffCache = {}
element.SelectPrioDebuff = SelectPrioDebuff

-- Create missing Sub-Widgets
if not element.icon then
Expand Down Expand Up @@ -427,6 +452,7 @@ local function Enable(self)
end

-- Update the dispelList at login and whenever spells change (talent or spec change)
self:RegisterEvent("PLAYER_LOGIN", ResetDispelList, true)
self:RegisterEvent("SPELLS_CHANGED", UpdateDispelList, true)
self:RegisterEvent("UNIT_AURA", Update)

Expand All @@ -441,6 +467,7 @@ local function Disable(self)

if element then
element.debuffCache = nil
self:UnregisterEvent("PLAYER_LOGIN", ResetDispelList, true)
self:UnregisterEvent("SPELLS_CHANGED", UpdateDispelList, true)
self:UnregisterEvent("UNIT_AURA", Update)
end
Expand Down

0 comments on commit 7c21f56

Please sign in to comment.