From ee481440c2a2e2181db564c27260b757e3612a05 Mon Sep 17 00:00:00 2001 From: yang <2101461382@qq.com> Date: Mon, 10 Jun 2024 16:41:06 +0800 Subject: [PATCH] [feat] Added the function to manually clear raids states of shared bot. --- src/PlayerbotFactory.cpp | 18 ++++++++++++++++++ src/PlayerbotFactory.h | 1 + src/PlayerbotMgr.cpp | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 672082c1..82ad1279 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -2624,6 +2624,24 @@ void PlayerbotFactory::InitMounts() } } +void PlayerbotFactory::UnbindInstance(){ + Player* p = bot; + ObjectGuid guid = p->GetGUID(); + + for (uint8 d = 0; d < MAX_DIFFICULTY; ++d) + { + std::vector toUnbind; + BoundInstancesMap const& m_boundInstances = sInstanceSaveMgr->PlayerGetBoundInstances(guid, Difficulty(d)); + for (BoundInstancesMap::const_iterator itr = m_boundInstances.begin(); itr != m_boundInstances.end(); ++itr) + { + InstanceSave* instanceSave = itr->second.save; + toUnbind.push_back(instanceSave); + } + for (std::vector::const_iterator itr = toUnbind.begin(); itr != toUnbind.end(); ++itr) + sInstanceSaveMgr->PlayerUnbindInstance(guid, (*itr)->GetMapId(), (*itr)->GetDifficulty(), true, p); + } +} + void PlayerbotFactory::InitPotions() { uint32 effects[] = { SPELL_EFFECT_HEAL, SPELL_EFFECT_ENERGIZE }; diff --git a/src/PlayerbotFactory.h b/src/PlayerbotFactory.h index 9dad3e38..1e4f6d51 100644 --- a/src/PlayerbotFactory.h +++ b/src/PlayerbotFactory.h @@ -136,6 +136,7 @@ class PlayerbotFactory void InitBags(bool destroyOld = true); void ApplyEnchantAndGemsNew(bool destoryOld = true); void InitInstanceQuests(); + void UnbindInstance(); private: void Prepare(); // void InitSecondEquipmentSet(); diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 099350f2..4c8f984f 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -615,6 +615,14 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje return "ok, gear score limit: " + std::to_string(gs / (ITEM_QUALITY_EPIC + 1)) + "(for epic)"; } } + + if (cmd == "refresh=raid") + { // TODO: This function is not perfect yet. If you are already in a raid, + // after the command is executed, the AI ​​needs to go back online or exit the raid and re-enter. + PlayerbotFactory factory(bot, bot->getLevel()); + factory.UnbindInstance(); + return "ok"; + } } if (cmd == "levelup" || cmd == "level")