Use ClassicAPI UnitPower* for power reads; drop GetUnitField/SuperWoW paths

Add ClassicAPI UnitPower/UnitPowerMax/UnitPowerMissing/UnitPowerType wrappers
and route the power conditionals through them:
- ValidatePower/ValidateRawPower/GetCachedPlayerPower(Percent) use UnitPower /
  UnitPowerMax (omitted type = primary power, matching the old UnitMana path).
- ValidatePowerLost uses UnitPowerMissing (one call vs max - current).
- powertype/nopowertype use ClassicAPI.UnitPowerType.

Replace the SuperWoW "2nd return of UnitMana = caster mana" druid hack in
ValidateDruidRawMana and the #showtooltip OOM check with UnitPower(unit, 0),
which reads the mana slot directly and survives shapeshift. Verified in Cat
Form: UnitPower('player', 0) returns caster mana while UnitPower('player', 3)
returns energy.

Remove the now-dead Nampower GetUnitField-based GetUnitPower/GetUnitMaxPower
wrappers and POWER_FIELDS tables (no caller passed a powerType, so that path
never ran).
This commit is contained in:
Brues
2026-07-27 19:27:25 -05:00
parent efc98bcd6a
commit 7c71f8fc26
4 changed files with 51 additions and 62 deletions
+28
View File
@@ -197,6 +197,34 @@ function API.GetSpellBonusHealing()
return GetSpellBonusHealing()
end
--------------------------------------------------------------------------------
-- Unit Power
--------------------------------------------------------------------------------
-- Current power for a specific Enum.PowerType (0=Mana, 1=Rage, 2=Focus,
-- 3=Energy, 4=Happiness), or the unit's primary power when powerType is omitted.
-- Display-divided (rage reads 0..100). Falls back to UnitMana without ClassicAPI.
function API.UnitPower(unit, powerType)
if type(UnitPower) == "function" then return UnitPower(unit, powerType) end
return UnitMana(unit)
end
function API.UnitPowerMax(unit, powerType)
if type(UnitPowerMax) == "function" then return UnitPowerMax(unit, powerType) end
return UnitManaMax(unit)
end
-- Power deficit (max - current) for the type / primary power, in one call.
function API.UnitPowerMissing(unit, powerType)
if type(UnitPowerMissing) == "function" then return UnitPowerMissing(unit, powerType) end
return (UnitManaMax(unit) or 0) - (UnitMana(unit) or 0)
end
-- Unit's primary power type as an integer (0=Mana .. 4=Happiness).
function API.UnitPowerType(unit)
return UnitPowerType(unit)
end
--------------------------------------------------------------------------------
-- State
--------------------------------------------------------------------------------
+15 -28
View File
@@ -55,15 +55,14 @@ function CleveRoids.GetCachedPlayerHealthPercent()
end
function CleveRoids.GetCachedPlayerPowerPercent()
local API = CleveRoids.NampowerAPI
local power = API and API.GetUnitPower and API.GetUnitPower("player") or UnitMana("player")
local max = API and API.GetUnitMaxPower and API.GetUnitMaxPower("player") or UnitManaMax("player")
local API = CleveRoids.ClassicAPI
local power = API.UnitPower("player")
local max = API.UnitPowerMax("player")
return max > 0 and (100 * power / max) or 0
end
function CleveRoids.GetCachedPlayerPower()
local API = CleveRoids.NampowerAPI
return API and API.GetUnitPower and API.GetUnitPower("player") or UnitMana("player")
return CleveRoids.ClassicAPI.UnitPower("player")
end
function CleveRoids.GetCachedTargetHealthPercent()
@@ -3299,9 +3298,9 @@ end
-- returns: True or false
function CleveRoids.ValidatePower(unit, operator, amount)
if not unit or not operator or not amount then return false end
local API = CleveRoids.NampowerAPI
local power = API and API.GetUnitPower and API.GetUnitPower(unit) or UnitMana(unit)
local maxPower = API and API.GetUnitMaxPower and API.GetUnitMaxPower(unit) or UnitManaMax(unit)
local API = CleveRoids.ClassicAPI
local power = API.UnitPower(unit)
local maxPower = API.UnitPowerMax(unit)
local powerPercent = maxPower > 0 and (100 * power / maxPower) or 0
if CleveRoids.operators[operator] then
@@ -3318,8 +3317,7 @@ end
-- returns: True or false
function CleveRoids.ValidateRawPower(unit, operator, amount)
if not unit or not operator or not amount then return false end
local API = CleveRoids.NampowerAPI
local power = API and API.GetUnitPower and API.GetUnitPower(unit) or UnitMana(unit)
local power = CleveRoids.ClassicAPI.UnitPower(unit)
if power and CleveRoids.operators[operator] then
return CleveRoids.comparators[operator](power, amount)
@@ -3328,23 +3326,15 @@ function CleveRoids.ValidateRawPower(unit, operator, amount)
return false
end
-- Raw caster-form mana for druids (SuperWoW: 2nd return of UnitMana)
-- Raw caster-form mana for druids. Read the mana power slot directly
-- (0 = Enum.PowerType.Mana) so it works while shapeshifted, when the druid's
-- primary power is rage/energy -- no SuperWoW 2nd-return-of-UnitMana needed.
function CleveRoids.ValidateDruidRawMana(unit, operator, amount)
unit = unit or "player"
if not operator or amount == nil then return false end
if (CleveRoids.playerClass ~= "DRUID") then return false end
-- SuperWoW returns: current-form power, caster-form mana
local _, casterMana = UnitMana(unit)
-- Fallback: if for some reason we didn't get a 2nd value and we're in caster form now
if type(casterMana) ~= "number" then
if UnitPowerType and UnitPowerType(unit) == 0 then
casterMana = UnitMana(unit)
else
return false
end
end
local casterMana = CleveRoids.ClassicAPI.UnitPower(unit, 0)
local cmp = CleveRoids.comparators and CleveRoids.comparators[operator]
return cmp and cmp(casterMana, amount) or false
@@ -3357,10 +3347,7 @@ end
-- returns: True or false
function CleveRoids.ValidatePowerLost(unit, operator, amount)
if not unit or not operator or not amount then return false end
local API = CleveRoids.NampowerAPI
local maxPower = API and API.GetUnitMaxPower and API.GetUnitMaxPower(unit) or UnitManaMax(unit)
local power = API and API.GetUnitPower and API.GetUnitPower(unit) or UnitMana(unit)
local powerLost = maxPower - power
local powerLost = CleveRoids.ClassicAPI.UnitPowerMissing(unit)
if CleveRoids.operators[operator] then
return CleveRoids.comparators[operator](powerLost, amount)
@@ -8266,7 +8253,7 @@ CleveRoids.Keywords = {
if not UnitExists(unit) then return false end
return Or(conditionals.powertype, function(powerTypeName)
local powerType = UnitPowerType(unit)
local powerType = CleveRoids.ClassicAPI.UnitPowerType(unit)
local powerTypeLower = string.lower(powerTypeName or "")
if powerTypeLower == "mana" then
@@ -8289,7 +8276,7 @@ CleveRoids.Keywords = {
if not UnitExists(unit) then return true end
return NegatedMulti(conditionals.nopowertype, function(powerTypeName)
local powerType = UnitPowerType(unit)
local powerType = CleveRoids.ClassicAPI.UnitPowerType(unit)
local powerTypeLower = string.lower(powerTypeName or "")
if powerTypeLower == "mana" then
+8 -7
View File
@@ -947,13 +947,14 @@ function CleveRoids.TestForActiveAction(actions)
-- Prefer IsSpellUsable result if available (Nampower)
actions.active.oom = (notEnoughPower == 1)
else
-- SuperWoW: UnitMana returns (current power, caster mana) for druids
local currentPower, casterMana = UnitMana("player")
-- For druids with SuperWoW, use caster mana for spell cost checks
local manaToCheck = currentPower
if CleveRoids.playerClass == "DRUID" and type(casterMana) == "number" then
manaToCheck = casterMana
-- Read caster mana directly for druids (the mana slot survives
-- shapeshift, 0 = Enum.PowerType.Mana); other classes use their
-- primary power. Replaces the SuperWoW UnitMana 2nd-return hack.
local manaToCheck
if CleveRoids.playerClass == "DRUID" then
manaToCheck = CleveRoids.ClassicAPI.UnitPower("player", 0)
else
manaToCheck = CleveRoids.ClassicAPI.UnitPower("player")
end
actions.active.oom = (manaToCheck < actions.active.spell.cost)
-27
View File
@@ -3492,32 +3492,5 @@ function API.GetUnitMaxHealth(unitToken)
return UnitHealthMax(unitToken)
end
-- powerType: nil=current, 0=mana, 1=rage, 2=focus, 3=energy
-- GetUnitField uses power1-power4 fields
local POWER_FIELDS = { [0] = "power1", [1] = "power2", [2] = "power3", [3] = "power4" }
local MAX_POWER_FIELDS = { [0] = "maxPower1", [1] = "maxPower2", [2] = "maxPower3", [3] = "maxPower4" }
function API.GetUnitPower(unitToken, powerType)
if API.features.hasGetUnitField and GetUnitField and powerType then
local field = POWER_FIELDS[powerType]
if field then
local val = GetUnitField(unitToken, field)
if val then return val end
end
end
return UnitMana(unitToken)
end
function API.GetUnitMaxPower(unitToken, powerType)
if API.features.hasGetUnitField and GetUnitField and powerType then
local field = MAX_POWER_FIELDS[powerType]
if field then
local val = GetUnitField(unitToken, field)
if val then return val end
end
end
return UnitManaMax(unitToken)
end
-- Expose API globally for other addons
_G.CleveRoidsNampowerAPI = API