Quantcast

Check that an aura is active by checking its stacks and start/end times.

Johnny C. Lam [11-26-13 - 14:04]
Check that an aura is active by checking its stacks and start/end times.

This is a prelude to allowing expired auras to be returned by aura
functions.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1202 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleComboPoints.lua
OvaleCooldown.lua
OvaleEclipse.lua
OvaleFuture.lua
OvalePower.lua
conditions/BuffAmount.lua
conditions/BuffComboPoints.lua
conditions/BuffDamageMultiplier.lua
conditions/BuffDuration.lua
conditions/BuffExpires.lua
conditions/BuffGain.lua
conditions/BuffRemains.lua
conditions/BuffSnapshot.lua
conditions/BuffStacks.lua
conditions/IsFeared.lua
conditions/IsIncapacitated.lua
conditions/IsRooted.lua
conditions/IsStunned.lua
conditions/NextTick.lua
conditions/StaggerRemains.lua
conditions/TickTime.lua
conditions/Ticks.lua
conditions/TicksAdded.lua
conditions/TicksRemain.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 487e0c9..4565d27 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -802,6 +802,11 @@ do
 		return start, ending, count
 	end

+	function statePrototype:IsActiveAura(aura)
+		local state = self
+		return (aura and aura.stacks > 0 and aura.start <= state.currentTime and state.currentTime <= aura.ending)
+	end
+
 	function statePrototype:NewAura(guid, spellId, filter, gain)
 		local state = self
 		if not state.aura[guid] then
diff --git a/OvaleComboPoints.lua b/OvaleComboPoints.lua
index b5e3201..5b3fb75 100644
--- a/OvaleComboPoints.lua
+++ b/OvaleComboPoints.lua
@@ -150,9 +150,12 @@ function OvaleComboPoints:ApplySpellAfterCast(state, spellId, startCast, endCast
 			"buff_combo_amount" is the number of extra points generated or used, defaulting to 1
 				(one extra point generated).
 		--]]
-		if si.buff_combo and state:GetAura("player", si.buff_combo, nil, true) then
-			local buffAmount = si.buff_combo_amount or 1
-			power = power + buffAmount
+		if si.buff_combo then
+			local aura = state:GetAura("player", si.buff_combo, nil, true)
+			if state:IsActiveAura(aura) then
+				local buffAmount = si.buff_combo_amount or 1
+				power = power + buffAmount
+			end
 		end
 		-- Clamp combo points to lower and upper limits.
 		if power < 0 then
diff --git a/OvaleCooldown.lua b/OvaleCooldown.lua
index 6b62c8e..e23205c 100644
--- a/OvaleCooldown.lua
+++ b/OvaleCooldown.lua
@@ -129,7 +129,7 @@ function OvaleCooldown:ApplySpellAfterCast(state, spellId, startCast, endCast, n
 				-- There is no cooldown if the buff named by "buffnocd" parameter is present.
 				if si.buffnocd then
 					local aura = state:GetAura("player", si.buffnocd)
-					if aura and aura.stacks > 0 then
+					if state:IsActiveAura(aura) then
 						Ovale:Logf("buffnocd stacks = %s, start = %s, ending = %s, startCast = %f", aura.stacks, aura.start, aura.ending, startCast)
 						if aura.start <= startCast and startCast < aura.ending then
 							cd.duration = 0
diff --git a/OvaleEclipse.lua b/OvaleEclipse.lua
index bab7748..71d9467 100644
--- a/OvaleEclipse.lua
+++ b/OvaleEclipse.lua
@@ -163,15 +163,18 @@ function OvaleEclipse:ApplySpellAfterCast(state, spellId, startCast, endCast, ne
 			if si.eclipsedir then
 				energy = energy * direction
 			end
-			if state:GetAura("player", CELESTIAL_ALIGNMENT, "HELPFUL", true) then
+			local aura = state:GetAura("player", CELESTIAL_ALIGNMENT, "HELPFUL", true)
+			if state:IsActiveAura(aura) then
 				-- Celestial Alignment prevents gaining Eclipse energy during its duration.
 				energy = 0
-			elseif OvaleSpellBook:IsKnownSpell(EUPHORIA)
-						and not state:GetAura("player", LUNAR_ECLIPSE, "HELPFUL", true)
-						and not state:GetAura("player", SOLAR_ECLIPSE, "HELPFUL", true) then
-				-- Euphoria: While not in an Eclipse state, your spells generate double the normal
-				-- amount of Solar or Lunar energy.
-				energy = energy * 2
+			elseif OvaleSpellBook:IsKnownSpell(EUPHORIA) then
+				local lunar = state:GetAura("player", LUNAR_ECLIPSE, "HELPFUL", true)
+				local solar = state:GetAura("player", SOLAR_ECLIPSE, "HELPFUL", true)
+				if not state:IsActiveAura(lunar) and not state:IsActiveAura(solar) then
+					-- Euphoria: While not in an Eclipse state, your spells generate double the normal
+					-- amount of Solar or Lunar energy.
+					energy = energy * 2
+				end
 			end
 			-- Only adjust Eclipse energy if the spell moves the Eclipse bar in the right direction.
 			if (direction <= 0 and energy < 0) or (direction >= 0 and energy > 0) then
diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index aa67223..e7e9702 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -109,10 +109,11 @@ local function GetDamageMultiplier(spellId)
 	if spellId then
 		local si = OvaleData.spellInfo[spellId]
 		if si and si.damageAura then
+			local now = API_GetTime()
 			for filter, auraList in pairs(si.damageAura) do
 				for auraSpellId, multiplier in pairs(auraList) do
-					local aura = OvaleAura:GetAuraByGUID(self_guid, auraSpellId, filter, nil, "player")
-					if aura and aura.stacks > 0 then
+					local aura = OvaleAura:GetAura("player", auraSpellId, filter)
+					if aura and aura.stacks > 0 and aura.start <= now and now <= aura.ending then
 						local auraSpellInfo = OvaleData.spellInfo[auraSpellId]
 						if auraSpellInfo.stacking and auraSpellInfo.stacking > 0 then
 							multiplier = 1 + (multiplier - 1) * aura.stacks
@@ -152,7 +153,13 @@ local function AddSpellToQueue(spellId, lineId, startTime, endTime, channeled, a

 	local si = OvaleData.spellInfo[spellId]
 	if si then
-		spellcast.nocd = (si.buffnocd and OvaleAura:GetAura("player", si.buffnocd))
+		if si.buffnocd then
+			local now = API_GetTime()
+			local aura = OvaleAura:GetAura("player", si.buffnocd)
+			if aura and aura.stacks > 0 and aura.start <= now and now <= aura.ending then
+				spellcast.nocd = true
+			end
+		end

 		-- Save the number of combo points used if this spell is a finisher.
 		if si.combo == 0 then
diff --git a/OvalePower.lua b/OvalePower.lua
index ebb2397..160e8f6 100644
--- a/OvalePower.lua
+++ b/OvalePower.lua
@@ -282,9 +282,12 @@ function OvalePower:ApplySpellAfterCast(state, spellId, startCast, endCast, next
 					--]]
 					local buffParam = "buff_" .. tostring(powerType)
 					local buffAmoumtParam = buffParam .. "_amount"
-					if si[buffParam] and state:GetAura("player", si[buffParam], nil, true) then
-						local buffAmount = si[buffAmountParam] or -1
-						power = power - buffAmount
+					if si[buffParam] then
+						local aura = state:GetAura("player", si[buffParam], nil, true)
+						if state:IsActiveAura(aura) then
+							local buffAmount = si[buffAmountParam] or -1
+							power = power - buffAmount
+						end
 					end
 					-- Clamp power to lower and upper limits.
 					local mini = powerInfo.mini or 0
diff --git a/conditions/BuffAmount.lua b/conditions/BuffAmount.lua
index 4a61f88..f3a2eca 100644
--- a/conditions/BuffAmount.lua
+++ b/conditions/BuffAmount.lua
@@ -54,7 +54,7 @@ do
 			statName = "value3"
 		end
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local value = aura[statName] or 0
 			return TestValue(start, ending, value, start, 0, comparator, limit)
diff --git a/conditions/BuffComboPoints.lua b/conditions/BuffComboPoints.lua
index 2d815e0..a4689ab 100644
--- a/conditions/BuffComboPoints.lua
+++ b/conditions/BuffComboPoints.lua
@@ -37,7 +37,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local value = aura and aura.combo or 0
 			return TestValue(start, ending, value, start, 0, comparator, limit)
diff --git a/conditions/BuffDamageMultiplier.lua b/conditions/BuffDamageMultiplier.lua
index e7c27c8..7955e81 100644
--- a/conditions/BuffDamageMultiplier.lua
+++ b/conditions/BuffDamageMultiplier.lua
@@ -37,7 +37,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local baseDamageMultiplier = aura.snapshot and aura.snapshot.baseDamageMultiplier or 1
 			local damageMultiplier = aura.damageMultiplier or 1
diff --git a/conditions/BuffDuration.lua b/conditions/BuffDuration.lua
index 870ac5c..e92b08e 100644
--- a/conditions/BuffDuration.lua
+++ b/conditions/BuffDuration.lua
@@ -35,7 +35,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local value = ending - start
 			return TestValue(start, ending, value, start, 0, comparator, limit)
diff --git a/conditions/BuffExpires.lua b/conditions/BuffExpires.lua
index 87e3cdc..66d3975 100644
--- a/conditions/BuffExpires.lua
+++ b/conditions/BuffExpires.lua
@@ -60,7 +60,7 @@ do
 		local auraId, seconds = condition[1], condition[2]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			seconds = TimeWithHaste(seconds or 0, condition.haste)
 			if ending - seconds <= start then
@@ -102,7 +102,7 @@ do
 		local auraId, seconds = condition[1], condition[2]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			seconds = TimeWithHaste(seconds or 0, condition.haste)
 			if ending - seconds <= start then
diff --git a/conditions/BuffGain.lua b/conditions/BuffGain.lua
index 25e845c..7600877 100644
--- a/conditions/BuffGain.lua
+++ b/conditions/BuffGain.lua
@@ -37,7 +37,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local gain = aura.gain or 0
 			if true then
 				Ovale:Error("not implemented")
diff --git a/conditions/BuffRemains.lua b/conditions/BuffRemains.lua
index d6ae93e..1033e89 100644
--- a/conditions/BuffRemains.lua
+++ b/conditions/BuffRemains.lua
@@ -41,7 +41,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			return TestValue(start, ending, ending - start, start, -1, comparator, limit)
 		end
diff --git a/conditions/BuffSnapshot.lua b/conditions/BuffSnapshot.lua
index c591bdb..4aeb7e7 100644
--- a/conditions/BuffSnapshot.lua
+++ b/conditions/BuffSnapshot.lua
@@ -23,7 +23,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local value = aura.snapshot and aura.snapshot[statName] or defaultValue
 			return TestValue(start, ending, value, start, 0, comparator, limit)
@@ -36,8 +36,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local value = aura.snapshot and aura.snapshot[statName] or defaultValue
 			if condition.unlimited ~= 1 and value > 100 then
diff --git a/conditions/BuffStacks.lua b/conditions/BuffStacks.lua
index e813d92..5568b63 100644
--- a/conditions/BuffStacks.lua
+++ b/conditions/BuffStacks.lua
@@ -43,7 +43,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local value = aura.stacks or 0
 			return TestValue(start, ending, value, start, 0, comparator, limit)
diff --git a/conditions/IsFeared.lua b/conditions/IsFeared.lua
index 20d004e..799448d 100644
--- a/conditions/IsFeared.lua
+++ b/conditions/IsFeared.lua
@@ -29,7 +29,8 @@ do

 	local function IsFeared(condition)
 		local yesno = condition[1]
-		local boolean = not API_HasFullControl() and state:GetAura("player", "fear", "HARMFUL")
+		local aura = state:GetAura("player", "fear", "HARMFUL")
+		local boolean = not API_HasFullControl() and state:IsActiveAura(aura)
 		return TestBoolean(boolean, yesno)
 	end

diff --git a/conditions/IsIncapacitated.lua b/conditions/IsIncapacitated.lua
index 64ef560..fdd076a 100644
--- a/conditions/IsIncapacitated.lua
+++ b/conditions/IsIncapacitated.lua
@@ -29,7 +29,8 @@ do

 	local function IsIncapacitated(condition)
 		local yesno = condition[1]
-		local boolean = not API_HasFullControl() and state:GetAura("player", "incapacitate", "HARMFUL")
+		local aura = state:GetAura("player", "incapacitate", "HARMFUL")
+		local boolean = not API_HasFullControl() and state:IsActiveAura(aura)
 		return TestBoolean(boolean, yesno)
 	end

diff --git a/conditions/IsRooted.lua b/conditions/IsRooted.lua
index a6305e0..b903c8d 100644
--- a/conditions/IsRooted.lua
+++ b/conditions/IsRooted.lua
@@ -28,7 +28,8 @@ do

 	local function IsRooted(condition)
 		local yesno = condition[1]
-		local boolean = state:GetAura("player", "root", "HARMFUL")
+		local aura = state:GetAura("player", "root", "HARMFUL")
+		local boolean = state:IsActiveAura(aura)
 		return TestBoolean(boolean, yesno)
 	end

diff --git a/conditions/IsStunned.lua b/conditions/IsStunned.lua
index 58a067a..26be4d0 100644
--- a/conditions/IsStunned.lua
+++ b/conditions/IsStunned.lua
@@ -29,7 +29,8 @@ do

 	local function IsStunned(condition)
 		local yesno = condition[1]
-		local boolean = not API_HasFullControl() and state:GetAura("player", "stun", "HARMFUL")
+		local aura = state:GetAura("player", "stun", "HARMFUL")
+		local boolean = not API_HasFullControl() and state:IsActiveAura(aura)
 		return TestBoolean(boolean, yesno)
 	end

diff --git a/conditions/NextTick.lua b/conditions/NextTick.lua
index 916e68c..41bbb35 100644
--- a/conditions/NextTick.lua
+++ b/conditions/NextTick.lua
@@ -38,7 +38,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending, tick = aura.start, aura.ending, aura.tick
 			if ending < math.huge and tick then
 				while ending - tick > state.currentTime do
diff --git a/conditions/StaggerRemains.lua b/conditions/StaggerRemains.lua
index 6a81f63..ac5001a 100644
--- a/conditions/StaggerRemains.lua
+++ b/conditions/StaggerRemains.lua
@@ -40,13 +40,13 @@ do
 		local comparator, limit = condition[1], condition[2]
 		local target = ParseCondition(condition)
 		local aura = state:GetAura(target, HEAVY_STAGGER, "HARMFUL")
-		if not aura or aura.stacks == 0 then
+		if not state:IsActiveAura(aura) then
 			aura = state:GetAura(target, MODERATE_STAGGER, "HARMFUL")
 		end
-		if not aura or aura.stacks == 0 then
+		if not state:IsActiveAura(aura) then
 			aura = state:GetAura(target, LIGHT_STAGGER, "HARMFUL")
 		end
-		if aura and aura.stacks > 0 then
+		if state:IsActiveAura(aura) then
 			local start, ending = aura.start, aura.ending
 			local stagger = API_UnitStagger(target)
 			local rate = -1 * stagger / (ending - start)
diff --git a/conditions/TickTime.lua b/conditions/TickTime.lua
index dd8cb53..aee890f 100644
--- a/conditions/TickTime.lua
+++ b/conditions/TickTime.lua
@@ -39,7 +39,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local value = aura.tick or OvaleData:GetTickLength(auraId)
 			return Compare(value, comparator, limit)
 		end
diff --git a/conditions/Ticks.lua b/conditions/Ticks.lua
index fb35227..e28ef47 100644
--- a/conditions/Ticks.lua
+++ b/conditions/Ticks.lua
@@ -35,7 +35,7 @@ do
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
 		local numTicks
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending, tick = aura.start, aura.ending, aura.tick
 			if tick and tick > 0 then
 				numTicks = floor((ending - start) / tick + 0.5)
diff --git a/conditions/TicksAdded.lua b/conditions/TicksAdded.lua
index e70f8ba..632511e 100644
--- a/conditions/TicksAdded.lua
+++ b/conditions/TicksAdded.lua
@@ -33,7 +33,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending, tick = aura.start, aura.ending, aura.tick
 			return TestValue(start, ending, 0, start, 0, comparator, limit)
 		end
diff --git a/conditions/TicksRemain.lua b/conditions/TicksRemain.lua
index d5e024c..b37c04e 100644
--- a/conditions/TicksRemain.lua
+++ b/conditions/TicksRemain.lua
@@ -42,7 +42,7 @@ do
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
-		if aura then
+		if state:IsActiveAura(aura) then
 			local start, ending, tick = aura.start, aura.ending, aura.tick
 			if tick and tick > 0 then
 				return TestValue(start, ending, 1, ending, -1/tick, comparator, limit)