From 01f0b71a172d5535a7d5755b897b19fbb4c76d16 Mon Sep 17 00:00:00 2001 From: kadeshar Date: Thu, 25 Sep 2025 20:31:42 +0200 Subject: [PATCH] - Code refactoring --- src/strategy/shaman/ShamanActions.cpp | 20 ++----------- src/strategy/shaman/ShamanActions.h | 40 ++++++++++++-------------- src/strategy/shaman/ShamanTriggers.cpp | 11 ++++--- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/strategy/shaman/ShamanActions.cpp b/src/strategy/shaman/ShamanActions.cpp index c1cacad9..83e915da 100644 --- a/src/strategy/shaman/ShamanActions.cpp +++ b/src/strategy/shaman/ShamanActions.cpp @@ -93,8 +93,9 @@ bool CastSpiritWalkAction::Execute(Event event) bool SetTotemAction::Execute(Event event) { + size_t spellIdsCount = sizeof(totemSpellIds) / sizeof(uint32); uint32 totemSpell = 0; - for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i) + for (int i = (int)spellIdsCount - 1; i >= 0; --i) { if (bot->HasSpell(totemSpellIds[i])) { @@ -107,20 +108,3 @@ bool SetTotemAction::Execute(Event event) bot->addActionButton(actionButtonId, totemSpell, ACTION_BUTTON_SPELL); 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 - for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i) - { - if (bot->HasSpell(totemSpellIds[i])) - return button->GetAction() != totemSpellIds[i]; - } - // Bot doesn't know any valid rank - return false; -} diff --git a/src/strategy/shaman/ShamanActions.h b/src/strategy/shaman/ShamanActions.h index a3d57102..4d64bb1d 100644 --- a/src/strategy/shaman/ShamanActions.h +++ b/src/strategy/shaman/ShamanActions.h @@ -531,14 +531,12 @@ public: class SetTotemAction : public Action { public: - SetTotemAction(PlayerbotAI* botAI, std::string const totemName, const uint32 totemSpellIds[], size_t totemSpellIdsCount, int actionButtonId) - : Action(botAI, "set " + totemName), totemSpellIds(totemSpellIds), totemSpellIdsCount(totemSpellIdsCount), actionButtonId(actionButtonId) + SetTotemAction(PlayerbotAI* botAI, std::string const totemName, const uint32 totemSpellIds[], int actionButtonId) + : Action(botAI, "set " + totemName), totemSpellIds(totemSpellIds), actionButtonId(actionButtonId) { } bool Execute(Event event) override; - bool isUseful() override; uint32 const* totemSpellIds; - size_t totemSpellIdsCount; int actionButtonId; }; @@ -546,119 +544,119 @@ class SetStrengthOfEarthTotemAction : public SetTotemAction { public: SetStrengthOfEarthTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "strength of earth totem", STRENGTH_OF_EARTH_TOTEM, sizeof(STRENGTH_OF_EARTH_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {} + : SetTotemAction(ai, "strength of earth totem", STRENGTH_OF_EARTH_TOTEM, TOTEM_BAR_SLOT_EARTH) {} }; class SetStoneskinTotemAction : public SetTotemAction { public: SetStoneskinTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "stoneskin totem", STONESKIN_TOTEM, sizeof(STONESKIN_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {} + : SetTotemAction(ai, "stoneskin totem", STONESKIN_TOTEM, TOTEM_BAR_SLOT_EARTH) {} }; class SetTremorTotemAction : public SetTotemAction { public: SetTremorTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "tremor totem", TREMOR_TOTEM, sizeof(TREMOR_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {} + : SetTotemAction(ai, "tremor totem", TREMOR_TOTEM, TOTEM_BAR_SLOT_EARTH) {} }; class SetEarthbindTotemAction : public SetTotemAction { public: SetEarthbindTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "earthbind totem", EARTHBIND_TOTEM, sizeof(EARTHBIND_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_EARTH) {} + : SetTotemAction(ai, "earthbind totem", EARTHBIND_TOTEM, TOTEM_BAR_SLOT_EARTH) {} }; class SetSearingTotemAction : public SetTotemAction { public: SetSearingTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "searing totem", SEARING_TOTEM, sizeof(SEARING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {} + : SetTotemAction(ai, "searing totem", SEARING_TOTEM, TOTEM_BAR_SLOT_FIRE) {} }; class SetMagmaTotemAction : public SetTotemAction { public: SetMagmaTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "magma totem", MAGMA_TOTEM, sizeof(MAGMA_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {} + : SetTotemAction(ai, "magma totem", MAGMA_TOTEM, TOTEM_BAR_SLOT_FIRE) {} }; class SetFlametongueTotemAction : public SetTotemAction { public: SetFlametongueTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "flametongue totem", FLAMETONGUE_TOTEM, sizeof(FLAMETONGUE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {} + : SetTotemAction(ai, "flametongue totem", FLAMETONGUE_TOTEM, TOTEM_BAR_SLOT_FIRE) {} }; class SetTotemOfWrathAction : public SetTotemAction { public: SetTotemOfWrathAction(PlayerbotAI* ai) - : SetTotemAction(ai, "totem of wrath", TOTEM_OF_WRATH, sizeof(TOTEM_OF_WRATH)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {} + : SetTotemAction(ai, "totem of wrath", TOTEM_OF_WRATH, TOTEM_BAR_SLOT_FIRE) {} }; class SetFrostResistanceTotemAction : public SetTotemAction { public: SetFrostResistanceTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "frost resistance totem", FROST_RESISTANCE_TOTEM, sizeof(FROST_RESISTANCE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_FIRE) {} + : SetTotemAction(ai, "frost resistance totem", FROST_RESISTANCE_TOTEM, TOTEM_BAR_SLOT_FIRE) {} }; class SetHealingStreamTotemAction : public SetTotemAction { public: SetHealingStreamTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "healing stream totem", HEALING_STREAM_TOTEM, sizeof(HEALING_STREAM_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {} + : SetTotemAction(ai, "healing stream totem", HEALING_STREAM_TOTEM, TOTEM_BAR_SLOT_WATER) {} }; class SetManaSpringTotemAction : public SetTotemAction { public: SetManaSpringTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "mana spring totem", MANA_SPRING_TOTEM, sizeof(MANA_SPRING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {} + : SetTotemAction(ai, "mana spring totem", MANA_SPRING_TOTEM, TOTEM_BAR_SLOT_WATER) {} }; class SetCleansingTotemAction : public SetTotemAction { public: SetCleansingTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "cleansing totem", CLEANSING_TOTEM, sizeof(CLEANSING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {} + : SetTotemAction(ai, "cleansing totem", CLEANSING_TOTEM, TOTEM_BAR_SLOT_WATER) {} }; class SetFireResistanceTotemAction : public SetTotemAction { public: SetFireResistanceTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "fire resistance totem", FIRE_RESISTANCE_TOTEM, sizeof(FIRE_RESISTANCE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_WATER) {} + : SetTotemAction(ai, "fire resistance totem", FIRE_RESISTANCE_TOTEM, TOTEM_BAR_SLOT_WATER) {} }; class SetWrathOfAirTotemAction : public SetTotemAction { public: SetWrathOfAirTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "wrath of air totem", WRATH_OF_AIR_TOTEM, sizeof(WRATH_OF_AIR_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {} + : SetTotemAction(ai, "wrath of air totem", WRATH_OF_AIR_TOTEM, TOTEM_BAR_SLOT_AIR) {} }; class SetWindfuryTotemAction : public SetTotemAction { public: SetWindfuryTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "windfury totem", WINDFURY_TOTEM, sizeof(WINDFURY_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {} + : SetTotemAction(ai, "windfury totem", WINDFURY_TOTEM, TOTEM_BAR_SLOT_AIR) {} }; class SetNatureResistanceTotemAction : public SetTotemAction { public: SetNatureResistanceTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "nature resistance totem", NATURE_RESISTANCE_TOTEM, sizeof(NATURE_RESISTANCE_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {} + : SetTotemAction(ai, "nature resistance totem", NATURE_RESISTANCE_TOTEM, TOTEM_BAR_SLOT_AIR) {} }; class SetGroundingTotemAction : public SetTotemAction { public: SetGroundingTotemAction(PlayerbotAI* ai) - : SetTotemAction(ai, "grounding totem", GROUNDING_TOTEM, sizeof(GROUNDING_TOTEM)/sizeof(uint32), TOTEM_BAR_SLOT_AIR) {} + : SetTotemAction(ai, "grounding totem", GROUNDING_TOTEM, TOTEM_BAR_SLOT_AIR) {} }; #endif diff --git a/src/strategy/shaman/ShamanTriggers.cpp b/src/strategy/shaman/ShamanTriggers.cpp index 35afbea1..225289e7 100644 --- a/src/strategy/shaman/ShamanTriggers.cpp +++ b/src/strategy/shaman/ShamanTriggers.cpp @@ -432,12 +432,15 @@ bool SetTotemTrigger::IsActive() return true; size_t totemSpellIdsCount = sizeof(totemSpellIds) / sizeof(uint32); - for (size_t i = 0; i < totemSpellIdsCount; ++i) + for (int i = (int)totemSpellIdsCount - 1; i >= 0; --i) + { - if (button->GetAction() == totemSpellIds[i]) + if (bot->HasSpell(totemSpellIds[i])) + { - return false; + return button->GetAction() != totemSpellIds[i]; } } - return true; + + return false; }