From ecd81ac57a2ed1889935972dc194861937c873d3 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Wed, 14 Oct 2020 03:19:44 +0200 Subject: [PATCH] Add 3pT2BS. --- 3pT2BS/3pT2BS.lua | 114 ++++++++++++++++++++++++++++++++++++++++++++++ 3pT2BS/3pT2BS.toc | 13 ++++++ 3pT2BS/README.md | 6 +++ 3pT2BS/util.lua | 15 ++++++ 4 files changed, 148 insertions(+) create mode 100644 3pT2BS/3pT2BS.lua create mode 100644 3pT2BS/3pT2BS.toc create mode 100644 3pT2BS/README.md create mode 100644 3pT2BS/util.lua diff --git a/3pT2BS/3pT2BS.lua b/3pT2BS/3pT2BS.lua new file mode 100644 index 0000000..e51b8ef --- /dev/null +++ b/3pT2BS/3pT2BS.lua @@ -0,0 +1,114 @@ +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 actionMacros = {} + + +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", wrathOff) +button:SetScript("PreClick", function (self, button, down) + if InCombatLockdown() then + return + end + if hasRecentlyBattleShouted() then + return self:SetAttribute("macrotext", actionMacros.takeWrathOff) + end + if not hasEnoughRageForBattleShout() then + if isBloodRageReady() then + return self:SetAttribute("macrotext", actionMacros.putWrathOn .. actionMacros.castBloodRage) + end + return self:SetAttribute("macrotext", actionMacros.takeWrathOff) + end + if not has3pT2() then + return self:SetAttribute("macrotext", actionMacros.putWrathOn) + end + return self:SetAttribute("macrotext", actionMacros.castBattleShout) +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() + 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", + "/stopmacro [combat]", + "/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 + actionMacros[action] = table.concat(lines, "\n") + 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 diff --git a/3pT2BS/3pT2BS.toc b/3pT2BS/3pT2BS.toc new file mode 100644 index 0000000..2d9c593 --- /dev/null +++ b/3pT2BS/3pT2BS.toc @@ -0,0 +1,13 @@ +## Interface: 11305 + +## Title: 3pT2BS +## Notes: Automatically switch to 3/8 Wrath Tier 2, cast Battle Shout, and then switch back to normal gear. +## Author: Caspervk +## Version: 0.0.1 + +## X-License: GNU General Public License v3 or later (GPLv3+) + +##SavedVariablesPerCharacter: ThreepT2BSDB + +util.lua +3pT2BS.lua diff --git a/3pT2BS/README.md b/3pT2BS/README.md new file mode 100644 index 0000000..2c5d48a --- /dev/null +++ b/3pT2BS/README.md @@ -0,0 +1,6 @@ +# 3pT2BS +World of Warcraft Classic AddOn for Fury Warriors to automatically switch to 3/8 Wrath Tier 2, cast Battle Shout, and +then switch back to normal gear with the press of one button. +Use `/click 3pT2BS` in a macro to keybind. + +Gear-sets needs to be modified in `WTF/Account/x/y/z/SavedVariables/3pT2BS.lua` after first run. diff --git a/3pT2BS/util.lua b/3pT2BS/util.lua new file mode 100644 index 0000000..7221d8c --- /dev/null +++ b/3pT2BS/util.lua @@ -0,0 +1,15 @@ + +function GetNumSetItemsEquipped(setID) + -- From WeakAuras.GetNumSetItemsEquipped + -- https://github.com/WeakAuras/WeakAuras2/blob/master/WeakAuras/Prototypes.lua#L969 + if not setID or not type(setID) == "number" then return end + local equipped = 0 + local setName = GetItemSetInfo(setID) + for i = 1, 18 do + local item = GetInventoryItemID("player", i) + if item and select(16, GetItemInfo(item)) == setID then + equipped = equipped + 1 + end + end + return equipped, 18, setName +end