forked from mod-playerbots/mod-playerbots
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
GPT suggestion.|
// BotAccessor.h
#pragma once
#include "Player.h"
#include <unordered_map>
class BotAccessor
{
public:
using BotMap = std::unordered_map<ObjectGuid, Player*>;
static void AddBot(Player* bot);
static void RemoveBot(Player* bot);
static BotMap const& GetBots();
private:
static BotMap _bots;
};
// BotAccessor.cpp
#include "BotAccessor.h"
BotAccessor::BotMap BotAccessor::_bots;
void BotAccessor::AddBot(Player* bot)
{
_bots[bot->GetGUID()] = bot;
}
void BotAccessor::RemoveBot(Player* bot)
{
_bots.erase(bot->GetGUID());
}
BotAccessor::BotMap const& BotAccessor::GetBots()
{
return _bots;
}
Hook
// PlayerbotMgr.cpp
#include "BotAccessor.h" // add include
bool PlayerbotMgr::AddPlayerBot(ObjectGuid guid, uint32 accountId)
{
// existing code that creates bot Player
Player* bot = ...;
if (bot)
{
// already goes into ObjectAccessor via LoginToWorld
BotAccessor::AddBot(bot); // <-- add this
return true;
}
return false;
}
void PlayerbotMgr::LogoutPlayerBot(ObjectGuid guid)
{
Player* bot = GetPlayerBot(guid);
if (!bot)
return;
BotAccessor::RemoveBot(bot); // <-- add this
// existing cleanup code (calls LogoutOfWorld -> RemoveObject in ObjectAccessor)
}
Metadata
Metadata
Assignees
Labels
No labels