Merge pull request #1651 from Tierisch/shaman_fix

Fix SetTotemAction - add `isUseful` and get array size instead of pointer size
This commit is contained in:
kadeshar
2025-09-27 23:08:18 +02:00
committed by GitHub
2 changed files with 25 additions and 10 deletions

View File

@@ -93,19 +93,26 @@ bool CastSpiritWalkAction::Execute(Event event)
bool SetTotemAction::Execute(Event event) bool SetTotemAction::Execute(Event event)
{ {
size_t spellIdsCount = sizeof(totemSpellIds) / sizeof(uint32); const size_t spellIdsCount = sizeof(totemSpellIds) / sizeof(uint32);
if (spellIdsCount == 0)
return false; // early return
uint32 totemSpell = 0; uint32 totemSpell = 0;
for (int i = spellIdsCount - 1; i >= 0; --i)
// Iterate backwards to prioritize the highest-rank totem spell the bot knows
for (size_t i = spellIdsCount; i-- > 0;)
{ {
if (bot->HasSpell(totemSpellIds[i])) const uint32 spellId = totemSpellIds[i];
if (bot->HasSpell(spellId))
{ {
totemSpell = totemSpellIds[i]; totemSpell = spellId;
break; break;
} }
} }
if (!totemSpell)
if (totemSpell == 0)
return false; return false;
bot->addActionButton(actionButtonId, totemSpell, ACTION_BUTTON_SPELL); bot->addActionButton(actionButtonId, totemSpell, ACTION_BUTTON_SPELL);
return true; return true;
} }

View File

@@ -424,6 +424,7 @@ bool SetTotemTrigger::IsActive()
{ {
if (!bot->HasSpell(SPELL_CALL_OF_THE_ELEMENTS)) if (!bot->HasSpell(SPELL_CALL_OF_THE_ELEMENTS))
return false; return false;
if (!bot->HasSpell(requiredSpellId)) if (!bot->HasSpell(requiredSpellId))
return false; return false;
@@ -431,13 +432,20 @@ bool SetTotemTrigger::IsActive()
if (!button || button->GetType() != ACTION_BUTTON_SPELL || button->GetAction() == 0) if (!button || button->GetType() != ACTION_BUTTON_SPELL || button->GetAction() == 0)
return true; return true;
size_t totemSpellIdsCount = sizeof(totemSpellIds) / sizeof(uint32); const size_t totemSpellIdsCount = sizeof(totemSpellIds) / sizeof(uint32);
for (size_t i = 0; i < totemSpellIdsCount; ++i) if (totemSpellIdsCount == 0)
{
if (button->GetAction() == totemSpellIds[i])
{ {
return false; return false;
} }
for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i)
{
const uint32 spellId = totemSpellIds[i];
if (bot->HasSpell(spellId))
{
return button->GetAction() != spellId;
} }
return true; }
return false;
} }