From 699e5d163dce202eed98405091b86653114829f2 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sun, 6 Apr 2014 18:45:54 +0000 Subject: [PATCH] Add TimeToMaxFocus() script condition. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1266 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- conditions/TimeToMaxEnergy.lua | 45 ---------------------------- conditions/TimeToMaxPower.lua | 64 ++++++++++++++++++++++++++++++++++++++++ conditions/conditions.xml | 2 +- 3 files changed, 65 insertions(+), 46 deletions(-) delete mode 100644 conditions/TimeToMaxEnergy.lua create mode 100644 conditions/TimeToMaxPower.lua diff --git a/conditions/TimeToMaxEnergy.lua b/conditions/TimeToMaxEnergy.lua deleted file mode 100644 index 7c2acad..0000000 --- a/conditions/TimeToMaxEnergy.lua +++ /dev/null @@ -1,45 +0,0 @@ ---[[-------------------------------------------------------------------- - Ovale Spell Priority - Copyright (C) 2013 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 - file accompanying this program. ---]]-------------------------------------------------------------------- - -local _, Ovale = ... - -do - local OvaleCondition = Ovale.OvaleCondition - local OvalePower = Ovale.OvalePower - local OvaleState = Ovale.OvaleState - - local Compare = OvaleCondition.Compare - local TestValue = OvaleCondition.TestValue - local state = OvaleState.state - - --- Get the number of seconds before the player reaches maximum energy for feral druids, non-mistweaver monks and rogues. - -- @name TimeToMaxEnergy - -- @paramsig number or boolean - -- @param operator Optional. Comparison operator: less, atMost, equal, atLeast, more. - -- @param number Optional. The number to compare against. - -- @return The number of seconds. - -- @see TimeToEnergyFor - -- @return A boolean value for the result of the comparison. - -- @usage - -- if TimeToMaxEnergy() < 1.2 Spell(sinister_strike) - - local function TimeToMaxEnergy(condition) - local comparator, limit = condition[1], condition[2] - local maxEnergy = OvalePower.maxPower.energy or 0 - local energy = state.energy or 0 - local energyRegen = state.powerRate.energy or 10 - local t = (maxEnergy - energy) / energyRegen - if t > 0 then - return TestValue(0, state.currentTime + t, t, state.currentTime, -1, comparator, limit) - end - return Compare(0, comparator, limit) - end - - OvaleCondition:RegisterCondition("timetomaxenergy", false, TimeToMaxEnergy) -end \ No newline at end of file diff --git a/conditions/TimeToMaxPower.lua b/conditions/TimeToMaxPower.lua new file mode 100644 index 0000000..97847e7 --- /dev/null +++ b/conditions/TimeToMaxPower.lua @@ -0,0 +1,64 @@ +--[[-------------------------------------------------------------------- + Ovale Spell Priority + Copyright (C) 2013 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 + file accompanying this program. +--]]-------------------------------------------------------------------- + +local _, Ovale = ... + +do + local OvaleCondition = Ovale.OvaleCondition + local OvalePower = Ovale.OvalePower + local OvaleState = Ovale.OvaleState + + local Compare = OvaleCondition.Compare + local TestValue = OvaleCondition.TestValue + local state = OvaleState.state + + --- Get the number of seconds before the player reaches maximum power. + local function TimeToMax(powerType, condition) + local comparator, limit = condition[1], condition[2] + local maxPower = OvalePower.maxPower[powerType] or 0 + local power = state[powerType] or 0 + local powerRegen = state.powerRate[powerType] or 1 + local t = (maxPower - power) / powerRegen + if t > 0 then + return TestValue(0, state.currentTime + t, t, state.currentTime, -1, comparator, limit) + end + return Compare(0, comparator, limit) + end + + --- Get the number of seconds before the player reaches maximum energy for feral druids, non-mistweaver monks and rogues. + -- @name TimeToMaxEnergy + -- @paramsig number or boolean + -- @param operator Optional. Comparison operator: less, atMost, equal, atLeast, more. + -- @param number Optional. The number to compare against. + -- @return The number of seconds. + -- @see TimeToEnergyFor + -- @return A boolean value for the result of the comparison. + -- @usage + -- if TimeToMaxEnergy() < 1.2 Spell(sinister_strike) + + local function TimeToMaxEnergy(condition) + return TimeToMax("energy", condition) + end + + --- Get the number of seconds before the player reaches maximum focus for hunters. + -- @name TimeToMaxFocus + -- @paramsig number or boolean + -- @param operator Optional. Comparison operator: less, atMost, equal, atLeast, more. + -- @param number Optional. The number to compare against. + -- @return The number of seconds. + -- @see TimeToEnergyFor + -- @return A boolean value for the result of the comparison. + + local function TimeToMaxFocus(condition) + return TimeToMax("focus", condition) + end + + OvaleCondition:RegisterCondition("timetomaxenergy", false, TimeToMaxEnergy) + OvaleCondition:RegisterCondition("timetomaxfocus", false, TimeToMaxFocus) +end \ No newline at end of file diff --git a/conditions/conditions.xml b/conditions/conditions.xml index 7bf9f3b..5e0d8bb 100644 --- a/conditions/conditions.xml +++ b/conditions/conditions.xml @@ -96,7 +96,7 @@