diff --git a/src/strategy/shaman/ShamanActions.cpp b/src/strategy/shaman/ShamanActions.cpp index 83e915da..42f3a8e9 100644 --- a/src/strategy/shaman/ShamanActions.cpp +++ b/src/strategy/shaman/ShamanActions.cpp @@ -93,18 +93,26 @@ bool CastSpiritWalkAction::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; - 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; } } - if (!totemSpell) + + if (totemSpell == 0) return false; + bot->addActionButton(actionButtonId, totemSpell, ACTION_BUTTON_SPELL); return true; } diff --git a/src/strategy/shaman/ShamanTriggers.cpp b/src/strategy/shaman/ShamanTriggers.cpp index 225289e7..cdee870c 100644 --- a/src/strategy/shaman/ShamanTriggers.cpp +++ b/src/strategy/shaman/ShamanTriggers.cpp @@ -424,6 +424,7 @@ bool SetTotemTrigger::IsActive() { if (!bot->HasSpell(SPELL_CALL_OF_THE_ELEMENTS)) return false; + if (!bot->HasSpell(requiredSpellId)) return false; @@ -431,14 +432,18 @@ bool SetTotemTrigger::IsActive() if (!button || button->GetType() != ACTION_BUTTON_SPELL || button->GetAction() == 0) return true; - size_t totemSpellIdsCount = sizeof(totemSpellIds) / sizeof(uint32); - for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i) - + const size_t totemSpellIdsCount = sizeof(totemSpellIds) / sizeof(uint32); + 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; } }