Expire cached aggro on UNIT_TARGET

UnitHasAggro caches a positive answer for 1s and a negative one for
0.3s, so the aggro glow lagged a taunt or a mob turning on a healer by
up to that long. A retarget now expires the entries it can affect: every
unit that had aggro and the retargeting unit's new target. The rest stay
cached, so the scan runs no more often. Mobs without a token of their
own fire it with their GUID, and "<guid>target" composes.
This commit is contained in:
Brues
2026-10-31 06:36:42 -05:00
parent cc5c562516
commit 8b5a27f9be
+16
View File
@@ -313,6 +313,7 @@ function pfUI.api.UnitHasAggro(unit)
if not data then data = { }; aggrodata[unit] = data end
data.check = now
data.state = 0
data.guid = UnitGUID(unit)
if UnitExists(unit) and UnitIsFriend(unit, "player") then
for i = 1, table.getn(aggroScan) do
@@ -329,6 +330,21 @@ function pfUI.api.UnitHasAggro(unit)
return data.state
end
-- A unit turned to someone else, so two kinds of cached answer may be stale:
-- every unit that had aggro (the attacker may have left it) and the new
-- target. Those recompute on their next read instead of riding out the
-- cache; the rest stay cached, since the retarget changes nothing for them.
-- Units without a token of their own (a raid member's target) still fire it
-- with their GUID, which composes with "target" like any token.
pfUI.events:RegisterFrameEventAndCallback("UNIT_TARGET", function(_, unit)
local target = UnitGUID(unit .. "target")
for _, data in pairs(aggrodata) do
if data.state > 0 or (target and data.guid == target) then
data.check = 0
end
end
end)
function pfUI.uf:UpdateVisibility()
local self = self or this