From 77f985a92718532a0f6d3be9684d105016eadc8c Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Mon, 27 Jul 2026 19:45:44 -0500 Subject: [PATCH] Read HP deficit via ClassicAPI UnitHealthMissing ValidateHpLost now gets the health deficit in one call through CleveRoids.ClassicAPI.UnitHealthMissing, mirroring how ValidatePowerLost uses UnitPowerMissing, instead of hand-computing max - current via NampowerAPI. --- ClassicAPI.lua | 19 +++++++++++++------ Conditionals.lua | 5 +---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ClassicAPI.lua b/ClassicAPI.lua index 63c9b13..3da1921 100644 --- a/ClassicAPI.lua +++ b/ClassicAPI.lua @@ -197,6 +197,16 @@ function API.GetSpellBonusHealing() return GetSpellBonusHealing() end +-------------------------------------------------------------------------------- +-- Unit Health +-------------------------------------------------------------------------------- + +-- Health deficit (max - current) for `unit` in one call. Falls back to +-- UnitHealthMax - UnitHealth without ClassicAPI. +API.UnitHealthMissing = UnitHealthMissing or function(unit) + return (UnitHealthMax(unit) or 0) - (UnitHealth(unit) or 0) +end + -------------------------------------------------------------------------------- -- Unit Power -------------------------------------------------------------------------------- @@ -204,19 +214,16 @@ end -- 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 +API.UnitPower = UnitPower or function(unit, powerType) return UnitMana(unit) end -function API.UnitPowerMax(unit, powerType) - if type(UnitPowerMax) == "function" then return UnitPowerMax(unit, powerType) end +API.UnitPowerMax = UnitPowerMax or function(unit, powerType) 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 +API.UnitPowerMissing = UnitPowerMissing or function(unit, powerType) return (UnitManaMax(unit) or 0) - (UnitMana(unit) or 0) end diff --git a/Conditionals.lua b/Conditionals.lua index 1e51fd1..58adce5 100644 --- a/Conditionals.lua +++ b/Conditionals.lua @@ -3399,10 +3399,7 @@ end -- returns: True or false function CleveRoids.ValidateHpLost(unit, operator, amount) if not unit or not operator or not amount then return false end - local API = CleveRoids.NampowerAPI - local maxHp = API and API.GetUnitMaxHealth and API.GetUnitMaxHealth(unit) or UnitHealthMax(unit) - local hp = API and API.GetUnitHealth and API.GetUnitHealth(unit) or UnitHealth(unit) - local hpLost = maxHp - hp + local hpLost = CleveRoids.ClassicAPI.UnitHealthMissing(unit) if CleveRoids.operators[operator] then return CleveRoids.comparators[operator](hpLost, amount)