Quantcast

De-couple OvaleFuture from OvaleComboPoints and OvalePower.

Johnny C. Lam [05-21-14 - 13:07]
De-couple OvaleFuture from OvaleComboPoints and OvalePower.

Add a way for modules to register additional information that they would
like to save to a spellcast at the time that it is cast.  This information
can be later retrieved by other modules.

Let OvaleComboPoints and OvalePower manage spellcast.combo and
spellcast.holy, respectively.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1475 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleComboPoints.lua
OvaleFuture.lua
OvalePower.lua
diff --git a/OvaleComboPoints.lua b/OvaleComboPoints.lua
index c5d2d7e..3837df8 100644
--- a/OvaleComboPoints.lua
+++ b/OvaleComboPoints.lua
@@ -15,7 +15,9 @@ Ovale.OvaleComboPoints = OvaleComboPoints

 --<private-static-properties>
 -- Forward declarations for module dependencies.
+local OvaleAura = nil
 local OvaleData = nil
+local OvaleFuture = nil
 local OvaleGUID = nil
 local OvaleState = nil

@@ -25,16 +27,54 @@ local MAX_COMBO_POINTS = MAX_COMBO_POINTS

 -- Player's class.
 local _, self_class = API_UnitClass("player")
+
+-- Table of functions to update spellcast information to register with OvaleFuture.
+local self_updateSpellcastInfo = {}
 --</private-static-properties>

 --<public-static-properties>
 OvaleComboPoints.combo = 0
 --</public-static-properties>

+--<private-static-methods>
+-- Manage spellcast.combo information.
+local function SaveToSpellcast(spellcast)
+	if spellcast.spellId then
+		local si = OvaleData.spellInfo[spellcast.spellId]
+		if si.combo == "finisher" then
+			-- If a buff is present that removes the combo point cost of the spell,
+			-- then treat it as a maximum combo-point finisher.
+			if si.buff_combo_none then
+				if OvaleAura:GetAura("player", si.buff_combo_none) then
+					spellcast.combo = MAX_COMBO_POINTS
+				end
+			end
+			local min_combo = si.min_combo or si.mincombo or 1
+			if OvaleComboPoints.combo >= min_combo then
+				spellcast.combo = OvaleComboPoints.combo
+			end
+		end
+	end
+end
+
+local function UpdateFromSpellcast(dest, spellcast)
+	if spellcast.combo then
+		dest.combo = spellcast.combo
+	end
+end
+
+do
+	self_updateSpellcastInfo.SaveToSpellcast = SaveToSpellcast
+	self_updateSpellcastInfo.UpdateFromSpellcast = UpdateFromSpellcast
+end
+--</private-static-methods>
+
 --<public-static-methods>
 function OvaleComboPoints:OnInitialize()
 	-- Resolve module dependencies.
+	OvaleAura = Ovale.OvaleAura
 	OvaleData = Ovale.OvaleData
+	OvaleFuture = Ovale.OvaleFuture
 	OvaleGUID = Ovale.OvaleGUID
 	OvaleState = Ovale.OvaleState
 end
@@ -48,12 +88,14 @@ function OvaleComboPoints:OnEnable()
 		self:RegisterEvent("UNIT_COMBO_POINTS")
 		self:RegisterEvent("UNIT_TARGET", "UNIT_COMBO_POINTS")
 		OvaleState:RegisterState(self, self.statePrototype)
+		OvaleFuture:RegisterSpellcastInfo(self_updateSpellcastInfo)
 	end
 end

 function OvaleComboPoints:OnDisable()
 	if self_class == "ROGUE" or self_class == "DRUID" then
 		OvaleState:UnregisterState(self)
+		OvaleFuture:UnregisterSpellcastInfo(self_updateSpellcastInfo)
 		self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
 		self:UnregisterEvent("PLAYER_ENTERING_WORLD")
 		self:UnregisterEvent("PLAYER_LOGIN")
diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index a2c3e4c..da901ec 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -19,11 +19,9 @@ local OvalePool = Ovale.OvalePool

 -- Forward declarations for module dependencies.
 local OvaleAura = nil
-local OvaleComboPoints = nil
 local OvaleData = nil
 local OvaleGUID = nil
 local OvalePaperDoll = nil
-local OvalePower = nil
 local OvaleScore = nil
 local OvaleSpellBook = nil
 local OvaleState = nil
@@ -65,6 +63,9 @@ local self_lastTarget = nil
 -- Time at which a player aura was last added.
 local self_timeAuraAdded = nil

+-- Table of external functions to save additional data about a spellcast.
+local self_updateSpellcastInfo = {}
+
 local OVALE_UNKNOWN_GUID = 0

 -- These CLEU events are eventually received after a successful spellcast.
@@ -187,38 +188,10 @@ local function AddSpellToQueue(spellId, lineId, startTime, endTime, channeled, a
 			end
 		end

-		-- Save the number of combo points used if this spell is a finisher.
-		if si.combo == "finisher" then
-			-- If a buff is present that removes the combo point cost of the spell,
-			-- then treat it as a maximum combo-point finisher.
-			if si.buff_combo_none then
-				if OvaleAura:GetAura("player", si.buff_combo_none) then
-					spellcast.combo = MAX_COMBO_POINTS
-				end
-			end
-			local min_combo = si.min_combo or si.mincombo or 1
-			if OvaleComboPoints.combo >= min_combo then
-				spellcast.combo = OvaleComboPoints.combo
-			end
-		end
-
-		-- Save the number of holy power used if this spell is a finisher.
-		if si.holy == "finisher" then
-			local max_holy = si.max_holy or 3
-			-- If a buff is present that removes the holy power cost of the spell,
-			-- then treat it as using the maximum amount of holy power.
-			if si.buff_holy_none then
-				if OvaleAura:GetAura("player", si.buff_holy_none) then
-					spellcast.holy = max_holy
-				end
-			end
-			local holy = OvalePower.power.holy
-			if holy > 0 then
-				if holy > max_holy then
-					spellcast.holy = max_holy
-				else
-					spellcast.holy = holy
-				end
+		-- Save additional information to the spellcast that are registered with this module.
+		for tbl in pairs(self_updateSpellcastInfo) do
+			if tbl.SaveToSpellcast then
+				tbl.SaveToSpellcast(spellcast)
 			end
 		end

@@ -328,11 +301,9 @@ end
 function OvaleFuture:OnInitialize()
 	-- Resolve module dependencies.
 	OvaleAura = Ovale.OvaleAura
-	OvaleComboPoints = Ovale.OvaleComboPoints
 	OvaleData = Ovale.OvaleData
 	OvaleGUID = Ovale.OvaleGUID
 	OvalePaperDoll = Ovale.OvalePaperDoll
-	OvalePower = Ovale.OvalePower
 	OvaleScore = Ovale.OvaleScore
 	OvaleSpellBook = Ovale.OvaleSpellBook
 	OvaleState = Ovale.OvaleState
@@ -603,11 +574,11 @@ function OvaleFuture:UpdateSnapshotFromSpellcast(dest, spellcast)
 	if spellcast.damageMultiplier then
 		dest.damageMultiplier = spellcast.damageMultiplier
 	end
-	if spellcast.combo then
-		dest.combo = spellcast.combo
-	end
-	if spellcast.holy then
-		dest.holy = spellcast.holy
+	-- Update additional information from the spellcast that are registered with this module.
+	for tbl in pairs(self_updateSpellcastInfo) do
+		if tbl.UpdateFromSpellcast then
+			tbl.UpdateFromSpellcast(dest, spellcast)
+		end
 	end
 end

@@ -630,6 +601,14 @@ function OvaleFuture:InFlight(spellId)
 	return false
 end

+function OvaleFuture:RegisterSpellcastInfo(functionTable)
+	self_updateSpellcastInfo[functionTable] = true
+end
+
+function OvaleFuture:UnregisterSpellcastInfo(functionTable)
+	self_updateSpellcastInfo[functionTable] = nil
+end
+
 function OvaleFuture:Debug()
 	if next(self_activeSpellcast) then
 		Ovale:Print("Spells in flight:")
diff --git a/OvalePower.lua b/OvalePower.lua
index 2f1cf03..883e4c0 100644
--- a/OvalePower.lua
+++ b/OvalePower.lua
@@ -14,6 +14,8 @@ Ovale.OvalePower = OvalePower

 --<private-static-properties>
 -- Forward declarations for module dependencies.
+local OvaleAura = nil
+local OvaleFuture = nil
 local OvaleData = nil
 local OvaleState = nil

@@ -38,6 +40,9 @@ local SPELL_POWER_RAGE = SPELL_POWER_RAGE
 local SPELL_POWER_RUNIC_POWER = SPELL_POWER_RUNIC_POWER
 local SPELL_POWER_SHADOW_ORBS = SPELL_POWER_SHADOW_ORBS
 local SPELL_POWER_SOUL_SHARDS = SPELL_POWER_SOUL_SHARDS
+
+-- Table of functions to update spellcast information to register with OvaleFuture.
+local self_updateSpellcastInfo = {}
 --</private-static-properties>

 --<public-static-properties>
@@ -99,10 +104,51 @@ do
 end
 --</public-static-properties>

+--<private-static-methods>
+-- Manage spellcast.holy information.
+local function SaveToSpellcast(spellcast)
+	if spellcast.spellId then
+		local si = OvaleData.spellInfo[spellcast.spellId]
+		-- Save the number of holy power used if this spell is a finisher.
+		if si.holy == "finisher" then
+			local max_holy = si.max_holy or 3
+			-- If a buff is present that removes the holy power cost of the spell,
+			-- then treat it as using the maximum amount of holy power.
+			if si.buff_holy_none then
+				if OvaleAura:GetAura("player", si.buff_holy_none) then
+					spellcast.holy = max_holy
+				end
+			end
+			local holy = OvalePower.power.holy
+			if holy > 0 then
+				if holy > max_holy then
+					spellcast.holy = max_holy
+				else
+					spellcast.holy = holy
+				end
+			end
+		end
+	end
+end
+
+local function UpdateFromSpellcast(dest, spellcast)
+	if spellcast.holy then
+		dest.holy = spellcast.holy
+	end
+end
+
+do
+	self_updateSpellcastInfo.SaveToSpellcast = SaveToSpellcast
+	self_updateSpellcastInfo.UpdateFromSpellcast = UpdateFromSpellcast
+end
+--</private-static-methods>
+
 --<public-static-methods>
 function OvalePower:OnInitialize()
 	-- Resolve module dependencies.
+	OvaleAura = Ovale.OvaleAura
 	OvaleData = Ovale.OvaleData
+	OvaleFuture = Ovale.OvaleFuture
 	OvaleState = Ovale.OvaleState
 end

@@ -121,10 +167,12 @@ function OvalePower:OnEnable()
 	self:RegisterEvent("UNIT_SPELL_HASTE", "UNIT_RANGEDDAMAGE")
 	self:RegisterMessage("Ovale_StanceChanged", "EventHandler")
 	OvaleState:RegisterState(self, self.statePrototype)
+	OvaleFuture:RegisterSpellcastInfo(self_updateSpellcastInfo)
 end

 function OvalePower:OnDisable()
 	OvaleState:UnregisterState(self)
+	OvaleFuture:UnregisterSpellcastInfo(self_updateSpellcastInfo)
 	self:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
 	self:UnregisterEvent("PLAYER_ALIVE")
 	self:UnregisterEvent("PLAYER_ENTERING_WORLD")