Quantcast

Improve encapsulation of OvaleData.

Johnny C. Lam [03-12-13 - 04:47]
Improve encapsulation of OvaleData.

Split out OvaleData:GetComputedSpellCD() into a new method GetSpellCD()
which queries the Blizzard API, and a second portion moved to
OvaleState:GetComputedSpellCD() that checks the frame state for any spell
CDs found there.  This de-couples OvaleData from OvaleState.

Use OvaleState:GetComputedSpellCD() in place of the removed
OvaleData:GetComputedSpellCD() in the various Ovale modules.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@757 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleBestAction.lua
OvaleCondition.lua
OvaleData.lua
OvaleState.lua
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index ea049d3..afe85df 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -102,7 +102,7 @@ function OvaleBestAction:GetActionInfo(element)
 			return nil
 		end

-		actionCooldownStart, actionCooldownDuration, actionEnable = OvaleData:GetComputedSpellCD(spellId)
+		actionCooldownStart, actionCooldownDuration, actionEnable = OvaleState:GetComputedSpellCD(spellId)
 		if not actionCooldownStart or not actionCooldownDuration then
 			Ovale:debugPrint("unknown_spells", "No cooldown data for spell "..spellId)
 		end
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index 1051272..b42f6f1 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -718,7 +718,7 @@ end
 	-- returns: bool
 OvaleCondition.conditions.cancast = function(condition)
 	local name, rank, icon, cost, isFunnel, powerType, castTime = OvaleData:GetSpellInfoOrNil(condition[1])
-	local actionCooldownStart, actionCooldownDuration, actionEnable = OvaleData:GetComputedSpellCD(condition[1])
+	local actionCooldownStart, actionCooldownDuration, actionEnable = OvaleState:GetComputedSpellCD(condition[1])
 	local startCast = actionCooldownStart + actionCooldownDuration
 	if startCast<OvaleState.currentTime then
 		startCast = OvaleState.currentTime
@@ -2372,7 +2372,7 @@ OvaleCondition.conditions.spellcooldown = function(condition)
 	elseif not OvaleData.spellList[condition[1]] then
 		return 0, nil, 0, OvaleState.currentTime + 3600, -1
 	else
-		local actionCooldownStart, actionCooldownDuration, actionEnable = OvaleData:GetComputedSpellCD(condition[1])
+		local actionCooldownStart, actionCooldownDuration, actionEnable = OvaleState:GetComputedSpellCD(condition[1])
 		return 0, nil, actionCooldownDuration, actionCooldownStart, -1
 	end
 end
diff --git a/OvaleData.lua b/OvaleData.lua
index 6d1e930..525e74f 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -14,9 +14,10 @@ OvaleData = Ovale:NewModule("OvaleData", "AceEvent-3.0")
 local ipairs, pairs, tinsert, tonumber, tostring, tsort = ipairs, pairs, table.insert, tonumber, tostring, table.sort
 local GetNumGlyphSockets = GetNumGlyphSockets
 local GetGlyphSocketInfo = GetGlyphSocketInfo
+local GetSpellCooldown = GetSpellCooldown
 local GetSpellBookItemInfo, GetSpellBookItemName = GetSpellBookItemInfo, GetSpellBookItemName
 local GetSpellInfo, GetSpellTabInfo, GetTalentInfo = GetSpellInfo, GetSpellTabInfo, GetTalentInfo
-local HasPetSpells, UnitBuff, UnitClass = HasPetSpells, UnitBuff, UnitClass
+local HasPetSpells = HasPetSpells
 local BOOKTYPE_SPELL, BOOKTYPE_PET = BOOKTYPE_SPELL, BOOKTYPE_PET
 local SPELL_POWER_ALTERNATE_POWER = SPELL_POWER_ALTERNATE_POWER
 local SPELL_POWER_BURNING_EMBERS = SPELL_POWER_BURNING_EMBERS
@@ -505,15 +506,16 @@ function OvaleData:GetGCD(spellId)

 	-- Default value
 	local class = OvalePaperDoll.class
-	if class == "ROGUE" or
-		(class == "MONK" and
-			(OvaleStance:IsStance("monk_stance_of_the_sturdy_ox") or OvaleStance:IsStance("monk_stance_of_the_fierce_tiger"))) or
-		(class == "DRUID" and OvaleStance:IsStance("druid_cat_form")) then
+	if class == "DEATHKNIGHT" or class == "ROGUE"
+		or (class == "MONK"
+			and (OvaleStance:IsStance("monk_stance_of_the_sturdy_ox")
+				or OvaleStance:IsStance("monk_stance_of_the_fierce_tiger")))
+		or (class == "DRUID" and OvaleStance:IsStance("druid_cat_form")) then
 		return 1.0
 	elseif class == "MAGE" or class == "WARLOCK" or class == "PRIEST" or
 			(class == "DRUID" and not OvaleStance:IsStance("druid_bear_form")) then
 		local cd = 1.5 / OvalePaperDoll:GetSpellHasteMultiplier()
-		if (cd<1) then
+		if cd < 1 then
 			cd = 1
 		end
 		return cd
@@ -523,30 +525,10 @@ function OvaleData:GetGCD(spellId)
 end

 --Compute the spell Cooldown
-function OvaleData:GetComputedSpellCD(spellId)
-	local actionCooldownStart, actionCooldownDuration, actionEnable
-	local cd = OvaleState:GetCD(spellId)
-	if cd and cd.start then
-		actionCooldownStart = cd.start
-		actionCooldownDuration = cd.duration
-		actionEnable = cd.enable
-	else
-		actionCooldownStart, actionCooldownDuration, actionEnable = GetSpellCooldown(spellId)
-		-- Les chevaliers de la mort ont des infos fausses sur le CD quand ils n'ont plus les runes
-		-- On force à 1,5s ou 1s en présence impie
-		-- TODO: is it still the case in MoP?
-		if OvalePaperDoll.class == "DEATHKNIGHT" and actionCooldownDuration == 10 and
-				(not self.spellInfo[spellId] or self.spellInfo[spellId].cd~=10) then
-			local impie = GetSpellInfo(48265)
-			if impie and UnitBuff("player", impie) then
-				actionCooldownDuration=1
-			else
-				actionCooldownDuration=1.5
-			end
-		end
-		if self.spellInfo[spellId] and self.spellInfo[spellId].forcecd then
-			actionCooldownStart, actionCooldownDuration = GetSpellCooldown(self.spellInfo[spellId].forcecd)
-		end
+function OvaleData:GetSpellCD(spellId)
+	local actionCooldownStart, actionCooldownDuration, actionEnable = GetSpellCooldown(spellId)
+	if self.spellInfo[spellId] and self.spellInfo[spellId].forcecd then
+		actionCooldownStart, actionCooldownDuration = GetSpellCooldown(self.spellInfo[spellId].forcecd)
 	end
 	return actionCooldownStart, actionCooldownDuration, actionEnable
 end
diff --git a/OvaleState.lua b/OvaleState.lua
index 32d95d2..f0c7c3e 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -465,6 +465,20 @@ function OvaleState:GetCD(spellId)
 	end
 end

+--Compute the spell Cooldown
+function OvaleState:GetComputedSpellCD(spellId)
+	local actionCooldownStart, actionCooldownDuration, actionEnable
+	local cd = self:GetCD(spellId)
+	if cd and cd.start then
+		actionCooldownStart = cd.start
+		actionCooldownDuration = cd.duration
+		actionEnable = cd.enable
+	else
+		actionCooldownStart, actionCooldownDuration, actionEnable = OvaleData:GetSpellCD(spellId)
+	end
+	return actionCooldownStart, actionCooldownDuration, actionEnable
+end
+
 function OvaleState:AddEclipse(endCast, spellId)
 	local newAura = self:NewAura(OvaleGUID.player, spellId)
 	newAura.start = endCast + 0.5