From beed1be23b1e95e7a263c456f70f546e139ecaa7 Mon Sep 17 00:00:00 2001 From: shagu Date: Thu, 2 Sep 2021 17:37:30 +0200 Subject: [PATCH] auto-stance: switch to required stance on cast --- README.md | 3 +++ ShaguTweaks.toc | 1 + mods/auto-stance.lua | 48 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 mods/auto-stance.lua diff --git a/README.md b/README.md index e912ddd..841933a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ Every of the listed features below, can be completely disabled in that menu in c - **Auto Dismount** *Automatically dismounts whenever a spell is casted.* +- **Auto Stance** + *Automatically switch to the required warrior or druid stance on spell cast.* + - **Tooltip Details** *Display health, class color, guild name, guild rank and current target on unit tooltips.* diff --git a/ShaguTweaks.toc b/ShaguTweaks.toc index 5df0ce8..62db42c 100644 --- a/ShaguTweaks.toc +++ b/ShaguTweaks.toc @@ -50,4 +50,5 @@ mods\item-colors.lua mods\chat-links.lua mods\health-numbers.lua mods\auto-dismount.lua +mods\auto-stance.lua mods\tooltip-details.lua diff --git a/mods/auto-stance.lua b/mods/auto-stance.lua new file mode 100644 index 0000000..fe89dae --- /dev/null +++ b/mods/auto-stance.lua @@ -0,0 +1,48 @@ +local _G = _G or getfenv(0) +local strsplit = ShaguTweaks.strsplit +local GetExpansion = ShaguTweaks.GetExpansion + +-- It's not possible to achieve it like that in TBC +if GetExpansion() == "tbc" then return end + +local module = ShaguTweaks:register({ + title = "Auto Stance", + description = "Automatically switch to the required warrior or druid stance on spell cast.", + enabled = nil, +}) + +module.enable = function(self) + local stancedance = CreateFrame("Frame") + stancedance:RegisterEvent("UI_ERROR_MESSAGE") + stancedance:SetScript("OnEvent", function() stancedance.lastError = arg1 end) + + stancedance.lastError = "" + stancedance.scanString = string.gsub(SPELL_FAILED_ONLY_SHAPESHIFT, "%%s", "(.+)") + stancedance.CastSpell = CastSpell + stancedance.CastSpellByName = CastSpellByName + stancedance.UseAction = UseAction + + stancedance.SwitchStance = function() + for stance in string.gfind(stancedance.lastError, stancedance.scanString) do + for _, stance in pairs({ strsplit(",", stance)}) do + stancedance.CastSpellByName(string.gsub(stance,"^%s*(.-)%s*$", "%1")) + end + end + stancedance.lastError = "" + end + + function CastSpell(spellId, spellbookTabNum) + stancedance:SwitchStance() + stancedance.CastSpell(spellId, spellbookTabNum) + end + + function CastSpellByName(spellName, onSelf) + stancedance:SwitchStance() + stancedance.CastSpellByName(spellName, onSelf) + end + + function UseAction(slot, checkCursor, onSelf) + stancedance:SwitchStance() + stancedance.UseAction(slot, checkCursor, onSelf) + end +end