Quantcast

Use simpler Lua idiom to express mix-in methods.

Johnny C. Lam [11-26-13 - 14:04]
Use simpler Lua idiom to express mix-in methods.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1203 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleCooldown.lua
OvaleFuture.lua
OvalePaperDoll.lua
OvalePower.lua
OvaleRunes.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 4565d27..eb6b880 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -636,8 +636,7 @@ do
 	local statePrototype = OvaleAura.statePrototype

 	-- Apply the auras caused by the given spell in the simulator.
-	function statePrototype:ApplySpellAuras(spellId, startCast, endCast, isChanneled, guid, auraList, spellcast)
-		local state = self
+	statePrototype.ApplySpellAuras = function(state, spellId, startCast, endCast, isChanneled, guid, auraList, spellcast)
 		local target = OvaleGUID:GetUnitId(guid)
 		for filter, filterInfo in pairs(auraList) do
 			for auraId, spellData in pairs(filterInfo) do
@@ -721,8 +720,7 @@ do
 		end
 	end

-	function statePrototype:GetAuraByGUID(guid, spellId, filter, mine, unitId)
-		local state = self
+	statePrototype.GetAuraByGUID = function(state, guid, spellId, filter, mine, unitId)
 		local auraFound
 		if mine then
 			local auraTable = state.aura[guid]
@@ -758,8 +756,7 @@ do
 		end
 	end

-	function statePrototype:GetAura(unitId, spellId, filter, mine)
-		local state = self
+	statePrototype.GetAura = function(state, unitId, spellId, filter, mine)
 		local guid = OvaleGUID:GetGUID(unitId)
 		if OvaleData.buffSpellList[spellId] then
 			local auraFound
@@ -777,8 +774,7 @@ do

 	-- Look for an aura on any target, excluding the given GUID.
 	-- Returns the earliest start time, the latest ending time, and the number of auras seen.
-	function statePrototype:GetAuraOnAnyTarget(spellId, filter, mine, excludingGUID)
-		local state = self
+	statePrototype.GetAuraOnAnyTarget = function(state, spellId, filter, mine, excludingGUID)
 		local start, ending, count = OvaleAura:GetAuraOnAnyTarget(spellId, filter, mine, excludingGUID)
 		-- TODO: This is broken because it doesn't properly account for removed auras in the current frame.
 		for guid, auraTable in pairs(state.aura) do
@@ -802,13 +798,11 @@ do
 		return start, ending, count
 	end

-	function statePrototype:IsActiveAura(aura)
-		local state = self
+	statePrototype.IsActiveAura = function(state, aura)
 		return (aura and aura.stacks > 0 and aura.start <= state.currentTime and state.currentTime <= aura.ending)
 	end

-	function statePrototype:NewAura(guid, spellId, filter, gain)
-		local state = self
+	statePrototype.NewAura = function(state, guid, spellId, filter, gain)
 		if not state.aura[guid] then
 			state.aura[guid] = {}
 		end
@@ -825,8 +819,7 @@ do
 		return aura
 	end

-	function statePrototype:GetDamageMultiplier(spellId)
-		local state = self
+	statePrototype.GetDamageMultiplier = function(state, spellId)
 		local damageMultiplier = 1
 		if spellId then
 			local si = OvaleData.spellInfo[spellId]
@@ -850,8 +843,7 @@ do
 	end

 	-- Returns the duration, tick length, and number of ticks of an aura.
-	function statePrototype:GetDuration(auraSpellId)
-		local state = self
+	statePrototype.GetDuration = function(state, auraSpellId)
 		local si
 		if type(auraSpellId) == "number" then
 			si = OvaleData.spellInfo[auraSpellId]
@@ -888,8 +880,7 @@ do
 	end

 	-- Add a new aura to the unit specified by GUID.
-	function statePrototype:AddAuraToGUID(guid, spellId, filter, mine, start, ending)
-		local state = self
+	statePrototype.AddAuraToGUID = function(state, guid, spellId, filter, mine, start, ending)
 		local aura = state:NewAura(guid, spellId, filter, start)
 		aura.mine = mine
 		aura.start = start
diff --git a/OvaleCooldown.lua b/OvaleCooldown.lua
index e23205c..7b17a6f 100644
--- a/OvaleCooldown.lua
+++ b/OvaleCooldown.lua
@@ -168,8 +168,7 @@ do
 	local statePrototype = OvaleCooldown.statePrototype

 	-- Return the table holding the simulator's cooldown information for the given spell.
-	function statePrototype:GetCD(spellId)
-		local state = self
+	statePrototype.GetCD = function(state, spellId)
 		if spellId then
 			local si = OvaleData.spellInfo[spellId]
 			if si and si.cd then
@@ -184,10 +183,9 @@ do
 	end

 	-- Return the cooldown for the spell in the simulator.
-	function statePrototype:GetSpellCooldown(spellId)
-		local state = self
+	statePrototype.GetSpellCooldown = function(state, spellId)
 		local start, duration, enable
-		local cd = state:GetCD(spellId)
+		local cd = state:GetCD(state, spellId)
 		if cd and cd.start then
 			start = cd.start
 			duration = cd.duration
@@ -199,10 +197,9 @@ do
 	end

 	-- Force the cooldown of a spell to reset at the specified time.
-	function statePrototype:ResetSpellCooldown(spellId, atTime)
-		local state = self
+	statePrototype.ResetSpellCooldown = function(state, spellId, atTime)
 		if atTime >= state.currentTime then
-			local cd = state:GetCD(spellId)
+			local cd = state:GetCD(state, spellId)
 			cd.start = state.currentTime
 			cd.duration = atTime - state.currentTime
 			cd.enable = 1
diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index e7e9702..1aaebb1 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -606,8 +606,7 @@ end
 do
 	local statePrototype = OvaleFuture.statePrototype

-	function statePrototype:GetCounterValue(id)
-		local state = self
+	statePrototype.GetCounterValue = function(state, id)
 		return state.counter[id] and state.counter[id] or 0
 	end
 end
diff --git a/OvalePaperDoll.lua b/OvalePaperDoll.lua
index 4a95fdd..ef7c861 100644
--- a/OvalePaperDoll.lua
+++ b/OvalePaperDoll.lua
@@ -512,23 +512,19 @@ end
 do
 	local statePrototype = OvalePaperDoll.statePrototype

-	function statePrototype:GetMasteryMultiplier()
-		local state = self
+	statePrototype.GetMasteryMultiplier = function(state)
 		return 1 + state.snapshot.masteryEffect / 100
 	end

-	function statePrototype:GetMeleeHasteMultiplier()
-		local state = self
+	statePrototype.GetMeleeHasteMultiplier = function(state)
 		return 1 + state.snapshot.meleeHaste / 100
 	end

-	function statePrototype:GetRangedHasteMultiplier()
-		local state = self
+	statePrototype.GetRangedHasteMultiplier = function(state)
 		return 1 + state.snapshot.rangedHaste / 100
 	end

-	function statePrototype:GetSpellHasteMultiplier()
-		local state = self
+	statePrototype.GetSpellHasteMultiplier = function(state)
 		return 1 + state.snapshot.spellHaste / 100
 	end
-end
\ No newline at end of file
+end
diff --git a/OvalePower.lua b/OvalePower.lua
index 160e8f6..91c2314 100644
--- a/OvalePower.lua
+++ b/OvalePower.lua
@@ -311,8 +311,7 @@ do
 	local statePrototype = OvalePower.statePrototype

 	-- Print out the levels of each power type in the current state.
-	function statePrototype:DebugPower()
-		local state = self
+	statePrototype.DebugPower = function(state)
 		for powerType in pairs(OvalePower.POWER_INFO) do
 			Ovale:FormatPrint("%s = %d", powerType, state[powerType])
 		end
diff --git a/OvaleRunes.lua b/OvaleRunes.lua
index b62c4a3..62b865e 100644
--- a/OvaleRunes.lua
+++ b/OvaleRunes.lua
@@ -223,7 +223,7 @@ end
 do
 	local statePrototype = OvaleRunes.statePrototype

-	function statePrototype:DebugRunes()
+	statePrototype.DebugRunes = function(state)
 		local now = state.currentTime
 		for slot = 1, 6 do
 			local rune = self.rune[slot]
@@ -236,8 +236,7 @@ do
 	end

 	-- Consume a rune of the given type.  Assume that the required runes are available.
-	function statePrototype:ConsumeRune(atTime, name)
-		local state = self
+	statePrototype.ConsumeRune = function(state, atTime, name)
 		--[[
 			Find a usable rune, preferring a regular rune of that rune type over death
 			runes of that rune type over death runes of any rune type.
@@ -306,8 +305,7 @@ do
 		end
 	end

-	function statePrototype:RuneCount(name, death)
-		local state = self
+	statePrototype.RuneCount = function(state, name, death)
 		local count = 0
 		local startCooldown, endCooldown = math.huge, math.huge
 		local runeType = RUNE_TYPE[name]
@@ -375,9 +373,7 @@ do
 		-- The latest time till a rune of that type is off cooldown, indexed by rune type.
 		local runeEndCooldown = {}

-		function statePrototype:GetRunesCooldown(blood, unholy, frost, death, deathCondition)
-			local state = self
-
+		statePrototype.GetRunesCooldown = function(state, blood, unholy, frost, death, deathCondition)
 			-- Initialize static variables.
 			runeCount[BLOOD_RUNE] = blood or 0
 			runeCount[UNHOLY_RUNE] = unholy or 0