From e327b45dffc62308b8c2863fd41ca2708bbcffa3 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Thu, 26 Sep 2013 05:34:00 +0000 Subject: [PATCH] Fix ticket 293 - TimeToHealthPercent. Add new script condition TimeToHealthPercent() that returns the number of seconds before the target's health percent reaches the given amount, e.g., if target.TimeToHealthPercent(25) <5 UsePotion() Patch from @ShmooDude. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1027 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleCondition.lua | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/OvaleCondition.lua b/OvaleCondition.lua index 5a16b1d..40babff 100644 --- a/OvaleCondition.lua +++ b/OvaleCondition.lua @@ -3332,18 +3332,14 @@ end --- Get the estimated number of seconds remaining before the target is dead. -- @name TimeToDie --- @paramsig number or boolean --- @param operator Optional. Comparison operator: less, more. --- @param number Optional. The number to compare against. +-- @paramsig number -- @param target Optional. Sets the target to check. The target may also be given as a prefix to the condition. -- Defaults to target=player. -- Valid values: player, target, focus, pet. -- @return The number of seconds. --- @return A boolean value for the result of the comparison. -- @see DeadIn -- @usage -- if target.TimeToDie() <2 and ComboPoints() >0 Spell(eviscerate) --- if target.TimeToDie(less 2) and ComboPoints() >0 Spell(eviscerate) OvaleCondition.conditions.timetodie = function(condition) local timeToDie = TimeToDie(GetTarget(condition)) @@ -3351,6 +3347,30 @@ OvaleCondition.conditions.timetodie = function(condition) end OvaleCondition.conditions.deadin = OvaleCondition.conditions.timetodie +--- Get the estimated number of seconds remaining before the target is reaches the given percent of max health. +-- @name TimeToHealthPercent +-- @paramsig number +-- @param percent The percent of max health of the target. +-- @param target Optional. Sets the target to check. The target may also be given as a prefix to the condition. +-- Defaults to target=player. +-- Valid values: player, target, focus, pet. +-- @return The number of seconds. +-- @see TimeToDie +-- @usage +-- if target.TimeToHealthPercent(25) <15 Item(virmens_bite_potion) + +OvaleCondition.conditions.timetohealthpercent = function(condition) + local timeToDie, health, maxHealth = TimeToDie(GetTarget(condition)) + local percent = condition[1] + local healthPercent = health / maxHealth * 100 + if healthPercent >= percent then + local t = timeToDie * (healthPercent - percent) / healthPercent + return 0, nil, t, OvaleState.maintenant, -1 + end + return 0, nil, 0, 0, 0 +end +OvaleCondition.conditions.timetolifepercent = OvaleCondition.conditions.timetohealthpercent + --- Get the number of seconds before the player has enough primary resources to cast the given spell. -- @name TimeToPowerFor -- @paramsig number -- 1.7.9.5