- Code optimalizations

This commit is contained in:
kadeshar
2025-09-27 20:57:10 +02:00
parent 01f0b71a17
commit 0547ce5cf7
2 changed files with 23 additions and 10 deletions

View File

@@ -93,18 +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 = (int)spellIdsCount - 1; i >= 0; --i)
// Iterate backwards due signed/unsigned int
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,14 +432,18 @@ 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 (int i = (int)totemSpellIdsCount - 1; i >= 0; --i) if (totemSpellIdsCount == 0)
{ {
if (bot->HasSpell(totemSpellIds[i])) return false;
}
for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i)
{
const uint32 spellId = totemSpellIds[i];
if (bot->HasSpell(spellId))
{ {
return button->GetAction() != totemSpellIds[i]; return button->GetAction() != spellId;
} }
} }