Quantcast

Re-add correct implementation of damage=Func SpellInfo parameter.

Johnny C. Lam [04-25-14 - 20:56]
Re-add correct implementation of damage=Func SpellInfo parameter.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1326 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCompile.lua
OvaleCondition.lua
conditions/Damage.lua
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 6512181..0de0949 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -92,6 +92,7 @@ local OVALE_FUNCTIONS = {
 --<public-static-properties>
 --master nodes of the current script (one node for each icon)
 OvaleCompile.masterNodes = {}
+OvaleCompile.customFunctionNode = {}
 --</public-static-properties>

 --<private-static-methods>
@@ -755,6 +756,7 @@ local function CompileDeclarations(text)
 end

 local function CompileScript(text)
+	local self = OvaleCompile
 	self_compileOnItems = false
 	self_compileOnStances = false
 	Ovale.bug = false
@@ -764,6 +766,7 @@ local function CompileScript(text)
 	wipe(self_customFunctions)
 	wipe(self_missingSpellList)
 	wipe(self_functionCalls)
+	wipe(self.customFunctionNode)

 	-- Return all existing nodes to the node pool.
 	for i, node in pairs(self_node) do
@@ -792,6 +795,8 @@ local function CompileScript(text)
 		local node = ParseAddFunction(name, p, t)
 		if node then
 			self_customFunctions[name] = node
+			local nodeId = strmatch(node, "node(%d+)")
+			self.customFunctionNode[name] = self_node[tonumber(nodeId)]
 		end
 	end

diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index daea14a..36656b6 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -47,6 +47,11 @@ local OvaleCondition = Ovale:NewModule("OvaleCondition")
 Ovale.OvaleCondition = OvaleCondition

 --<private-static-properties>
+-- Forward declarations for module dependencies.
+local OvaleBestAction = nil
+local OvaleCompile = nil
+local OvaleData = nil
+
 local type = type
 local wipe = table.wipe

@@ -75,6 +80,13 @@ OvaleCondition.TestValue = nil
 --</public-static-properties>

 --<public-static-methods>
+function OvaleCondition:OnInitialize()
+	-- Resolve module dependencies.
+	OvaleBestAction = Ovale.OvaleBestAction
+	OvaleCompile = Ovale.OvaleCompile
+	OvaleData = Ovale.OvaleData
+end
+
 function OvaleCondition:RegisterCondition(name, isSpellbookCondition, func, arg)
 	if arg then
 		if type(func) == "string" then
@@ -105,9 +117,29 @@ function OvaleCondition:EvaluateCondition(name, ...)
 	return self_condition[name](...)
 end

+function OvaleCondition.ComputeParameter(spellId, paramName, state)
+	local si = OvaleData:GetSpellInfo(spellId)
+	if si and si[paramName] then
+		local name = si[paramName]
+		local node = OvaleCompile.customFunctionNode[name]
+		if node then
+			local timeSpan, priority, element = OvaleBestAction:Compute(node, state)
+			if element and element.type == "value" then
+				local value = element.value + (state.currentTime - element.origin) * element.rate
+				return value
+			end
+		else
+			return si[paramName]
+		end
+	end
+	return nil
+end
+
 OvaleCondition.ParseCondition = function(condition, defaultTarget)
 	defaultTarget = defaultTarget or "player"
 	local target = condition.target or defaultTarget
+	-- Side-effect: set condition.target to the correct value if not present.
+	condition.target = condition.target or target
 	if target == "target" then
 		target = OvaleCondition.defaultTarget
 	end
diff --git a/conditions/Damage.lua b/conditions/Damage.lua
index a6e58d4..d6e697e 100644
--- a/conditions/Damage.lua
+++ b/conditions/Damage.lua
@@ -15,6 +15,7 @@ do
 	local OvaleState = Ovale.OvaleState

 	local Compare = OvaleCondition.Compare
+	local ComputeParameter = OvaleCondition.ComputeParameter
 	local state = OvaleState.state

 	-- Return the non-critical-strike damage of a spell, given the player's current stats.
@@ -45,9 +46,13 @@ do

 	local function CritDamage(condition)
 		local spellId, comparator, limit = condition[1], condition[2], condition[3]
+		local value = ComputeParameter(spellId, "damage", state)
+		if not value then
+			value = GetDamage(spellId)
+		end
 		-- TODO: Need to account for increased crit effect from meta-gems.
 		local critFactor = 2
-		local value = critFactor * GetDamage(spellId)
+		local value = critFactor * value
 		return Compare(value, comparator, limit)
 	end

@@ -75,7 +80,10 @@ do

 	local function Damage(condition)
 		local spellId, comparator, limit = condition[1], condition[2], condition[3]
-		local value = GetDamage(spellId)
+		local value = ComputeParameter(spellId, "damage", state)
+		if not value then
+			value = GetDamage(spellId)
+		end
 		return Compare(value, comparator, limit)
 	end