-- Windfury Reminder: a pulsing Windfury icon at the top of the screen while a -- shaman's main hand has no Windfury (Windfury Weapon or Windfury Totem), and -- a countdown in the last 30 seconds of a long one. Hidden while dead, on a -- flight, with no main hand weapon, and in rest areas out of combat. -- -- The weapon enchant API gives enchant IDs but no names, so the main hand -- tooltip is read for a "Windfury" line. IDs found that way are saved. If the -- client hides the values in combat, the last readable state is kept and its -- expiry counted down. local SLOT = 16 -- main hand inventory slot local WARN = 30 -- seconds left that count as expiring local LONG = 60 -- only enchants this long get a countdown (the totem's lasts 10s) local POLL = 0.25 local PREVIEW = 4 local MATCH = "Windfury" local SPELL = "Windfury Weapon" local ICON = "Interface\\Icons\\Spell_Nature_Cyclone" local SOUND = (SOUNDKIT and SOUNDKIT.RAID_WARNING) or 8959 local PERMANENT = (Enum and Enum.ItemEnchantType and Enum.ItemEnchantType.Permanent) or 1 local function secret(v) return issecretvalue ~= nil and issecretvalue(v) end local function readable(v) return v ~= nil and not secret(v) end local db local notWindfury = {} -- enchant IDs seen without Windfury, this session only local st = { shaman = false, known = false, seen = false, -- had one readable answer since login expires = nil, -- GetTime() when the current Windfury ends, nil = none peak = 0, -- longest time left seen on the current Windfury mode = nil, -- "missing", "expiring" or nil previewUntil = 0, } -- Reading the weapon -------------------------------------------------------- local function enchants() if C_Item and C_Item.GetWeaponEnchantInfo then return C_Item.GetWeaponEnchantInfo(Enum.WeaponSlot.MainHand) end local has, ms, charges, id = GetWeaponEnchantInfo() return { { hasEnchant = has, enchantType = 2, timeLeft = ms, charges = charges, enchantID = id } } end -- true / false, or nil when the tooltip can't be read. Line 1 is the item -- name, which is skipped so a weapon called "Windfury ..." doesn't count. local function tooltipSaysWindfury() if not C_TooltipInfo then return nil end local data = C_TooltipInfo.GetInventoryItem("player", SLOT) if not readable(data) or not readable(data.lines) or #data.lines < 2 then return nil end for i = 2, #data.lines do local text = data.lines[i].leftText if text ~= nil then if secret(text) then return nil end if text:find(MATCH, 1, true) then return true end end end return false end -- has (bool), seconds left (number) — or nil when nothing can be read. local function readWeapon() local ok, list = pcall(enchants) if not ok or not readable(list) then return nil end local temps, unknown = {}, {} for _, e in pairs(list) do if not readable(e) or not readable(e.hasEnchant) then return nil end if e.hasEnchant and e.enchantType ~= PERMANENT then temps[#temps + 1] = e local id = e.enchantID if not readable(id) or (db.ids[id] == nil and not notWindfury[id]) then unknown[#unknown + 1] = e end end end -- A saved Windfury ID settles it, and the tooltip's Windfury line would be -- that one's anyway, so it can't name the others. local best for _, e in ipairs(temps) do if readable(e.enchantID) and db.ids[e.enchantID] then if not readable(e.timeLeft) then return nil end best = math.max(best or 0, e.timeLeft / 1000) end end if best or #unknown == 0 then return best ~= nil, best or 0 end local tip = tooltipSaysWindfury() if tip == nil then return nil end if not tip then for _, e in ipairs(unknown) do if readable(e.enchantID) then notWindfury[e.enchantID] = true end end return false, 0 end -- One unnamed enchant: the Windfury line is that one's. With more, take the -- shortest time left, so the countdown never comes late. if #unknown == 1 and readable(unknown[1].enchantID) then db.ids[unknown[1].enchantID] = true end for _, e in ipairs(unknown) do if not readable(e.timeLeft) then return nil end best = math.min(best or math.huge, e.timeLeft / 1000) end return true, best end local function knowsWindfury() local info = C_Spell.GetSpellInfo(SPELL) if not readable(info) or not readable(info.spellID) then return false end local ok, known = pcall(C_SpellBook.IsSpellKnownOrInSpellBook, info.spellID) if not ok or not readable(known) then return true end return known end local function relevant() if not db.enabled or not st.shaman or not st.known or not st.seen then return false end if UnitIsDeadOrGhost("player") or UnitOnTaxi("player") then return false end if not GetInventoryItemID("player", SLOT) then return false end if IsResting() and not InCombatLockdown() then return false end return true end -- Display ------------------------------------------------------------------- local f = CreateFrame("Frame", "WindfuryReminderFrame", UIParent) f:SetSize(64, 64) 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:SetSize(150, 150) glow:SetPoint("CENTER") local icon = f:CreateTexture(nil, "ARTWORK") icon:SetTexture(ICON) icon:SetAllPoints() icon:SetTexCoord(0.07, 0.93, 0.07, 0.93) local label = f:CreateFontString(nil, "OVERLAY") label:SetFont(STANDARD_TEXT_FONT, 22, "THICKOUTLINE") 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, 220) 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 pulse = 0 f:SetScript("OnUpdate", function(_, elapsed) pulse = pulse + elapsed local speed = InCombatLockdown() and 9 or 4 local s = 0.5 + 0.5 * math.sin(pulse * speed) if st.mode == "missing" then glow:SetAlpha(0.35 + 0.65 * s) icon:SetAlpha(0.6 + 0.4 * s) else glow:SetAlpha(0.3 * s) icon:SetAlpha(1) end end) local function show(mode, left) st.mode = mode if mode == "missing" then glow:SetVertexColor(1, 0.15, 0.1) icon:SetDesaturated(true) label:SetTextColor(1, 0.25, 0.2) label:SetText("NO WINDFURY") else glow:SetVertexColor(1, 0.8, 0.1) icon:SetDesaturated(false) label:SetTextColor(1, 0.85, 0.1) left = math.ceil(left) label:SetText(string.format("WINDFURY %d:%02d", math.floor(left / 60), left % 60)) end f:Show() end local function hide() st.mode = nil if not db or not db.moving then f:Hide() end end -- State --------------------------------------------------------------------- local function update() if not db then return end local now = GetTime() local wasActive = st.expires ~= nil local has, left = readWeapon() if has ~= nil then st.seen = true if has then if not wasActive or left > st.peak then st.peak = left end st.expires = now + left else st.expires = nil end elseif st.expires and st.expires <= now then st.expires = nil -- unreadable, but the countdown has run out end if not st.expires then -- A long Windfury just ran out mid-fight: sound the alarm. if wasActive and st.peak > LONG and InCombatLockdown() and db.sound and relevant() then PlaySound(SOUND, "Master") end st.peak = 0 end if now < st.previewUntil then show("missing") elseif not relevant() then hide() elseif not st.expires then show("missing") elseif st.peak > LONG and st.expires - now <= WARN then show("expiring", st.expires - now) else hide() end if db.moving then f:Show() end end -- Events -------------------------------------------------------------------- local ev = CreateFrame("Frame") ev:RegisterEvent("ADDON_LOADED") ev:SetScript("OnEvent", function(self, event, arg1) if event == "ADDON_LOADED" then if arg1 ~= "WindfuryReminder" then return end WindfuryReminderDB = WindfuryReminderDB or {} db = WindfuryReminderDB if db.enabled == nil then db.enabled = true end if db.sound == nil then db.sound = true end db.ids = db.ids or {} db.moving = nil place() self:UnregisterEvent("ADDON_LOADED") for _, e in ipairs({ "PLAYER_ENTERING_WORLD", "PLAYER_EQUIPMENT_CHANGED", "WEAPON_ENCHANT_CHANGED", "PLAYER_REGEN_DISABLED", "PLAYER_REGEN_ENABLED", "PLAYER_UPDATE_RESTING", "PLAYER_DEAD", "PLAYER_ALIVE", "PLAYER_UNGHOST", "SPELLS_CHANGED", "LEARNED_SPELL_IN_TAB" }) do pcall(self.RegisterEvent, self, e) end self:RegisterUnitEvent("UNIT_INVENTORY_CHANGED", "player") C_Timer.NewTicker(POLL, update) return end if event == "PLAYER_ENTERING_WORLD" or event == "SPELLS_CHANGED" or event == "LEARNED_SPELL_IN_TAB" then st.shaman = select(2, UnitClass("player")) == "SHAMAN" st.known = st.shaman and knowsWindfury() end update() if event == "PLAYER_REGEN_DISABLED" and st.mode == "missing" and db.sound then PlaySound(SOUND, "Master") end end) -- Slash command ------------------------------------------------------------- local function say(msg) print("|cff66ccffWindfury Reminder|r " .. msg) end SLASH_WINDFURYREMINDER1 = "/wfr" SlashCmdList.WINDFURYREMINDER = 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 /wfr move again." or "locked.") elseif msg == "reset" then db.point = nil place() say("position reset.") else st.previewUntil = GetTime() + PREVIEW local now = GetTime() local state = st.expires and string.format("Windfury %ds left", math.floor(st.expires - now)) or (st.seen and "no Windfury" or "weapon not read yet") say(string.format("%s, sound %s. %s. %s. /wfr on|off, sound on|off, move, reset", db.enabled and "on" or "off", db.sound and "on" or "off", not st.shaman and "Not a shaman" or (st.known and SPELL .. " known" or SPELL .. " not learned"), state)) end update() end