From 97bb940c0948575759dfd68c8cd3999898302fb7 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sun, 6 Apr 2014 18:45:35 +0000 Subject: [PATCH] Allow for providing "Power"Percent() script conditions for each power type. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1263 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- conditions/ManaPercent.lua | 62 -------------------------------------------- conditions/Power.lua | 44 +++++++++++++++++++++++++++++++ conditions/conditions.xml | 1 - 3 files changed, 44 insertions(+), 63 deletions(-) delete mode 100644 conditions/ManaPercent.lua diff --git a/conditions/ManaPercent.lua b/conditions/ManaPercent.lua deleted file mode 100644 index 7efef65..0000000 --- a/conditions/ManaPercent.lua +++ /dev/null @@ -1,62 +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 API_UnitPower = UnitPower - local API_UnitPowerMax = UnitPowerMax - local Compare = OvaleCondition.Compare - local ParseCondition = OvaleCondition.ParseCondition - local TestValue = OvaleCondition.TestValue - local state = OvaleState.state - - --- Get the current percent level of mana (between 0 and 100) of the target. - -- @name ManaPercent - -- @paramsig number or boolean - -- @param operator Optional. Comparison operator: less, atMost, equal, atLeast, more. - -- @param number Optional. The number to compare against. - -- @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 current mana percent. - -- @return A boolean value for the result of the comparison. - -- @usage - -- if ManaPercent() >90 Spell(arcane_blast) - -- if ManaPercent(more 90) Spell(arcane_blast) - - local function ManaPercent(condition) - local comparator, limit = condition[1], condition[2] - local target = ParseCondition(condition) - if target == "player" then - local powerMax = OvalePower.maxPower.mana or 0 - if powerMax > 0 then - local conversion = 100 / powerMax - local value, origin, rate = state.mana * conversion, state.currentTime, state.powerRate.mana * conversion - local start, ending = state.currentTime, math.huge - return TestValue(start, ending, value, origin, rate, comparator, limit) - end - else - local powerInfo = OvalePower.POWER_INFO.mana - local powerMax = API_UnitPowerMax(target, powerInfo.id) or 0 - if powerMax > 0 then - local conversion = 100 / powerMax - local value = API_UnitPower(target, powerInfo.id) * conversion - return Compare(value, comparator, limit) - end - end - return Compare(0, comparator, limit) - end - - OvaleCondition:RegisterCondition("manapercent", false, ManaPercent) -end diff --git a/conditions/Power.lua b/conditions/Power.lua index f8d5ec9..983fe94 100644 --- a/conditions/Power.lua +++ b/conditions/Power.lua @@ -50,6 +50,30 @@ do end end + --- Return the current percent level of power (between 0 and 100) on the target. + local function PowerPercent(powerType, condition) + local comparator, limit = condition[1], condition[2] + local target = ParseCondition(condition) + if target == "player" then + local powerMax = OvalePower.maxPower[powerType] or 0 + if powerMax > 0 then + local conversion = 100 / powerMax + local value, origin, rate = state[powerType] * conversion, state.currentTime, state.powerRate[powerType] * conversion + local start, ending = state.currentTime, math.huge + return TestValue(start, ending, value, origin, rate, comparator, limit) + end + else + local powerInfo = OvalePower.POWER_INFO[powerType] + local powerMax = API_UnitPowerMax(target, powerInfo.id, powerInfo.segments) or 0 + if powerMax > 0 then + local conversion = 100 / powerMax + local value = API_UnitPower(target, powerInfo.id) * conversion + return Compare(value, comparator, limit) + end + end + return Compare(0, comparator, limit) + end + --- Get the current amount of alternate power displayed on the alternate power bar. -- @name AlternatePower -- @paramsig number or boolean @@ -242,6 +266,26 @@ do OvaleCondition:RegisterCondition("shadoworbs", false, ShadowOrbs) OvaleCondition:RegisterCondition("soulshards", false, SoulShards) + --- Get the current percent level of mana (between 0 and 100) of the target. + -- @name ManaPercent + -- @paramsig number or boolean + -- @param operator Optional. Comparison operator: less, atMost, equal, atLeast, more. + -- @param number Optional. The number to compare against. + -- @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 current mana percent. + -- @return A boolean value for the result of the comparison. + -- @usage + -- if ManaPercent() >90 Spell(arcane_blast) + -- if ManaPercent(more 90) Spell(arcane_blast) + + local function ManaPercent(condition) + return PowerPercent("mana", condition) + end + + OvaleCondition:RegisterCondition("manapercent", false, ManaPercent) + --- Get the maximum amount of alternate power of the target. -- Alternate power is the resource tracked by the alternate power bar in certain boss fights. -- @name MaxAlternatePower diff --git a/conditions/conditions.xml b/conditions/conditions.xml index d3192b2..e5b5a63 100644 --- a/conditions/conditions.xml +++ b/conditions/conditions.xml @@ -64,7 +64,6 @@