Quantcast

Add TotemRemains() condition to return seconds before a totem expires.

Johnny C. Lam [04-06-14 - 18:47]
Add TotemRemains() condition to return seconds before a totem expires.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1278 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
conditions/TotemExpires.lua
diff --git a/conditions/TotemExpires.lua b/conditions/TotemExpires.lua
index 306fa39..fe6969a 100644
--- a/conditions/TotemExpires.lua
+++ b/conditions/TotemExpires.lua
@@ -1,7 +1,7 @@
 --[[--------------------------------------------------------------------
     Ovale Spell Priority
     Copyright (C) 2012, 2013 Sidoine
-    Copyright (C) 2012, 2013 Johnny C. Lam
+    Copyright (C) 2012, 2013, 2014 Johnny C. Lam

     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License in the LICENSE
@@ -16,6 +16,8 @@ do

 	local type = type
 	local API_GetTotemInfo = GetTotemInfo
+	local Compare = OvaleCondition.Compare
+	local TestValue = OvaleCondition.TestValue

 	local OVALE_TOTEMTYPE =
 	{
@@ -40,7 +42,7 @@ do
 	-- @param totem Optional. Sets the specific totem to check of given totem ID type.
 	--     Valid values: any totem spell ID
 	-- @return A boolean value.
-	-- @see TotemPresent
+	-- @see TotemPresent, TotemRemains
 	-- @usage
 	-- if TotemExpires(fire) Spell(searing_totem)
 	-- if TotemPresent(water totem=healing_stream_totem) and TotemExpires(water 3) Spell(totemic_recall)
@@ -52,13 +54,10 @@ do
 			totemId = OVALE_TOTEMTYPE[totemId]
 		end
 		local haveTotem, name, startTime, duration = API_GetTotemInfo(totemId)
-		if not haveTotem or not startTime then
-			return 0, math.huge
+		if haveTotem and startTime and (not condition.totem or OvaleSpellBook:GetSpellName(condition.totem) == name) then
+			return startTime + duration - seconds, math.huge
 		end
-		if condition.totem and OvaleSpellBook:GetSpellName(condition.totem) ~= name then
-			return 0, math.huge
-		end
-		return startTime + duration - seconds, math.huge
+		return 0, math.huge
 	end

 	--- Test if the totem for shamans, the ghoul for death knights, or the statue for monks is present.
@@ -69,7 +68,7 @@ do
 	-- @param totem Optional. Sets the specific totem to check of given totem ID type.
 	--     Valid values: any totem spell ID
 	-- @return A boolean value.
-	-- @see TotemExpires
+	-- @see TotemExpires, TotemRemains
 	-- @usage
 	-- if not TotemPresent(fire) Spell(searing_totem)
 	-- if TotemPresent(water totem=healing_stream_totem) and TotemExpires(water 3) Spell(totemic_recall)
@@ -80,15 +79,42 @@ do
 			totemId = OVALE_TOTEMTYPE[totemId]
 		end
 		local haveTotem, name, startTime, duration = API_GetTotemInfo(totemId)
-		if not haveTotem or not startTime then
-			return nil
-		end
-		if condition.totem and OvaleSpellBook:GetSpellName(condition.totem) ~= name then
-			return nil
+		if haveTotem and startTime and (not condition.totem or OvaleSpellBook:GetSpellName(condition.totem) == name) then
+			return startTime, startTime + duration
 		end
-		return startTime, startTime + duration
+		return nil
 	end

 	OvaleCondition:RegisterCondition("totemexpires", false, TotemExpires)
 	OvaleCondition:RegisterCondition("totempresent", false, TotemPresent)
-end
\ No newline at end of file
+
+	--- Get the remaining time in seconds before a totem expires.
+	-- @name TotemRemains
+	-- @paramsig number or boolean
+	-- @param id The totem ID of the totem, ghoul or statue, or the type of totem.
+	--     Valid types: fire, water, air, earth, ghoul, statue.
+	-- @param operator Optional. Comparison operator: less, atMost, equal, atLeast, more.
+	-- @param number Optional. The number to compare against.
+	-- @param totem Optional. Sets the specific totem to check of given totem ID type.
+	--     Valid values: any totem spell ID
+	-- @return The number of seconds.
+	-- @return A boolean value for the result of the comparison.
+	-- @see TotemExpires, TotemPresent
+	-- @usage
+	-- if TotemRemains(water totem=healing_stream_totem) <2 Spell(totemic_recall)
+
+	local function TotemRemains(condition)
+		local totemId = condition[1]
+		if type(totemId) ~= "number" then
+			totemId = OVALE_TOTEMTYPE[totemId]
+		end
+		local haveTotem, name, startTime, duration = API_GetTotemInfo(totemId)
+		if haveTotem and startTime and (not condition.totem or OvaleSpellBook:GetSpellName(condition.totem) == name) then
+			local start, ending = startTime, startTime + duration
+			return TestValue(start, ending, duration, start, -1, comparator, limit)
+		end
+		return Compare(0, comparator, limit)
+	end
+
+	OvaleCondition:RegisterCondition("totemremains", false, TotemRemains)
+end