Quantcast

Rename OvaleState:GetRunes to GetRunesCooldown() and be more DRY.

Johnny C. Lam [03-19-13 - 23:31]
Rename OvaleState:GetRunes to GetRunesCooldown() and be more DRY.

Make OvaleConditions use OvaleState:GetRunesCooldown() instead of
reimplementing almost the exact same function.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@800 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleBestAction.lua
OvaleCondition.lua
OvaleState.lua
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index cf36ef0..979d5b2 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -146,7 +146,7 @@ function OvaleBestAction:GetActionInfo(element)
 			end
 			if actionCooldownStart and actionCooldownDuration then
 				if si.blood or si.frost or si.unholy or si.death then
-					local runecd = OvaleState:GetRunes(si.blood, si.frost, si.unholy, si.death, false)
+					local runecd = OvaleState:GetRunesCooldown(si.blood, si.frost, si.unholy, si.death, false)
 					if runecd > actionCooldownStart + actionCooldownDuration then
 						actionCooldownDuration = runecd - actionCooldownStart
 					end
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index 2fa3b24..8929f81 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -66,7 +66,6 @@ local API_UnitPower = UnitPower
 local API_UnitPowerMax = UnitPowerMax

 local self_runes = {}
-local self_runesCD = {}

 local self_lastSaved = {}
 local self_savedHealth = {}
@@ -241,70 +240,19 @@ local function GetRuneCount(type, death)
 	end
 end

-local function GetRune(condition)
-	local nombre = 0
-	local nombreCD = 0
-	local maxCD = nil
-
-	for i=1,4 do
-		self_runes[i] = 0
-		self_runesCD[i] = 0
+local function GetRunesCooldown(condition)
+	for k in pairs(OVALE_RUNETYPE) do
+		self_runes[k] = 0
 	end
-
-	local k=1
+
+	local k = 1
 	while true do
-		local type = OVALE_RUNETYPE[condition[k*2-1]]
-		if not type then
-			break
-		end
-		local howMany = condition[k*2]
-		self_runes[type] = self_runes[type] + howMany
-		k = k + 1
-	end
-
-	for i=1,6 do
-		local rune = OvaleState.state.rune[i]
-		if rune then
-			if self_runes[rune.type] > 0 then
-				self_runes[rune.type] = self_runes[rune.type] - 1
-				if rune.cd > self_runesCD[rune.type] then
-					self_runesCD[rune.type] = rune.cd
-				end
-			elseif rune.cd < self_runesCD[rune.type] then
-				self_runesCD[rune.type] = rune.cd
-			end
-		end
-	end
-
-	if not condition.nodeath then
-		for i=1,6 do
-			local rune = OvaleState.state.rune[i]
-			if rune and rune.type == 4 then
-				for j=1,3 do
-					if self_runes[j]>0 then
-						self_runes[j] = self_runes[j] - 1
-						if rune.cd > self_runesCD[j] then
-							self_runesCD[j] = rune.cd
-						end
-						break
-					elseif rune.cd < self_runesCD[j] then
-						self_runesCD[j] = rune.cd
-						break
-					end
-				end
-			end
-		end
-	end
-
-	for i=1,4 do
-		if self_runes[i]> 0 then
-			return nil
-		end
-		if not maxCD or self_runesCD[i]>maxCD then
-			maxCD = self_runesCD[i]
-		end
+		local type = condition[2 * k - 1]
+		if not OVALE_RUNETYPE[type] then break end
+		self_runes[type] = self_runes[type] + condition[2 * k]
+		k = k + 1
 	end
-	return maxCD
+	return OvaleState:GetRunesCooldown(self_runes.blood, self_runes.frost, self_runes.unholy, self_runes.death, condition.nodeath)
 end

 local lastEnergyValue = nil
@@ -2224,7 +2172,7 @@ end
 -- if Runes(frost 1) Spell(howling_blast)

 OvaleCondition.conditions.runes = function(condition)
-	return GetRune(condition)
+	return GetRunesCooldown(condition)
 end

 --- Get the current number of runes of the given type for death knights.
@@ -2262,7 +2210,7 @@ end
 -- if Runes(frost 1) Spell(howling_blast)

 OvaleCondition.conditions.runescooldown = function(condition)
-	local ret = GetRune(condition)
+	local ret = GetRunesCooldown(condition)
 	if not ret then
 		return nil
 	end
diff --git a/OvaleState.lua b/OvaleState.lua
index cb93cd8..f6afa68 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -35,8 +35,8 @@ local API_UnitPower = UnitPower
 local API_UnitPowerMax = UnitPowerMax
 local MAX_COMBO_POINTS = MAX_COMBO_POINTS

-local runes = {}
-local runesCD = {}
+local self_runes = {}
+local self_runesCD = {}
 --</private-static-properties>

 --<public-static-properties>
@@ -583,30 +583,31 @@ function OvaleState:GetEclipseDir()
 	end
 end

-function OvaleState:GetRunes(blood, frost, unholy, death, nodeath)
+-- Returns the cooldown time before all of the required runes are available.
+function OvaleState:GetRunesCooldown(blood, frost, unholy, death, nodeath)
 	local nombre = 0
 	local nombreCD = 0
 	local maxCD = nil

 	for i=1,4 do
-		runesCD[i] = 0
+		self_runesCD[i] = 0
 	end

-	runes[1] = blood or 0
-	runes[2] = frost or 0
-	runes[3] = unholy or 0
-	runes[4] = death or 0
+	self_runes[1] = blood or 0
+	self_runes[2] = frost or 0
+	self_runes[3] = unholy or 0
+	self_runes[4] = death or 0

 	for i=1,6 do
 		local rune = self.state.rune[i]
 		if rune then
-			if runes[rune.type] > 0 then
-				runes[rune.type] = runes[rune.type] - 1
-				if rune.cd > runesCD[rune.type] then
-					runesCD[rune.type] = rune.cd
+			if self_runes[rune.type] > 0 then
+				self_runes[rune.type] = self_runes[rune.type] - 1
+				if rune.cd > self_runesCD[rune.type] then
+					self_runesCD[rune.type] = rune.cd
 				end
-			elseif rune.cd < runesCD[rune.type] then
-				runesCD[rune.type] = rune.cd
+			elseif rune.cd < self_runesCD[rune.type] then
+				self_runesCD[rune.type] = rune.cd
 			end
 		end
 	end
@@ -616,14 +617,14 @@ function OvaleState:GetRunes(blood, frost, unholy, death, nodeath)
 			local rune = self.state.rune[i]
 			if rune and rune.type == 4 then
 				for j=1,3 do
-					if runes[j]>0 then
-						runes[j] = runes[j] - 1
-						if rune.cd > runesCD[j] then
-							runesCD[j] = rune.cd
+					if self_runes[j]>0 then
+						self_runes[j] = self_runes[j] - 1
+						if rune.cd > self_runesCD[j] then
+							self_runesCD[j] = rune.cd
 						end
 						break
-					elseif rune.cd < runesCD[j] then
-						runesCD[j] = rune.cd
+					elseif rune.cd < self_runesCD[j] then
+						self_runesCD[j] = rune.cd
 						break
 					end
 				end
@@ -632,11 +633,11 @@ function OvaleState:GetRunes(blood, frost, unholy, death, nodeath)
 	end

 	for i=1,4 do
-		if runes[i]> 0 then
+		if self_runes[i]> 0 then
 			return nil
 		end
-		if not maxCD or runesCD[i]>maxCD then
-			maxCD = runesCD[i]
+		if not maxCD or self_runesCD[i]>maxCD then
+			maxCD = self_runesCD[i]
 		end
 	end
 	return maxCD