fix: UnitPowerType falls back to party member stats for out-of-range units

Previously UnitPowerType returned 0 (MANA) for party members who are
out of entity range. Now falls back to SMSG_PARTY_MEMBER_STATS power
type data, so raid frame addons correctly color rage/energy/runic
power bars for distant party members.
This commit is contained in:
Kelsi 2026-03-21 09:18:25 -07:00
parent 9267aec0b0
commit 4364fa7bbe

View file

@ -619,10 +619,22 @@ static int lua_UnitRace(lua_State* L) {
static int lua_UnitPowerType(lua_State* L) {
const char* uid = luaL_optstring(L, 1, "player");
auto* unit = resolveUnit(L, uid);
static const char* kPowerNames[] = {"MANA","RAGE","FOCUS","ENERGY","HAPPINESS","","RUNIC_POWER"};
if (unit) {
lua_pushnumber(L, unit->getPowerType());
static const char* kPowerNames[] = {"MANA","RAGE","FOCUS","ENERGY","HAPPINESS","","RUNIC_POWER"};
uint8_t pt = unit->getPowerType();
lua_pushnumber(L, pt);
lua_pushstring(L, (pt < 7) ? kPowerNames[pt] : "MANA");
return 2;
}
// Fallback: party member stats for out-of-range members
auto* gh = getGameHandler(L);
std::string uidStr(uid);
for (char& c : uidStr) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
uint64_t guid = gh ? resolveUnitGuid(gh, uidStr) : 0;
const auto* pm = findPartyMember(gh, guid);
if (pm) {
uint8_t pt = pm->powerType;
lua_pushnumber(L, pt);
lua_pushstring(L, (pt < 7) ? kPowerNames[pt] : "MANA");
return 2;
}