Fix SetTotemAction

Add isUseful and check array size instead of pointer size
This commit is contained in:
Spargel
2025-09-21 21:17:53 -05:00
parent 0b74820f80
commit ca0dafd67b
2 changed files with 46 additions and 22 deletions

View File

@@ -93,10 +93,8 @@ bool CastSpiritWalkAction::Execute(Event event)
bool SetTotemAction::Execute(Event event) bool SetTotemAction::Execute(Event event)
{ {
size_t spellIdsCount = sizeof(totemSpellIds) / sizeof(uint32);
uint32 totemSpell = 0; uint32 totemSpell = 0;
for (int i = spellIdsCount - 1; i >= 0; --i) for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i)
{ {
if (bot->HasSpell(totemSpellIds[i])) if (bot->HasSpell(totemSpellIds[i]))
{ {
@@ -109,3 +107,27 @@ bool SetTotemAction::Execute(Event event)
bot->addActionButton(actionButtonId, totemSpell, ACTION_BUTTON_SPELL); bot->addActionButton(actionButtonId, totemSpell, ACTION_BUTTON_SPELL);
return true; return true;
} }
bool SetTotemAction::isUseful()
{
Player* bot = botAI->GetBot();
ActionButton const* button = bot->GetActionButton(actionButtonId);
if (!button || button->GetType() != ACTION_BUTTON_SPELL || button->GetAction() == 0)
return true; // No totem assigned
// Find the highest rank the bot knows
uint32 highestKnown = 0;
for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i)
{
if (bot->HasSpell(totemSpellIds[i]))
{
highestKnown = totemSpellIds[i];
break;
}
}
if (!highestKnown)
return false; // Bot doesn't know any valid rank
// Only consider the bar set if the highest rank is assigned
return button->GetAction() != highestKnown;
}

View File

@@ -531,12 +531,14 @@ public:
class SetTotemAction : public Action class SetTotemAction : public Action
{ {
public: public:
SetTotemAction(PlayerbotAI* botAI, std::string const totemName, const uint32 totemSpellIds[], int actionButtonId) SetTotemAction(PlayerbotAI* botAI, std::string const totemName, const uint32 totemSpellIds[], size_t totemSpellIdsCount, int actionButtonId)
: Action(botAI, "set " + totemName), totemSpellIds(totemSpellIds), actionButtonId(actionButtonId) : Action(botAI, "set " + totemName), totemSpellIds(totemSpellIds), totemSpellIdsCount(totemSpellIdsCount), actionButtonId(actionButtonId)
{ {
} }
bool Execute(Event event) override; bool Execute(Event event) override;
bool isUseful() override;
uint32 const* totemSpellIds; uint32 const* totemSpellIds;
size_t totemSpellIdsCount;
int actionButtonId; int actionButtonId;
}; };
@@ -544,119 +546,119 @@ class SetStrengthOfEarthTotemAction : public SetTotemAction
{ {
public: public:
SetStrengthOfEarthTotemAction(PlayerbotAI* ai) SetStrengthOfEarthTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "strength of earth totem", STRENGTH_OF_EARTH_TOTEM, TOTEM_BAR_SLOT_EARTH) {} : SetTotemAction(ai, "strength of earth totem", STRENGTH_OF_EARTH_TOTEM, sizeof(STRENGTH_OF_EARTH_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {}
}; };
class SetStoneskinTotemAction : public SetTotemAction class SetStoneskinTotemAction : public SetTotemAction
{ {
public: public:
SetStoneskinTotemAction(PlayerbotAI* ai) SetStoneskinTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "stoneskin totem", STONESKIN_TOTEM, TOTEM_BAR_SLOT_EARTH) {} : SetTotemAction(ai, "stoneskin totem", STONESKIN_TOTEM, sizeof(STONESKIN_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {}
}; };
class SetTremorTotemAction : public SetTotemAction class SetTremorTotemAction : public SetTotemAction
{ {
public: public:
SetTremorTotemAction(PlayerbotAI* ai) SetTremorTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "tremor totem", TREMOR_TOTEM, TOTEM_BAR_SLOT_EARTH) {} : SetTotemAction(ai, "tremor totem", TREMOR_TOTEM, sizeof(TREMOR_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {}
}; };
class SetEarthbindTotemAction : public SetTotemAction class SetEarthbindTotemAction : public SetTotemAction
{ {
public: public:
SetEarthbindTotemAction(PlayerbotAI* ai) SetEarthbindTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "earthbind totem", EARTHBIND_TOTEM, TOTEM_BAR_SLOT_EARTH) {} : SetTotemAction(ai, "earthbind totem", EARTHBIND_TOTEM, sizeof(EARTHBIND_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {}
}; };
class SetSearingTotemAction : public SetTotemAction class SetSearingTotemAction : public SetTotemAction
{ {
public: public:
SetSearingTotemAction(PlayerbotAI* ai) SetSearingTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "searing totem", SEARING_TOTEM, TOTEM_BAR_SLOT_FIRE) {} : SetTotemAction(ai, "searing totem", SEARING_TOTEM, sizeof(SEARING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {}
}; };
class SetMagmaTotemAction : public SetTotemAction class SetMagmaTotemAction : public SetTotemAction
{ {
public: public:
SetMagmaTotemAction(PlayerbotAI* ai) SetMagmaTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "magma totem", MAGMA_TOTEM, TOTEM_BAR_SLOT_FIRE) {} : SetTotemAction(ai, "magma totem", MAGMA_TOTEM, sizeof(MAGMA_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {}
}; };
class SetFlametongueTotemAction : public SetTotemAction class SetFlametongueTotemAction : public SetTotemAction
{ {
public: public:
SetFlametongueTotemAction(PlayerbotAI* ai) SetFlametongueTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "flametongue totem", FLAMETONGUE_TOTEM, TOTEM_BAR_SLOT_FIRE) {} : SetTotemAction(ai, "flametongue totem", FLAMETONGUE_TOTEM, sizeof(FLAMETONGUE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {}
}; };
class SetTotemOfWrathAction : public SetTotemAction class SetTotemOfWrathAction : public SetTotemAction
{ {
public: public:
SetTotemOfWrathAction(PlayerbotAI* ai) SetTotemOfWrathAction(PlayerbotAI* ai)
: SetTotemAction(ai, "totem of wrath", TOTEM_OF_WRATH, TOTEM_BAR_SLOT_FIRE) {} : SetTotemAction(ai, "totem of wrath", TOTEM_OF_WRATH, sizeof(TOTEM_OF_WRATH)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {}
}; };
class SetFrostResistanceTotemAction : public SetTotemAction class SetFrostResistanceTotemAction : public SetTotemAction
{ {
public: public:
SetFrostResistanceTotemAction(PlayerbotAI* ai) SetFrostResistanceTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "frost resistance totem", FROST_RESISTANCE_TOTEM, TOTEM_BAR_SLOT_FIRE) {} : SetTotemAction(ai, "frost resistance totem", FROST_RESISTANCE_TOTEM, sizeof(FROST_RESISTANCE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {}
}; };
class SetHealingStreamTotemAction : public SetTotemAction class SetHealingStreamTotemAction : public SetTotemAction
{ {
public: public:
SetHealingStreamTotemAction(PlayerbotAI* ai) SetHealingStreamTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "healing stream totem", HEALING_STREAM_TOTEM, TOTEM_BAR_SLOT_WATER) {} : SetTotemAction(ai, "healing stream totem", HEALING_STREAM_TOTEM, sizeof(HEALING_STREAM_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {}
}; };
class SetManaSpringTotemAction : public SetTotemAction class SetManaSpringTotemAction : public SetTotemAction
{ {
public: public:
SetManaSpringTotemAction(PlayerbotAI* ai) SetManaSpringTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "mana spring totem", MANA_SPRING_TOTEM, TOTEM_BAR_SLOT_WATER) {} : SetTotemAction(ai, "mana spring totem", MANA_SPRING_TOTEM, sizeof(MANA_SPRING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {}
}; };
class SetCleansingTotemAction : public SetTotemAction class SetCleansingTotemAction : public SetTotemAction
{ {
public: public:
SetCleansingTotemAction(PlayerbotAI* ai) SetCleansingTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "cleansing totem", CLEANSING_TOTEM, TOTEM_BAR_SLOT_WATER) {} : SetTotemAction(ai, "cleansing totem", CLEANSING_TOTEM, sizeof(CLEANSING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {}
}; };
class SetFireResistanceTotemAction : public SetTotemAction class SetFireResistanceTotemAction : public SetTotemAction
{ {
public: public:
SetFireResistanceTotemAction(PlayerbotAI* ai) SetFireResistanceTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "fire resistance totem", FIRE_RESISTANCE_TOTEM, TOTEM_BAR_SLOT_WATER) {} : SetTotemAction(ai, "fire resistance totem", FIRE_RESISTANCE_TOTEM, sizeof(FIRE_RESISTANCE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {}
}; };
class SetWrathOfAirTotemAction : public SetTotemAction class SetWrathOfAirTotemAction : public SetTotemAction
{ {
public: public:
SetWrathOfAirTotemAction(PlayerbotAI* ai) SetWrathOfAirTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "wrath of air totem", WRATH_OF_AIR_TOTEM, TOTEM_BAR_SLOT_AIR) {} : SetTotemAction(ai, "wrath of air totem", WRATH_OF_AIR_TOTEM, sizeof(WRATH_OF_AIR_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {}
}; };
class SetWindfuryTotemAction : public SetTotemAction class SetWindfuryTotemAction : public SetTotemAction
{ {
public: public:
SetWindfuryTotemAction(PlayerbotAI* ai) SetWindfuryTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "windfury totem", WINDFURY_TOTEM, TOTEM_BAR_SLOT_AIR) {} : SetTotemAction(ai, "windfury totem", WINDFURY_TOTEM, sizeof(WINDFURY_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {}
}; };
class SetNatureResistanceTotemAction : public SetTotemAction class SetNatureResistanceTotemAction : public SetTotemAction
{ {
public: public:
SetNatureResistanceTotemAction(PlayerbotAI* ai) SetNatureResistanceTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "nature resistance totem", NATURE_RESISTANCE_TOTEM, TOTEM_BAR_SLOT_AIR) {} : SetTotemAction(ai, "nature resistance totem", NATURE_RESISTANCE_TOTEM, sizeof(NATURE_RESISTANCE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {}
}; };
class SetGroundingTotemAction : public SetTotemAction class SetGroundingTotemAction : public SetTotemAction
{ {
public: public:
SetGroundingTotemAction(PlayerbotAI* ai) SetGroundingTotemAction(PlayerbotAI* ai)
: SetTotemAction(ai, "grounding totem", GROUNDING_TOTEM, TOTEM_BAR_SLOT_AIR) {} : SetTotemAction(ai, "grounding totem", GROUNDING_TOTEM, sizeof(GROUNDING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {}
}; };
#endif #endif