Skip to content

Create new object assessor specific for bots tor reduce checks. #8

@Celandriel

Description

@Celandriel

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions