From 88dc1aa8e2583b79fd5c62f8f9e336363ec0a414 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sun, 6 Apr 2014 18:47:54 +0000 Subject: [PATCH] Factor out state method to compute the cost of a spell. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1285 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvalePower.lua | 58 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/OvalePower.lua b/OvalePower.lua index bd7d287..c4202c8 100644 --- a/OvalePower.lua +++ b/OvalePower.lua @@ -282,9 +282,9 @@ function OvalePower:ApplySpellAfterCast(state, spellId, targetGUID, startCast, e -- Update power using information from GetSpellInfo() if there is no SpellInfo() for the spell's cost. do - local _, _, _, cost, _, powerType = API_GetSpellInfo(spellId) - if cost and powerType then - powerType = self.POWER_TYPE[powerType] + local _, _, _, cost, _, powerTypeId = API_GetSpellInfo(spellId) + if cost and powerTypeId then + powerType = self.POWER_TYPE[powerTypeId] if not si or not si[powerType] then state[powerType] = state[powerType] - cost end @@ -295,7 +295,7 @@ function OvalePower:ApplySpellAfterCast(state, spellId, targetGUID, startCast, e -- Update power state except for eclipse energy (handled by OvaleEclipse). for powerType, powerInfo in pairs(self.POWER_INFO) do if powerType ~= "eclipse" then - local cost = si[powerType] + local cost = state:PowerCost(spellId, powerType) local power = state[powerType] or 0 if cost then --[[ @@ -308,21 +308,6 @@ function OvalePower:ApplySpellAfterCast(state, spellId, targetGUID, startCast, e else power = power - cost end - --[[ - 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). - --]] - local buffParam = "buff_" .. tostring(powerType) - local buffAmoumtParam = buffParam .. "_amount" - if si[buffParam] then - local aura = state:GetAura("player", si[buffParam], nil, true) - if state:IsActiveAura(aura) then - local buffAmount = si[buffAmountParam] or -1 - power = power - buffAmount - end - end -- Clamp power to lower and upper limits. local mini = powerInfo.mini or 0 local maxi = powerInfo.maxi or self.maxPower[powerType] @@ -341,6 +326,41 @@ end -- -- +statePrototype.PowerCost = function(state, spellId, powerType) + local spellCost = nil + local si = OvaleData.spellInfo[spellId] + if si and si[powerType] then + local cost = si[powerType] + --[[ + cost > 0 means that the spell costs resources. + cost < 0 means that the spell generates resources. + cost == 0 means that the spell uses all of the resources (zeroes it out). + + 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). + --]] + local buffParam = "buff_" .. tostring(powerType) + local buffAmoumtParam = buffParam .. "_amount" + if si[buffParam] then + local aura = state:GetAura("player", si[buffParam], nil, true) + if state:IsActiveAura(aura) then + local buffAmount = si[buffAmountParam] or -1 + cost = cost + buffAmount + 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 + end + end + return spellCost +end + -- Print out the levels of each power type in the current state. statePrototype.DebugPower = function(state) for powerType in pairs(OvalePower.POWER_INFO) do -- 1.7.9.5