Johnny C. Lam [07-16-14 - 22:08]
diff --git a/OvaleStance.lua b/OvaleStance.lua
index f39386e..082bd0e 100644
--- a/OvaleStance.lua
+++ b/OvaleStance.lua
@@ -14,6 +14,10 @@ local OvaleStance = Ovale:NewModule("OvaleStance", "AceEvent-3.0")
Ovale.OvaleStance = OvaleStance
--<private-static-properties>
+-- Forward declarations for module dependencies.
+local OvaleData = nil
+local OvaleState = nil
+
local ipairs = ipairs
local pairs = pairs
local tinsert = table.insert
@@ -93,11 +97,19 @@ local OVALE_SPELLID_TO_STANCE = {
OvaleStance.ready = false
-- List of available stances, populated by CreateStanceList()
OvaleStance.stanceList = {}
+-- Map stance names to stance ID (index on shapeshift/stance bar).
+OvaleStance.stanceId = {}
-- Player's current stance.
OvaleStance.stance = nil
--</public-static-properties>
--<public-static-methods>
+function OvaleStance:OnInitialize()
+ -- Resolve module dependencies.
+ OvaleData = Ovale.OvaleData
+ OvaleState = Ovale.OvaleState
+end
+
function OvaleStance:OnEnable()
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED", "UpdateStances")
self:RegisterEvent("PLAYER_ALIVE", "UpdateStances")
@@ -106,9 +118,11 @@ function OvaleStance:OnEnable()
self:RegisterEvent("SPELLS_CHANGED", "UpdateStances")
self:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
+ OvaleState:RegisterState(self, self.statePrototype)
end
function OvaleStance:OnDisable()
+ OvaleState:UnregisterState(self)
self:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
self:UnregisterEvent("PLAYER_ALIVE")
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
@@ -136,12 +150,14 @@ end
function OvaleStance:CreateStanceList()
profiler.Start("OvaleStance_CreateStanceList")
wipe(self.stanceList)
+ wipe(self.stanceId)
local _, name, stanceName
for i = 1, API_GetNumShapeshiftForms() do
_, name = API_GetShapeshiftFormInfo(i)
stanceName = OVALE_SPELLID_TO_STANCE[name]
if stanceName then
self.stanceList[i] = stanceName
+ self.stanceId[stanceName] = i
end
end
profiler.Stop("OvaleStance_CreateStanceList")
@@ -198,3 +214,59 @@ function OvaleStance:UpdateStances()
self.ready = true
end
--</public-static-methods>
+
+--[[----------------------------------------------------------------------------
+ State machine for simulator.
+--]]----------------------------------------------------------------------------
+
+--<public-static-properties>
+OvaleStance.statePrototype = {}
+--</public-static-properties>
+
+--<private-static-properties>
+local statePrototype = OvaleStance.statePrototype
+--</private-static-properties>
+
+--<state-properties>
+statePrototype.stance = nil
+--</state-properties>
+
+--<public-static-methods>
+-- Initialize the state.
+function OvaleStance:InitializeState(state)
+ state.stance = nil
+end
+
+-- Reset the state to the current conditions.
+function OvaleStance:ResetState(state)
+ profiler.Start("OvaleStance_ResetState")
+ state.stance = self.stance or 0
+ profiler.Stop("OvaleStance_ResetState")
+end
+
+-- Apply the effects of the spell on the player's state, assuming the spellcast completes.
+function OvaleStance:ApplySpellAfterCast(state, spellId, targetGUID, startCast, endCast, nextCast, isChanneled, nocd, spellcast)
+ profiler.Start("OvaleStance_ApplySpellAfterCast")
+ local si = OvaleData.spellInfo[spellId]
+ if si and si.to_stance then
+ local stance = si.to_stance
+ stance = (type(stance) == "number") and stance or self.stanceId[stance]
+ state.stance = stance
+ end
+ profiler.Stop("OvaleStance_ApplySpellAfterCast")
+end
+--</public-static-methods>
+
+--<state-methods>
+-- Return true if the stance matches the given name.
+statePrototype.IsStance = function(state, name)
+ if name and state.stance then
+ if type(name) == "number" then
+ return name == state.stance
+ else
+ return name == OvaleStance.stanceList[state.stance]
+ end
+ end
+ return false
+end
+--</state-methods>
diff --git a/conditions/Stance.lua b/conditions/Stance.lua
index cfd914c..e3b5f8f 100644
--- a/conditions/Stance.lua
+++ b/conditions/Stance.lua
@@ -12,8 +12,10 @@ local _, Ovale = ...
do
local OvaleCondition = Ovale.OvaleCondition
local OvaleStance = Ovale.OvaleStance
+ local OvaleState = Ovale.OvaleState
local TestBoolean = OvaleCondition.TestBoolean
+ local state = OvaleState.state
--- Test if the player is in a given stance.
-- @name Stance
@@ -28,7 +30,7 @@ do
local function Stance(condition)
local stance, yesno = condition[1], condition[2]
- local boolean = OvaleStance:IsStance(stance)
+ local boolean = state:IsStance(stance)
return TestBoolean(boolean, yesno)
end
diff --git a/scripts/ovale_deathknight_spells.lua b/scripts/ovale_deathknight_spells.lua
index f55e5d1..6bdbcd6 100644
--- a/scripts/ovale_deathknight_spells.lua
+++ b/scripts/ovale_deathknight_spells.lua
@@ -32,6 +32,7 @@ Define(blood_plague 59879)
Define(blood_plague_debuff 55078)
SpellInfo(blood_plague_debuff duration=30 tick=3)
Define(blood_presence 48263)
+ SpellInfo(blood_presence to_stance=deathknight_blood_presence)
Define(blood_tap 45529)
SpellAddBuff(blood_tap blood_charge_buff=-5)
Define(blood_tap_talent 13)
@@ -88,6 +89,7 @@ Define(festering_strike 85948)
Define(frost_fever_debuff 55095)
SpellInfo(frost_fever_debuff duration=30 tick=3)
Define(frost_presence 48266)
+ SpellInfo(frost_presence to_stance=deathknight_frost_presence)
Define(frost_strike 49143)
SpellInfo(frost_strike runicpower=35)
SpellInfo(frost_strike runicpower=20 if_spell=improved_frost_presence if_stance=deathknight_frost_presence)
@@ -205,6 +207,7 @@ Define(unholy_frenzy 49016)
SpellInfo(unholy_frenzy cd=180)
SpellInfo(unholy_frenzy buff_cdr=cooldown_reduction_strength_buff specialization=unholy)
Define(unholy_presence 48265)
+ SpellInfo(unholy_presence to_stance=deathknight_unholy_presence)
Define(vampiric_blood 55233)
SpellInfo(vampiric_blood cd=60)
SpellInfo(vampiric_blood addcd=-10 itemset=T14_tank itemcount=2)
diff --git a/scripts/ovale_druid_spells.lua b/scripts/ovale_druid_spells.lua
index 7b18b2d..4d7bb57 100644
--- a/scripts/ovale_druid_spells.lua
+++ b/scripts/ovale_druid_spells.lua
@@ -15,7 +15,7 @@ Define(barkskin 22812)
SpellInfo(barkskin buff_cdr=cooldown_reduction_tank_buff specialization=guardian)
SpellInfo(barkskin addcd=-15 if_spell=malfurions_gift)
Define(bear_form 5487)
- SpellInfo(bear_form rage=-10)
+ SpellInfo(bear_form rage=-10 to_stance=druid_bear_form)
Define(berserk_bear 50334)
SpellInfo(berserk_bear cd=180)
SpellInfo(berserk_bear buff_cdr=cooldown_reduction_tank_buff specialization=guardian)
@@ -29,6 +29,7 @@ Define(berserk_cat 106951)
Define(berserk_cat_buff 106951)
SpellInfo(berserk_cat duration=15)
Define(cat_form 768)
+ SpellInfo(cat_form to_stance=druid_cat_form)
Define(celestial_alignment 112071)
SpellInfo(celestial_alignment cd=180)
SpellAddBuff(celestial_alignment celestial_alignment_buff=1)
@@ -185,6 +186,7 @@ Define(moonfire_debuff 8921)
SpellInfo(moonfire_debuff damage=BalanceMoonfireTickDamage specialization=balance)
SpellInfo(moonfire_debuff lastEstimatedDamage=BalanceMoonfireTickLastDamage specialization=balance)
Define(moonkin_form 24858)
+ SpellInfo(moonkin_form to_stance=druid_moonkin_form)
Define(natures_grace_buff 16886)
SpellInfo(natures_grace_buff duration=15)
Define(natures_swiftness 132158)
diff --git a/scripts/ovale_hunter_spells.lua b/scripts/ovale_hunter_spells.lua
index c8c5851..9ab9197 100644
--- a/scripts/ovale_hunter_spells.lua
+++ b/scripts/ovale_hunter_spells.lua
@@ -24,9 +24,9 @@ Define(arcane_shot 3044)
SpellAddBuff(arcane_shot thrill_of_the_hunt_buff=-1)
SpellAddTargetDebuff(arcane_shot hunters_mark_debuff=1)
Define(aspect_of_the_hawk 13165)
- SpellInfo(aspect_of_the_hawk cd=1)
+ SpellInfo(aspect_of_the_hawk cd=1 to_stance=hunter_aspect_of_the_hawk)
Define(aspect_of_the_iron_hawk 109260)
- SpellInfo(aspect_of_the_iron_hawk cd=1)
+ SpellInfo(aspect_of_the_iron_hawk cd=1 to_stance=hunter_aspect_of_the_iron_hawk)
Define(aspect_of_the_iron_hawk_talent 8)
Define(barrage 120360)
SpellInfo(barrage cd=30 focus=30)
diff --git a/scripts/ovale_monk_spells.lua b/scripts/ovale_monk_spells.lua
index 05c1584..d29bc11 100644
--- a/scripts/ovale_monk_spells.lua
+++ b/scripts/ovale_monk_spells.lua
@@ -157,8 +157,11 @@ Define(spear_hand_strike 116705)
Define(spinning_crane_kick 101546)
SpellInfo(spinning_crane_kick duration=2 haste=melee tick=0.75)
Define(stance_of_the_fierce_tiger 103985)
+ SpellInfo(stance_of_the_fierce_tiger to_stance=monk_stance_of_the_fierce_tiger)
Define(stance_of_the_sturdy_ox 115069)
+ SpellInfo(stance_of_the_sturdy_ox to_stance=monk_stance_of_the_sturdy_ox)
Define(stance_of_the_wise_serpent 115070)
+ SpellInfo(stance_of_the_wise_serpent to_stance=monk_stance_of_the_wise_serpent)
Define(summon_black_ox_statue 115315)
SpellInfo(summon_black_ox_statue cd=30)
Define(summon_jade_serpent_statue 115313)
diff --git a/scripts/ovale_paladin_spells.lua b/scripts/ovale_paladin_spells.lua
index ad2872f..1859fc1 100644
--- a/scripts/ovale_paladin_spells.lua
+++ b/scripts/ovale_paladin_spells.lua
@@ -208,8 +208,11 @@ Define(sacred_shield_talent 9)
Define(sanctified_wrath_talent 14)
Define(sanctity_of_battle 25956)
Define(seal_of_insight 20165)
+ SpellInfo(seal_of_insight to_stance=paladin_seal_of_insight)
Define(seal_of_righteousness 20154)
+ SpellInfo(seal_of_righteousness to_stance=paladin_seal_of_righteousness)
Define(seal_of_truth 31801)
+ SpellInfo(seal_of_truth to_stance=paladin_seal_of_truth)
Define(selfless_healer_buff 114250)
SpellInfo(selfless_healer_buff duration=15)
Define(selfless_healer_talent 7)
diff --git a/scripts/ovale_priest_spells.lua b/scripts/ovale_priest_spells.lua
index 2e8fbc3..bdbd997 100644
--- a/scripts/ovale_priest_spells.lua
+++ b/scripts/ovale_priest_spells.lua
@@ -68,6 +68,7 @@ Define(shadow_word_pain_debuff 589)
Define(shadowfiend 34433)
SpellInfo(shadowfiend cd=180)
Define(shadowform 15473)
+ SpellInfo(shadowform to_stance=priest_shadowform)
Define(silence 15487)
SpellInfo(silence cd=45)
Define(solace_and_insanity_talent 9)
diff --git a/scripts/ovale_rogue_spells.lua b/scripts/ovale_rogue_spells.lua
index 3e880ee..697eba2 100644
--- a/scripts/ovale_rogue_spells.lua
+++ b/scripts/ovale_rogue_spells.lua
@@ -183,7 +183,7 @@ Define(shadow_blades_buff 121471)
SpellInfo(shadow_blades_buff duration=12)
SpellInfo(shadow_blades_buff addduration=12 itemset=T14 itemcount=4)
Define(shadow_dance 51713)
- SpellInfo(shadow_dance cd=60)
+ SpellInfo(shadow_dance cd=60 to_stance=rogue_shadow_dance)
SpellInfo(shadow_dance buff_cdr=cooldown_reduction_agility_buff)
SpellAddBuff(shadow_dance shadow_dance_buff=1)
Define(shadow_dance_buff 51713)
@@ -214,7 +214,7 @@ Define(slice_and_dice 5171)
Define(slice_and_dice_buff 5171)
SpellInfo(slice_and_dice adddurationcp=6 duration=6 tick=3)
Define(stealth 1784)
- SpellInfo(stealth cd=6)
+ SpellInfo(stealth cd=6 to_stance=rogue_stealth)
SpellInfo(stealth addcd=-4 glyph=glyph_of_stealth)
SpellList(steath_buff 1784 11327)
Define(subterfuge_talent 2)
diff --git a/scripts/ovale_warlock_spells.lua b/scripts/ovale_warlock_spells.lua
index ef4b260..de825bb 100644
--- a/scripts/ovale_warlock_spells.lua
+++ b/scripts/ovale_warlock_spells.lua
@@ -125,7 +125,7 @@ Define(life_tap 1454)
Define(malefic_grasp 103103)
# SpellInfo(malefic_grasp channel=4 haste=spell) # XXX Don't interrupt channeling Malefic Grasp.
Define(metamorphosis 103958)
- SpellInfo(metamorphosis demonicfury=0 cd=10)
+ SpellInfo(metamorphosis demonicfury=0 cd=10 to_stance=warlock_metamorphosis)
SpellAddBuff(metamorphosis metamorphosis_buff=1)
Define(metamorphosis_buff 103958)
Define(molten_core_buff 122355)
diff --git a/scripts/ovale_warrior_spells.lua b/scripts/ovale_warrior_spells.lua
index 9bc5dae..45c2fa3 100644
--- a/scripts/ovale_warrior_spells.lua
+++ b/scripts/ovale_warrior_spells.lua
@@ -17,11 +17,11 @@ Define(battle_shout 6673)
SpellInfo(battle_shout cd=60 rage=-20)
SpellInfo(battle_shout cd=30 rage=-10 glyph=glyph_of_hoarse_voice)
Define(battle_stance 2457)
- SpellInfo(battle_stance cd=1.5)
+ SpellInfo(battle_stance cd=1.5 to_stance=warrior_battle_stance)
Define(berserker_rage 18499)
SpellInfo(berserker_rage cd=30 rage=-10)
Define(berserker_stance 2458)
- SpellInfo(berserker_stance cd=1.5)
+ SpellInfo(berserker_stance cd=1.5 to_stance=warrior_berserker_stance)
Define(bladestorm 46924)
SpellInfo(bladestorm cd=60)
SpellInfo(bladestorm buff_cdr=cooldown_reduction_strength_buff specialization=arms)
@@ -70,7 +70,7 @@ Define(deep_wounds 115767)
Define(deep_wounds_debuff 115767)
SpellInfo(deep_wounds_debuff duration=15 tick=3)
Define(defensive_stance 71)
- SpellInfo(defensive_stance cd=1.5)
+ SpellInfo(defensive_stance cd=1.5 to_stance=warrior_defensive_stance)
Define(demoralizing_banner 114203)
SpellInfo(demoralizing_banner cd=180)
Define(demoralizing_shout 1160)