Skip to content

Commit

Permalink
Make the playerbotai and playerbotmgr unique ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed Jan 22, 2024
1 parent d4f3b27 commit 436f9c7
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions playerbot/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ void PlayerbotHolder::DisablePlayerBot(uint32 guid)

if (bot->GetPlayerbotAI())
{
{
delete bot->GetPlayerbotAI();
}
bot->SetPlayerbotAI(0);
bot->RemovePlayerbotAI();
}
}
}
Expand All @@ -245,8 +242,7 @@ void PlayerbotHolder::OnBotLogin(Player * const bot)
PlayerbotAI* ai = bot->GetPlayerbotAI();
if (!ai)
{
ai = new PlayerbotAI(bot);
bot->SetPlayerbotAI(ai);
bot->CreatePlayerbotAI();
}

OnBotLoginInternal(bot);
Expand Down Expand Up @@ -826,33 +822,35 @@ list<string> PlayerbotHolder::HandlePlayerbotCommand(char const* args, Player* m
bool hasBot = false;

if (!master)
{
master = GetPlayerBotsBegin()->second;
}

PlayerbotAI* ai = master->GetPlayerbotAI();

if (ai)
{
hasBot = true;
}
else
{
ai = new PlayerbotAI(master);
master->SetPlayerbotAI(ai);
master->CreatePlayerbotAI();
ai = master->GetPlayerbotAI();
ai->SetMaster(master);
ai->ResetStrategies();
}

command = command.substr(6);

if(ai->DoSpecificAction("cdebug", Event(".bot",command,master), true))
{
messages.push_back("debug failed");
}

if (!hasBot)
{
if (master->GetPlayerbotAI())
{
{
delete master->GetPlayerbotAI();
}
master->SetPlayerbotAI(0);
master->RemovePlayerbotAI();
}
}

Expand Down

0 comments on commit 436f9c7

Please sign in to comment.