Quantcast

Add parameter "excludeTarget" to conditions that scan over all targets.

Johnny C. Lam [05-15-14 - 23:19]
Add parameter "excludeTarget" to conditions that scan over all targets.

BuffCountOnAny, BuffRemainsOnAny, and BuffStacksOnAny now accept a new
parameter "excludeTarget" (0 or 1) that signals whether to exclude the
current target from the scan.  This allows for checking when DoTs are
expiring on other targets and need to be spread from the current target
again.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1453 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
conditions/BuffCountOnAny.lua
conditions/BuffRemainsOnAny.lua
conditions/BuffStacksOnAny.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index c55ab53..a6dbe98 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -1174,19 +1174,20 @@ do
 	--[[
 		Return the total count and stacks of the given aura across all units, the start/end times of
 		the first aura to expire that will change the total count, and the time interval over which
-		the count is more than 0.
+		the count is more than 0.  If excludeUnitId is given, then that unit is excluded from the count.
 	--]]
-	statePrototype.AuraCount = function(state, auraId, filter, mine, minStacks)
+	statePrototype.AuraCount = function(state, auraId, filter, mine, minStacks, excludeUnitId)
 		-- Initialize.
-		minStacks = minStacks or 0
+		minStacks = minStacks or 1
 		count = 0
 		stacks = 0
 		startChangeCount, endingChangeCount = math.huge, math.huge
 		startFirst, endingLast = math.huge, 0
+		local excludeGUID = excludeUnitId and OvaleGUID:GetGUID(excludeUnitId) or nil

 		-- Loop through auras not kept in the simulator that match the criteria.
 		for guid, auraTable in pairs(OvaleAura.aura) do
-			if auraTable[auraId] then
+			if guid ~= excludeGUID and auraTable[auraId] then
 				if mine then
 					local aura = GetStateAura(state, guid, auraId, self_guid)
 					if state:IsActiveAura(aura) and aura.filter == filter and aura.stacks >= minStacks and not aura.state then
@@ -1204,7 +1205,7 @@ do
 		end
 		-- Loop through auras in the simulator that match the criteria.
 		for guid, auraTable in pairs(state.aura) do
-			if auraTable[auraId] then
+			if guid ~= excludeGUID and auraTable[auraId] then
 				if mine then
 					local aura = auraTable[auraId][self_guid]
 					if aura then
diff --git a/conditions/BuffCountOnAny.lua b/conditions/BuffCountOnAny.lua
index ec58267..73dea43 100644
--- a/conditions/BuffCountOnAny.lua
+++ b/conditions/BuffCountOnAny.lua
@@ -30,6 +30,9 @@ do
 	-- @param any Optional. Sets by whom the aura was applied. If the aura can be applied by anyone, then set any=1.
 	--     Defaults to any=0.
 	--     Valid values: 0, 1.
+	-- @param excludeTarget Optional. Sets whether to ignore the current target when scanning targets.
+	--     Defaults to excludeTarget=0.
+	--     Valid values: 0, 1.
 	-- @return The total aura count.
 	-- @return A boolean value for the result of the comparison.
 	-- @see DebuffCountOnAny
@@ -37,8 +40,9 @@ do
 	local function BuffCountOnAny(condition)
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local _, filter, mine = ParseCondition(condition)
+		local excludeUnitId = (condition.excludeTarget == 1) and OvaleCondition.defaultTarget or nil

-		local count, stacks, startChangeCount, endingChangeCount, startFirst, endingLast = state:AuraCount(auraId, filter, mine, condition.stacks)
+		local count, stacks, startChangeCount, endingChangeCount, startFirst, endingLast = state:AuraCount(auraId, filter, mine, condition.stacks, excludeUnitId)
 		if count > 0 and startChangeCount < math.huge then
 			local origin = startChangeCount
 			local rate = -1 / (endingChangeCount - startChangeCount)
diff --git a/conditions/BuffRemainsOnAny.lua b/conditions/BuffRemainsOnAny.lua
index d50d5dc..54f0898 100644
--- a/conditions/BuffRemainsOnAny.lua
+++ b/conditions/BuffRemainsOnAny.lua
@@ -30,6 +30,9 @@ do
 	-- @param any Optional. Sets by whom the aura was applied. If the aura can be applied by anyone, then set any=1.
 	--     Defaults to any=0.
 	--     Valid values: 0, 1.
+	-- @param excludeTarget Optional. Sets whether to ignore the current target when scanning targets.
+	--     Defaults to excludeTarget=0.
+	--     Valid values: 0, 1.
 	-- @return The number of seconds.
 	-- @return A boolean value for the result of the comparison.
 	-- @see DebuffRemainsOnAny
@@ -37,8 +40,9 @@ do
 	local function BuffRemainsOnAny(condition)
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local _, filter, mine = ParseCondition(condition)
+		local excludeUnitId = (condition.excludeTarget == 1) and OvaleCondition.defaultTarget or nil

-		local count, stacks, startChangeCount, endingChangeCount, startFirst, endingLast = state:AuraCount(auraId, filter, mine, condition.stacks)
+		local count, stacks, startChangeCount, endingChangeCount, startFirst, endingLast = state:AuraCount(auraId, filter, mine, condition.stacks, excludeUnitId)
 		if count > 0 then
 			local start, ending = startFirst, endingLast
 			return TestValue(start, math.huge, 0, ending, -1, comparator, limit)
diff --git a/conditions/BuffStacksOnAny.lua b/conditions/BuffStacksOnAny.lua
index b6da3ae..1f93277 100644
--- a/conditions/BuffStacksOnAny.lua
+++ b/conditions/BuffStacksOnAny.lua
@@ -27,6 +27,9 @@ do
 	-- @param any Optional. Sets by whom the aura was applied. If the aura can be applied by anyone, then set any=1.
 	--     Defaults to any=0.
 	--     Valid values: 0, 1.
+	-- @param excludeTarget Optional. Sets whether to ignore the current target when scanning targets.
+	--     Defaults to excludeTarget=0.
+	--     Valid values: 0, 1.
 	-- @return The total number of stacks.
 	-- @return A boolean value for the result of the comparison.
 	-- @see DebuffStacksOnAny
@@ -34,8 +37,9 @@ do
 	local function BuffStacksOnAny(condition)
 		local auraId, comparator, limit = condition[1], condition[2], condition[3]
 		local _, filter, mine = ParseCondition(condition)
+		local excludeUnitId = (condition.excludeTarget == 1) and OvaleCondition.defaultTarget or nil

-		local count, stacks, startChangeCount, endingChangeCount, startFirst, endingLast = state:AuraCount(auraId, filter, mine)
+		local count, stacks, startChangeCount, endingChangeCount, startFirst, endingLast = state:AuraCount(auraId, filter, mine, 1, excludeUnitId)
 		if count > 0 then
 			local start, ending = startFirst, endingChangeCount
 			return TestValue(start, ending, stacks, start, 0, comparator, limit)