From 93c3ef80d413b0606e7b2a74a70d34e0ee0213e2 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Wed, 13 Feb 2013 19:55:14 +0000 Subject: [PATCH] Fix ticket #209 regarding stance numbers. There are occasions where the order of stances on the stance/shapeshift bar differ between Mac and PC, which causes problems in scripts that reference stance numbers (indices). Implement new module OvaleStance to track stance and mastery changes. OvaleStance maps stance indices (in the stance bar) to Ovale stance names in a locale-independent way. The list of stance names is available by running "/ovale stance", e.g.: druid_bear_form druid_cat_form monk_stance_of_the_sturdy_ox monk_stance_of_the_fierce_tiger warrior_battle_stance These stance names can be used in place of the stance indices, e.g.: unless Stance(monk_stance_of_the_sturdy_ox) Spell(stance_of_the_sturdy_ox) git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@689 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.toc | 1 + OvaleAura.lua | 37 +----------- OvaleBestAction.lua | 2 +- OvaleCompile.lua | 14 ++--- OvaleCondition.lua | 7 ++- OvaleOptions.lua | 11 +++- OvaleStance.lua | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++ OvaleState.lua | 2 +- 8 files changed, 192 insertions(+), 50 deletions(-) create mode 100644 OvaleStance.lua diff --git a/Ovale.toc b/Ovale.toc index ae4e969..6e7f593 100644 --- a/Ovale.toc +++ b/Ovale.toc @@ -42,6 +42,7 @@ OvaleOptions.lua OvaleRecount.lua OvaleSkada.lua OvaleSpellDamage.lua +OvaleStance.lua OvaleState.lua OvaleSwing.lua defaut\Chaman.lua diff --git a/OvaleAura.lua b/OvaleAura.lua index 54f9330..baea4c3 100644 --- a/OvaleAura.lua +++ b/OvaleAura.lua @@ -14,8 +14,6 @@ OvaleAura = LibStub("AceAddon-3.0"):NewAddon("OvaleAura", "AceEvent-3.0") -- OvaleAura.aura = {} -OvaleAura.mastery = nil -OvaleAura.stance = 0 OvaleAura.serial = 0 OvaleAura.spellHaste = 1 OvaleAura.meleeHaste = 1 @@ -26,32 +24,20 @@ OvaleAura.playerGUID = nil local baseDamageMultiplier = 1 local pairs, select, strfind = pairs, select, string.find -local GetSpecialization, GetShapeshiftForm, UnitAura = GetSpecialization, GetShapeshiftForm, UnitAura +local UnitAura = UnitAura -- -- Events -- function OvaleAura:OnEnable() self.playerGUID = UnitGUID("player") - self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") - self:RegisterEvent("PLAYER_ENTERING_WORLD") self:RegisterEvent("UNIT_AURA") - self:RegisterEvent("UPDATE_SHAPESHIFT_FORM") - self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS") end function OvaleAura:OnDisable() - self:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED") self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED") - self:UnregisterEvent("PLAYER_ENTERING_WORLD") self:UnregisterEvent("UNIT_AURA") - self:UnregisterEvent("UPDATE_SHAPESHIFT_FORM") - self:UnregisterEvent("UPDATE_SHAPESHIFT_FORMS") -end - -function OvaleAura:ACTIVE_TALENT_GROUP_CHANGED(event) - self.mastery = GetSpecialization() end function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...) @@ -87,11 +73,6 @@ function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...) end end -function OvaleAura:PLAYER_ENTERING_WORLD(event) - self.mastery = GetSpecialization() - self.stance = GetShapeshiftForm() -end - function OvaleAura:UNIT_AURA(event, unitId) if unitId == "player" then self:UpdateAuras("player", self.playerGUID) @@ -100,14 +81,6 @@ function OvaleAura:UNIT_AURA(event, unitId) end end -function OvaleAura:UPDATE_SHAPESHIFT_FORM(event) - self:ShapeshiftEventHandler() -end - -function OvaleAura:UPDATE_SHAPESHIFT_FORMS(event) - self:ShapeshiftEventHandler() -end - function OvaleAura:AddAura(unitGUID, spellId, unitCaster, icon, count, debuffType, duration, expirationTime, isStealable, name, value) local auraList = self.aura[unitGUID] @@ -156,14 +129,6 @@ function OvaleAura:AddAura(unitGUID, spellId, unitCaster, icon, count, debuffTyp end -- Private methods -function OvaleAura:ShapeshiftEventHandler() - local newStance = GetShapeshiftForm() - if self.stance ~= newStance then - self.stance = newStance - self:SendMessage("Ovale_UpdateShapeshiftForm") - end -end - function OvaleAura:UpdateAuras(unitId, unitGUID) self.serial = self.serial + 1 diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua index 09e9096..d5f1089 100644 --- a/OvaleBestAction.lua +++ b/OvaleBestAction.lua @@ -105,7 +105,7 @@ function OvaleBestAction:GetActionInfo(element) local si = OvaleData:GetSpellInfo(spellId) if si then - if si.stance and OvaleAura.stance ~= si.stance then + if si.stance and not OvaleStance:IsStance(si.stance) then return nil end diff --git a/OvaleCompile.lua b/OvaleCompile.lua index 2ea77a4..899e931 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -7,11 +7,11 @@ file accompanying this program. ----------------------------------------------------------------------]] -local L = LibStub("AceLocale-3.0"):GetLocale("Ovale") - OvaleCompile = {} -- +local L = LibStub("AceLocale-3.0"):GetLocale("Ovale") + local node={} local defines = {} local customFunctions = {} @@ -88,19 +88,17 @@ local function TestConditions(paramList) if paramList.glyph and not HasGlyph(paramList.glyph) then return false end - if paramList.mastery and paramList.mastery~=GetSpecialization() then + if paramList.mastery and not OvaleStance:IsSpecialization(paramList.mastery) then return false end if paramList.if_stance then Ovale.compileOnStances = true - if paramList.if_stance ~= GetShapeshiftForm() then + if not OvaleStance:IsStance(paramList.if_stance) then return false end end - if paramList.if_spell then - if not OvaleData.spellList[paramList.if_spell] then - return false - end + if paramList.if_spell and not OvaleData.spellList[paramList.if_spell] then + return false end if paramList.talent and not HasTalent(paramList.talent) then return false diff --git a/OvaleCondition.lua b/OvaleCondition.lua index 23889b0..f65b1f6 100644 --- a/OvaleCondition.lua +++ b/OvaleCondition.lua @@ -13,6 +13,7 @@ OvaleCondition = {} local LBCT = LibStub("LibBabble-CreatureType-3.0"):GetLookupTable() local LRC = LibStub("LibRangeCheck-2.0", true) + local runes = {} local runesCD = {} @@ -2356,13 +2357,13 @@ end --- Test if the player is in a given stance. -- @name Stance -- @paramsig boolean --- @param stance A number representing the stance index. +-- @param stance The stance name or a number representing the stance index. -- @return A boolean value. -- @usage --- unless Stance(1) Spell(bear_form) +-- unless Stance(druid_bear_form) Spell(bear_form) OvaleCondition.conditions.stance = function(condition) - if (OvaleAura.stance == condition[1]) then + if OvaleStance:IsStance(condition[1]) then return 0 else return nil diff --git a/OvaleOptions.lua b/OvaleOptions.lua index 74a267d..b3fd084 100644 --- a/OvaleOptions.lua +++ b/OvaleOptions.lua @@ -438,7 +438,16 @@ local options = func = function() OvaleData:DebugSpellList() end - } + }, + stance = + { + order = -9, + name = "List stances", + type = "execute", + func = function() + OvaleStance:DebugStances() + end + }, } } } diff --git a/OvaleStance.lua b/OvaleStance.lua new file mode 100644 index 0000000..2c7e500 --- /dev/null +++ b/OvaleStance.lua @@ -0,0 +1,168 @@ +--[[-------------------------------------------------------------------- + Ovale Spell Priority + Copyright (C) 2013 Johnny C. Lam + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License in the LICENSE + file accompanying this program. +--]]-------------------------------------------------------------------- + +-- This addon tracks the player's current stance. + +OvaleStance = LibStub("AceAddon-3.0"):NewAddon("OvaleStance", "AceEvent-3.0") + +-- +local Ovale = LibStub("AceAddon-3.0"):GetAddon("Ovale") + +local ipairs = ipairs +local pairs = pairs +local strfind = string.find +local tinsert = table.insert +local tsort = table.sort +local GetNumShapeshiftForms = GetNumShapeshiftForms +local GetShapeshiftForm = GetShapeshiftForm +local GetSpecialization = GetSpecialization +local GetSpellInfo = GetSpellInfo + +local spellIdToStance = { + -- Death Knight + [GetSpellInfo(48263)] = "death_knight_blood_presence", + [GetSpellInfo(48265)] = "death_knight_unholy_presence", + [GetSpellInfo(48266)] = "death_knight_frost_presence", + -- Druid + [GetSpellInfo(768)] = "druid_cat_form", + [GetSpellInfo(783)] = "druid_travel_form", + [GetSpellInfo(1066)] = "druid_aquatic_form", + [GetSpellInfo(5487)] = "druid_bear_form", + [GetSpellInfo(24858)] = "druid_moonkin_form", + [GetSpellInfo(33943)] = "druid_flight_form", + [GetSpellInfo(40120)] = "druid_swift_flight_form", + -- Monk + [GetSpellInfo(103985)] = "monk_stance_of_the_fierce_tiger", + [GetSpellInfo(115069)] = "monk_stance_of_the_sturdy_ox", + [GetSpellInfo(115070)] = "monk_stance_of_the_wise_serpent", + -- Paladin + [GetSpellInfo(20154)] = "paladin_seal_of_righteousness", + [GetSpellInfo(20164)] = "paladin_seal_of_justice", + [GetSpellInfo(20165)] = "paladin_seal_of_insight", + [GetSpellInfo(31801)] = "paladin_seal_of_truth", + [GetSpellInfo(105361)] = "paladin_seal_of_command", + -- Priest + [GetSpellInfo(15473)] = "priest_shadowform", + -- Rogue + [GetSpellInfo(1784)] = "rogue_stealth", + [GetSpellInfo(51713)] = "rogue_shadow_dance", + -- Warlock + [GetSpellInfo(103958)] = "warlock_metamorphosis", + -- Warrior + [GetSpellInfo(71)] = "warrior_defensive_stance", + [GetSpellInfo(2457)] = "warrior_battle_stance", + [GetSpellInfo(2458)] = "warrior_berserker_stance", +} + +-- List of available stances, populated by CreateStanceList() +local stanceList +-- Player's current stance. +local stance +-- Player's current specialization/mastery. +local specialization +-- + +-- +function OvaleStance:OnEnable() + self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") + self:RegisterEvent("PLAYER_ENTERING_WORLD") + self:RegisterEvent("PLAYER_TALENT_UPDATE") + self:RegisterEvent("UPDATE_SHAPESHIFT_FORM") + self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS") +end + +function OvaleStance:OnDisable() + self:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED") + self:UnregisterEvent("PLAYER_ENTERING_WORLD") + self:UnregisterEvent("PLAYER_TALENT_UPDATE") + self:UnregisterEvent("UPDATE_SHAPESHIFT_FORM") + self:UnregisterEvent("UPDATE_SHAPESHIFT_FORMS") +end + +function OvaleStance:ACTIVE_TALENT_GROUP_CHANGED(event) + specialization = GetSpecialization() +end + +function OvaleStance:PLAYER_ENTERING_WORLD(event) + self:CreateStanceList() + self:ACTIVE_TALENT_GROUP_CHANGED(event) + self:ShapeshiftEventHandler() +end + +function OvaleStance:PLAYER_TALENT_UPDATE(event) + self:CreateStanceList() + self:ShapeshiftEventHandler() +end + +function OvaleStance:UPDATE_SHAPESHIFT_FORM(event) + self:ShapeshiftEventHandler() +end + +function OvaleStance:UPDATE_SHAPESHIFT_FORMS(event) + self:ShapeshiftEventHandler() +end + +-- Fill stanceList with stance bar index <-> Ovale stance name mappings. +function OvaleStance:CreateStanceList() + stanceList = {} + local name, stanceName + for i = 1, GetNumShapeshiftForms() do + _, name = GetShapeshiftFormInfo(i) + stanceName = spellIdToStance[name] + if stanceName then + stanceList[i] = stanceName + end + end +end + +-- Print out the list of stances in alphabetical order. +function OvaleStance:DebugStances() + local array = {} + for k, v in pairs(stanceList) do + if stance == k then + tinsert(array, v .. " (active)") + else + tinsert(array, v) + end + end + tsort(array) + for _, v in ipairs(array) do + Ovale:Print(v) + end +end + +function OvaleStance:Debug() + Ovale:Print("current stance: " .. stance) + Ovale:Print("current specialization: " .. specialization) +end + +-- Return true if the current specialization matches the given name. +function OvaleStance:IsSpecialization(name) + if not name then return false end + return name == specialization +end + +-- Return true if the current stance matches the given name. +function OvaleStance:IsStance(name) + if not name then return false end + if type(name) == "number" then + return name == stance + else + return name == stanceList[stance] + end +end + +function OvaleStance:ShapeshiftEventHandler() + local newStance = GetShapeshiftForm() + if stance ~= newStance then + stance = newStance + self:SendMessage("Ovale_UpdateShapeshiftForm") + end +end +-- diff --git a/OvaleState.lua b/OvaleState.lua index e341c30..d11b018 100644 --- a/OvaleState.lua +++ b/OvaleState.lua @@ -61,7 +61,7 @@ function OvaleState:UpdatePowerRates() end -- Stance of the Sturdy Ox (brewmaster monk) - if OvaleAura.mastery == 1 and OvaleAura.stance == 1 then + if OvaleStance:IsStance("monk_stance_of_the_sturdy_ox") then self.powerRate.energy = self.powerRate.energy * 1.1 end end -- 1.7.9.5