mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-25 09:06:03 +00:00
b7c3fe5333
ClassicAPI's RegisterUnitEvent registers for an event but only delivers it when arg1 is one of the given units, so a handler for one unit stops waking for every other one in the world. Convert the 26 registrations whose unit set is fixed and known at registration time. The rule throughout is register the superset and keep the handler's own check: the filter narrows what arrives, it does not decide what to act on. castbar is the case that matters -- the player's own casts only ever fire arg1=="player", never "target"/"focus", so the target and focus bars must register "player" too, and their UnitIsUnit test is what still rejects a "player" event while you are targeting a mob. Two that are not one-line swaps: actionbar's two unit events are keys in tables that also drive dispatch, so they cannot leave the tables -- and they cannot be plain-registered first, because a registration keeps its kind and RegisterUnitEvent over a plain one stays plain. They route through a small event_units map instead. swingtimer's UNIT_DIED carries a GUID, not a token. The filter is a plain case-insensitive string compare with no GUID resolution, so the player's own GUID -- fixed for the session -- filters it exactly. Guards that are now unreachable stay put: the filter applies only when arg1 is a string, so an event that ever fires with a number or no argument is delivered as if plainly registered, and the handler's own test is what still rejects it. Left alone: api/unitframes.lua (the frame's unit changes at runtime and the handler also matches on GUID), nameplates' six nameplateN events, libdebuff and libpredict's UNIT_HEALTH (genuinely any unit), and raid.lua's UNIT_PET (any raid member can own the pet).
136 lines
4.5 KiB
Lua
136 lines
4.5 KiB
Lua
local function getAdjustedTickTimer()
|
|
local adjustedEnergyTick = 2
|
|
|
|
-- Check rogue talents and compute energy tick timing reduction for Combat spec (1.18.0 Blade Rush Talent)
|
|
if UnitClassBase("player") == "ROGUE" then
|
|
local _, _, _, _, currRank = GetTalentInfo(2, 16)
|
|
local bladeRushRank = currRank or 0
|
|
|
|
if bladeRushRank > 0 then
|
|
local agility = UnitStat("player", 2) -- 2 is agility stat index
|
|
local reductionPerAgi = 0.0006 * bladeRushRank -- 0.0006 for rank 1, 0.0012 for rank 2
|
|
local totalReduction = agility * reductionPerAgi
|
|
adjustedEnergyTick = adjustedEnergyTick - totalReduction
|
|
end
|
|
end
|
|
|
|
return adjustedEnergyTick
|
|
end
|
|
|
|
pfUI:RegisterModule("energytick", function()
|
|
if not pfUI.uf or not pfUI.uf.player then
|
|
return
|
|
end
|
|
|
|
local energytick = CreateFrame("Frame", nil, pfUI.uf.player.power.bar)
|
|
energytick:SetAllPoints(pfUI.uf.player.power.bar)
|
|
energytick:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
energytick:RegisterUnitEvent("UNIT_DISPLAYPOWER", "player")
|
|
energytick:RegisterUnitEvent("UNIT_ENERGY", "player")
|
|
energytick:RegisterUnitEvent("UNIT_MANA", "player")
|
|
energytick:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF")
|
|
energytick:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS")
|
|
|
|
energytick:SetScript("OnEvent", function()
|
|
if UnitPowerType("player") == Enum.PowerType.Mana and C.unitframes.player.manatick == "1" then
|
|
this.mode = "MANA"
|
|
this:Show()
|
|
elseif UnitPowerType("player") == Enum.PowerType.Energy and C.unitframes.player.energy == "1" then
|
|
this.mode = "ENERGY"
|
|
this:Show()
|
|
else
|
|
this:Hide()
|
|
end
|
|
|
|
-- Filter nur eigene Energy-Gewinne von Talents/Buffs
|
|
if event == "CHAT_MSG_SPELL_SELF_BUFF" or event == "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS" then
|
|
if string.find(arg1, "You gain") and string.find(arg1, "Energy from") then
|
|
this.ignoreNextGain = true
|
|
end
|
|
return
|
|
end
|
|
|
|
if event == "PLAYER_ENTERING_WORLD" then
|
|
this.lastMana = UnitPower("player")
|
|
end
|
|
|
|
if (event == "UNIT_MANA" or event == "UNIT_ENERGY") and arg1 == "player" then
|
|
this.currentMana = UnitPower("player")
|
|
local diff = 0
|
|
if this.lastMana then
|
|
diff = this.currentMana - this.lastMana
|
|
end
|
|
|
|
if this.mode == "MANA" and diff < 0 then
|
|
this.target = 5
|
|
elseif this.mode == "MANA" and diff > 0 then
|
|
if UnitPower("player") >= UnitPowerMax("player") then
|
|
this.start = nil
|
|
this.spark:SetAlpha(0)
|
|
this:Hide()
|
|
elseif this.max ~= 5 and diff > (this.badtick and this.badtick * 1.2 or 5) then
|
|
this.target = 2
|
|
else
|
|
this.badtick = diff
|
|
end
|
|
elseif this.mode == "ENERGY" and diff >= 0 then
|
|
if not this.ignoreNextGain then
|
|
this.target = getAdjustedTickTimer()
|
|
end
|
|
this.ignoreNextGain = false
|
|
end
|
|
this.lastMana = this.currentMana
|
|
end
|
|
end)
|
|
|
|
energytick:SetScript("OnUpdate", function()
|
|
-- Throttle for performance
|
|
if (this.tick or 0) > GetTime() then
|
|
return
|
|
end
|
|
this.tick = GetTime() + 0.020 -- ~50 FPS
|
|
|
|
if this.target then
|
|
this.start, this.max = GetTime(), this.target
|
|
this.target = nil
|
|
this.spark:SetAlpha(1)
|
|
this:Show()
|
|
end
|
|
|
|
if not this.start then
|
|
return
|
|
end
|
|
|
|
this.current = GetTime() - this.start
|
|
|
|
if this.current > this.max then
|
|
-- Don't restart tick timer if mana is full
|
|
if this.mode == "MANA" and UnitPower("player") >= UnitPowerMax("player") then
|
|
this.start = nil
|
|
this.spark:SetAlpha(0)
|
|
return
|
|
end
|
|
this.start, this.max, this.current = GetTime(), getAdjustedTickTimer(), 0
|
|
end
|
|
|
|
local pos = (C.unitframes.player.pwidth ~= "-1" and C.unitframes.player.pwidth or C.unitframes.player.width)
|
|
* (this.current / this.max)
|
|
if not C.unitframes.player.pheight then
|
|
return
|
|
end
|
|
this.spark:SetPoint("LEFT", pos - ((C.unitframes.player.pheight + 5) / 2), 0)
|
|
end)
|
|
|
|
energytick.spark = energytick:CreateTexture(nil, "OVERLAY")
|
|
energytick.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
|
|
energytick.spark:SetHeight(C.unitframes.player.pheight + 15)
|
|
energytick.spark:SetWidth(C.unitframes.player.pheight + 5)
|
|
energytick.spark:SetBlendMode("ADD")
|
|
|
|
local hookUpdateConfig = pfUI.uf.player.UpdateConfig
|
|
function pfUI.uf.player.UpdateConfig()
|
|
energytick.spark:SetHeight(C.unitframes.player.pheight + 15)
|
|
energytick.spark:SetWidth(C.unitframes.player.pheight + 5)
|
|
hookUpdateConfig(pfUI.uf.player)
|
|
end
|
|
end) |