libdebuff: add experimental self cast tracking

This commit is contained in:
shagu
2025-05-25 13:29:22 +02:00
parent 967448002c
commit 3d4e67e7f4
+13 -7
View File
@@ -83,7 +83,7 @@ function libdebuff:UpdateUnits()
pfUI.uf:RefreshUnit(pfUI.uf.target, "aura") pfUI.uf:RefreshUnit(pfUI.uf.target, "aura")
end end
function libdebuff:AddPending(unit, unitlevel, effect, duration) function libdebuff:AddPending(unit, unitlevel, effect, duration, caster)
if not unit or duration <= 0 then return end if not unit or duration <= 0 then return end
if not L["debuffs"][effect] or libdebuff.pending[3] == effect then return end if not L["debuffs"][effect] or libdebuff.pending[3] == effect then return end
@@ -91,6 +91,7 @@ function libdebuff:AddPending(unit, unitlevel, effect, duration)
libdebuff.pending[2] = unitlevel or 0 libdebuff.pending[2] = unitlevel or 0
libdebuff.pending[3] = effect libdebuff.pending[3] = effect
libdebuff.pending[4] = duration -- or libdebuff:GetDuration(effect) libdebuff.pending[4] = duration -- or libdebuff:GetDuration(effect)
libdebuff.pending[5] = caster
end end
function libdebuff:RemovePending() function libdebuff:RemovePending()
@@ -98,12 +99,13 @@ function libdebuff:RemovePending()
libdebuff.pending[2] = nil libdebuff.pending[2] = nil
libdebuff.pending[3] = nil libdebuff.pending[3] = nil
libdebuff.pending[4] = nil libdebuff.pending[4] = nil
libdebuff.pending[5] = nil
end end
function libdebuff:PersistPending(effect) function libdebuff:PersistPending(effect)
if not libdebuff.pending[3] then return end if not libdebuff.pending[3] then return end
if libdebuff.pending[3] == effect or ( effect == nil and libdebuff.pending[3] ) then if libdebuff.pending[3] == effect or ( effect == nil and libdebuff.pending[3] ) then
libdebuff:AddEffect(libdebuff.pending[1], libdebuff.pending[2], libdebuff.pending[3], libdebuff.pending[4]) libdebuff:AddEffect(libdebuff.pending[1], libdebuff.pending[2], libdebuff.pending[3], libdebuff.pending[4], libdebuff.pending[5])
libdebuff:RemovePending() libdebuff:RemovePending()
end end
end end
@@ -114,7 +116,7 @@ function libdebuff:RevertLastAction()
libdebuff:UpdateUnits() libdebuff:UpdateUnits()
end end
function libdebuff:AddEffect(unit, unitlevel, effect, duration) function libdebuff:AddEffect(unit, unitlevel, effect, duration, caster)
if not unit or not effect then return end if not unit or not effect then return end
unitlevel = unitlevel or 0 unitlevel = unitlevel or 0
if not libdebuff.objects[unit] then libdebuff.objects[unit] = {} end if not libdebuff.objects[unit] then libdebuff.objects[unit] = {} end
@@ -128,6 +130,7 @@ function libdebuff:AddEffect(unit, unitlevel, effect, duration)
libdebuff.objects[unit][unitlevel][effect].start_old = libdebuff.objects[unit][unitlevel][effect].start libdebuff.objects[unit][unitlevel][effect].start_old = libdebuff.objects[unit][unitlevel][effect].start
libdebuff.objects[unit][unitlevel][effect].start = GetTime() libdebuff.objects[unit][unitlevel][effect].start = GetTime()
libdebuff.objects[unit][unitlevel][effect].duration = duration or libdebuff:GetDuration(effect) libdebuff.objects[unit][unitlevel][effect].duration = duration or libdebuff:GetDuration(effect)
libdebuff.objects[unit][unitlevel][effect].caster = caster
libdebuff:UpdateUnits() libdebuff:UpdateUnits()
end end
@@ -227,13 +230,13 @@ end)
hooksecurefunc("CastSpell", function(id, bookType) hooksecurefunc("CastSpell", function(id, bookType)
local rawEffect, rank = libspell.GetSpellInfo(id, bookType) local rawEffect, rank = libspell.GetSpellInfo(id, bookType)
local duration = libdebuff:GetDuration(rawEffect, rank) local duration = libdebuff:GetDuration(rawEffect, rank)
libdebuff:AddPending(UnitName("target"), UnitLevel("target"), rawEffect, duration) libdebuff:AddPending(UnitName("target"), UnitLevel("target"), rawEffect, duration, "player")
end, true) end, true)
hooksecurefunc("CastSpellByName", function(effect, target) hooksecurefunc("CastSpellByName", function(effect, target)
local rawEffect, rank = libspell.GetSpellInfo(effect) local rawEffect, rank = libspell.GetSpellInfo(effect)
local duration = libdebuff:GetDuration(rawEffect, rank) local duration = libdebuff:GetDuration(rawEffect, rank)
libdebuff:AddPending(UnitName("target"), UnitLevel("target"), rawEffect, duration) libdebuff:AddPending(UnitName("target"), UnitLevel("target"), rawEffect, duration, "player")
end, true) end, true)
hooksecurefunc("UseAction", function(slot, target, button) hooksecurefunc("UseAction", function(slot, target, button)
@@ -241,7 +244,7 @@ hooksecurefunc("UseAction", function(slot, target, button)
scanner:SetAction(slot) scanner:SetAction(slot)
local rawEffect, rank = scanner:Line(1) local rawEffect, rank = scanner:Line(1)
local duration = libdebuff:GetDuration(rawEffect, rank) local duration = libdebuff:GetDuration(rawEffect, rank)
libdebuff:AddPending(UnitName("target"), UnitLevel("target"), rawEffect, duration) libdebuff:AddPending(UnitName("target"), UnitLevel("target"), rawEffect, duration, "player")
end, true) end, true)
function libdebuff:UnitDebuff(unit, id) function libdebuff:UnitDebuff(unit, id)
@@ -250,6 +253,7 @@ function libdebuff:UnitDebuff(unit, id)
local texture, stacks, dtype = UnitDebuff(unit, id) local texture, stacks, dtype = UnitDebuff(unit, id)
local duration, timeleft = nil, -1 local duration, timeleft = nil, -1
local rank = nil -- no backport local rank = nil -- no backport
local caster = nil -- experimental
local effect local effect
if texture then if texture then
@@ -264,6 +268,7 @@ function libdebuff:UnitDebuff(unit, id)
else else
duration = libdebuff.objects[unitname][unitlevel][effect].duration duration = libdebuff.objects[unitname][unitlevel][effect].duration
timeleft = duration + libdebuff.objects[unitname][unitlevel][effect].start - GetTime() timeleft = duration + libdebuff.objects[unitname][unitlevel][effect].start - GetTime()
caster = libdebuff.objects[unitname][unitlevel][effect].caster
end end
-- no level data -- no level data
@@ -274,10 +279,11 @@ function libdebuff:UnitDebuff(unit, id)
else else
duration = libdebuff.objects[unitname][0][effect].duration duration = libdebuff.objects[unitname][0][effect].duration
timeleft = duration + libdebuff.objects[unitname][0][effect].start - GetTime() timeleft = duration + libdebuff.objects[unitname][0][effect].start - GetTime()
caster = libdebuff.objects[unitname][0][effect].caster
end end
end end
return effect, rank, texture, stacks, dtype, duration, timeleft return effect, rank, texture, stacks, dtype, duration, timeleft, caster
end end
-- add libdebuff to pfUI API -- add libdebuff to pfUI API