[Command] Fix self command

This commit is contained in:
Yunfan Li
2024-07-19 14:52:19 +08:00
parent 2f93eeedc9
commit cdd4ab7080
2 changed files with 17 additions and 15 deletions

View File

@@ -842,7 +842,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
if (GET_PLAYERBOT_AI(master)) if (GET_PLAYERBOT_AI(master))
{ {
messages.push_back("Disable player botAI"); messages.push_back("Disable player botAI");
DisablePlayerBot(master->GetGUID()); delete GET_PLAYERBOT_AI(master);
} }
else if (sPlayerbotAIConfig->selfBotLevel == 0) else if (sPlayerbotAIConfig->selfBotLevel == 0)
messages.push_back("Self-bot is disabled"); messages.push_back("Self-bot is disabled");
@@ -851,7 +851,8 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
else else
{ {
messages.push_back("Enable player botAI"); messages.push_back("Enable player botAI");
OnBotLogin(master); sPlayerbotsMgr->AddPlayerbotData(master, true);
GET_PLAYERBOT_AI(master)->SetMaster(master);
} }
return messages; return messages;
@@ -1427,27 +1428,28 @@ void PlayerbotsMgr::AddPlayerbotData(Player* player, bool isBotAI)
return; return;
} }
// If the guid already exists in the map, remove it // If the guid already exists in the map, remove it
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsAIMap.find(player->GetGUID());
if (itr != _playerbotsAIMap.end()) if (!isBotAI)
{ {
_playerbotsAIMap.erase(itr); std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsMgrMap.find(player->GetGUID());
}
itr = _playerbotsMgrMap.find(player->GetGUID());
if (itr != _playerbotsMgrMap.end()) if (itr != _playerbotsMgrMap.end())
{ {
_playerbotsMgrMap.erase(itr); _playerbotsMgrMap.erase(itr);
} }
if (!isBotAI)
{
PlayerbotMgr* playerbotMgr = new PlayerbotMgr(player); PlayerbotMgr* playerbotMgr = new PlayerbotMgr(player);
ASSERT(_playerbotsAIMap.emplace(player->GetGUID(), playerbotMgr).second); ASSERT(_playerbotsMgrMap.emplace(player->GetGUID(), playerbotMgr).second);
playerbotMgr->OnPlayerLogin(player); playerbotMgr->OnPlayerLogin(player);
} }
else else
{ {
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsAIMap.find(player->GetGUID());
if (itr != _playerbotsAIMap.end())
{
_playerbotsAIMap.erase(itr);
}
PlayerbotAI* botAI = new PlayerbotAI(player); PlayerbotAI* botAI = new PlayerbotAI(player);
ASSERT(_playerbotsMgrMap.emplace(player->GetGUID(), botAI).second); ASSERT(_playerbotsAIMap.emplace(player->GetGUID(), botAI).second);
} }
} }

View File

@@ -299,7 +299,7 @@ class PlayerbotsScript : public PlayerbotScript
{ {
botAI->HandleBotOutgoingPacket(*packet); botAI->HandleBotOutgoingPacket(*packet);
} }
else if (PlayerbotMgr* playerbotMgr = GET_PLAYERBOT_MGR(player)) if (PlayerbotMgr* playerbotMgr = GET_PLAYERBOT_MGR(player))
{ {
playerbotMgr->HandleMasterOutgoingPacket(*packet); playerbotMgr->HandleMasterOutgoingPacket(*packet);
} }