fix: IsUsableAction now checks spell power cost from DBC

IsUsableAction previously always returned notEnoughMana=false. Now it
checks the spell's mana cost from SpellDataResolver against the player's
current power, matching the same fix applied to IsUsableSpell.

This fixes action bar addons (Bartender, Dominos) incorrectly showing
abilities as usable when the player lacks mana/rage/energy.
This commit is contained in:
Kelsi 2026-03-21 04:23:07 -07:00
parent 91794f421e
commit 6a0e86efe8

View file

@ -2394,11 +2394,26 @@ static int lua_IsUsableAction(lua_State* L) {
} }
const auto& action = bar[slot]; const auto& action = bar[slot];
bool usable = action.isReady(); bool usable = action.isReady();
bool noMana = false;
if (action.type == game::ActionBarSlot::SPELL) { if (action.type == game::ActionBarSlot::SPELL) {
usable = usable && gh->getKnownSpells().count(action.id); usable = usable && gh->getKnownSpells().count(action.id);
// Check power cost
if (usable && action.id != 0) {
auto spellData = gh->getSpellData(action.id);
if (spellData.manaCost > 0) {
auto pe = gh->getEntityManager().getEntity(gh->getPlayerGuid());
if (pe) {
auto* unit = dynamic_cast<game::Unit*>(pe.get());
if (unit && unit->getPower() < spellData.manaCost) {
noMana = true;
usable = false;
}
}
}
}
} }
lua_pushboolean(L, usable ? 1 : 0); lua_pushboolean(L, usable ? 1 : 0);
lua_pushboolean(L, 0); // notEnoughMana (can't determine without cost data) lua_pushboolean(L, noMana ? 1 : 0);
return 2; return 2;
} }