Read unit power from ClassicAPI instead of Nampower's GetUnitField

GetUnitStats parsed the power type out of the bytes0 descriptor field and
read each power slot via GetUnitField(guid, "powerN")/"maxPowerN", manually
dividing rage by 10. ClassicAPI's UnitPower/UnitPowerMax read the same
descriptor slots and apply the engine's own power-divisor table (rage /10,
happiness scaling), so:

  powerType = UnitPowerType(unitstr) or 0
  power = UnitPower(unitstr, powerType)
  maxPower = UnitPowerMax(unitstr, powerType)

is equivalent and drops nine GetUnitField calls plus the bytes0 parsing.
Power now resolves through the hard-dep ClassicAPI even without Nampower;
GetUnitField in this path is left only for health, which has no ClassicAPI
real-HP equivalent.
This commit is contained in:
Brues
2026-07-24 16:51:36 -05:00
parent f06af48bc2
commit a31d10384b
+5 -38
View File
@@ -138,8 +138,11 @@ pfUI.api.lastUnitStats = pfUI.api.lastUnitStats or {}
function pfUI.api.GetUnitStats(unitstr, trackStats)
local hp, maxHp, power, maxPower, powerType
local usedNampower = false
powerType = UnitPowerType(unitstr) or 0
power = UnitPower(unitstr, powerType)
maxPower = UnitPowerMax(unitstr, powerType)
-- Try GetUnitField first if available (for all units: players, pets, NPCs)
if GetUnitField then
-- Use the standard check first, then get guid separately
@@ -152,39 +155,6 @@ function pfUI.api.GetUnitStats(unitstr, trackStats)
hp = GetUnitField(guid, "health")
maxHp = GetUnitField(guid, "maxHealth")
-- Get power type from bytes0
local bytes0 = GetUnitField(guid, "bytes0")
if bytes0 then
local temp = math.floor(bytes0 / 16777216)
powerType = temp - math.floor(temp / 256) * 256
else
powerType = UnitPowerType(unitstr) or 0
end
-- Get power values based on type
if powerType == Enum.PowerType.Rage then
-- Rage (Nampower stores rage * 10, maxPower2 stores maxRage * 10)
local rage = GetUnitField(guid, "power2")
local maxRage = GetUnitField(guid, "maxPower2")
power = rage and math.floor(rage / 10) or UnitPower(unitstr)
maxPower = maxRage and math.floor(maxRage / 10) or UnitPowerMax(unitstr)
elseif powerType == Enum.PowerType.Energy then
-- Energy
power = GetUnitField(guid, "power4") or UnitPower(unitstr)
if power then power = math.floor(power) end
maxPower = GetUnitField(guid, "maxPower4") or UnitPowerMax(unitstr)
elseif powerType == Enum.PowerType.Focus then
-- Focus (Hunter pets use power3)
power = GetUnitField(guid, "power3") or UnitPower(unitstr)
if power then power = math.floor(power) end
maxPower = GetUnitField(guid, "maxPower3") or UnitPowerMax(unitstr)
else
-- Mana (default)
power = GetUnitField(guid, "power1") or UnitPower(unitstr)
maxPower = GetUnitField(guid, "maxPower1") or UnitPowerMax(unitstr)
end
-- Check if Nampower gave valid health data
if hp and hp > 0 and maxHp and maxHp > 0 then
usedNampower = true
@@ -213,9 +183,6 @@ function pfUI.api.GetUnitStats(unitstr, trackStats)
-- Fallback to standard API (for players when Nampower fails)
hp = UnitHealth(unitstr) or 0
maxHp = UnitHealthMax(unitstr) or 1
powerType = UnitPowerType(unitstr) or 0
power = UnitPower(unitstr) or 0
maxPower = UnitPowerMax(unitstr) or 1
-- Track Fallback usage - NUR bei echten Änderungen
if trackStats and not usedNampower then