From 062d30e7f91a3a1ded2d2b31b0bbd9cda35d4ffc Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Tue, 19 Mar 2013 23:31:26 +0000 Subject: [PATCH] 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 --- OvaleBestAction.lua | 2 +- OvaleCondition.lua | 76 ++++++++------------------------------------------- OvaleState.lua | 47 +++++++++++++++---------------- 3 files changed, 37 insertions(+), 88 deletions(-) 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 = {} -- -- @@ -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 -- 1.7.9.5