Quantcast

Move all aura-related methods into OvaleAura and its state machine.

Johnny C. Lam [12-05-13 - 08:19]
Move all aura-related methods into OvaleAura and its state machine.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1239 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleData.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 2bdd753..eec5840 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -212,6 +212,24 @@ end
 local function IsWithinAuraLag(time1, time2)
 	return (time1 - time2 < self_auraLag/1000) and (time2 - time1 < self_auraLag/1000)
 end
+
+local function GetTickLength(auraId, snapshot)
+	local tick = 3
+	local si = OvaleData.spellInfo[auraId]
+	if si then
+		tick = si.tick or tick
+		local hasteMultiplier = 1
+		if si.haste then
+			if si.haste == "spell" then
+				hasteMultiplier = OvalePaperDoll:GetSpellHasteMultiplier(snapshot)
+			elseif si.haste == "melee" then
+				hasteMultiplier = OvalePaperDoll:GetMeleeHasteMultiplier(snapshot)
+			end
+			tick = tick / hasteMultiplier
+		end
+	end
+	return tick
+end
 --</private-static-methods>

 --<public-static-methods>
@@ -274,7 +292,7 @@ function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 				-- This isn't a known periodic aura, but it's ticking so treat this as the first tick.
 				local si = OvaleData.spellInfo[spellId]
 				if si and si.tick then
-					tick = OvaleData:GetTickLength(spellId, aura.snapshot)
+					tick = GetTickLength(spellId, aura.snapshot)
 				elseif bit_band(spellSchool, CLEU_SCHOOL_MASK_MAGIC) > 0 then
 					tick = 3 / OvalePaperDoll:GetSpellHasteMultiplier(aura.snapshot)
 				else
@@ -426,7 +444,7 @@ function OvaleAura:GainedAuraOnGUID(guid, atTime, auraId, casterGUID, filter, ic
 				-- Only set the initial tick information for new auras.
 				if not auraIsActive then
 					aura.ticksSeen = 0
-					aura.tick = OvaleData:GetTickLength(auraId, aura.snapshot)
+					aura.tick = GetTickLength(auraId, aura.snapshot)
 				end
 			end
 		end
@@ -692,6 +710,35 @@ local function GetStateAuraOnGUID(state, guid, auraId, filter, mine)
 	return auraFound
 end

+-- Returns the raw duration, DoT duration, tick length, and number of ticks of an aura.
+statePrototype.GetDuration = function(state, auraId, spellcast)
+	local snapshot, combo, holy
+	if spellcast then
+		snapshot, combo, holy = spellcast.snapshot, spellcast.combo, spellcast.holy
+	else
+		snapshot, combo, holy = state.snapshot, state.combo, state.holy
+	end
+
+	local duration = math.huge
+	local tick = GetTickLength(auraId, snapshot)
+
+	local si = OvaleData.spellInfo[auraId]
+	if si and si.duration then
+		duration = si.duration
+		if si.adddurationcp and combo then
+			duration = duration + si.adddurationcp * combo
+		end
+		if si.adddurationholy and holy then
+			duration = duration + si.adddurationholy * (holy - 1)
+		end
+	end
+
+	local numTicks = floor(duration/tick + 0.5)
+	local dotDuration = tick * numTicks
+
+	return duration, dotDuration, tick, numTicks
+end
+
 -- Print the auras matching the filter on the unit in alphabetical order.
 do
 	local array = {}
diff --git a/OvaleData.lua b/OvaleData.lua
index 2c2ee4e..0874d3e 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -13,11 +13,6 @@ local OvaleData = Ovale:NewModule("OvaleData")
 Ovale.OvaleData = OvaleData

 --<private-static-properties>
--- Forward declarations for module dependencies.
-local OvalePaperDoll = nil
-local OvaleState = nil
-
-local floor = math.floor
 local API_GetSpellCooldown = GetSpellCooldown

 -- Auras that are refreshed by spells that don't trigger a new snapshot.
@@ -248,20 +243,6 @@ OvaleData.buffSpellList.heroism = OvaleData.buffSpellList.burst_haste
 --</public-static-properties>

 --<public-static-methods>
-function OvaleData:OnInitialize()
-	-- Resolve module dependencies.
-	OvalePaperDoll = Ovale.OvalePaperDoll
-	OvaleState = Ovale.OvaleState
-end
-
-function OvaleData:OnEnable()
-	OvaleState:RegisterState(self, self.statePrototype)
-end
-
-function OvaleData:OnDisable()
-	OvaleState:UnregisterState(self)
-end
-
 function OvaleData:ResetSpellInfo()
 	self.spellInfo = {}
 end
@@ -330,69 +311,4 @@ function OvaleData:GetDamage(spellId, attackpower, spellpower, mainHandWeaponDam
 	end
 	return damage
 end
-
-function OvaleData:GetTickLength(auraId, snapshot)
-	local tick = 3
-	local si = self.spellInfo[auraId]
-	if si then
-		tick = si.tick or tick
-		local hasteMultiplier = 1
-		if si.haste then
-			if si.haste == "spell" then
-				hasteMultiplier = OvalePaperDoll:GetSpellHasteMultiplier(snapshot)
-			elseif si.haste == "melee" then
-				hasteMultiplier = OvalePaperDoll:GetMeleeHasteMultiplier(snapshot)
-			end
-			tick = tick / hasteMultiplier
-		end
-	end
-	return tick
-end
 --</public-static-methods>
-
---[[----------------------------------------------------------------------------
-	State machine for simulator.
---]]----------------------------------------------------------------------------
-
---<public-static-properties>
-OvaleData.statePrototype = {}
---</public-static-properties>
-
---<private-static-properties>
-local statePrototype = OvaleData.statePrototype
---</private-static-properties>
-
---<state-methods>
-statePrototype.GetTickLength = function(state, auraId, snapshot)
-	return OvaleData:GetTickLength(auraId, snapshot)
-end
-
--- Returns the raw duration, DoT duration, tick length, and number of ticks of an aura.
-statePrototype.GetDuration = function(state, auraId, spellcast)
-	local snapshot, combo, holy
-	if spellcast then
-		snapshot, combo, holy = spellcast.snapshot, spellcast.combo, spellcast.holy
-	else
-		snapshot, combo, holy = state.snapshot, state.combo, state.holy
-	end
-
-	local duration = math.huge
-	local tick = state:GetTickLength(auraId, snapshot)
-
-	local si = OvaleData.spellInfo[auraId]
-	if si and si.duration then
-		duration = si.duration
-		if si.adddurationcp and combo then
-			duration = duration + si.adddurationcp * combo
-		end
-		if si.adddurationholy and holy then
-			duration = duration + si.adddurationholy * (holy - 1)
-		end
-	end
-
-	local numTicks = floor(duration/tick + 0.5)
-	local dotDuration = tick * numTicks
-
-	return duration, dotDuration, tick, numTicks
-end
---</state-methods>