Quantcast

Modify some state mix-in methods to take an optional snapshot parameter.

Johnny C. Lam [11-26-13 - 14:05]
Modify some state mix-in methods to take an optional snapshot parameter.

This allows for computing haste multipliers relative to the correct
snapshot at the time the spell was cast.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1212 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCooldown.lua
OvaleData.lua
OvalePaperDoll.lua
OvaleRunes.lua
diff --git a/OvaleCooldown.lua b/OvaleCooldown.lua
index 5856643..f4f21ac 100644
--- a/OvaleCooldown.lua
+++ b/OvaleCooldown.lua
@@ -151,9 +151,9 @@ function OvaleCooldown:ApplySpellAfterCast(state, spellId, targetGUID, startCast
 			-- Adjust cooldown duration if it is affected by haste: "cd_haste=melee" or "cd_haste=spell".
 			if cd.duration > 0 and si.cd_haste then
 				if si.cd_haste == "melee" then
-					cd.duration = cd.duration / state:GetMeleeHasteMultiplier()
+					cd.duration = cd.duration / state:GetMeleeHasteMultiplier(spellcast.snapshot)
 				elseif si.cd_haste == "spell" then
-					cd.duration = cd.duration / state:GetSpellHasteMultiplier()
+					cd.duration = cd.duration / state:GetSpellHasteMultiplier(spellcast.snapshot)
 				end
 			end

diff --git a/OvaleData.lua b/OvaleData.lua
index 076a9db..07d5e2c 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -362,7 +362,7 @@ OvaleData.statePrototype = {}
 do
 	local statePrototype = OvaleData.statePrototype

-	statePrototype.GetTickLength = function(state, auraId)
+	statePrototype.GetTickLength = function(state, auraId, snapshot)
 		local tick = 3
 		local si = OvaleData.spellInfo[auraId]
 		if si then
@@ -370,9 +370,9 @@ do
 			local hasteMultiplier = 1
 			if si.haste then
 				if si.haste == "spell" then
-					hasteMultiplier = state:GetSpellHasteMultiplier()
+					hasteMultiplier = state:GetSpellHasteMultiplier(snapshot)
 				elseif si.haste == "melee" then
-					hasteMultiplier = state:GetMeleeHasteMultiplier()
+					hasteMultiplier = state:GetMeleeHasteMultiplier(snapshot)
 				end
 				tick = tick / hasteMultiplier
 			end
@@ -381,22 +381,29 @@ do
 	end

 	-- Returns the raw duration, DoT duration, tick length, and number of ticks of an aura.
-	statePrototype.GetDuration = function(state, auraId)
+	statePrototype.GetDuration = function(state, auraId, spellcast)
+		local snapshot, combo, holy
+		if spellcast then
+			snapshot, combo, holy = spellcast.snapshot, spellcast.combo, spellcast.holy
+		else
+			snapshot, combo, holy = state.snapshot, state.combo, state.holy
+		end
+
 		local duration = math.huge
-		local tick = state:GetTickLength(auraId)
+		local tick = state:GetTickLength(auraId, snapshot)

 		local si = OvaleData.spellInfo[auraId]
 		if si and si.duration then
 			duration = si.duration
-			if si.adddurationcp and state.combo then
-				duration = duration + si.adddurationcp * state.combo
+			if si.adddurationcp and combo then
+				duration = duration + si.adddurationcp * combo
 			end
-			if si.adddurationholy and state.holy then
-				duration = duration + si.adddurationholy * (state.holy - 1)
+			if si.adddurationholy and holy then
+				duration = duration + si.adddurationholy * (holy - 1)
 			end
 		end

-		local numTicks = floor(duration / tick + 0.5)
+		local numTicks = floor(duration/tick + 0.5)
 		local dotDuration = tick * numTicks

 		return duration, dotDuration, tick, numTicks
diff --git a/OvalePaperDoll.lua b/OvalePaperDoll.lua
index 502f0c8..4156473 100644
--- a/OvalePaperDoll.lua
+++ b/OvalePaperDoll.lua
@@ -513,20 +513,24 @@ end
 do
 	local statePrototype = OvalePaperDoll.statePrototype

-	statePrototype.GetMasteryMultiplier = function(state)
-		return 1 + state.snapshot.masteryEffect / 100
+	statePrototype.GetMasteryMultiplier = function(state, snapshot)
+		snapshot = snapshot or state.snapshot
+		return 1 + snapshot.masteryEffect / 100
 	end

-	statePrototype.GetMeleeHasteMultiplier = function(state)
-		return 1 + state.snapshot.meleeHaste / 100
+	statePrototype.GetMeleeHasteMultiplier = function(state, snapshot)
+		snapshot = snapshot or state.snapshot
+		return 1 + snapshot.meleeHaste / 100
 	end

-	statePrototype.GetRangedHasteMultiplier = function(state)
-		return 1 + state.snapshot.rangedHaste / 100
+	statePrototype.GetRangedHasteMultiplier = function(state, snapshot)
+		snapshot = snapshot or state.snapshot
+		return 1 + snapshot.rangedHaste / 100
 	end

-	statePrototype.GetSpellHasteMultiplier = function(state)
-		return 1 + state.snapshot.spellHaste / 100
+	statePrototype.GetSpellHasteMultiplier = function(state, snapshot)
+		snapshot = snapshot or state.snapshot
+		return 1 + snapshot.spellHaste / 100
 	end
 end
 --</state-methods>
diff --git a/OvaleRunes.lua b/OvaleRunes.lua
index a21f9c2..99c4c0f 100644
--- a/OvaleRunes.lua
+++ b/OvaleRunes.lua
@@ -211,7 +211,7 @@ function OvaleRunes:ApplySpellAfterCast(state, spellId, targetGUID, startCast, e
 			local count = si[name] or 0
 			while count > 0 do
 				local atTime = isChanneled and startCast or endCast
-				state:ConsumeRune(atTime, name)
+				state:ConsumeRune(atTime, name, spellcast.snapshot)
 				count = count - 1
 			end
 		end
@@ -236,7 +236,7 @@ do
 	end

 	-- Consume a rune of the given type.  Assume that the required runes are available.
-	statePrototype.ConsumeRune = function(state, atTime, name)
+	statePrototype.ConsumeRune = function(state, atTime, name, snapshot)
 		--[[
 			Find a usable rune, preferring a regular rune of that rune type over death
 			runes of that rune type over death runes of any rune type.
@@ -282,7 +282,7 @@ do
 					start = rune.endCooldown
 				end
 			end
-			local duration = 10 / state:GetSpellHasteMultiplier()
+			local duration = 10 / state:GetSpellHasteMultiplier(snapshot)
 			if OvaleStance:IsStance("death_knight_blood_presence") and OvaleSpellBook:IsKnownSpell(IMPROVED_BLOOD_PRESENCE) then
 				-- Improved Blood Presence increases rune regeneration rate by 20%.
 				duration = duration / 1.2