wow-addons/MaelstromAlert/MaelstromAlert.lua
rope 3a26e31458 Maelstrom Alert: 5-stack Maelstrom Weapon alert
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 20:18:17 +00:00

263 lines
10 KiB
Lua

-- Maelstrom Alert: a big pulsing Maelstrom Weapon icon with a chime when it
-- reaches 5 stacks, gone again when they're spent.
--
-- Aura data turns secret in combat unless Blizzard flags the buff as never
-- secret, and then the stacks can't be read. While they can't, three signals
-- stand in: the "Maelstrom Ready" combat text (type SPELL_ACTIVE, whose text
-- is secret in combat but whose type isn't; a shaman has no other reactive
-- spell), the proc overlay, and the glow on the spells 5 stacks make instant.
-- The combat text has no "gone" event, so casting one of those spells or
-- READY_TIME passing clears it. MaelstromAlertDB.log counts which sources
-- were seen, so a silent addon can be diagnosed from SavedVariables.
local NAME = "Maelstrom Weapon"
local STACKS = 5
local POLL = 0.1
local PREVIEW = 3
local READY_TIME = 30 -- how long the buff lasts, for the combat text signal
local ICON = "Interface\\Icons\\Spell_Shaman_MaelstromWeapon"
local SOUND = (SOUNDKIT and SOUNDKIT.ALARM_CLOCK_WARNING_3) or 12889
-- Spells 5 stacks make instant: their glow means ready, casting one spends it.
local SPENDERS = {
["Lightning Bolt"] = true, ["Chain Lightning"] = true, ["Healing Wave"] = true,
["Lesser Healing Wave"] = true, ["Chain Heal"] = true,
}
local function secret(v) return issecretvalue ~= nil and issecretvalue(v) end
local function readable(v) return v ~= nil and not secret(v) end
local function count(t, k) t[k] = (t[k] or 0) + 1 end
local db
local st = {
shaman = false,
stacks = nil, -- readable stack count, 0 = no buff, nil = can't tell
overlay = false, -- Maelstrom proc overlay showing
glow = {}, -- glowing spell IDs from GLOW_SPELLS
textUntil = 0, -- "Maelstrom Ready" combat text seen, counts until then
ready = false,
previewUntil = 0,
}
-- Reading -------------------------------------------------------------------
local function spellName(id)
if not readable(id) or not C_Spell or not C_Spell.GetSpellName then return nil end
local n = C_Spell.GetSpellName(id)
return readable(n) and n or nil
end
local function aurasSecret()
if not C_Secrets then return false end
if db.spellID then
local ok, s = pcall(C_Secrets.ShouldSpellAuraBeSecret, db.spellID)
if ok and readable(s) then return s end
end
local ok, s = pcall(C_Secrets.ShouldAurasBeSecret)
return ok and readable(s) and s or false
end
local function readStacks()
local ok, aura = pcall(C_UnitAuras.GetAuraDataBySpellName, "player", NAME, "HELPFUL")
if not ok then return nil end
if aura == nil then
-- No answer means no buff, unless auras are secret right now.
if aurasSecret() then return nil end
return 0
end
if not readable(aura) or not readable(aura.applications) then return nil end
if readable(aura.spellId) and db.spellID ~= aura.spellId then
db.spellID = aura.spellId
if C_Secrets and C_Secrets.GetSpellAuraSecrecy then
local ok2, lvl = pcall(C_Secrets.GetSpellAuraSecrecy, aura.spellId)
if ok2 and readable(lvl) then db.log.secrecy = lvl end -- 0 never, 1 always, 2 contextually
end
end
if readable(aura.icon) then db.icon = aura.icon end
return math.max(aura.applications, 1)
end
-- Display -------------------------------------------------------------------
local f = CreateFrame("Frame", "MaelstromAlertFrame", UIParent)
f:SetSize(72, 72)
f:SetFrameStrata("HIGH")
f:SetMovable(true)
f:SetClampedToScreen(true)
f:EnableMouse(false)
f:RegisterForDrag("LeftButton")
f:Hide()
local glow = f:CreateTexture(nil, "BACKGROUND")
glow:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
glow:SetBlendMode("ADD")
glow:SetVertexColor(0.45, 0.6, 1)
glow:SetSize(170, 170)
glow:SetPoint("CENTER")
local icon = f:CreateTexture(nil, "ARTWORK")
icon:SetAllPoints()
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
local label = f:CreateFontString(nil, "OVERLAY")
label:SetFont(STANDARD_TEXT_FONT, 24, "THICKOUTLINE")
label:SetTextColor(0.75, 0.85, 1)
label:SetPoint("TOP", f, "BOTTOM", 0, -6)
local function place()
f:ClearAllPoints()
local p = db.point
if p then f:SetPoint(p[1], UIParent, p[2], p[3], p[4]) else f:SetPoint("CENTER", UIParent, "CENTER", 0, 90) end
end
f:SetScript("OnDragStart", function(self) self:StartMoving() end)
f:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local p, _, rp, x, y = self:GetPoint()
db.point = { p, rp, x, y }
end)
local t = 0
f:SetScript("OnUpdate", function(self, elapsed)
t = t + elapsed
-- Slam in over 0.15s, then throb.
local scale = t < 0.15 and 1 + 0.8 * (1 - t / 0.15) or 1 + 0.05 * math.sin(t * 12)
self:SetScale(scale)
glow:SetAlpha(0.55 + 0.45 * math.sin(t * 12))
end)
local function render(ready, preview)
if ready or preview or (db and db.moving) then
if not f:IsShown() then t = 0 end
icon:SetTexture(db.icon or ICON)
label:SetText(st.stacks and st.stacks >= STACKS and ("MAELSTROM " .. st.stacks) or "MAELSTROM")
f:Show()
else
f:Hide()
end
end
-- State ---------------------------------------------------------------------
local function update()
if not db then return end
st.stacks = readStacks()
if st.stacks == 0 then st.textUntil = 0 end
local ready
if not db.enabled or not st.shaman or UnitIsDeadOrGhost("player") then
ready = false
elseif st.stacks ~= nil then
ready = st.stacks >= STACKS
else
ready = st.overlay or next(st.glow) ~= nil or GetTime() < st.textUntil
end
if InCombatLockdown() then
count(db.log.reads, st.stacks == nil and "secret" or (st.stacks == 0 and "none" or "readable"))
end
if ready and not st.ready then
db.procs = db.procs + 1
if db.sound then PlaySound(SOUND, "Master") end
end
st.ready = ready
render(ready, GetTime() < st.previewUntil)
end
-- Events --------------------------------------------------------------------
local ev = CreateFrame("Frame")
ev:RegisterEvent("ADDON_LOADED")
ev:SetScript("OnEvent", function(self, event, a1, _, a3)
if event == "ADDON_LOADED" then
if a1 ~= "MaelstromAlert" then return end
MaelstromAlertDB = MaelstromAlertDB or {}
db = MaelstromAlertDB
if db.enabled == nil then db.enabled = true end
if db.sound == nil then db.sound = true end
db.procs = db.procs or 0
db.log = db.log or {}
db.log.reads = db.log.reads or {}
db.log.overlays = db.log.overlays or {}
db.log.glows = db.log.glows or {}
db.log.text = db.log.text or {}
db.moving = nil
place()
self:UnregisterEvent("ADDON_LOADED")
for _, e in ipairs({ "PLAYER_ENTERING_WORLD", "PLAYER_DEAD", "COMBAT_TEXT_UPDATE",
"SPELL_ACTIVATION_OVERLAY_SHOW", "SPELL_ACTIVATION_OVERLAY_HIDE",
"SPELL_ACTIVATION_OVERLAY_GLOW_SHOW", "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" }) do
pcall(self.RegisterEvent, self, e)
end
self:RegisterUnitEvent("UNIT_AURA", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
local acc = 0
self:SetScript("OnUpdate", function(_, elapsed)
acc = acc + elapsed
if acc >= POLL then acc = 0; update() end
end)
return
end
if event == "PLAYER_ENTERING_WORLD" then
st.shaman = select(2, UnitClass("player")) == "SHAMAN"
st.overlay, st.glow, st.textUntil = false, {}, 0
elseif event == "PLAYER_DEAD" then
st.overlay, st.glow, st.textUntil = false, {}, 0
elseif event == "COMBAT_TEXT_UPDATE" then
if not readable(a1) or a1 ~= "SPELL_ACTIVE" then return end
local text = C_CombatText.GetCurrentEventInfo()
if readable(text) then
count(db.log.text, text)
if not text:find("Maelstrom", 1, true) then return end
else
count(db.log.text, "secret")
end
st.textUntil = GetTime() + READY_TIME
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
local name = spellName(a3)
if not (name and SPENDERS[name]) then return end
st.textUntil = 0
elseif event == "SPELL_ACTIVATION_OVERLAY_SHOW" or event == "SPELL_ACTIVATION_OVERLAY_HIDE" then
local name = spellName(a1)
if event == "SPELL_ACTIVATION_OVERLAY_SHOW" then count(db.log.overlays, readable(a1) and (a1 .. " " .. (name or "?")) or "secret") end
if a1 == nil then st.overlay = false -- hide with no spell = all overlays gone
elseif readable(a1) and (name == NAME or a1 == db.spellID) then
st.overlay = event == "SPELL_ACTIVATION_OVERLAY_SHOW"
end
elseif event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" or event == "SPELL_ACTIVATION_OVERLAY_GLOW_HIDE" then
local name = spellName(a1)
if event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" then count(db.log.glows, readable(a1) and (a1 .. " " .. (name or "?")) or "secret") end
if readable(a1) and name and SPENDERS[name] then
st.glow[a1] = event == "SPELL_ACTIVATION_OVERLAY_GLOW_SHOW" or nil
end
end
update()
end)
-- Slash command -------------------------------------------------------------
local function say(msg) print("|cff7799ffMaelstrom Alert|r " .. msg) end
SLASH_MAELSTROMALERT1 = "/mw"
SlashCmdList.MAELSTROMALERT = function(msg)
msg = (msg or ""):lower():gsub("^%s+", ""):gsub("%s+$", "")
if msg == "on" or msg == "off" then
db.enabled = msg == "on"
say(db.enabled and "on." or "off.")
elseif msg == "sound on" or msg == "sound off" then
db.sound = msg == "sound on"
say(db.sound and "sound on." or "sound off.")
elseif msg == "move" then
db.moving = not db.moving
f:EnableMouse(db.moving)
say(db.moving and "drag it, then /mw move again." or "locked.")
elseif msg == "reset" then
db.point = nil
place()
say("position reset.")
else
st.previewUntil = GetTime() + PREVIEW
if db.sound then PlaySound(SOUND, "Master") end
say(string.format("%s, sound %s, %d procs. Stacks: %s. /mw on|off, sound on|off, move, reset",
db.enabled and "on" or "off", db.sound and "on" or "off", db.procs,
st.stacks == nil and "hidden" or tostring(st.stacks)))
end
update()
end