From ab83394765df09ad39d07ae6557d8d2b39e7136d Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sat, 3 May 2014 00:25:43 +0000 Subject: [PATCH] Support more power reduction buffs. Instead of just "_half" and "_none" for 50% and 100% reduction, also support "_less15" and "_less75" for 15% and 75% reduction as well. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1355 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvalePower.lua | 140 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 65 deletions(-) diff --git a/OvalePower.lua b/OvalePower.lua index 5deefa9..2545b79 100644 --- a/OvalePower.lua +++ b/OvalePower.lua @@ -350,85 +350,95 @@ statePrototype.TimeToPower = function(state, spellId, powerType) end -- Return the amount of the given resource needed to cast the given spell. -statePrototype.PowerCost = function(state, spellId, powerType) - local buffParam = "buff_" .. powerType - local spellCost = 0 - local si = OvaleData.spellInfo[spellId] - if si and si[powerType] then - --[[ - cost == 0 means the that spell uses no resources. - cost > 0 means that the spell costs resources. - cost < 0 means that the spell generates resources. - cost == "finisher" means that the spell uses all of the resources (zeroes it out). - --]] - local cost = si[powerType] - if cost == "finisher" then - -- This spell is a finisher so compute the cost based on the amount of resources consumed. - cost = state[powerType] - -- Clamp cost between values defined by min_ and max_. - local minCostParam = "min_" .. powerType - local maxCostParam = "max_" .. powerType - local minCost = si[minCostParam] or 1 - local maxCost = si[maxCostParam] - if cost < minCost then - cost = minCost - end - if maxCost and cost > maxCost then - cost = maxCost - end - else +do + local BUFF_PERCENT_REDUCTION = { + ["_less15"] = 0.85, + ["_less50"] = 0.50, + ["_less75"] = 0.25, + ["_half"] = 0.5, + } + + statePrototype.PowerCost = function(state, spellId, powerType) + local buffParam = "buff_" .. powerType + local spellCost = 0 + local si = OvaleData.spellInfo[spellId] + if si and si[powerType] then --[[ - Add extra resource generated by presence of a buff. - "buff_" is the spell ID of the buff that causes extra resources to be generated or used. - "buff__amount" is the amount of extra resources generated or used, defaulting to -1 - (one extra resource generated). + cost == 0 means the that spell uses no resources. + cost > 0 means that the spell costs resources. + cost < 0 means that the spell generates resources. + cost == "finisher" means that the spell uses all of the resources (zeroes it out). --]] - local buffExtraParam = buffParam - local buffAmountParam = buffParam .. "_amount" - local buffExtra = si[buffExtraParam] - if buffExtra then - local aura = state:GetAura("player", buffExtra, nil, true) - if state:IsActiveAura(aura) then - local buffAmount = si[buffAmountParam] or -1 - cost = cost + buffAmount + local cost = si[powerType] + if cost == "finisher" then + -- This spell is a finisher so compute the cost based on the amount of resources consumed. + cost = state[powerType] + -- Clamp cost between values defined by min_ and max_. + local minCostParam = "min_" .. powerType + local maxCostParam = "max_" .. powerType + local minCost = si[minCostParam] or 1 + local maxCost = si[maxCostParam] + if cost < minCost then + cost = minCost end - end - if cost > 0 then + if maxCost and cost > maxCost then + cost = maxCost + end + else --[[ - Apply any percent reductions to cost after fixed reductions are applied. - This seems to be a consistent Blizzard rule for spell costs so that you - never end up with a negative spell cost. + Add extra resource generated by presence of a buff. + "buff_" is the spell ID of the buff that causes extra resources to be generated or used. + "buff__amount" is the amount of extra resources generated or used, defaulting to -1 + (one extra resource generated). --]] - -- "buff__half" is the spell ID of the buff that makes casting the spell cost half the resources. - local buffHalfCostParam = buffParam .. "_half" - local buffHalfCost = si[buffHalfCostParam] - if buffHalfCost then - local aura = state:GetAura("player", buffHalfCost) + local buffExtraParam = buffParam + local buffAmountParam = buffParam .. "_amount" + local buffExtra = si[buffExtraParam] + if buffExtra then + local aura = state:GetAura("player", buffExtra, nil, true) if state:IsActiveAura(aura) then - cost = ceil(cost / 2) + local buffAmount = si[buffAmountParam] or -1 + cost = cost + buffAmount + end + end + if cost > 0 then + --[[ + Apply any percent reductions to cost after fixed reductions are applied. + This seems to be a consistent Blizzard rule for spell costs so that you + never end up with a negative spell cost. + --]] + for suffix, multiplier in pairs(BUFF_PERCENT_REDUCTION) do + local buffPercentReduction = si[buffParam .. suffix] + if buffPercentReduction then + local aura = state:GetAura("player", buffPercentReduction) + if state:IsActiveAura(aura) then + cost = cost * multiplier + end + end end + cost = ceil(cost) end end - end - local buffNoCostParam = buffParam .. "_none" - local buffNoCost = si[buffNoCostParam] - if buffNoCost then - -- "buff__none" is the spell ID of the buff that makes casting the spell resource-free. - local aura = state:GetAura("player", buffNoCost) - if state:IsActiveAura(aura) then - cost = 0 + local buffNoCostParam = buffParam .. "_none" + local buffNoCost = si[buffNoCostParam] + if buffNoCost then + -- "buff__none" is the spell ID of the buff that makes casting the spell resource-free. + local aura = state:GetAura("player", buffNoCost) + if state:IsActiveAura(aura) then + cost = 0 + end end - end - spellCost = cost - else - -- Determine cost using information from GetSpellInfo() if there is no SpellInfo() for the spell's cost. - local _, _, _, cost, _, powerTypeId = API_GetSpellInfo(spellId) - if cost and powerTypeId and powerType == OvalePower.POWER_TYPE[powerTypeId] then spellCost = cost + else + -- Determine cost using information from GetSpellInfo() if there is no SpellInfo() for the spell's cost. + local _, _, _, cost, _, powerTypeId = API_GetSpellInfo(spellId) + if cost and powerTypeId and powerType == OvalePower.POWER_TYPE[powerTypeId] then + spellCost = cost + end end + return spellCost end - return spellCost end -- Print out the levels of each power type in the current state. -- 1.7.9.5