From db1cfa6abc63db576bda65586a7364f778093417 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Jul 2024 23:01:25 +0800 Subject: [PATCH] [Random bots] Ensure teleport after randomize --- src/strategy/actions/ActionContext.h | 2 ++ src/strategy/actions/AutoLearnSpellAction.cpp | 13 ++++++++++++- src/strategy/actions/AutoLearnSpellAction.h | 8 ++++++++ src/strategy/actions/AutoTeleportForLevelAction.cpp | 13 ------------- src/strategy/actions/AutoTeleportForLevelAction.h | 2 -- src/strategy/generic/WorldPacketHandlerStrategy.cpp | 7 ++++--- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/strategy/actions/ActionContext.h b/src/strategy/actions/ActionContext.h index f2c1062c..ea8b3362 100644 --- a/src/strategy/actions/ActionContext.h +++ b/src/strategy/actions/ActionContext.h @@ -152,6 +152,7 @@ class ActionContext : public NamedObjectContext creators["auto talents"] = &ActionContext::auto_talents; creators["auto learn spell"] = &ActionContext::auto_learn_spell; creators["auto teleport for level"] = &ActionContext::auto_teleport_for_level; + creators["auto upgrade equip"] = &ActionContext::auto_upgrade_equip; creators["xp gain"] = &ActionContext::xp_gain; creators["invite nearby"] = &ActionContext::invite_nearby; creators["invite guild"] = &ActionContext::invite_guild; @@ -319,6 +320,7 @@ class ActionContext : public NamedObjectContext static Action* auto_talents(PlayerbotAI* botAI) { return new AutoSetTalentsAction(botAI); } static Action* auto_learn_spell(PlayerbotAI* botAI) { return new AutoLearnSpellAction(botAI); } static Action* auto_teleport_for_level(PlayerbotAI* botAI) { return new AutoTeleportForLevelAction(botAI); } + static Action* auto_upgrade_equip(PlayerbotAI* botAI) { return new AutoUpgradeEquipAction(botAI); } static Action* xp_gain(PlayerbotAI* botAI) { return new XpGainAction(botAI); } static Action* invite_nearby(PlayerbotAI* botAI) { return new InviteNearbyToGroupAction(botAI); } static Action* invite_guild(PlayerbotAI* botAI) { return new InviteGuildToGroupAction(botAI); } diff --git a/src/strategy/actions/AutoLearnSpellAction.cpp b/src/strategy/actions/AutoLearnSpellAction.cpp index 3202eb96..d742d4ad 100644 --- a/src/strategy/actions/AutoLearnSpellAction.cpp +++ b/src/strategy/actions/AutoLearnSpellAction.cpp @@ -24,7 +24,6 @@ bool AutoLearnSpellAction::Execute(Event event) out << "."; botAI->TellMaster(out); } - return true; } @@ -181,3 +180,15 @@ void AutoLearnSpellAction::LearnSpell(uint32 spellId, std::ostringstream* out) } } } + +bool AutoUpgradeEquipAction::Execute(Event event) { + if (!sPlayerbotAIConfig->autoUpgradeEquip || !sRandomPlayerbotMgr->IsRandomBot(bot)) { + return false; + } + PlayerbotFactory factory(bot, bot->GetLevel(), ITEM_QUALITY_RARE); + if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) { + factory.InitEquipment(true); + } + factory.InitAmmo(); + return true; +} diff --git a/src/strategy/actions/AutoLearnSpellAction.h b/src/strategy/actions/AutoLearnSpellAction.h index 9e6267c3..1cefaf48 100644 --- a/src/strategy/actions/AutoLearnSpellAction.h +++ b/src/strategy/actions/AutoLearnSpellAction.h @@ -23,4 +23,12 @@ class AutoLearnSpellAction : public Action void LearnSpell(uint32 spellId, std::ostringstream* out); }; +class AutoUpgradeEquipAction : public Action +{ + public: + AutoUpgradeEquipAction(PlayerbotAI* botAI, std::string const name = "auto upgrade equip") : Action(botAI, name) { } + + bool Execute(Event event); +}; + #endif diff --git a/src/strategy/actions/AutoTeleportForLevelAction.cpp b/src/strategy/actions/AutoTeleportForLevelAction.cpp index 1ad4e0c4..0f4c8f63 100644 --- a/src/strategy/actions/AutoTeleportForLevelAction.cpp +++ b/src/strategy/actions/AutoTeleportForLevelAction.cpp @@ -6,8 +6,6 @@ #include "SharedDefines.h" bool AutoTeleportForLevelAction::Execute(Event event) { - AutoUpgradeEquip(); - if (!sPlayerbotAIConfig->autoTeleportForLevel || !sRandomPlayerbotMgr->IsRandomBot(bot)) { return false; } @@ -16,15 +14,4 @@ bool AutoTeleportForLevelAction::Execute(Event event) { } sRandomPlayerbotMgr->RandomTeleportForLevel(bot); return true; -} - -void AutoTeleportForLevelAction::AutoUpgradeEquip() { - if (!sPlayerbotAIConfig->autoUpgradeEquip || !sRandomPlayerbotMgr->IsRandomBot(bot)) { - return; - } - PlayerbotFactory factory(bot, bot->GetLevel(), ITEM_QUALITY_RARE); - if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) { - factory.InitEquipment(true); - } - factory.InitAmmo(); } \ No newline at end of file diff --git a/src/strategy/actions/AutoTeleportForLevelAction.h b/src/strategy/actions/AutoTeleportForLevelAction.h index c8397d53..ca13edf2 100644 --- a/src/strategy/actions/AutoTeleportForLevelAction.h +++ b/src/strategy/actions/AutoTeleportForLevelAction.h @@ -15,8 +15,6 @@ class AutoTeleportForLevelAction : public Action AutoTeleportForLevelAction(PlayerbotAI* botAI, std::string const name = "auto teleport for level") : Action(botAI, name) { } bool Execute(Event event); - private: - void AutoUpgradeEquip(); }; #endif diff --git a/src/strategy/generic/WorldPacketHandlerStrategy.cpp b/src/strategy/generic/WorldPacketHandlerStrategy.cpp index a5c1065d..2db5ed84 100644 --- a/src/strategy/generic/WorldPacketHandlerStrategy.cpp +++ b/src/strategy/generic/WorldPacketHandlerStrategy.cpp @@ -37,9 +37,10 @@ void WorldPacketHandlerStrategy::InitTriggers(std::vector& trigger triggers.push_back(new TriggerNode("bg status", NextAction::array(0, new NextAction("bg status", relevance), nullptr))); triggers.push_back(new TriggerNode("xpgain", NextAction::array(0, new NextAction("xp gain", relevance), nullptr))); triggers.push_back(new TriggerNode("levelup", NextAction::array(0, - new NextAction("auto talents", relevance), - new NextAction("auto learn spell", relevance), - new NextAction("auto teleport for level", relevance), + new NextAction("auto teleport for level", relevance + 3), + new NextAction("auto talents", relevance + 2), + new NextAction("auto learn spell", relevance + 1), + new NextAction("auto upgrade equip", relevance), nullptr))); // triggers.push_back(new TriggerNode("group destroyed", NextAction::array(0, new NextAction("reset botAI", relevance), nullptr))); triggers.push_back(new TriggerNode("questgiver quest details", NextAction::array(0, new NextAction("turn in query quest", relevance), nullptr)));