ThreepT2BS = {} ThreepT2BS.title = GetAddOnMetadata("3pT2BS", "Title") ThreepT2BS.version = GetAddOnMetadata("3pT2BS", "Version") ThreepT2BS.author = GetAddOnMetadata("3pT2BS", "Author") print(("Loaded %s v%s by %s."):format(ThreepT2BS.title, ThreepT2BS.version, ThreepT2BS.author)) local lastT2BattleShout = 0 local actions = {} local function hasRecentlyBattleShouted() return lastT2BattleShout + ThreepT2BSDB.battleShoutPausePeriod > GetTime() end local function has3pT2() return GetNumSetItemsEquipped(ThreepT2BSDB.wrathSetId) >= 3 end local function hasEnoughRageForBattleShout() return UnitPower("player") >= GetSpellPowerCost("Battle Shout")[1].cost end local function isBloodRageReady() local start, duration, enabled, modRate = GetSpellCooldown("Bloodrage") return start == 0 and duration == 0 end local button = CreateFrame("Button", "3pT2BS", UIParent, "SecureActionButtonTemplate") button:SetAttribute("type", "macro") button:SetAttribute("macrotext", actions.takeWrathOff) button:SetScript("PreClick", function (self, button, down) if InCombatLockdown() then return end if hasRecentlyBattleShouted() then return self:SetAttribute("macrotext", actions.takeWrathOff) end if not hasEnoughRageForBattleShout() then if isBloodRageReady() then return self:SetAttribute("macrotext", actions.putWrathOn .. actions.castBloodRage) end return self:SetAttribute("macrotext", actions.takeWrathOff) end if not has3pT2() then return self:SetAttribute("macrotext", actions.putWrathOn) end return self:SetAttribute("macrotext", actions.castBattleShout .. actions.takeWrathOff) end) local frame, events = CreateFrame("FRAME"), {}; function events:COMBAT_LOG_EVENT_UNFILTERED() local _, event, _, _, name, _, _, _, _, _, _, _, spellName = CombatLogGetCurrentEventInfo() if spellName == "Battle Shout" and event == "SPELL_CAST_SUCCESS" and name == UnitName("player") and has3pT2() then lastT2BattleShout = GetTime() end end function events:ADDON_LOADED(addOnName) if addOnName ~= "33pT2BS" then return end ThreepT2BSDB = ThreepT2BSDB or { ["battleShoutPausePeriod"] = 10, ["wrathSetId"] = 218, ["actions"] = { -- we always stop if in combat, since that means we might not have had a chance to set the correct macrotext ["castBloodRage"] = { "/stopmacro [combat]", "/cast Bloodrage", }, ["putWrathOn"] = { "/cancelaura Bloodrage", "/stopmacro [combat]", "/eq Helm of Wrath", "#/eq Pauldrons of Wrath", "#/eq Breastplate of Wrath", "#/eq Bracelets of Wrath", "#/eq Gauntlets of Wrath", "/eq Waistband of Wrath", "#/eq Legplates of Wrath", "/eq Sabatons of Wrath", }, ["castBattleShout"] = { "/cancelaura Bloodrage", "/cast Battle Shout", }, ["takeWrathOff"] = { "/cancelaura Bloodrage", "/stopmacro [combat]", "/eq Lionheart Helm", "/eq Onslaught Girdle", "/eq Chromatic Boots", }, }, } for action, lines in pairs(ThreepT2BSDB.actions) do actions[action] = table.concat(lines, "\n") .. "\n" -- extra newline allows for action composition end end frame:SetScript("OnEvent", function(self, event, ...) events[event](...) end) for k, v in pairs(events) do frame:RegisterEvent(k) -- register all events for which handlers have been defined end