diff --git a/FreshShit/WarlockDispelMaster/event.lua b/FreshShit/WarlockDispelMaster/event.lua new file mode 100644 index 0000000..4bd5fdd --- /dev/null +++ b/FreshShit/WarlockDispelMaster/event.lua @@ -0,0 +1,16 @@ +-- TICKER_200 +function() + for _, unit in ipairs(Units) do + if UnitExists(unit) and not UnitIsDeadOrGhost(unit) and HasDispellableDebuff(unit) then + local unitName = UnitName(unit) + local frame = GetFrameFromName(unitName) + if frame == nil then + print("Frame not found for " .. unitName) + -- Unexpected behavior, bail! + return + end + print("Dispel " .. unitName) + MakeFrameGlow(frame) + end + end +end \ No newline at end of file diff --git a/FreshShit/WarlockDispelMaster/event2.lua b/FreshShit/WarlockDispelMaster/event2.lua new file mode 100644 index 0000000..019cd5c --- /dev/null +++ b/FreshShit/WarlockDispelMaster/event2.lua @@ -0,0 +1,4 @@ +-- TICKER_1000 +function() + SetupPartyCache() +end \ No newline at end of file diff --git a/FreshShit/WarlockDispelMaster/init.lua b/FreshShit/WarlockDispelMaster/init.lua new file mode 100644 index 0000000..d7d9596 --- /dev/null +++ b/FreshShit/WarlockDispelMaster/init.lua @@ -0,0 +1,85 @@ +LCG = LibStub("LibCustomGlow-1.0") +---@table +BusyFrames = {} + +Units = { + "player", + "party1", + "party2", + "party3", + "party4", + "party5", +} + +---@param unit string +---@return boolean, nil|string +function HasDispellableDebuff(unit) + for i = 1, 20 do + local debuff, _, _, _, type = UnitDebuff(unit, i) + if debuff == nil then + return false, nil + end + if type == "Magic" then + return true, nil + end + end + + return false, nil +end + +---@param frame Frame +---@return string, nil|string +function GetNameFromFrame(frame) + if frame == nil then + return "", "Frame is nil" + end + ---@diagnostic disable-next-line: undefined-field + if frame.Name == nil then + return "", "Frame.Name is nil" + end + ---@diagnostic disable-next-line: undefined-field + return frame.Name:GetText(), nil +end + +---@param name string +---@return Frame|nil +function GetFrameFromName(name) + return PartyCache[name] +end + +---@param name string +---@return string +---@return number +function RemoveNamePadding(name) + return string.gsub(name, "|c%w%w%w%w%w%w%w%w", "", 1) +end + +function MakeFrameGlow(frame) + local frameName = frame:GetName() + if frame ~= nil and BusyFrames[frameName] == nil then + ---@type Frame + ---@diagnostic disable-next-line: undefined-field + local healthBar = frame.Health + if healthBar ~= nil then + LCG.PixelGlow_Start(healthBar, {1, 1, 0, 1}, 16, 0.35, 8, 4) + BusyFrames[frameName] = true + C_Timer.After(1, function() + LCG.PixelGlow_Stop(healthBar) + BusyFrames[frameName] = nil + end) + end + end +end + +PartyCache = {} +function SetupPartyCache() + for i = 1, 5 do + -- /dump _G[string.format("ElvUF_RaidGroup1UnitButton%d", 1)].Name:GetText() + local raidFrame = _G[string.format("ElvUF_RaidGroup1UnitButton%d", i + 1)] + local name, err = GetNameFromFrame(raidFrame) + if err == nil then + name = RemoveNamePadding(name) + PartyCache[name] = raidFrame + end + end +end