Improper singletons migration to clean Meyer's singletons (cherry-pick) (#2082)

# Pull Request

- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )

Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---

## Complexity & Impact

- Does this change add new decision branches?
    - [x] No
    - [ ] Yes (**explain below**)

- Does this change increase per-bot or per-tick processing?
    - [x] No
    - [ ] Yes (**describe and justify impact**)

- Could this logic scale poorly under load?
    - [x] No
    - [ ] Yes (**explain why**)

---

## Defaults & Configuration

- Does this change modify default bot behavior?
    - [x] No
    - [ ] Yes (**explain why**)

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)
---

## Final Checklist

- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.

---------

Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
This commit is contained in:
bashermens
2026-01-30 21:49:37 +01:00
committed by GitHub
parent a92886032c
commit 13fff46fa0
233 changed files with 2460 additions and 2354 deletions

View File

@@ -48,7 +48,7 @@ void session(socket_ptr sock)
std::string buffer, request;
while (ReadLine(sock, &buffer, &request))
{
std::string const response = sRandomPlayerbotMgr->HandleRemoteCommand(request) + "\n";
std::string const response = sRandomPlayerbotMgr.HandleRemoteCommand(request) + "\n";
boost::asio::write(*sock, boost::asio::buffer(response.c_str(), response.size()));
request = "";
}
@@ -72,19 +72,19 @@ void server(Acore::Asio::IoContext& io_service, short port)
void Run()
{
if (!sPlayerbotAIConfig->commandServerPort)
if (!sPlayerbotAIConfig.commandServerPort)
{
return;
}
std::ostringstream s;
s << "Starting Playerbots Command Server on port " << sPlayerbotAIConfig->commandServerPort;
s << "Starting Playerbots Command Server on port " << sPlayerbotAIConfig.commandServerPort;
LOG_INFO("playerbots", "{}", s.str().c_str());
try
{
Acore::Asio::IoContext io_service;
server(io_service, sPlayerbotAIConfig->commandServerPort);
server(io_service, sPlayerbotAIConfig.commandServerPort);
}
catch (std::exception& e)

View File

@@ -9,17 +9,24 @@
class PlayerbotCommandServer
{
public:
PlayerbotCommandServer() {}
virtual ~PlayerbotCommandServer() {}
static PlayerbotCommandServer* instance()
static PlayerbotCommandServer& instance()
{
static PlayerbotCommandServer instance;
return &instance;
return instance;
}
void Start();
private:
PlayerbotCommandServer() = default;
~PlayerbotCommandServer() = default;
PlayerbotCommandServer(const PlayerbotCommandServer&) = delete;
PlayerbotCommandServer& operator=(const PlayerbotCommandServer&) = delete;
PlayerbotCommandServer(PlayerbotCommandServer&&) = delete;
PlayerbotCommandServer& operator=(PlayerbotCommandServer&&) = delete;
};
#define sPlayerbotCommandServer PlayerbotCommandServer::instance()
#endif

View File

@@ -10,7 +10,7 @@
PerfMonitorOperation* PerfMonitor::start(PerformanceMetric metric, std::string const name,
PerformanceStack* stack)
{
if (!sPlayerbotAIConfig->perfMonEnabled)
if (!sPlayerbotAIConfig.perfMonEnabled)
return nullptr;
std::string stackName = name;

View File

@@ -11,17 +11,16 @@
#include <map>
#include <mutex>
#include <vector>
#include "Common.h"
#include <cstdint>
typedef std::vector<std::string> PerformanceStack;
struct PerformanceData
{
uint64 minTime;
uint64 maxTime;
uint64 totalTime;
uint32 count;
uint64_t minTime;
uint64_t maxTime;
uint64_t totalTime;
uint32_t count;
std::mutex lock;
};
@@ -50,21 +49,28 @@ private:
class PerfMonitor
{
public:
PerfMonitor(){};
virtual ~PerfMonitor(){};
static PerfMonitor* instance()
static PerfMonitor& instance()
{
static PerfMonitor instance;
return &instance;
return instance;
}
public:
PerfMonitorOperation* start(PerformanceMetric metric, std::string const name,
PerformanceStack* stack = nullptr);
void PrintStats(bool perTick = false, bool fullStack = false);
void Reset();
private:
PerfMonitor() = default;
virtual ~PerfMonitor() = default;
PerfMonitor(const PerfMonitor&) = delete;
PerfMonitor& operator=(const PerfMonitor&) = delete;
PerfMonitor(PerfMonitor&&) = delete;
PerfMonitor& operator=(PerfMonitor&&) = delete;
std::map<PerformanceMetric, std::map<std::string, PerformanceData*> > data;
std::mutex lock;
};

View File

@@ -142,7 +142,7 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
{
LogAction("--- AI Tick ---");
if (sPlayerbotAIConfig->logValuesPerTick)
if (sPlayerbotAIConfig.logValuesPerTick)
LogValues();
bool actionExecuted = false;
@@ -154,7 +154,7 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
PushDefaultActions();
uint32 iterations = 0;
uint32 iterationsPerTick = queue.Size() * (minimal ? 2 : sPlayerbotAIConfig->iterationsPerTick);
uint32 iterationsPerTick = queue.Size() * (minimal ? 2 : sPlayerbotAIConfig.iterationsPerTick);
while (++iterations <= iterationsPerTick)
{
@@ -204,7 +204,7 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
}
}
PerfMonitorOperation* pmo = sPerfMonitor->start(PERF_MON_ACTION, action->getName(), &aiObjectContext->performanceStack);
PerfMonitorOperation* pmo = sPerfMonitor.start(PERF_MON_ACTION, action->getName(), &aiObjectContext->performanceStack);
actionExecuted = ListenAndExecute(action, event);
if (pmo)
pmo->finish();
@@ -457,7 +457,7 @@ void Engine::ProcessTriggers(bool minimal)
continue;
PerfMonitorOperation* pmo =
sPerfMonitor->start(PERF_MON_TRIGGER, trigger->getName(), &aiObjectContext->performanceStack);
sPerfMonitor.start(PERF_MON_TRIGGER, trigger->getName(), &aiObjectContext->performanceStack);
Event event = trigger->Check();
if (pmo)
pmo->finish();
@@ -599,7 +599,7 @@ bool Engine::ListenAndExecute(Action* action, Event event)
void Engine::LogAction(char const* format, ...)
{
Player* bot = botAI->GetBot();
if (sPlayerbotAIConfig->logInGroupOnly && (!bot->GetGroup() || !botAI->HasRealPlayerMaster()) && !testMode)
if (sPlayerbotAIConfig.logInGroupOnly && (!bot->GetGroup() || !botAI->HasRealPlayerMaster()) && !testMode)
return;
char buf[1024];
@@ -661,7 +661,7 @@ void Engine::LogValues()
return;
Player* bot = botAI->GetBot();
if (sPlayerbotAIConfig->logInGroupOnly && (!bot->GetGroup() || !botAI->HasRealPlayerMaster()))
if (sPlayerbotAIConfig.logInGroupOnly && (!bot->GetGroup() || !botAI->HasRealPlayerMaster()))
return;
std::string const text = botAI->GetAiObjectContext()->FormatValues();

View File

@@ -14,7 +14,7 @@ void PlayerbotAIBase::UpdateAI(uint32 elapsed, bool minimal)
if (totalPmo)
totalPmo->finish();
totalPmo = sPerfMonitor->start(PERF_MON_TOTAL, "PlayerbotAIBase::FullTick");
totalPmo = sPerfMonitor.start(PERF_MON_TOTAL, "PlayerbotAIBase::FullTick");
if (nextAICheckDelay > elapsed)
nextAICheckDelay -= elapsed;
@@ -35,7 +35,7 @@ void PlayerbotAIBase::SetNextCheckDelay(uint32 const delay)
nextAICheckDelay = delay;
// if (nextAICheckDelay > sPlayerbotAIConfig->globalCoolDown)
// if (nextAICheckDelay > sPlayerbotAIConfig.globalCoolDown)
// LOG_DEBUG("playerbots", "std::set next check delay: {}", nextAICheckDelay);
}
@@ -43,7 +43,7 @@ void PlayerbotAIBase::IncreaseNextCheckDelay(uint32 delay)
{
nextAICheckDelay += delay;
// if (nextAICheckDelay > sPlayerbotAIConfig->globalCoolDown)
// if (nextAICheckDelay > sPlayerbotAIConfig.globalCoolDown)
// LOG_DEBUG("playerbots", "increase next check delay: {}", nextAICheckDelay);
}
@@ -55,6 +55,6 @@ void PlayerbotAIBase::YieldThread(uint32 delay)
nextAICheckDelay = delay;
}
bool PlayerbotAIBase::IsActive() { return nextAICheckDelay < sPlayerbotAIConfig->maxWaitForMove; }
bool PlayerbotAIBase::IsActive() { return nextAICheckDelay < sPlayerbotAIConfig.maxWaitForMove; }
bool PlayerbotAIBase::IsBotAI() const { return _isBotAI; }

View File

@@ -17,7 +17,7 @@ public:
bool CanUpdateAI();
void SetNextCheckDelay(uint32 const delay);
void IncreaseNextCheckDelay(uint32 delay);
void YieldThread(uint32 delay = sPlayerbotAIConfig->reactDelay);
void YieldThread(uint32 delay = sPlayerbotAIConfig.reactDelay);
virtual void UpdateAI(uint32 elapsed, bool minimal = false);
virtual void UpdateAIInternal(uint32 elapsed, bool minimal = false) = 0;
bool IsActive();

View File

@@ -123,7 +123,7 @@ Unit* UnitCalculatedValue::Get()
{
if (checkInterval < 2)
{
PerfMonitorOperation* pmo = sPerfMonitor->start(
PerfMonitorOperation* pmo = sPerfMonitor.start(
PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
if (pmo)
@@ -135,7 +135,7 @@ Unit* UnitCalculatedValue::Get()
if (!lastCheckTime || now - lastCheckTime >= checkInterval)
{
lastCheckTime = now;
PerfMonitorOperation* pmo = sPerfMonitor->start(
PerfMonitorOperation* pmo = sPerfMonitor.start(
PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
if (pmo)
@@ -154,4 +154,4 @@ Unit* UnitManualSetValue::Get()
if (value && value->IsInWorld())
return value;
return nullptr;
}
}

View File

@@ -72,7 +72,7 @@ public:
{
if (checkInterval < 2)
{
// PerfMonitorOperation* pmo = sPerfMonitor->start(PERF_MON_VALUE, this->getName(),
// PerfMonitorOperation* pmo = sPerfMonitor.start(PERF_MON_VALUE, this->getName(),
// this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
// if (pmo)
@@ -84,7 +84,7 @@ public:
if (!lastCheckTime || now - lastCheckTime >= checkInterval)
{
lastCheckTime = now;
// PerfMonitorOperation* pmo = sPerfMonitor->start(PERF_MON_VALUE, this->getName(),
// PerfMonitorOperation* pmo = sPerfMonitor.start(PERF_MON_VALUE, this->getName(),
// this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
// if (pmo)
@@ -105,7 +105,7 @@ public:
{
if (checkInterval < 2)
{
// PerfMonitorOperation* pmo = sPerfMonitor->start(PERF_MON_VALUE, this->getName(),
// PerfMonitorOperation* pmo = sPerfMonitor.start(PERF_MON_VALUE, this->getName(),
// this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
// if (pmo)
@@ -117,7 +117,7 @@ public:
if (!lastCheckTime || now - lastCheckTime >= checkInterval)
{
lastCheckTime = now;
// PerfMonitorOperation* pmo = sPerfMonitor->start(PERF_MON_VALUE, this->getName(),
// PerfMonitorOperation* pmo = sPerfMonitor.start(PERF_MON_VALUE, this->getName(),
// this->context ? &this->context->performanceStack : nullptr);
value = Calculate();
// if (pmo)
@@ -154,7 +154,7 @@ public:
{
this->lastCheckTime = now;
PerfMonitorOperation* pmo = sPerfMonitor->start(
PerfMonitorOperation* pmo = sPerfMonitor.start(
PERF_MON_VALUE, this->getName(), this->context ? &this->context->performanceStack : nullptr);
this->value = this->Calculate();
if (pmo)

View File

@@ -281,7 +281,7 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
if (!player->InBattleground())
engine->addStrategiesNoInit("racials", "chat", "default", "cast time", "potions", "duel", "boost", nullptr);
if (sPlayerbotAIConfig->autoAvoidAoe && facade->HasRealPlayerMaster())
if (sPlayerbotAIConfig.autoAvoidAoe && facade->HasRealPlayerMaster())
engine->addStrategy("avoid aoe", false);
engine->addStrategy("formation", false);
@@ -399,13 +399,13 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
if (PlayerbotAI::IsHeal(player, true))
{
if (sPlayerbotAIConfig->autoSaveMana)
if (sPlayerbotAIConfig.autoSaveMana)
engine->addStrategy("save mana", false);
if (!sPlayerbotAIConfig->IsRestrictedHealerDPSMap(player->GetMapId()))
if (!sPlayerbotAIConfig.IsRestrictedHealerDPSMap(player->GetMapId()))
engine->addStrategy("healer dps", false);
}
if (facade->IsRealPlayer() || sRandomPlayerbotMgr->IsRandomBot(player))
if (facade->IsRealPlayer() || sRandomPlayerbotMgr.IsRandomBot(player))
{
if (!player->GetGroup())
{
@@ -448,10 +448,10 @@ void AiFactory::AddDefaultCombatStrategies(Player* player, PlayerbotAI* const fa
}
}
}
if (sRandomPlayerbotMgr->IsRandomBot(player))
engine->ChangeStrategy(sPlayerbotAIConfig->randomBotCombatStrategies);
if (sRandomPlayerbotMgr.IsRandomBot(player))
engine->ChangeStrategy(sPlayerbotAIConfig.randomBotCombatStrategies);
else
engine->ChangeStrategy(sPlayerbotAIConfig->combatStrategies);
engine->ChangeStrategy(sPlayerbotAIConfig.combatStrategies);
// Battleground switch
if (player->InBattleground() && player->GetBattleground())
@@ -586,10 +586,10 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
"gather", "duel", "pvp", "buff", "mount", "emote", nullptr);
}
if (sPlayerbotAIConfig->autoSaveMana && PlayerbotAI::IsHeal(player, true))
if (sPlayerbotAIConfig.autoSaveMana && PlayerbotAI::IsHeal(player, true))
nonCombatEngine->addStrategy("save mana", false);
if ((sRandomPlayerbotMgr->IsRandomBot(player)) && !player->InBattleground())
if ((sRandomPlayerbotMgr.IsRandomBot(player)) && !player->InBattleground())
{
Player* master = facade->GetMaster();
@@ -597,7 +597,7 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
if (!urand(0, 3))
nonCombatEngine->addStrategy("start duel", false);
if (sPlayerbotAIConfig->randomBotJoinLfg)
if (sPlayerbotAIConfig.randomBotJoinLfg)
nonCombatEngine->addStrategy("lfg", false);
if (!player->GetGroup() || player->GetGroup()->GetLeaderGUID() == player->GetGUID())
@@ -612,9 +612,9 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
// nonCombatEngine->addStrategy("guild");
nonCombatEngine->addStrategy("grind", false);
if (sPlayerbotAIConfig->enableNewRpgStrategy)
if (sPlayerbotAIConfig.enableNewRpgStrategy)
nonCombatEngine->addStrategy("new rpg", false);
else if (sPlayerbotAIConfig->autoDoQuests)
else if (sPlayerbotAIConfig.autoDoQuests)
{
// nonCombatEngine->addStrategy("travel");
nonCombatEngine->addStrategy("rpg", false);
@@ -622,13 +622,13 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
else
nonCombatEngine->addStrategy("move random", false);
if (sPlayerbotAIConfig->randomBotJoinBG)
if (sPlayerbotAIConfig.randomBotJoinBG)
nonCombatEngine->addStrategy("bg", false);
// if (!master || GET_PLAYERBOT_AI(master))
// nonCombatEngine->addStrategy("maintenance");
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig->randomBotNonCombatStrategies);
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig.randomBotNonCombatStrategies);
}
else
{
@@ -637,14 +637,14 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
if (master)
{
PlayerbotAI* masterBotAI = GET_PLAYERBOT_AI(master);
if (masterBotAI || sRandomPlayerbotMgr->IsRandomBot(player))
if (masterBotAI || sRandomPlayerbotMgr.IsRandomBot(player))
{
// nonCombatEngine->addStrategy("pvp", false);
// nonCombatEngine->addStrategy("collision");
// nonCombatEngine->addStrategy("group");
// nonCombatEngine->addStrategy("guild");
// if (sPlayerbotAIConfig->autoDoQuests)
// if (sPlayerbotAIConfig.autoDoQuests)
// {
// // nonCombatEngine->addStrategy("travel");
// nonCombatEngine->addStrategy("rpg");
@@ -657,19 +657,19 @@ void AiFactory::AddDefaultNonCombatStrategies(Player* player, PlayerbotAI* const
// if (masterBotAI)
// nonCombatEngine->addStrategy("maintenance");
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig->randomBotNonCombatStrategies);
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig.randomBotNonCombatStrategies);
}
else
{
// nonCombatEngine->addStrategy("pvp", false);
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig->nonCombatStrategies);
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig.nonCombatStrategies);
}
}
}
}
}
else
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig->nonCombatStrategies);
nonCombatEngine->ChangeStrategy(sPlayerbotAIConfig.nonCombatStrategies);
// Battleground switch
if (player->InBattleground() && player->GetBattleground())
@@ -726,7 +726,7 @@ void AiFactory::AddDefaultDeadStrategies(Player* player, PlayerbotAI* const faca
(void)facade; // unused and remove warning
deadEngine->addStrategiesNoInit("dead", "stay", "chat", "default", "follow", nullptr);
if (sRandomPlayerbotMgr->IsRandomBot(player) && !player->GetGroup())
if (sRandomPlayerbotMgr.IsRandomBot(player) && !player->GetGroup())
deadEngine->removeStrategy("follow", false);
}

View File

@@ -68,18 +68,18 @@ PlayerbotFactory::PlayerbotFactory(Player* bot, uint32 level, uint32 itemQuality
botAI = GET_PLAYERBOT_AI(bot);
if (!this->itemQuality)
{
uint32 gs = sPlayerbotAIConfig->randomGearScoreLimit == 0
uint32 gs = sPlayerbotAIConfig.randomGearScoreLimit == 0
? 0
: PlayerbotFactory::CalcMixedGearScore(sPlayerbotAIConfig->randomGearScoreLimit,
sPlayerbotAIConfig->randomGearQualityLimit);
this->itemQuality = sPlayerbotAIConfig->randomGearQualityLimit;
: PlayerbotFactory::CalcMixedGearScore(sPlayerbotAIConfig.randomGearScoreLimit,
sPlayerbotAIConfig.randomGearQualityLimit);
this->itemQuality = sPlayerbotAIConfig.randomGearQualityLimit;
this->gearScoreLimit = gs;
}
}
void PlayerbotFactory::Init()
{
if (sPlayerbotAIConfig->randomBotPreQuests)
if (sPlayerbotAIConfig.randomBotPreQuests)
{
ObjectMgr::QuestMap const& questTemplates = sObjectMgr->GetQuestTemplates();
for (ObjectMgr::QuestMap::const_iterator i = questTemplates.begin(); i != questTemplates.end(); ++i)
@@ -111,8 +111,8 @@ void PlayerbotFactory::Init()
}
}
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig->randomBotQuestIds.begin();
i != sPlayerbotAIConfig->randomBotQuestIds.end(); ++i)
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig.randomBotQuestIds.begin();
i != sPlayerbotAIConfig.randomBotQuestIds.end(); ++i)
{
uint32 questId = *i;
AddPrevQuests(questId, specialQuestIds);
@@ -190,7 +190,7 @@ void PlayerbotFactory::Init()
continue;
}
if (sRandomItemMgr->IsTestItem(gemId))
if (sRandomItemMgr.IsTestItem(gemId))
{
continue;
}
@@ -218,12 +218,12 @@ void PlayerbotFactory::Prepare()
{
bot->SetUInt32Value(PLAYER_XP, 0);
}
if (!sPlayerbotAIConfig->randomBotShowHelmet || !urand(0, 4))
if (!sPlayerbotAIConfig.randomBotShowHelmet || !urand(0, 4))
{
bot->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_HELM);
}
if (!sPlayerbotAIConfig->randomBotShowCloak || !urand(0, 4))
if (!sPlayerbotAIConfig.randomBotShowCloak || !urand(0, 4))
{
bot->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_HIDE_CLOAK);
}
@@ -231,7 +231,7 @@ void PlayerbotFactory::Prepare()
void PlayerbotFactory::Randomize(bool incremental)
{
// if (sPlayerbotAIConfig->disableRandomLevels)
// if (sPlayerbotAIConfig.disableRandomLevels)
// {
// return;
// }
@@ -240,8 +240,8 @@ void PlayerbotFactory::Randomize(bool incremental)
// LOG_DEBUG("playerbots", "Preparing to {} randomize...", (incremental ? "incremental" : "full"));
Prepare();
LOG_DEBUG("playerbots", "Resetting player...");
PerfMonitorOperation* pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reset");
if (!sPlayerbotAIConfig->equipmentPersistence || level < sPlayerbotAIConfig->equipmentPersistenceLevel)
PerfMonitorOperation* pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reset");
if (!sPlayerbotAIConfig.equipmentPersistence || level < sPlayerbotAIConfig.equipmentPersistenceLevel)
{
bot->resetTalents(true);
}
@@ -250,7 +250,7 @@ void PlayerbotFactory::Randomize(bool incremental)
ClearSkills();
ClearSpells();
ResetQuests();
if (!sPlayerbotAIConfig->equipmentPersistence || level < sPlayerbotAIConfig->equipmentPersistenceLevel)
if (!sPlayerbotAIConfig.equipmentPersistence || level < sPlayerbotAIConfig.equipmentPersistenceLevel)
{
ClearAllItems();
}
@@ -266,15 +266,15 @@ void PlayerbotFactory::Randomize(bool incremental)
if (pmo)
pmo->finish();
// pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Immersive");
// pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Immersive");
// LOG_INFO("playerbots", "Initializing immersive...");
// InitImmersive();
// if (pmo)
// pmo->finish();
if (sPlayerbotAIConfig->randomBotPreQuests)
if (sPlayerbotAIConfig.randomBotPreQuests)
{
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Quests");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Quests");
InitInstanceQuests();
InitAttunementQuests();
if (pmo)
@@ -282,157 +282,157 @@ void PlayerbotFactory::Randomize(bool incremental)
}
else
{
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Quests");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Quests");
InitAttunementQuests();
if (pmo)
pmo->finish();
}
LOG_DEBUG("playerbots", "Initializing skills (step 1)...");
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills1");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills1");
bot->LearnDefaultSkills();
InitSkills();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1");
LOG_DEBUG("playerbots", "Initializing spells (step 1)...");
InitClassSpells();
InitAvailableSpells();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Talents");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Talents");
LOG_DEBUG("playerbots", "Initializing talents...");
if (!incremental || !sPlayerbotAIConfig->equipmentPersistence ||
bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
if (!incremental || !sPlayerbotAIConfig.equipmentPersistence ||
bot->GetLevel() < sPlayerbotAIConfig.equipmentPersistenceLevel)
{
InitTalentsTree();
}
sRandomPlayerbotMgr->SetValue(bot->GetGUID().GetCounter(), "specNo", 0);
sRandomPlayerbotMgr.SetValue(bot->GetGUID().GetCounter(), "specNo", 0);
if (botAI)
{
sPlayerbotRepository->Reset(botAI);
PlayerbotRepository::instance().Reset(botAI);
// botAI->DoSpecificAction("auto talents");
botAI->ResetStrategies(false); // fix wrong stored strategy
}
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells2");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells2");
LOG_DEBUG("playerbots", "Initializing spells (step 2)...");
InitAvailableSpells();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reputation");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reputation");
LOG_DEBUG("playerbots", "Initializing reputation...");
InitReputation();
if (pmo)
pmo->finish();
LOG_DEBUG("playerbots", "Initializing special spells...");
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells3");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells3");
InitSpecialSpells();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts");
LOG_DEBUG("playerbots", "Initializing mounts...");
InitMounts();
// bot->SaveToDB(false, false);
if (pmo)
pmo->finish();
// pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills2");
// pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills2");
// LOG_INFO("playerbots", "Initializing skills (step 2)...");
// UpdateTradeSkills();
// if (pmo)
// pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Equip");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Equip");
LOG_DEBUG("playerbots", "Initializing equipmemt...");
if (!incremental || !sPlayerbotAIConfig->equipmentPersistence ||
bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
if (!incremental || !sPlayerbotAIConfig.equipmentPersistence ||
bot->GetLevel() < sPlayerbotAIConfig.equipmentPersistenceLevel)
{
if (sPlayerbotAIConfig->incrementalGearInit || !incremental)
InitEquipment(incremental, incremental ? false : sPlayerbotAIConfig->twoRoundsGearInit);
if (sPlayerbotAIConfig.incrementalGearInit || !incremental)
InitEquipment(incremental, incremental ? false : sPlayerbotAIConfig.twoRoundsGearInit);
}
// bot->SaveToDB(false, false);
if (pmo)
pmo->finish();
// if (bot->GetLevel() >= sPlayerbotAIConfig->minEnchantingBotLevel)
// if (bot->GetLevel() >= sPlayerbotAIConfig.minEnchantingBotLevel)
// {
// pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Enchant");
// pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Enchant");
// LOG_INFO("playerbots", "Initializing enchant templates...");
// LoadEnchantContainer();
// if (pmo)
// pmo->finish();
// }
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Bags");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Bags");
LOG_DEBUG("playerbots", "Initializing bags...");
InitBags();
// bot->SaveToDB(false, false);
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Ammo");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Ammo");
LOG_DEBUG("playerbots", "Initializing ammo...");
InitAmmo();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Food");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Food");
LOG_DEBUG("playerbots", "Initializing food...");
InitFood();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Potions");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Potions");
LOG_DEBUG("playerbots", "Initializing potions...");
InitPotions();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Reagents");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reagents");
LOG_DEBUG("playerbots", "Initializing reagents...");
InitReagents();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Keys");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Keys");
LOG_DEBUG("playerbots", "Initializing keys...");
InitKeyring();
if (pmo)
pmo->finish();
// pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_EqSets");
// pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_EqSets");
// LOG_DEBUG("playerbots", "Initializing second equipment set...");
// InitSecondEquipmentSet();
// if (pmo)
// pmo->finish();
if (bot->GetLevel() >= sPlayerbotAIConfig->minEnchantingBotLevel)
if (bot->GetLevel() >= sPlayerbotAIConfig.minEnchantingBotLevel)
{
ApplyEnchantAndGemsNew();
}
// {
// pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_EnchantTemplate");
// pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_EnchantTemplate");
// LOG_INFO("playerbots", "Initializing enchant templates...");
// ApplyEnchantTemplate();
// if (pmo)
// pmo->finish();
// }
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory");
LOG_DEBUG("playerbots", "Initializing inventory...");
// InitInventory();
if (pmo)
pmo->finish();
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Consumable");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Consumable");
LOG_DEBUG("playerbots", "Initializing consumables...");
InitConsumables();
if (pmo)
@@ -442,9 +442,9 @@ void PlayerbotFactory::Randomize(bool incremental)
InitGlyphs();
// bot->SaveToDB(false, false);
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Guilds");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Guilds");
// bot->SaveToDB(false, false);
if (sPlayerbotAIConfig->randomBotGuildCount > 0)
if (sPlayerbotAIConfig.randomBotGuildCount > 0)
{
LOG_DEBUG("playerbots", "Initializing guilds...");
InitGuild();
@@ -455,7 +455,7 @@ void PlayerbotFactory::Randomize(bool incremental)
if (bot->GetLevel() >= 70)
{
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Arenas");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Arenas");
// LOG_INFO("playerbots", "Initializing arena teams...");
InitArenaTeam();
if (pmo)
@@ -470,7 +470,7 @@ void PlayerbotFactory::Randomize(bool incremental)
}
if (bot->GetLevel() >= 10)
{
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Pet");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Pet");
LOG_DEBUG("playerbots", "Initializing pet...");
InitPet();
// bot->SaveToDB(false, false);
@@ -479,7 +479,7 @@ void PlayerbotFactory::Randomize(bool incremental)
pmo->finish();
}
pmo = sPerfMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Save");
pmo = sPerfMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Save");
LOG_DEBUG("playerbots", "Saving to DB...");
bot->SetMoney(urand(level * 100000, level * 5 * 100000));
bot->SetHealth(bot->GetMaxHealth());
@@ -493,7 +493,7 @@ void PlayerbotFactory::Randomize(bool incremental)
void PlayerbotFactory::Refresh()
{
// Prepare();
// if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
// if (!sPlayerbotAIConfig.equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig.equipmentPersistenceLevel)
// {
// InitEquipment(true);
// }
@@ -513,11 +513,11 @@ void PlayerbotFactory::Refresh()
InitSpecialSpells();
InitMounts();
InitKeyring();
if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel)
if (!sPlayerbotAIConfig.equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig.equipmentPersistenceLevel)
{
InitTalentsTree(true, true, true);
}
if (bot->GetLevel() >= sPlayerbotAIConfig->minEnchantingBotLevel)
if (bot->GetLevel() >= sPlayerbotAIConfig.minEnchantingBotLevel)
{
ApplyEnchantAndGemsNew();
}
@@ -746,7 +746,7 @@ void PlayerbotFactory::InitConsumables()
void PlayerbotFactory::InitPetTalents()
{
if (bot->GetLevel() <= 70 && sPlayerbotAIConfig->limitTalentsExpansion)
if (bot->GetLevel() <= 70 && sPlayerbotAIConfig.limitTalentsExpansion)
return;
Pet* pet = bot->GetPet();
@@ -794,7 +794,7 @@ void PlayerbotFactory::InitPetTalents()
}
std::vector<std::vector<uint32>> order =
sPlayerbotAIConfig->parsedHunterPetLinkOrder[pet_family->petTalentType][20];
sPlayerbotAIConfig.parsedHunterPetLinkOrder[pet_family->petTalentType][20];
uint32 maxTalentPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel());
if (order.empty())
@@ -842,16 +842,16 @@ void PlayerbotFactory::InitPetTalents()
uint32 spec = pet_family->petTalentType;
uint32 startPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel());
while (startPoints > 1 && startPoints < 20 &&
sPlayerbotAIConfig->parsedHunterPetLinkOrder[spec][startPoints].size() == 0)
sPlayerbotAIConfig.parsedHunterPetLinkOrder[spec][startPoints].size() == 0)
{
startPoints--;
}
for (uint32 points = startPoints; points <= 20; points++)
{
if (sPlayerbotAIConfig->parsedHunterPetLinkOrder[spec][points].size() == 0)
if (sPlayerbotAIConfig.parsedHunterPetLinkOrder[spec][points].size() == 0)
continue;
for (std::vector<uint32>& p : sPlayerbotAIConfig->parsedHunterPetLinkOrder[spec][points])
for (std::vector<uint32>& p : sPlayerbotAIConfig.parsedHunterPetLinkOrder[spec][points])
{
uint32 row = p[0], col = p[1], lvl = p[2];
uint32 talentID = 0;
@@ -924,17 +924,17 @@ void PlayerbotFactory::InitPet()
if (itr->second.minlevel > bot->GetLevel())
continue;
bool onlyWolf = sPlayerbotAIConfig->hunterWolfPet == 2 ||
(sPlayerbotAIConfig->hunterWolfPet == 1 &&
bool onlyWolf = sPlayerbotAIConfig.hunterWolfPet == 2 ||
(sPlayerbotAIConfig.hunterWolfPet == 1 &&
bot->GetLevel() >= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL));
// Wolf only (for higher dps)
if (onlyWolf && itr->second.family != CREATURE_FAMILY_WOLF)
continue;
// Exclude configured pet families
if (std::find(sPlayerbotAIConfig->excludedHunterPetFamilies.begin(),
sPlayerbotAIConfig->excludedHunterPetFamilies.end(),
itr->second.family) != sPlayerbotAIConfig->excludedHunterPetFamilies.end())
if (std::find(sPlayerbotAIConfig.excludedHunterPetFamilies.begin(),
sPlayerbotAIConfig.excludedHunterPetFamilies.end(),
itr->second.family) != sPlayerbotAIConfig.excludedHunterPetFamilies.end())
continue;
ids.push_back(itr->first);
@@ -1123,8 +1123,8 @@ void PlayerbotFactory::InitTalentsTree(bool increment /*false*/, bool use_templa
bool isCat = !bot->HasAura(16931);
if (!isCat && bot->GetLevel() == 20)
{
uint32 bearP = sPlayerbotAIConfig->randomClassSpecProb[cls][1];
uint32 catP = sPlayerbotAIConfig->randomClassSpecProb[cls][3];
uint32 bearP = sPlayerbotAIConfig.randomClassSpecProb[cls][1];
uint32 catP = sPlayerbotAIConfig.randomClassSpecProb[cls][3];
if (urand(1, bearP + catP) <= catP)
isCat = true;
}
@@ -1139,14 +1139,14 @@ void PlayerbotFactory::InitTalentsTree(bool increment /*false*/, bool use_templa
uint32 pointSum = 0;
for (int i = 0; i < MAX_SPECNO; i++)
{
pointSum += sPlayerbotAIConfig->randomClassSpecProb[cls][i];
pointSum += sPlayerbotAIConfig.randomClassSpecProb[cls][i];
}
uint32 point = urand(1, pointSum);
uint32 currentP = 0;
int i;
for (i = 0; i < MAX_SPECNO; i++)
{
currentP += sPlayerbotAIConfig->randomClassSpecProb[cls][i];
currentP += sPlayerbotAIConfig.randomClassSpecProb[cls][i];
if (point <= currentP)
{
specTab = i;
@@ -1204,17 +1204,17 @@ void PlayerbotFactory::InitTalentsBySpecNo(Player* bot, int specNo, bool reset)
spells_row[talentInfo->Row].push_back(talentInfo);
}
while (startLevel > 1 && startLevel < 80 &&
sPlayerbotAIConfig->parsedSpecLinkOrder[cls][specNo][startLevel].size() == 0)
sPlayerbotAIConfig.parsedSpecLinkOrder[cls][specNo][startLevel].size() == 0)
{
startLevel--;
}
for (int level = startLevel; level <= 80; level++)
{
if (sPlayerbotAIConfig->parsedSpecLinkOrder[cls][specNo][level].size() == 0)
if (sPlayerbotAIConfig.parsedSpecLinkOrder[cls][specNo][level].size() == 0)
{
continue;
}
for (std::vector<uint32>& p : sPlayerbotAIConfig->parsedSpecLinkOrder[cls][specNo][level])
for (std::vector<uint32>& p : sPlayerbotAIConfig.parsedSpecLinkOrder[cls][specNo][level])
{
uint32 tab = p[0], row = p[1], col = p[2], lvl = p[3];
uint32 talentID = -1;
@@ -1341,7 +1341,7 @@ private:
if (keep.find(id) != keep.end())
return false;
if (sPlayerbotAIConfig->IsInRandomQuestItemList(id))
if (sPlayerbotAIConfig.IsInRandomQuestItemList(id))
return true;
return false;
@@ -1603,7 +1603,7 @@ void Shuffle(std::vector<uint32>& items)
// bool noItem = false;
// uint32 quality = urand(ITEM_QUALITY_UNCOMMON, ITEM_QUALITY_EPIC);
// uint32 attempts = 10;
// if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && quality > ITEM_QUALITY_NORMAL)
// if (urand(0, 100) < 100 * sPlayerbotAIConfig.randomGearLoweringChance && quality > ITEM_QUALITY_NORMAL)
// {
// quality--;
// }
@@ -1614,11 +1614,11 @@ void Shuffle(std::vector<uint32>& items)
// uint32 itemInSlot = isUpgrade ? oldItem->GetTemplate()->ItemId : 0;
// uint32 maxLevel = sPlayerbotAIConfig->randomBotMaxLevel;
// uint32 maxLevel = sPlayerbotAIConfig.randomBotMaxLevel;
// if (maxLevel > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
// maxLevel = sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL);
// uint32 minLevel = sPlayerbotAIConfig->randomBotMinLevel;
// uint32 minLevel = sPlayerbotAIConfig.randomBotMinLevel;
// if (minLevel < sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL))
// minLevel = sWorld->getIntConfig(CONFIG_START_PLAYER_LEVEL);
@@ -1627,7 +1627,7 @@ void Shuffle(std::vector<uint32>& items)
// {
// if (isUpgrade)
// {
// std::vector<uint32> ids = sRandomItemMgr->GetUpgradeList(bot, specName, slot, 0, itemInSlot);
// std::vector<uint32> ids = sRandomItemMgr.GetUpgradeList(bot, specName, slot, 0, itemInSlot);
// if (!ids.empty())
// Shuffle(ids);
@@ -1667,7 +1667,7 @@ void Shuffle(std::vector<uint32>& items)
// }
// else
// {
// std::vector<uint32> ids = sRandomItemMgr->GetUpgradeList(bot, specName, slot, quality, itemInSlot);
// std::vector<uint32> ids = sRandomItemMgr.GetUpgradeList(bot, specName, slot, quality, itemInSlot);
// if (!ids.empty())
// Shuffle(ids);
@@ -1706,7 +1706,7 @@ void Shuffle(std::vector<uint32>& items)
void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
{
if (incremental && !sPlayerbotAIConfig->incrementalGearInit)
if (incremental && !sPlayerbotAIConfig.incrementalGearInit)
return;
if (level < 5)
@@ -1786,7 +1786,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
int32 desiredQuality = itemQuality;
if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL)
if (urand(0, 100) < 100 * sPlayerbotAIConfig.randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL)
{
desiredQuality--;
}
@@ -1797,7 +1797,7 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
{
for (InventoryType inventoryType : GetPossibleInventoryTypeListBySlot((EquipmentSlots)slot))
{
for (uint32 itemId : sRandomItemMgr->GetCachedEquipments(requiredLevel, inventoryType))
for (uint32 itemId : sRandomItemMgr.GetCachedEquipments(requiredLevel, inventoryType))
{
if (itemId == 46978) // shaman earth ring totem
{
@@ -1808,10 +1808,10 @@ void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
continue;
// disable next expansion gear
if (sPlayerbotAIConfig->limitGearExpansion && bot->GetLevel() <= 60 && itemId >= 23728)
if (sPlayerbotAIConfig.limitGearExpansion && bot->GetLevel() <= 60 && itemId >= 23728)
continue;
if (sPlayerbotAIConfig->limitGearExpansion && bot->GetLevel() <= 70 && itemId >= 35570 &&
if (sPlayerbotAIConfig.limitGearExpansion && bot->GetLevel() <= 70 && itemId >= 35570 &&
itemId != 36737 && itemId != 37739 &&
itemId != 37740) // transition point from TBC -> WOTLK isn't as clear, and there are other
// wearable TBC items above 35570 but nothing of significance
@@ -2009,7 +2009,7 @@ bool PlayerbotFactory::IsDesiredReplacement(Item* item)
}
// if (!requiredLevel)
// {
// requiredLevel = sRandomItemMgr->GetMinLevelFromCache(proto->ItemId);
// requiredLevel = sRandomItemMgr.GetMinLevelFromCache(proto->ItemId);
// }
uint32 delta = 1 + (80 - bot->GetLevel()) / 10;
@@ -2039,7 +2039,7 @@ inline Item* StoreNewItemInInventorySlot(Player* player, uint32 newItemId, uint3
// std::map<uint32, std::vector<uint32>> items;
// uint32 desiredQuality = itemQuality;
// while (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality >
// while (urand(0, 100) < 100 * sPlayerbotAIConfig.randomGearLoweringChance && desiredQuality >
// ITEM_QUALITY_NORMAL)
// {
// desiredQuality--;
@@ -2061,9 +2061,9 @@ inline Item* StoreNewItemInInventorySlot(Player* player, uint32 newItemId, uint3
// //if (!CanEquipWeapon(proto))
// // continue;
// if (sRandomItemMgr->HasStatWeight(proto->ItemId))
// if (sRandomItemMgr.HasStatWeight(proto->ItemId))
// {
// if (!sRandomItemMgr->GetLiveStatWeight(bot, proto->ItemId))
// if (!sRandomItemMgr.GetLiveStatWeight(bot, proto->ItemId))
// continue;
// }
@@ -2096,9 +2096,9 @@ inline Item* StoreNewItemInInventorySlot(Player* player, uint32 newItemId, uint3
// //if (!CanEquipArmor(proto))
// // continue;
// if (sRandomItemMgr->HasStatWeight(proto->ItemId))
// if (sRandomItemMgr.HasStatWeight(proto->ItemId))
// {
// if (!sRandomItemMgr->GetLiveStatWeight(bot, proto->ItemId))
// if (!sRandomItemMgr.GetLiveStatWeight(bot, proto->ItemId))
// continue;
// }
@@ -2173,10 +2173,10 @@ void PlayerbotFactory::InitBags(bool destroyOld)
void PlayerbotFactory::EnchantItem(Item* item)
{
if (bot->GetLevel() < sPlayerbotAIConfig->minEnchantingBotLevel)
if (bot->GetLevel() < sPlayerbotAIConfig.minEnchantingBotLevel)
return;
if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance)
if (urand(0, 100) < 100 * sPlayerbotAIConfig.randomGearLoweringChance)
return;
ItemTemplate const* proto = item->GetTemplate();
@@ -2279,8 +2279,8 @@ bool PlayerbotFactory::CanEquipUnseenItem(uint8 slot, uint16& dest, uint32 item)
void PlayerbotFactory::InitTradeSkills()
{
uint16 firstSkill = sRandomPlayerbotMgr->GetValue(bot, "firstSkill");
uint16 secondSkill = sRandomPlayerbotMgr->GetValue(bot, "secondSkill");
uint16 firstSkill = sRandomPlayerbotMgr.GetValue(bot, "firstSkill");
uint16 secondSkill = sRandomPlayerbotMgr.GetValue(bot, "secondSkill");
if (!firstSkill || !secondSkill)
{
std::vector<uint32> firstSkills;
@@ -2332,8 +2332,8 @@ void PlayerbotFactory::InitTradeSkills()
break;
}
sRandomPlayerbotMgr->SetValue(bot, "firstSkill", firstSkill);
sRandomPlayerbotMgr->SetValue(bot, "secondSkill", secondSkill);
sRandomPlayerbotMgr.SetValue(bot, "firstSkill", firstSkill);
sRandomPlayerbotMgr.SetValue(bot, "secondSkill", secondSkill);
}
SetRandomSkill(SKILL_FIRST_AID);
@@ -2359,13 +2359,13 @@ void PlayerbotFactory::InitSkills()
bot->UpdateSkillsForLevel();
bot->SetSkill(SKILL_RIDING, 0, 0, 0);
if (bot->GetLevel() >= sPlayerbotAIConfig->useGroundMountAtMinLevel)
if (bot->GetLevel() >= sPlayerbotAIConfig.useGroundMountAtMinLevel)
bot->learnSpell(33388);
if (bot->GetLevel() >= sPlayerbotAIConfig->useFastGroundMountAtMinLevel)
if (bot->GetLevel() >= sPlayerbotAIConfig.useFastGroundMountAtMinLevel)
bot->learnSpell(33391);
if (bot->GetLevel() >= sPlayerbotAIConfig->useFlyMountAtMinLevel)
if (bot->GetLevel() >= sPlayerbotAIConfig.useFlyMountAtMinLevel)
bot->learnSpell(34090);
if (bot->GetLevel() >= sPlayerbotAIConfig->useFastFlyMountAtMinLevel)
if (bot->GetLevel() >= sPlayerbotAIConfig.useFastFlyMountAtMinLevel)
bot->learnSpell(34091);
uint32 skillLevel = bot->GetLevel() < 40 ? 0 : 1;
@@ -2680,8 +2680,8 @@ void PlayerbotFactory::InitClassSpells()
void PlayerbotFactory::InitSpecialSpells()
{
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig->randomBotSpellIds.begin();
i != sPlayerbotAIConfig->randomBotSpellIds.end(); ++i)
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig.randomBotSpellIds.begin();
i != sPlayerbotAIConfig.randomBotSpellIds.end(); ++i)
{
uint32 spellId = *i;
bot->learnSpell(spellId);
@@ -2752,13 +2752,13 @@ void PlayerbotFactory::InitTalents(uint32 specNo)
void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab)
{
// if (sPlayerbotAIConfig->parsedSpecLinkOrder[bot->getClass()][specNo][80].size() == 0)
// if (sPlayerbotAIConfig.parsedSpecLinkOrder[bot->getClass()][specNo][80].size() == 0)
// {
// return;
// }
uint32 cls = bot->getClass();
int startLevel = bot->GetLevel();
uint32 specIndex = sPlayerbotAIConfig->randomClassSpecIndex[cls][specTab];
uint32 specIndex = sPlayerbotAIConfig.randomClassSpecIndex[cls][specTab];
uint32 classMask = bot->getClassMask();
std::unordered_map<uint32, std::vector<TalentEntry const*>> spells_row;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
@@ -2777,23 +2777,23 @@ void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab)
spells_row[talentInfo->Row].push_back(talentInfo);
}
while (startLevel > 1 && startLevel < 80 &&
sPlayerbotAIConfig->parsedSpecLinkOrder[cls][specIndex][startLevel].size() == 0)
sPlayerbotAIConfig.parsedSpecLinkOrder[cls][specIndex][startLevel].size() == 0)
{
startLevel--;
}
for (int level = startLevel; level <= 80; level++)
{
if (sPlayerbotAIConfig->parsedSpecLinkOrder[cls][specIndex][level].size() == 0)
if (sPlayerbotAIConfig.parsedSpecLinkOrder[cls][specIndex][level].size() == 0)
{
continue;
}
for (std::vector<uint32>& p : sPlayerbotAIConfig->parsedSpecLinkOrder[cls][specIndex][level])
for (std::vector<uint32>& p : sPlayerbotAIConfig.parsedSpecLinkOrder[cls][specIndex][level])
{
uint32 tab = p[0], row = p[1], col = p[2], lvl = p[3];
if (sPlayerbotAIConfig->limitTalentsExpansion && bot->GetLevel() <= 60 && (row > 6 || (row == 6 && col != 1)))
if (sPlayerbotAIConfig.limitTalentsExpansion && bot->GetLevel() <= 60 && (row > 6 || (row == 6 && col != 1)))
continue;
if (sPlayerbotAIConfig->limitTalentsExpansion && bot->GetLevel() <= 70 && (row > 8 || (row == 8 && col != 1)))
if (sPlayerbotAIConfig.limitTalentsExpansion && bot->GetLevel() <= 70 && (row > 8 || (row == 8 && col != 1)))
continue;
uint32 talentID = 0;
@@ -2848,8 +2848,8 @@ void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab)
ObjectGuid PlayerbotFactory::GetRandomBot()
{
GuidVector guids;
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig->randomBotAccounts.begin();
i != sPlayerbotAIConfig->randomBotAccounts.end(); i++)
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig.randomBotAccounts.begin();
i != sPlayerbotAIConfig.randomBotAccounts.end(); i++)
{
uint32 accountId = *i;
if (!AccountMgr::GetCharactersCount(accountId))
@@ -2981,7 +2981,7 @@ void PlayerbotFactory::InitAmmo()
if (!subClass)
return;
std::vector<uint32> ammoEntryList = sRandomItemMgr->GetAmmo(level, subClass);
std::vector<uint32> ammoEntryList = sRandomItemMgr.GetAmmo(level, subClass);
uint32 entry = 0;
for (uint32 tEntry : ammoEntryList)
{
@@ -2990,10 +2990,10 @@ void PlayerbotFactory::InitAmmo()
continue;
// disable next expansion ammo
if (sPlayerbotAIConfig->limitGearExpansion && bot->GetLevel() <= 60 && tEntry >= 23728)
if (sPlayerbotAIConfig.limitGearExpansion && bot->GetLevel() <= 60 && tEntry >= 23728)
continue;
if (sPlayerbotAIConfig->limitGearExpansion && bot->GetLevel() <= 70 && tEntry >= 35570)
if (sPlayerbotAIConfig.limitGearExpansion && bot->GetLevel() <= 70 && tEntry >= 35570)
continue;
entry = tEntry;
@@ -3023,10 +3023,10 @@ uint32 PlayerbotFactory::CalcMixedGearScore(uint32 gs, uint32 quality)
void PlayerbotFactory::InitMounts()
{
uint32 firstmount = sPlayerbotAIConfig->useGroundMountAtMinLevel;
uint32 secondmount = sPlayerbotAIConfig->useFastGroundMountAtMinLevel;
uint32 thirdmount = sPlayerbotAIConfig->useFlyMountAtMinLevel;
uint32 fourthmount = sPlayerbotAIConfig->useFastFlyMountAtMinLevel;
uint32 firstmount = sPlayerbotAIConfig.useGroundMountAtMinLevel;
uint32 secondmount = sPlayerbotAIConfig.useFastGroundMountAtMinLevel;
uint32 thirdmount = sPlayerbotAIConfig.useFlyMountAtMinLevel;
uint32 fourthmount = sPlayerbotAIConfig.useFastFlyMountAtMinLevel;
if (bot->GetLevel() < firstmount)
return;
@@ -3165,7 +3165,7 @@ void PlayerbotFactory::InitPotions()
if (!visitor.GetResult().empty())
continue;
uint32 itemId = sRandomItemMgr->GetRandomPotion(level, effect);
uint32 itemId = sRandomItemMgr.GetRandomPotion(level, effect);
if (!itemId)
{
// LOG_INFO("playerbots", "No potions (type {}) available for bot {} ({} level)", effect,
@@ -3499,7 +3499,7 @@ void PlayerbotFactory::InitGlyphs(bool increment)
}
}
if (sPlayerbotAIConfig->limitTalentsExpansion && bot->GetLevel() <= 70)
if (sPlayerbotAIConfig.limitTalentsExpansion && bot->GetLevel() <= 70)
{
bot->SendTalentsInfoData(false);
return;
@@ -3722,10 +3722,10 @@ void PlayerbotFactory::InitGlyphs(bool increment)
// GlyphSlotEntry const *gs = sGlyphSlotStore.LookupEntry(slot);
// if (!gs)
// continue;
if (sPlayerbotAIConfig->parsedSpecGlyph[cls][tab].size() > slotIndex &&
sPlayerbotAIConfig->parsedSpecGlyph[cls][tab][slotIndex] != 0)
if (sPlayerbotAIConfig.parsedSpecGlyph[cls][tab].size() > slotIndex &&
sPlayerbotAIConfig.parsedSpecGlyph[cls][tab][slotIndex] != 0)
{
uint32 itemId = sPlayerbotAIConfig->parsedSpecGlyph[cls][tab][slotIndex];
uint32 itemId = sPlayerbotAIConfig.parsedSpecGlyph[cls][tab][slotIndex];
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId);
if (proto->Class != ITEM_CLASS_GLYPH)
continue;
@@ -3859,7 +3859,7 @@ Item* PlayerbotFactory::StoreItem(uint32 itemId, uint32 count)
void PlayerbotFactory::InitInventoryTrade()
{
uint32 itemId = sRandomItemMgr->GetRandomTrade(level);
uint32 itemId = sRandomItemMgr.GetRandomTrade(level);
if (!itemId)
{
LOG_ERROR("playerbots", "No trade items available for bot {} ({} level)", bot->GetName().c_str(),
@@ -3895,7 +3895,7 @@ void PlayerbotFactory::InitInventoryEquip()
std::vector<uint32> ids;
uint32 desiredQuality = itemQuality;
if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL)
if (urand(0, 100) < 100 * sPlayerbotAIConfig.randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL)
{
desiredQuality--;
}
@@ -3949,21 +3949,21 @@ void PlayerbotFactory::InitGuild()
return;
}
std::string guildName = sPlayerbotGuildMgr->AssignToGuild(bot);
std::string guildName = PlayerbotGuildMgr::instance().AssignToGuild(bot);
if (guildName.empty())
return;
Guild* guild = sGuildMgr->GetGuildByName(guildName);
if (!guild)
{
if (!sPlayerbotGuildMgr->CreateGuild(bot, guildName))
if (!PlayerbotGuildMgr::instance().CreateGuild(bot, guildName))
LOG_ERROR("playerbots","Failed to create guild {} for bot {}", guildName, bot->GetName());
return;
}
else
{
if (guild->AddMember(bot->GetGUID(),urand(GR_OFFICER, GR_INITIATE)))
sPlayerbotGuildMgr->OnGuildUpdate(guild);
PlayerbotGuildMgr::instance().OnGuildUpdate(guild);
else
LOG_ERROR("playerbots","Bot {} failed to join guild {}.", bot->GetName(), guildName);
}
@@ -3985,7 +3985,7 @@ void PlayerbotFactory::InitImmersive()
std::ostringstream name;
name << "immersive_stat_" << i;
uint32 value = sRandomPlayerbotMgr->GetValue(owner, name.str());
uint32 value = sRandomPlayerbotMgr.GetValue(owner, name.str());
if (value)
initialized = true;
@@ -4058,7 +4058,7 @@ void PlayerbotFactory::InitImmersive()
std::ostringstream name;
name << "immersive_stat_" << i;
sRandomPlayerbotMgr->SetValue(owner, name.str(), percentMap[type]);
sRandomPlayerbotMgr.SetValue(owner, name.str(), percentMap[type]);
}
}
}
@@ -4066,15 +4066,15 @@ void PlayerbotFactory::InitImmersive()
void PlayerbotFactory::InitArenaTeam()
{
if (!sPlayerbotAIConfig->IsInRandomAccountList(bot->GetSession()->GetAccountId()))
if (!sPlayerbotAIConfig.IsInRandomAccountList(bot->GetSession()->GetAccountId()))
return;
// Currently the teams are only remade after a server restart and if deleteRandomBotArenaTeams = 1
// This is because randomBotArenaTeams is only empty on server restart.
// A manual reinitalization (.playerbots rndbot init) is also required after the teams have been deleted.
if (sPlayerbotAIConfig->randomBotArenaTeams.empty())
if (sPlayerbotAIConfig.randomBotArenaTeams.empty())
{
if (sPlayerbotAIConfig->deleteRandomBotArenaTeams)
if (sPlayerbotAIConfig.deleteRandomBotArenaTeams)
{
LOG_INFO("playerbots", "Deleting random bot arena teams...");
@@ -4099,14 +4099,14 @@ void PlayerbotFactory::InitArenaTeam()
LOG_INFO("playerbots", "Random bot arena teams deleted");
}
RandomPlayerbotFactory::CreateRandomArenaTeams(ARENA_TYPE_2v2, sPlayerbotAIConfig->randomBotArenaTeam2v2Count);
RandomPlayerbotFactory::CreateRandomArenaTeams(ARENA_TYPE_3v3, sPlayerbotAIConfig->randomBotArenaTeam3v3Count);
RandomPlayerbotFactory::CreateRandomArenaTeams(ARENA_TYPE_5v5, sPlayerbotAIConfig->randomBotArenaTeam5v5Count);
RandomPlayerbotFactory::CreateRandomArenaTeams(ARENA_TYPE_2v2, sPlayerbotAIConfig.randomBotArenaTeam2v2Count);
RandomPlayerbotFactory::CreateRandomArenaTeams(ARENA_TYPE_3v3, sPlayerbotAIConfig.randomBotArenaTeam3v3Count);
RandomPlayerbotFactory::CreateRandomArenaTeams(ARENA_TYPE_5v5, sPlayerbotAIConfig.randomBotArenaTeam5v5Count);
}
std::vector<uint32> arenateams;
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig->randomBotArenaTeams.begin();
i != sPlayerbotAIConfig->randomBotArenaTeams.end(); ++i)
for (std::vector<uint32>::iterator i = sPlayerbotAIConfig.randomBotArenaTeams.begin();
i != sPlayerbotAIConfig.randomBotArenaTeams.end(); ++i)
arenateams.push_back(*i);
if (arenateams.empty())
@@ -4300,7 +4300,7 @@ void PlayerbotFactory::ApplyEnchantAndGemsNew(bool destroyOld)
if (!gemProperties)
continue;
if (sPlayerbotAIConfig->limitEnchantExpansion && bot->GetLevel() <= 70 && enchantGem >= 39900)
if (sPlayerbotAIConfig.limitEnchantExpansion && bot->GetLevel() <= 70 && enchantGem >= 39900)
continue;
uint32 requiredLevel = gemTemplate->ItemLevel;
@@ -4363,10 +4363,10 @@ void PlayerbotFactory::ApplyEnchantAndGemsNew(bool destroyOld)
}
// disable next expansion enchantments
if (sPlayerbotAIConfig->limitEnchantExpansion && bot->GetLevel() <= 60 && enchantSpell >= 27899)
if (sPlayerbotAIConfig.limitEnchantExpansion && bot->GetLevel() <= 60 && enchantSpell >= 27899)
continue;
if (sPlayerbotAIConfig->limitEnchantExpansion && bot->GetLevel() <= 70 && enchantSpell >= 44483)
if (sPlayerbotAIConfig.limitEnchantExpansion && bot->GetLevel() <= 70 && enchantSpell >= 44483)
continue;
for (uint8 j = 0; j < MAX_SPELL_EFFECTS; ++j)

View File

@@ -317,14 +317,14 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount()
{
// Reset account types if features are disabled
// Reset is done here to precede needed accounts calculations
if (sPlayerbotAIConfig->maxRandomBots == 0 || sPlayerbotAIConfig->addClassAccountPoolSize == 0)
if (sPlayerbotAIConfig.maxRandomBots == 0 || sPlayerbotAIConfig.addClassAccountPoolSize == 0)
{
if (sPlayerbotAIConfig->maxRandomBots == 0)
if (sPlayerbotAIConfig.maxRandomBots == 0)
{
PlayerbotsDatabase.Execute("UPDATE playerbots_account_type SET account_type = 0 WHERE account_type = 1");
LOG_INFO("playerbots", "MaxRandomBots set to 0, any RNDbot accounts (type 1) will be unassigned (type 0)");
}
if (sPlayerbotAIConfig->addClassAccountPoolSize == 0)
if (sPlayerbotAIConfig.addClassAccountPoolSize == 0)
{
PlayerbotsDatabase.Execute("UPDATE playerbots_account_type SET account_type = 0 WHERE account_type = 2");
LOG_INFO("playerbots", "AddClassAccountPoolSize set to 0, any AddClass accounts (type 2) will be unassigned (type 0)");
@@ -334,8 +334,8 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount()
for (int waited = 0; waited < 1000; waited += 50)
{
QueryResult res = PlayerbotsDatabase.Query("SELECT COUNT(*) FROM playerbots_account_type WHERE account_type IN ({}, {})",
sPlayerbotAIConfig->maxRandomBots == 0 ? 1 : -1,
sPlayerbotAIConfig->addClassAccountPoolSize == 0 ? 2 : -1);
sPlayerbotAIConfig.maxRandomBots == 0 ? 1 : -1,
sPlayerbotAIConfig.addClassAccountPoolSize == 0 ? 2 : -1);
if (!res || res->Fetch()[0].Get<uint64>() == 0)
{
@@ -347,8 +347,8 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount()
}
// Checks if randomBotAccountCount is set, otherwise calculate it dynamically.
if (sPlayerbotAIConfig->randomBotAccountCount > 0)
return sPlayerbotAIConfig->randomBotAccountCount;
if (sPlayerbotAIConfig.randomBotAccountCount > 0)
return sPlayerbotAIConfig.randomBotAccountCount;
// Check existing account types
uint32 existingRndBotAccounts = 0;
@@ -374,17 +374,17 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount()
int divisor = CalculateAvailableCharsPerAccount();
// Calculate max bots
int maxBots = sPlayerbotAIConfig->maxRandomBots;
int maxBots = sPlayerbotAIConfig.maxRandomBots;
// Take periodic online - offline into account
if (sPlayerbotAIConfig->enablePeriodicOnlineOffline)
if (sPlayerbotAIConfig.enablePeriodicOnlineOffline)
{
maxBots *= sPlayerbotAIConfig->periodicOnlineOfflineRatio;
maxBots *= sPlayerbotAIConfig.periodicOnlineOfflineRatio;
}
// Calculate number of accounts needed for RNDbots
// Result is rounded up for maxBots not cleanly divisible by the divisor
uint32 neededRndBotAccounts = (maxBots + divisor - 1) / divisor;
uint32 neededAddClassAccounts = sPlayerbotAIConfig->addClassAccountPoolSize;
uint32 neededAddClassAccounts = sPlayerbotAIConfig.addClassAccountPoolSize;
// Start with existing total
uint32 existingTotal = existingRndBotAccounts + existingAddClassAccounts + existingUnassignedAccounts;
@@ -425,12 +425,12 @@ uint32 RandomPlayerbotFactory::CalculateTotalAccountCount()
uint32 RandomPlayerbotFactory::CalculateAvailableCharsPerAccount()
{
bool noDK = sPlayerbotAIConfig->disableDeathKnightLogin || sWorld->getIntConfig(CONFIG_EXPANSION) != EXPANSION_WRATH_OF_THE_LICH_KING;
bool noDK = sPlayerbotAIConfig.disableDeathKnightLogin || sWorld->getIntConfig(CONFIG_EXPANSION) != EXPANSION_WRATH_OF_THE_LICH_KING;
uint32 availableChars = noDK ? 9 : 10;
uint32 hordeRatio = sPlayerbotAIConfig->randomBotHordeRatio;
uint32 allianceRatio = sPlayerbotAIConfig->randomBotAllianceRatio;
uint32 hordeRatio = sPlayerbotAIConfig.randomBotHordeRatio;
uint32 allianceRatio = sPlayerbotAIConfig.randomBotAllianceRatio;
// horde : alliance = 50 : 50 -> 0%
// horde : alliance = 0 : 50 -> 50%
@@ -451,7 +451,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
{
/* multi-thread here is meaningless? since the async db operations */
if (sPlayerbotAIConfig->deleteRandomBotAccounts)
if (sPlayerbotAIConfig.deleteRandomBotAccounts)
{
std::vector<uint32> botAccounts;
std::vector<uint32> botFriends;
@@ -462,7 +462,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
{
std::ostringstream out;
out << sPlayerbotAIConfig->randomBotAccountPrefix << accountNumber;
out << sPlayerbotAIConfig.randomBotAccountPrefix << accountNumber;
std::string const accountName = out.str();
if (uint32 accountId = AccountMgr::GetId(accountName))
@@ -482,7 +482,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
// Delete all characters from bot accounts
CharacterDatabase.Execute("DELETE FROM characters WHERE account IN (SELECT id FROM " + loginDBName + ".account WHERE username LIKE '{}%%')",
sPlayerbotAIConfig->randomBotAccountPrefix.c_str());
sPlayerbotAIConfig.randomBotAccountPrefix.c_str());
// Wait for the characters to be deleted before proceeding to dependent deletes
while (CharacterDatabase.QueueSize())
@@ -496,7 +496,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
// Clean up orphaned entries in playerbots_db_store
PlayerbotsDatabase.Execute("DELETE FROM playerbots_db_store WHERE guid NOT IN (SELECT guid FROM " + characterDBName + ".characters WHERE account IN (SELECT id FROM " + loginDBName + ".account WHERE username NOT LIKE '{}%%'))",
sPlayerbotAIConfig->randomBotAccountPrefix.c_str());
sPlayerbotAIConfig.randomBotAccountPrefix.c_str());
// Clean up orphaned records in character-related tables
CharacterDatabase.Execute("DELETE FROM arena_team_member WHERE guid NOT IN (SELECT guid FROM characters)");
@@ -551,7 +551,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
// Finally, delete the bot accounts themselves
LOG_INFO("playerbots", "Deleting random bot accounts...");
QueryResult results = LoginDatabase.Query("SELECT id FROM account WHERE username LIKE '{}%%'",
sPlayerbotAIConfig->randomBotAccountPrefix.c_str());
sPlayerbotAIConfig.randomBotAccountPrefix.c_str());
int32 deletion_count = 0;
if (results)
{
@@ -601,7 +601,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
{
std::ostringstream out;
out << sPlayerbotAIConfig->randomBotAccountPrefix << accountNumber;
out << sPlayerbotAIConfig.randomBotAccountPrefix << accountNumber;
std::string const accountName = out.str();
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCOUNT_ID_BY_USERNAME);
@@ -613,7 +613,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
}
account_creation++;
std::string password = "";
if (sPlayerbotAIConfig->randomBotRandomPassword)
if (sPlayerbotAIConfig.randomBotRandomPassword)
{
for (int i = 0; i < 10; i++)
{
@@ -649,7 +649,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
{
std::ostringstream out;
out << sPlayerbotAIConfig->randomBotAccountPrefix << accountNumber;
out << sPlayerbotAIConfig.randomBotAccountPrefix << accountNumber;
std::string const accountName = out.str();
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCOUNT_ID_BY_USERNAME);
@@ -661,7 +661,7 @@ void RandomPlayerbotFactory::CreateRandomBots()
Field* fields = result->Fetch();
uint32 accountId = fields[0].Get<uint32>();
sPlayerbotAIConfig->randomBotAccounts.push_back(accountId);
sPlayerbotAIConfig.randomBotAccounts.push_back(accountId);
uint32 count = AccountMgr::GetCharactersCount(accountId);
if (count >= 10)
@@ -746,13 +746,13 @@ void RandomPlayerbotFactory::CreateRandomBots()
for (WorldSession* session : sessionBots)
delete session;
for (uint32 accountId : sPlayerbotAIConfig->randomBotAccounts)
for (uint32 accountId : sPlayerbotAIConfig.randomBotAccounts)
{
totalRandomBotChars += AccountMgr::GetCharactersCount(accountId);
}
LOG_INFO("server.loading", ">> {} random bot accounts with {} characters available",
sPlayerbotAIConfig->randomBotAccounts.size(), totalRandomBotChars);
sPlayerbotAIConfig.randomBotAccounts.size(), totalRandomBotChars);
}
std::string const RandomPlayerbotFactory::CreateRandomGuildName()
@@ -811,7 +811,7 @@ void RandomPlayerbotFactory::CreateRandomArenaTeams(ArenaType type, uint32 count
if (arenateam)
{
++arenaTeamNumber;
sPlayerbotAIConfig->randomBotArenaTeams.push_back(arenateam->GetId());
sPlayerbotAIConfig.randomBotArenaTeams.push_back(arenateam->GetId());
}
else
{
@@ -872,7 +872,7 @@ void RandomPlayerbotFactory::CreateRandomArenaTeams(ArenaType type, uint32 count
// set random rating
arenateam->SetRatingForAll(
urand(sPlayerbotAIConfig->randomBotArenaTeamMinRating, sPlayerbotAIConfig->randomBotArenaTeamMaxRating));
urand(sPlayerbotAIConfig.randomBotArenaTeamMinRating, sPlayerbotAIConfig.randomBotArenaTeamMaxRating));
// set random emblem
uint32 backgroundColor = urand(0xFF000000, 0xFFFFFFFF);
@@ -891,7 +891,7 @@ void RandomPlayerbotFactory::CreateRandomArenaTeams(ArenaType type, uint32 count
arenateam->SaveToDB();
sArenaTeamMgr->AddArenaTeam(arenateam);
sPlayerbotAIConfig->randomBotArenaTeams.push_back(arenateam->GetId());
sPlayerbotAIConfig.randomBotArenaTeams.push_back(arenateam->GetId());
}
LOG_DEBUG("playerbots", "{} random bot {}vs{} arena teams available", arenaTeamNumber, type, type);

View File

@@ -16,7 +16,6 @@
#include "CharacterPackets.h"
#include "ChatHelper.h"
#include "Common.h"
#include "CreatureAIImpl.h"
#include "CreatureData.h"
#include "EmoteAction.h"
#include "Engine.h"
@@ -33,7 +32,6 @@
#include "LootObjectStack.h"
#include "MapMgr.h"
#include "MotionMaster.h"
#include "MoveSpline.h"
#include "MoveSplineInit.h"
#include "NewRpgStrategy.h"
#include "ObjectGuid.h"
@@ -45,7 +43,6 @@
#include "PlayerbotMgr.h"
#include "PlayerbotGuildMgr.h"
#include "Playerbots.h"
#include "PointMovementGenerator.h"
#include "PositionValue.h"
#include "RandomPlayerbotMgr.h"
#include "SayAction.h"
@@ -153,7 +150,7 @@ PlayerbotAI::PlayerbotAI(Player* bot)
engines[BOT_STATE_COMBAT] = AiFactory::createCombatEngine(bot, this, aiObjectContext);
engines[BOT_STATE_NON_COMBAT] = AiFactory::createNonCombatEngine(bot, this, aiObjectContext);
engines[BOT_STATE_DEAD] = AiFactory::createDeadEngine(bot, this, aiObjectContext);
if (sPlayerbotAIConfig->applyInstanceStrategies)
if (sPlayerbotAIConfig.applyInstanceStrategies)
ApplyInstanceStrategies(bot->GetMapId());
currentEngine = engines[BOT_STATE_NON_COMBAT];
currentState = BOT_STATE_NON_COMBAT;
@@ -233,7 +230,7 @@ PlayerbotAI::~PlayerbotAI()
delete aiObjectContext;
if (bot)
sPlayerbotsMgr->RemovePlayerBotData(bot->GetGUID(), true);
PlayerbotsMgr::instance().RemovePlayerBotData(bot->GetGUID(), true);
}
void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
@@ -251,7 +248,7 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
// Handle cheat options (set bot health and power if cheats are enabled)
if (bot->IsAlive() &&
(static_cast<uint32>(GetCheat()) > 0 || static_cast<uint32>(sPlayerbotAIConfig->botCheatMask) > 0))
(static_cast<uint32>(GetCheat()) > 0 || static_cast<uint32>(sPlayerbotAIConfig.botCheatMask) > 0))
{
if (HasCheat(BotCheatMask::health))
bot->SetFullHealth();
@@ -332,7 +329,7 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
if (spellTarget && !bot->HasInArc(CAST_ANGLE_IN_FRONT, spellTarget) &&
(spellInfo->FacingCasterFlags & SPELL_FACING_FLAG_INFRONT))
{
sServerFacade->SetFacingTo(bot, spellTarget);
ServerFacade::instance().SetFacingTo(bot, spellTarget);
}
// Wait for spell cast
@@ -387,7 +384,7 @@ void PlayerbotAI::UpdateAIGroupMaster()
Group* group = bot->GetGroup();
bool IsRandomBot = sRandomPlayerbotMgr->IsRandomBot(bot);
bool IsRandomBot = sRandomPlayerbotMgr.IsRandomBot(bot);
// If bot is not in group verify that for is RandomBot before clearing master and resetting.
if (!group)
@@ -451,7 +448,7 @@ void PlayerbotAI::UpdateAIInternal([[maybe_unused]] uint32 elapsed, bool minimal
std::string const mapString = WorldPosition(bot).isOverworld() ? std::to_string(bot->GetMapId()) : "I";
PerfMonitorOperation* pmo =
sPerfMonitor->start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAIInternal " + mapString);
sPerfMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAIInternal " + mapString);
ExternalEventHelper helper(aiObjectContext);
// chat replies
@@ -503,12 +500,12 @@ void PlayerbotAI::UpdateAIInternal([[maybe_unused]] uint32 elapsed, bool minimal
}
else
{
sRandomPlayerbotMgr->LogoutPlayerBot(bot->GetGUID());
sRandomPlayerbotMgr.LogoutPlayerBot(bot->GetGUID());
}
return;
}
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
return;
}
@@ -583,10 +580,10 @@ void PlayerbotAI::HandleCommand(uint32 type, const std::string& text, Player& fr
if (type == CHAT_MSG_SYSTEM)
return;
if (filtered.find(sPlayerbotAIConfig->commandSeparator) != std::string::npos)
if (filtered.find(sPlayerbotAIConfig.commandSeparator) != std::string::npos)
{
std::vector<std::string> commands;
split(commands, filtered, sPlayerbotAIConfig->commandSeparator.c_str());
split(commands, filtered, sPlayerbotAIConfig.commandSeparator.c_str());
for (std::vector<std::string>::iterator i = commands.begin(); i != commands.end(); ++i)
{
HandleCommand(type, *i, fromPlayer);
@@ -594,12 +591,12 @@ void PlayerbotAI::HandleCommand(uint32 type, const std::string& text, Player& fr
return;
}
if (!sPlayerbotAIConfig->commandPrefix.empty())
if (!sPlayerbotAIConfig.commandPrefix.empty())
{
if (filtered.find(sPlayerbotAIConfig->commandPrefix) != 0)
if (filtered.find(sPlayerbotAIConfig.commandPrefix) != 0)
return;
filtered = filtered.substr(sPlayerbotAIConfig->commandPrefix.size());
filtered = filtered.substr(sPlayerbotAIConfig.commandPrefix.size());
}
if (chatMap.empty())
@@ -631,7 +628,7 @@ void PlayerbotAI::HandleCommand(uint32 type, const std::string& text, Player& fr
WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_ADDON, response.c_str(), LANG_ADDON, CHAT_TAG_NONE, bot->GetGUID(),
bot->GetName());
sServerFacade->SendPacket(&fromPlayer, &data);
ServerFacade::instance().SendPacket(&fromPlayer, &data);
return;
}
@@ -761,10 +758,10 @@ void PlayerbotAI::HandleTeleportAck()
}
// apply instance-related strategies after map attach
if (sPlayerbotAIConfig->applyInstanceStrategies)
if (sPlayerbotAIConfig.applyInstanceStrategies)
ApplyInstanceStrategies(bot->GetMapId(), true);
if (sPlayerbotAIConfig->restrictHealerDPS)
if (sPlayerbotAIConfig.restrictHealerDPS)
EvaluateHealerDpsStrategy();
// reset AI state after teleport
@@ -855,7 +852,7 @@ void PlayerbotAI::Reset(bool full)
aiObjectContext->GetValue<LastMovement&>("last taxi")->Get().Set(nullptr);
aiObjectContext->GetValue<TravelTarget*>("travel target")
->Get()
->setTarget(sTravelMgr->nullTravelDestination, sTravelMgr->nullWorldPosition, true);
->setTarget(TravelMgr::instance().nullTravelDestination, TravelMgr::instance().nullWorldPosition, true);
aiObjectContext->GetValue<TravelTarget*>("travel target")->Get()->setStatus(TRAVEL_STATUS_EXPIRED);
aiObjectContext->GetValue<TravelTarget*>("travel target")->Get()->setExpireIn(1000);
rpgInfo = NewRpgInfo();
@@ -920,10 +917,10 @@ void PlayerbotAI::HandleCommand(uint32 type, std::string const text, Player* fro
if (type == CHAT_MSG_SYSTEM)
return;
if (text.find(sPlayerbotAIConfig->commandSeparator) != std::string::npos)
if (text.find(sPlayerbotAIConfig.commandSeparator) != std::string::npos)
{
std::vector<std::string> commands;
split(commands, text, sPlayerbotAIConfig->commandSeparator.c_str());
split(commands, text, sPlayerbotAIConfig.commandSeparator.c_str());
for (std::vector<std::string>::iterator i = commands.begin(); i != commands.end(); ++i)
{
HandleCommand(type, *i, fromPlayer);
@@ -933,12 +930,12 @@ void PlayerbotAI::HandleCommand(uint32 type, std::string const text, Player* fro
}
std::string filtered = text;
if (!sPlayerbotAIConfig->commandPrefix.empty())
if (!sPlayerbotAIConfig.commandPrefix.empty())
{
if (filtered.find(sPlayerbotAIConfig->commandPrefix) != 0)
if (filtered.find(sPlayerbotAIConfig.commandPrefix) != 0)
return;
filtered = filtered.substr(sPlayerbotAIConfig->commandPrefix.size());
filtered = filtered.substr(sPlayerbotAIConfig.commandPrefix.size());
}
if (chatMap.empty())
@@ -1100,7 +1097,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
}
case SMSG_MESSAGECHAT: // do not react to self or if not ready to reply
{
if (!sPlayerbotAIConfig->randomBotTalk)
if (!sPlayerbotAIConfig.randomBotTalk)
return;
if (!AllowActivity())
@@ -1156,7 +1153,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
bool isFromFreeBot = false;
sCharacterCache->GetCharacterNameByGuid(guid1, name);
uint32 accountId = sCharacterCache->GetCharacterAccountIdByGuid(guid1);
isFromFreeBot = sPlayerbotAIConfig->IsInRandomAccountList(accountId);
isFromFreeBot = sPlayerbotAIConfig.IsInRandomAccountList(accountId);
bool isMentioned = message.find(bot->GetName()) != std::string::npos;
// ChatChannelSource chatChannelSource = GetChatChannelSource(bot, msgtype, chanName);
@@ -1174,20 +1171,20 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
if (lang == LANG_ADDON)
return;
if (message.starts_with(sPlayerbotAIConfig->toxicLinksPrefix) &&
if (message.starts_with(sPlayerbotAIConfig.toxicLinksPrefix) &&
(GetChatHelper()->ExtractAllItemIds(message).size() > 0 ||
GetChatHelper()->ExtractAllQuestIds(message).size() > 0) &&
sPlayerbotAIConfig->toxicLinksRepliesChance)
sPlayerbotAIConfig.toxicLinksRepliesChance)
{
if (urand(0, 50) > 0 || urand(1, 100) > sPlayerbotAIConfig->toxicLinksRepliesChance)
if (urand(0, 50) > 0 || urand(1, 100) > sPlayerbotAIConfig.toxicLinksRepliesChance)
{
return;
}
}
else if ((GetChatHelper()->ExtractAllItemIds(message).count(19019) &&
sPlayerbotAIConfig->thunderfuryRepliesChance))
sPlayerbotAIConfig.thunderfuryRepliesChance))
{
if (urand(0, 60) > 0 || urand(1, 100) > sPlayerbotAIConfig->thunderfuryRepliesChance)
if (urand(0, 60) > 0 || urand(1, 100) > sPlayerbotAIConfig.thunderfuryRepliesChance)
{
return;
}
@@ -1197,8 +1194,8 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
if (isFromFreeBot && urand(0, 20))
return;
// if (msgtype == CHAT_MSG_GUILD && (!sPlayerbotAIConfig->guildRepliesRate || urand(1, 100) >=
// sPlayerbotAIConfig->guildRepliesRate)) return;
// if (msgtype == CHAT_MSG_GUILD && (!sPlayerbotAIConfig.guildRepliesRate || urand(1, 100) >=
// sPlayerbotAIConfig.guildRepliesRate)) return;
if (!isFromFreeBot)
{
@@ -1285,7 +1282,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)
// bot->GetMotionMaster()->MoveKnockbackFrom(fx, fy, horizontalSpeed, verticalSpeed);
// // set delay based on actual distance
// float newdis = sqrt(sServerFacade->GetDistance2d(bot, fx, fy));
// float newdis = sqrt(ServerFacade::instance().GetDistance2d(bot, fx, fy));
// SetNextCheckDelay((uint32)((newdis / dis) * moveTimeHalf * 4 * IN_MILLISECONDS));
// // add moveflags
@@ -1347,9 +1344,9 @@ int32 PlayerbotAI::CalculateGlobalCooldown(uint32 spellid)
return 0;
if (bot->HasSpellCooldown(spellid))
return sPlayerbotAIConfig->globalCoolDown;
return sPlayerbotAIConfig.globalCoolDown;
return sPlayerbotAIConfig->reactDelay;
return sPlayerbotAIConfig.reactDelay;
}
void PlayerbotAI::HandleMasterIncomingPacket(WorldPacket const& packet)
@@ -1410,7 +1407,7 @@ void PlayerbotAI::DoNextAction(bool min)
{
if (!bot->IsInWorld() || bot->IsBeingTeleported() || (GetMaster() && GetMaster()->IsBeingTeleported()))
{
SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
SetNextCheckDelay(sPlayerbotAIConfig.globalCoolDown);
return;
}
@@ -1454,7 +1451,7 @@ void PlayerbotAI::DoNextAction(bool min)
}
}
bool minimal = !AllowActivity();
bool minimal = !this->AllowActivity();
currentEngine->DoNextAction(nullptr, 0, (minimal || min));
@@ -1463,7 +1460,7 @@ void PlayerbotAI::DoNextAction(bool min)
if (!bot->isAFK() && !bot->InBattleground() && !HasRealPlayerMaster())
bot->ToggleAFK();
SetNextCheckDelay(sPlayerbotAIConfig->passiveDelay);
SetNextCheckDelay(sPlayerbotAIConfig.passiveDelay);
return;
}
else if (bot->isAFK())
@@ -1471,7 +1468,8 @@ void PlayerbotAI::DoNextAction(bool min)
if (master && master->IsInWorld())
{
float distance = sServerFacade->GetDistance2d(bot, master);
float distance = ServerFacade::instance().GetDistance2d(bot, master);
if (master->m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING) && distance < 20.0f)
bot->m_movementInfo.AddMovementFlag(MOVEMENTFLAG_WALKING);
else
@@ -1704,7 +1702,7 @@ bool PlayerbotAI::PlayEmote(uint32 emote)
WorldPacket data(SMSG_TEXT_EMOTE);
data << (TextEmotes)emote;
data << EmoteAction::GetNumberOfEmoteVariants((TextEmotes)emote, bot->getRace(), bot->getGender());
data << ((master && (sServerFacade->GetDistance2d(bot, master) < 30.0f) && urand(0, 1)) ? master->GetGUID()
data << ((master && (ServerFacade::instance().GetDistance2d(bot, master) < 30.0f) && urand(0, 1)) ? master->GetGUID()
: (bot->GetTarget() && urand(0, 1)) ? bot->GetTarget()
: ObjectGuid::Empty);
bot->GetSession()->HandleTextEmoteOpcode(data);
@@ -1733,14 +1731,14 @@ void PlayerbotAI::ResetStrategies(bool load)
AiFactory::AddDefaultCombatStrategies(bot, this, engines[BOT_STATE_COMBAT]);
AiFactory::AddDefaultNonCombatStrategies(bot, this, engines[BOT_STATE_NON_COMBAT]);
AiFactory::AddDefaultDeadStrategies(bot, this, engines[BOT_STATE_DEAD]);
if (sPlayerbotAIConfig->applyInstanceStrategies)
if (sPlayerbotAIConfig.applyInstanceStrategies)
ApplyInstanceStrategies(bot->GetMapId());
for (uint8 i = 0; i < BOT_STATE_MAX; i++)
engines[i]->Init();
// if (load)
// sPlayerbotRepository->Load(this);
// PlayerbotRepository::instance().Load(this);
}
bool PlayerbotAI::IsRanged(Player* player, bool bySpec)
@@ -2718,7 +2716,7 @@ bool PlayerbotAI::SayToParty(const std::string& msg)
for (auto reciever : GetPlayersInGroup())
{
sServerFacade->SendPacket(reciever, &data);
ServerFacade::instance().SendPacket(reciever, &data);
}
return true;
@@ -2735,7 +2733,7 @@ bool PlayerbotAI::SayToRaid(const std::string& msg)
for (auto reciever : GetPlayersInGroup())
{
sServerFacade->SendPacket(reciever, &data);
ServerFacade::instance().SendPacket(reciever, &data);
}
return true;
@@ -2802,7 +2800,7 @@ bool PlayerbotAI::TellMasterNoFacing(std::string const text, PlayerbotSecurityLe
masterBotAI = GET_PLAYERBOT_AI(master);
if ((!master || (masterBotAI && !masterBotAI->IsRealPlayer())) &&
(sPlayerbotAIConfig->randomBotSayWithoutMaster || HasStrategy("debug", BOT_STATE_NON_COMBAT)))
(sPlayerbotAIConfig.randomBotSayWithoutMaster || HasStrategy("debug", BOT_STATE_NON_COMBAT)))
{
bot->Say(text, (bot->GetTeamId() == TEAM_ALLIANCE ? LANG_COMMON : LANG_ORCISH));
return true;
@@ -2813,7 +2811,7 @@ bool PlayerbotAI::TellMasterNoFacing(std::string const text, PlayerbotSecurityLe
time_t lastSaid = whispers[text];
if (!lastSaid || (time(nullptr) - lastSaid) >= sPlayerbotAIConfig->repeatDelay / 1000)
if (!lastSaid || (time(nullptr) - lastSaid) >= sPlayerbotAIConfig.repeatDelay / 1000)
{
whispers[text] = time(nullptr);
@@ -2851,10 +2849,10 @@ bool PlayerbotAI::IsTellAllowed(PlayerbotSecurityLevel securityLevel)
if (!GetSecurity()->CheckLevelFor(securityLevel, true, master))
return false;
if (sPlayerbotAIConfig->whisperDistance && !bot->GetGroup() && sRandomPlayerbotMgr->IsRandomBot(bot) &&
if (sPlayerbotAIConfig.whisperDistance && !bot->GetGroup() && sRandomPlayerbotMgr.IsRandomBot(bot) &&
master->GetSession()->GetSecurity() < SEC_GAMEMASTER &&
(bot->GetMapId() != master->GetMapId() ||
sServerFacade->GetDistance2d(bot, master) > sPlayerbotAIConfig->whisperDistance))
ServerFacade::instance().GetDistance2d(bot, master) > sPlayerbotAIConfig.whisperDistance))
return false;
return true;
@@ -2869,7 +2867,7 @@ bool PlayerbotAI::TellMaster(std::string const text, PlayerbotSecurityLevel secu
{
if (!master)
{
if (sPlayerbotAIConfig->randomBotSayWithoutMaster)
if (sPlayerbotAIConfig.randomBotSayWithoutMaster)
return TellMasterNoFacing(text, securityLevel);
}
if (!TellMasterNoFacing(text, securityLevel))
@@ -2878,7 +2876,7 @@ bool PlayerbotAI::TellMaster(std::string const text, PlayerbotSecurityLevel secu
if (!bot->isMoving() && !bot->IsInCombat() && bot->GetMapId() == master->GetMapId() &&
!bot->HasUnitState(UNIT_STATE_IN_FLIGHT) && !bot->IsFlying())
{
if (!bot->HasInArc(EMOTE_ANGLE_IN_FRONT, master, sPlayerbotAIConfig->sightDistance))
if (!bot->HasInArc(EMOTE_ANGLE_IN_FRONT, master, sPlayerbotAIConfig.sightDistance))
bot->SetFacingToObject(master);
bot->HandleEmoteCommand(EMOTE_ONESHOT_TALK);
@@ -3092,7 +3090,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
{
if (!spellid)
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots", "Can cast spell failed. No spellid. - spellid: {}, bot name: {}", spellid,
bot->GetName());
@@ -3102,7 +3100,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
if (bot->HasUnitState(UNIT_STATE_LOST_CONTROL))
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots", "Can cast spell failed. Unit state lost control. - spellid: {}, bot name: {}",
spellid, bot->GetName());
@@ -3122,7 +3120,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
if (checkHasSpell && !bot->HasSpell(spellid))
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots",
"Can cast spell failed. Bot not has spell. - target name: {}, spellid: {}, bot name: {}",
@@ -3133,7 +3131,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
if (bot->GetCurrentSpell(CURRENT_CHANNELED_SPELL) != nullptr)
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG(
"playerbots",
@@ -3145,7 +3143,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
if (bot->HasSpellCooldown(spellid))
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots",
"Can cast spell failed. Spell not has cooldown. - target name: {}, spellid: {}, bot name: {}",
@@ -3157,7 +3155,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellid);
if (!spellInfo)
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots", "Can cast spell failed. No spellInfo. - target name: {}, spellid: {}, bot name: {}",
target->GetName(), spellid, bot->GetName());
@@ -3167,7 +3165,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
if ((bot->GetShapeshiftForm() == FORM_FLIGHT || bot->GetShapeshiftForm() == FORM_FLIGHT_EPIC) && !bot->IsInCombat())
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG(
"playerbots",
@@ -3181,7 +3179,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
// bool interruptOnMove = spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_MOVEMENT;
if ((CastingTime || spellInfo->IsAutoRepeatRangedSpell()) && bot->isMoving())
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots", "Casting time and bot is moving - target name: {}, spellid: {}, bot name: {}",
target->GetName(), spellid, bot->GetName());
@@ -3196,7 +3194,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
{
if (spellid != 44572) // Deep Freeze
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots", "target is immuned to spell - target name: {}, spellid: {}, bot name: {}",
target->GetName(), spellid, bot->GetName());
@@ -3206,9 +3204,9 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
// Otherwise, allow Deep Freeze even if immune
}
if (bot != target && sServerFacade->GetDistance2d(bot, target) > sPlayerbotAIConfig->sightDistance)
if (bot != target && ServerFacade::instance().GetDistance2d(bot, target) > sPlayerbotAIConfig.sightDistance)
{
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots", "target is out of sight distance - target name: {}, spellid: {}, bot name: {}",
target->GetName(), spellid, bot->GetName());
@@ -3234,7 +3232,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
SpellCastResult result = spell->CheckCast(true);
delete spell;
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// if (result != SPELL_FAILED_NOT_READY && result != SPELL_CAST_OK)
// {
@@ -3258,7 +3256,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, Unit* target, bool checkHasSpell,
case SPELL_FAILED_OUT_OF_RANGE:
return true;
default:
if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
{
LOG_DEBUG("playerbots",
"CanCastSpell Check Failed. - target name: {}, spellid: {}, bot name: {}, result: {}",
@@ -3294,7 +3292,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, GameObject* goTarget, bool checkH
if (CastingTime > 0 && bot->isMoving())
return false;
if (sServerFacade->GetDistance2d(bot, goTarget) > sPlayerbotAIConfig->sightDistance)
if (ServerFacade::instance().GetDistance2d(bot, goTarget) > sPlayerbotAIConfig.sightDistance)
return false;
// ObjectGuid oldSel = bot->GetTarget();
@@ -3347,7 +3345,7 @@ bool PlayerbotAI::CanCastSpell(uint32 spellid, float x, float y, float z, bool c
if (!itemTarget)
{
if (bot->GetDistance(x, y, z) > sPlayerbotAIConfig->sightDistance)
if (bot->GetDistance(x, y, z) > sPlayerbotAIConfig.sightDistance)
return false;
}
@@ -3449,7 +3447,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
if (bot->IsFlying() || bot->HasUnitState(UNIT_STATE_IN_FLIGHT))
{
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast is flying - target name: {}, spellid: {}, bot name: {}}",
// target->GetName(), spellId, bot->GetName());
@@ -3472,13 +3470,13 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
WorldObject* faceTo = target;
if (!bot->HasInArc(CAST_ANGLE_IN_FRONT, faceTo) && (spellInfo->FacingCasterFlags & SPELL_FACING_FLAG_INFRONT))
{
sServerFacade->SetFacingTo(bot, faceTo);
ServerFacade::instance().SetFacingTo(bot, faceTo);
// failWithDelay = true;
}
if (failWithDelay)
{
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
return false;
}
@@ -3495,7 +3493,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
{
bot->GetTradeData()->SetSpell(spellId);
delete spell;
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast no item - target name: {}, spellid: {}, bot name: {}",
// target->GetName(), spellId, bot->GetName());
@@ -3557,7 +3555,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
if (bot->isMoving() && spell->GetCastTime())
{
// bot->StopMoving();
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
spell->cancel();
delete spell;
return false;
@@ -3565,7 +3563,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
// spell->m_targets.SetUnitTarget(target);
// SpellCastResult spellSuccess = spell->CheckCast(true);
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast result - target name: {}, spellid: {}, bot name: {}, result: {}",
// target->GetName(), spellId, bot->GetName(), spellSuccess);
@@ -3577,7 +3575,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
if (result != SPELL_CAST_OK)
{
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast failed. - target name: {}, spellid: {}, bot name: {}, result: {}",
// target->GetName(), spellId, bot->GetName(), result);
@@ -3645,7 +3643,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
// {
// spell->cancel();
// delete spell;
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// if (!sPlayerbotAIConfig.logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster()))
// {
// LOG_DEBUG("playerbots", "Spell cast loot - target name: {}, spellid: {}, bot name: {}",
// target->GetName(), spellId, bot->GetName());
@@ -3725,7 +3723,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, float x, float y, float z, Item* ite
if (failWithDelay)
{
SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
SetNextCheckDelay(sPlayerbotAIConfig.globalCoolDown);
return false;
}
@@ -3768,7 +3766,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, float x, float y, float z, Item* ite
if (bot->isMoving() && spell->GetCastTime())
{
// bot->StopMoving();
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
spell->cancel();
delete spell;
return false;
@@ -3846,12 +3844,12 @@ bool PlayerbotAI::CanCastVehicleSpell(uint32 spellId, Unit* target)
if (CastingTime && vehicleBase->isMoving())
return false;
if (vehicleBase != spellTarget && sServerFacade->GetDistance2d(vehicleBase, spellTarget) > 120.0f)
if (vehicleBase != spellTarget && ServerFacade::instance().GetDistance2d(vehicleBase, spellTarget) > 120.0f)
return false;
if (!target && siegePos.isSet())
{
if (sServerFacade->GetDistance2d(vehicleBase, siegePos.x, siegePos.y) > 120.0f)
if (ServerFacade::instance().GetDistance2d(vehicleBase, siegePos.x, siegePos.y) > 120.0f)
return false;
}
@@ -3921,7 +3919,7 @@ bool PlayerbotAI::CastVehicleSpell(uint32 spellId, Unit* target)
PositionInfo siegePos = GetAiObjectContext()->GetValue<PositionMap&>("position")->Get()["bg siege"];
if (!target && siegePos.isSet())
{
if (sServerFacade->GetDistance2d(vehicleBase, siegePos.x, siegePos.y) > 120.0f)
if (ServerFacade::instance().GetDistance2d(vehicleBase, siegePos.x, siegePos.y) > 120.0f)
return false;
}
@@ -3959,7 +3957,7 @@ bool PlayerbotAI::CastVehicleSpell(uint32 spellId, Unit* target)
if (failWithDelay)
{
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
return false;
}
@@ -4000,7 +3998,7 @@ bool PlayerbotAI::CastVehicleSpell(uint32 spellId, Unit* target)
if (seat->CanControl() && vehicleBase->isMoving() && spell->GetCastTime())
{
vehicleBase->StopMoving();
SetNextCheckDelay(sPlayerbotAIConfig->globalCoolDown);
SetNextCheckDelay(sPlayerbotAIConfig.globalCoolDown);
spell->cancel();
// delete spell;
return false;
@@ -4077,7 +4075,7 @@ void PlayerbotAI::WaitForSpellCast(Spell* spell)
castTime += duration;
}
SetNextCheckDelay(castTime + sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(castTime + sPlayerbotAIConfig.reactDelay);
}
void PlayerbotAI::InterruptSpell()
@@ -4169,8 +4167,8 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
if (!aura || aura->IsPassive() || aura->IsRemoved())
continue;
if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() &&
aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
if (sPlayerbotAIConfig.dispelAuraDuration && aura->GetDuration() &&
aura->GetDuration() < (int32)sPlayerbotAIConfig.dispelAuraDuration)
continue;
SpellInfo const* spellInfo = aura->GetSpellInfo();
@@ -4290,7 +4288,7 @@ bool PlayerbotAI::HasRealPlayerMaster()
bool PlayerbotAI::HasActivePlayerMaster() { return master && !GET_PLAYERBOT_AI(master); }
bool PlayerbotAI::IsAlt() { return HasRealPlayerMaster() && !sRandomPlayerbotMgr->IsRandomBot(bot); }
bool PlayerbotAI::IsAlt() { return HasRealPlayerMaster() && !sRandomPlayerbotMgr.IsRandomBot(bot); }
Player* PlayerbotAI::GetGroupLeader()
{
@@ -4379,7 +4377,7 @@ bool PlayerbotAI::HasPlayerNearby(WorldPosition* pos, float range)
{
float sqRange = range * range;
bool nearPlayer = false;
for (auto& player : sRandomPlayerbotMgr->GetPlayers())
for (auto& player : sRandomPlayerbotMgr.GetPlayers())
{
if (!player->IsGameMaster() || player->isGMVisible())
{
@@ -4413,9 +4411,9 @@ bool PlayerbotAI::HasManyPlayersNearby(uint32 trigerrValue, float range)
float sqRange = range * range;
uint32 found = 0;
for (auto& player : sRandomPlayerbotMgr->GetPlayers())
for (auto& player : sRandomPlayerbotMgr.GetPlayers())
{
if ((!player->IsGameMaster() || player->isGMVisible()) && sServerFacade->GetDistance2d(player, bot) < sqRange)
if ((!player->IsGameMaster() || player->isGMVisible()) && ServerFacade::instance().GetDistance2d(player, bot) < sqRange)
{
found++;
@@ -4461,7 +4459,7 @@ inline bool ZoneHasRealPlayers(Player* bot)
return false;
}
for (Player* player : sRandomPlayerbotMgr->GetPlayers())
for (Player* player : sRandomPlayerbotMgr.GetPlayers())
{
if (player->GetMapId() != bot->GetMapId())
continue;
@@ -4492,7 +4490,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
return false;
// when botActiveAlone is 100% and smartScale disabled
if (sPlayerbotAIConfig->botActiveAlone >= 100 && !sPlayerbotAIConfig->botActiveAloneSmartScale)
if (sPlayerbotAIConfig.botActiveAlone >= 100 && !sPlayerbotAIConfig.botActiveAloneSmartScale)
{
return true;
}
@@ -4510,7 +4508,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
// which prevents unneeded expensive GameTime calls.
if (_isBotInitializing)
{
_isBotInitializing = GameTime::GetUptime().count() < sPlayerbotAIConfig->maxRandomBots * 0.11;
_isBotInitializing = GameTime::GetUptime().count() < sPlayerbotAIConfig.maxRandomBots * 0.11;
// no activity allowed during bot initialization
if (_isBotInitializing)
@@ -4532,7 +4530,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
}
// bot map has active players.
if (sPlayerbotAIConfig->BotActiveAloneForceWhenInMap)
if (sPlayerbotAIConfig.BotActiveAloneForceWhenInMap)
{
if (HasRealPlayers(bot->GetMap()))
{
@@ -4541,7 +4539,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
}
// bot zone has active players.
if (sPlayerbotAIConfig->BotActiveAloneForceWhenInZone)
if (sPlayerbotAIConfig.BotActiveAloneForceWhenInZone)
{
if (ZoneHasRealPlayers(bot))
{
@@ -4550,7 +4548,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
}
// when in real guild
if (sPlayerbotAIConfig->BotActiveAloneForceWhenInGuild)
if (sPlayerbotAIConfig.BotActiveAloneForceWhenInGuild)
{
if (IsInRealGuild())
{
@@ -4559,7 +4557,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
}
// Player is near. Always active.
if (HasPlayerNearby(sPlayerbotAIConfig->BotActiveAloneForceWhenInRadius))
if (HasPlayerNearby(sPlayerbotAIConfig.BotActiveAloneForceWhenInRadius))
{
return true;
}
@@ -4631,13 +4629,13 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
}
// HasFriend
if (sPlayerbotAIConfig->BotActiveAloneForceWhenIsFriend)
if (sPlayerbotAIConfig.BotActiveAloneForceWhenIsFriend)
{
// shouldnt be needed analyse in future
if (!bot->GetGUID())
return false;
for (auto& player : sRandomPlayerbotMgr->GetPlayers())
for (auto& player : sRandomPlayerbotMgr.GetPlayers())
{
if (!player || !player->GetSession() || !player->IsInWorld() || player->IsDuringRemoveFromWorld() ||
player->GetSession()->isLogingOut())
@@ -4669,7 +4667,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
return false;
}
if (sPlayerbotAIConfig->botActiveAlone <= 0)
if (sPlayerbotAIConfig.botActiveAlone <= 0)
{
return false;
}
@@ -4681,19 +4679,19 @@ bool PlayerbotAI::AllowActive(ActivityType activityType)
// Below is code to have a specified % of bots active at all times.
// The default is 100%. With 1% of all bots going active or inactive each minute.
uint32 mod = sPlayerbotAIConfig->botActiveAlone > 100 ? 100 : sPlayerbotAIConfig->botActiveAlone;
if (sPlayerbotAIConfig->botActiveAloneSmartScale &&
bot->GetLevel() >= sPlayerbotAIConfig->botActiveAloneSmartScaleWhenMinLevel &&
bot->GetLevel() <= sPlayerbotAIConfig->botActiveAloneSmartScaleWhenMaxLevel)
uint32 mod = sPlayerbotAIConfig.botActiveAlone > 100 ? 100 : sPlayerbotAIConfig.botActiveAlone;
if (sPlayerbotAIConfig.botActiveAloneSmartScale &&
bot->GetLevel() >= sPlayerbotAIConfig.botActiveAloneSmartScaleWhenMinLevel &&
bot->GetLevel() <= sPlayerbotAIConfig.botActiveAloneSmartScaleWhenMaxLevel)
{
mod = AutoScaleActivity(mod);
}
uint32 ActivityNumber =
GetFixedBotNumer(100, sPlayerbotAIConfig->botActiveAlone * static_cast<float>(mod) / 100 * 0.01f);
GetFixedBotNumer(100, sPlayerbotAIConfig.botActiveAlone * static_cast<float>(mod) / 100 * 0.01f);
return ActivityNumber <=
(sPlayerbotAIConfig->botActiveAlone * mod) /
(sPlayerbotAIConfig.botActiveAlone * mod) /
100; // The given percentage of bots should be active and rotate 1% of those active bots each minute.
}
@@ -4725,8 +4723,8 @@ uint32 PlayerbotAI::AutoScaleActivity(uint32 mod)
{
// Current max server update time (ms), and the configured floor/ceiling values for bot scaling
uint32 maxDiff = sWorldUpdateTime.GetMaxUpdateTimeOfCurrentTable();
uint32 diffLimitFloor = sPlayerbotAIConfig->botActiveAloneSmartScaleDiffLimitfloor;
uint32 diffLimitCeiling = sPlayerbotAIConfig->botActiveAloneSmartScaleDiffLimitCeiling;
uint32 diffLimitFloor = sPlayerbotAIConfig.botActiveAloneSmartScaleDiffLimitfloor;
uint32 diffLimitCeiling = sPlayerbotAIConfig.botActiveAloneSmartScaleDiffLimitCeiling;
if (diffLimitCeiling <= diffLimitFloor)
{
@@ -5318,19 +5316,19 @@ float PlayerbotAI::GetRange(std::string const type)
return val;
if (type == "spell")
return sPlayerbotAIConfig->spellDistance;
return sPlayerbotAIConfig.spellDistance;
if (type == "shoot")
return sPlayerbotAIConfig->shootDistance;
return sPlayerbotAIConfig.shootDistance;
if (type == "flee")
return sPlayerbotAIConfig->fleeDistance;
return sPlayerbotAIConfig.fleeDistance;
if (type == "heal")
return sPlayerbotAIConfig->healDistance;
return sPlayerbotAIConfig.healDistance;
if (type == "melee")
return sPlayerbotAIConfig->meleeDistance;
return sPlayerbotAIConfig.meleeDistance;
return 0;
}
@@ -5999,7 +5997,7 @@ bool PlayerbotAI::IsInRealGuild()
if (!bot->GetGuildId())
return false;
return sPlayerbotGuildMgr->IsRealGuild(bot->GetGuildId());
return PlayerbotGuildMgr::instance().IsRealGuild(bot->GetGuildId());
}
void PlayerbotAI::QueueChatResponse(const ChatQueuedReply chatReply) { chatReplies.push_back(std::move(chatReply)); }
@@ -6553,17 +6551,17 @@ std::set<uint32> PlayerbotAI::GetCurrentIncompleteQuestIds()
uint32 PlayerbotAI::GetReactDelay()
{
uint32 base = sPlayerbotAIConfig->reactDelay; // Default 100(ms)
uint32 base = sPlayerbotAIConfig.reactDelay; // Default 100(ms)
// If dynamic react delay is disabled, use a static calculation
if (!sPlayerbotAIConfig->dynamicReactDelay)
if (!sPlayerbotAIConfig.dynamicReactDelay)
{
if (HasRealPlayerMaster())
return base;
bool inBG = bot->InBattleground() || bot->InArena();
if (sPlayerbotAIConfig->fastReactInBG && inBG)
if (sPlayerbotAIConfig.fastReactInBG && inBG)
return base;
bool inCombat = bot->IsInCombat();
@@ -6588,11 +6586,11 @@ uint32 PlayerbotAI::GetReactDelay()
{
if (bot->IsInCombat() || currentState == BOT_STATE_COMBAT)
{
return static_cast<uint32>(base * (sPlayerbotAIConfig->fastReactInBG ? 2.5f : 5.0f));
return static_cast<uint32>(base * (sPlayerbotAIConfig.fastReactInBG ? 2.5f : 5.0f));
}
else
{
return static_cast<uint32>(base * (sPlayerbotAIConfig->fastReactInBG ? 1.0f : 10.0f));
return static_cast<uint32>(base * (sPlayerbotAIConfig.fastReactInBG ? 1.0f : 10.0f));
}
}
@@ -6765,7 +6763,7 @@ void PlayerbotAI::EvaluateHealerDpsStrategy()
if (!IsHeal(bot, true))
return;
if (sPlayerbotAIConfig->IsRestrictedHealerDPSMap(bot->GetMapId()))
if (sPlayerbotAIConfig.IsRestrictedHealerDPSMap(bot->GetMapId()))
ChangeStrategy("-healer dps", BOT_STATE_COMBAT);
else
ChangeStrategy("+healer dps", BOT_STATE_COMBAT);

View File

@@ -491,7 +491,7 @@ public:
void ImbueItem(Item* item);
void EnchantItemT(uint32 spellid, uint8 slot);
uint32 GetBuffedCount(Player* player, std::string const spellname);
int32 GetNearGroupMemberCount(float dis = sPlayerbotAIConfig->sightDistance);
int32 GetNearGroupMemberCount(float dis = sPlayerbotAIConfig.sightDistance);
virtual bool CanCastSpell(std::string const name, Unit* target, Item* itemTarget = nullptr);
virtual bool CastSpell(std::string const name, Unit* target, Item* itemTarget = nullptr);
@@ -545,9 +545,9 @@ public:
uint32 GetFixedBotNumer(uint32 maxNum = 100, float cyclePerMin = 1);
GrouperType GetGrouperType();
GuilderType GetGuilderType();
bool HasPlayerNearby(WorldPosition* pos, float range = sPlayerbotAIConfig->reactDistance);
bool HasPlayerNearby(float range = sPlayerbotAIConfig->reactDistance);
bool HasManyPlayersNearby(uint32 trigerrValue = 20, float range = sPlayerbotAIConfig->sightDistance);
bool HasPlayerNearby(WorldPosition* pos, float range = sPlayerbotAIConfig.reactDistance);
bool HasPlayerNearby(float range = sPlayerbotAIConfig.reactDistance);
bool HasManyPlayersNearby(uint32 trigerrValue = 20, float range = sPlayerbotAIConfig.sightDistance);
bool AllowActive(ActivityType activityType);
bool AllowActivity(ActivityType activityType = ALL_ACTIVITY, bool checkNow = false);
uint32 AutoScaleActivity(uint32 mod);
@@ -562,7 +562,7 @@ public:
bool HasCheat(BotCheatMask mask)
{
return ((uint32)mask & (uint32)cheatMask) != 0 ||
((uint32)mask & (uint32)sPlayerbotAIConfig->botCheatMask) != 0;
((uint32)mask & (uint32)sPlayerbotAIConfig.botCheatMask) != 0;
}
BotCheatMask GetCheat() { return cheatMask; }
void SetCheat(BotCheatMask mask) { cheatMask = mask; }

View File

@@ -102,11 +102,11 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
Player* masterPlayer = masterSession ? masterSession->GetPlayer() : nullptr;
bool isRndbot = !masterAccountId;
bool sameAccount = sPlayerbotAIConfig->allowAccountBots && accountId == masterAccountId;
bool sameAccount = sPlayerbotAIConfig.allowAccountBots && accountId == masterAccountId;
Guild* guild = masterPlayer ? sGuildMgr->GetGuildById(masterPlayer->GetGuildId()) : nullptr;
bool sameGuild = sPlayerbotAIConfig->allowGuildBots && guild && guild->GetMember(playerGuid);
bool addClassBot = sRandomPlayerbotMgr->IsAddclassBot(playerGuid.GetCounter());
bool linkedAccount = sPlayerbotAIConfig->allowTrustedAccountBots && IsAccountLinked(accountId, masterAccountId);
bool sameGuild = sPlayerbotAIConfig.allowGuildBots && guild && guild->GetMember(playerGuid);
bool addClassBot = sRandomPlayerbotMgr.IsAddclassBot(playerGuid.GetCounter());
bool linkedAccount = sPlayerbotAIConfig.allowTrustedAccountBots && IsAccountLinked(accountId, masterAccountId);
bool allowed = true;
std::ostringstream out;
@@ -126,10 +126,10 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
return;
}
uint32 count = mgr->GetPlayerbotsCount() + botLoading.size();
if (count >= sPlayerbotAIConfig->maxAddedBots)
if (count >= sPlayerbotAIConfig.maxAddedBots)
{
allowed = false;
out << "Failure: You have added too many bots (more than " << sPlayerbotAIConfig->maxAddedBots << ")";
out << "Failure: You have added too many bots (more than " << sPlayerbotAIConfig.maxAddedBots << ")";
}
}
if (!allowed)
@@ -156,7 +156,6 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
[](SQLQueryHolderBase const& queryHolder)
{
PlayerbotLoginQueryHolder const& holder = static_cast<PlayerbotLoginQueryHolder const&>(queryHolder);
PlayerbotHolder* mgr = sRandomPlayerbotMgr; // could be null
uint32 masterAccountId = holder.GetMasterAccountId();
if (masterAccountId)
@@ -164,14 +163,25 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
// verify and find current world session of master
WorldSession* masterSession = sWorldSessionMgr->FindSession(masterAccountId);
Player* masterPlayer = masterSession ? masterSession->GetPlayer() : nullptr;
if (masterPlayer)
mgr = GET_PLAYERBOT_MGR(masterPlayer);
{
PlayerbotHolder* mgr = PlayerbotsMgr::instance().GetPlayerbotMgr(masterPlayer);
if (mgr != nullptr)
{
mgr->HandlePlayerBotLoginCallback(holder);
return;
}
PlayerbotHolder::botLoading.erase(holder.GetGuid());
return;
}
}
if (mgr)
mgr->HandlePlayerBotLoginCallback(holder);
else
PlayerbotHolder::botLoading.erase(holder.GetGuid());
RandomPlayerbotMgr ::instance().HandlePlayerBotLoginCallback(holder);
});
}
@@ -216,9 +226,9 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
masterAccountId);
}
sRandomPlayerbotMgr->OnPlayerLogin(bot);
sRandomPlayerbotMgr.OnPlayerLogin(bot);
auto op = std::make_unique<OnBotLoginOperation>(bot->GetGUID(), masterAccountId);
sPlayerbotWorldProcessor->QueueOperation(std::move(op));
PlayerbotWorldThreadProcessor::instance().QueueOperation(std::move(op));
PlayerbotHolder::botLoading.erase(holder.GetGuid());
}
@@ -312,8 +322,8 @@ void PlayerbotMgr::CancelLogout()
}
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin();
it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr.GetPlayerBotsBegin();
it != sRandomPlayerbotMgr.GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
@@ -341,7 +351,7 @@ void PlayerbotHolder::LogoutPlayerBot(ObjectGuid guid)
// Queue group cleanup operation for world thread
auto cleanupOp = std::make_unique<BotLogoutGroupCleanupOperation>(guid);
sPlayerbotWorldProcessor->QueueOperation(std::move(cleanupOp));
PlayerbotWorldThreadProcessor::instance().QueueOperation(std::move(cleanupOp));
LOG_DEBUG("playerbots", "Bot {} logging out", bot->GetName().c_str());
bot->SaveToDB(false, false);
@@ -442,7 +452,7 @@ void PlayerbotHolder::DisablePlayerBot(ObjectGuid guid)
Group* group = bot->GetGroup();
if (group && !bot->InBattleground() && !bot->InBattlegroundQueue() && botAI->HasActivePlayerMaster())
{
sPlayerbotRepository->Save(botAI);
PlayerbotRepository::instance().Save(botAI);
}
LOG_DEBUG("playerbots", "Bot {} logged out", bot->GetName().c_str());
@@ -488,7 +498,7 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
return;
}
sPlayerbotsMgr->AddPlayerbotData(bot, true);
PlayerbotsMgr::instance().AddPlayerbotData(bot, true);
playerBots[bot->GetGUID()] = bot;
OnBotLoginInternal(bot);
@@ -528,10 +538,10 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
// Don't disband alt groups when master goes away
// Controlled by config
if (sPlayerbotAIConfig->KeepAltsInGroup())
if (sPlayerbotAIConfig.KeepAltsInGroup())
{
uint32 account = sCharacterCache->GetCharacterAccountIdByGuid(member);
if (!sPlayerbotAIConfig->IsInRandomAccountList(account))
if (!sPlayerbotAIConfig.IsInRandomAccountList(account))
{
groupValid = true;
break;
@@ -552,9 +562,9 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
}
else
{
botAI->ResetStrategies(!sRandomPlayerbotMgr->IsRandomBot(bot));
botAI->ResetStrategies(!sRandomPlayerbotMgr.IsRandomBot(bot));
}
sPlayerbotRepository->Load(botAI);
PlayerbotRepository::instance().Load(botAI);
if (master && !master->HasUnitState(UNIT_STATE_IN_FLIGHT))
{
@@ -580,52 +590,52 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
{
// Queue ConvertToRaid operation
auto convertOp = std::make_unique<GroupConvertToRaidOperation>(master->GetGUID());
sPlayerbotWorldProcessor->QueueOperation(std::move(convertOp));
PlayerbotWorldThreadProcessor::instance().QueueOperation(std::move(convertOp));
}
if (mgroup->isRaidGroup())
{
// Queue AddMember operation
auto addOp = std::make_unique<GroupInviteOperation>(master->GetGUID(), bot->GetGUID());
sPlayerbotWorldProcessor->QueueOperation(std::move(addOp));
PlayerbotWorldThreadProcessor::instance().QueueOperation(std::move(addOp));
}
}
else
{
// Queue AddMember operation
auto addOp = std::make_unique<GroupInviteOperation>(master->GetGUID(), bot->GetGUID());
sPlayerbotWorldProcessor->QueueOperation(std::move(addOp));
PlayerbotWorldThreadProcessor::instance().QueueOperation(std::move(addOp));
}
}
else if (master && !group)
{
// Queue group creation and AddMember operation
auto inviteOp = std::make_unique<GroupInviteOperation>(master->GetGUID(), bot->GetGUID());
sPlayerbotWorldProcessor->QueueOperation(std::move(inviteOp));
PlayerbotWorldThreadProcessor::instance().QueueOperation(std::move(inviteOp));
}
// if (master)
// {
// // bot->TeleportTo(master);
// }
uint32 accountId = bot->GetSession()->GetAccountId();
bool isRandomAccount = sPlayerbotAIConfig->IsInRandomAccountList(accountId);
bool isRandomAccount = sPlayerbotAIConfig.IsInRandomAccountList(accountId);
if (isRandomAccount && sPlayerbotAIConfig->randomBotFixedLevel)
if (isRandomAccount && sPlayerbotAIConfig.randomBotFixedLevel)
{
bot->SetPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
}
else if (isRandomAccount && !sPlayerbotAIConfig->randomBotFixedLevel)
else if (isRandomAccount && !sPlayerbotAIConfig.randomBotFixedLevel)
{
bot->RemovePlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
}
bot->SaveToDB(false, false);
bool addClassBot = sRandomPlayerbotMgr->IsAccountType(accountId, 2);
bool addClassBot = sRandomPlayerbotMgr.IsAccountType(accountId, 2);
if (addClassBot && master && abs((int)master->GetLevel() - (int)bot->GetLevel()) > 3)
{
// PlayerbotFactory factory(bot, master->GetLevel());
// factory.Randomize(false);
uint32 mixedGearScore =
PlayerbotAI::GetMixedGearScore(master, true, false, 12) * sPlayerbotAIConfig->autoInitEquipLevelLimitRatio;
PlayerbotAI::GetMixedGearScore(master, true, false, 12) * sPlayerbotAIConfig.autoInitEquipLevelLimitRatio;
// work around: distinguish from 0 if no gear
if (mixedGearScore == 0)
mixedGearScore = 1;
@@ -634,7 +644,7 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
}
// bots join World chat if not solo oriented
if (bot->GetLevel() >= 10 && sRandomPlayerbotMgr->IsRandomBot(bot) && GET_PLAYERBOT_AI(bot) &&
if (bot->GetLevel() >= 10 && sRandomPlayerbotMgr.IsRandomBot(bot) && GET_PLAYERBOT_AI(bot) &&
GET_PLAYERBOT_AI(bot)->GetGrouperType() != GrouperType::SOLO)
{
// TODO make action/config
@@ -702,12 +712,12 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, ObjectGuid guid, ObjectGuid masterguid,
bool admin, uint32 masterAccountId, uint32 masterGuildId)
{
if (!sPlayerbotAIConfig->enabled || guid.IsEmpty())
if (!sPlayerbotAIConfig.enabled || guid.IsEmpty())
return "bot system is disabled";
uint32 botAccount = sCharacterCache->GetCharacterAccountIdByGuid(guid);
//bool isRandomBot = sRandomPlayerbotMgr->IsRandomBot(guid.GetCounter()); //not used, line marked for removal.
//bool isRandomAccount = sPlayerbotAIConfig->IsInRandomAccountList(botAccount); //not used, shadowed, line marked for removal.
//bool isRandomBot = sRandomPlayerbotMgr.IsRandomBot(guid.GetCounter()); //not used, line marked for removal.
//bool isRandomAccount = sPlayerbotAIConfig.IsInRandomAccountList(botAccount); //not used, shadowed, line marked for removal.
//bool isMasterAccount = (masterAccountId == botAccount); //not used, line marked for removal.
if (cmd == "add" || cmd == "addaccount" || cmd == "login")
@@ -722,8 +732,8 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
if (!accountId)
return "character not found";
if (!sPlayerbotAIConfig->allowAccountBots && accountId != masterAccountId &&
!(sPlayerbotAIConfig->allowTrustedAccountBots && IsAccountLinked(accountId, masterAccountId)))
if (!sPlayerbotAIConfig.allowAccountBots && accountId != masterAccountId &&
!(sPlayerbotAIConfig.allowTrustedAccountBots && IsAccountLinked(accountId, masterAccountId)))
{
return "you can only add bots from your own account or linked accounts";
}
@@ -748,12 +758,12 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
// {
Player* bot = GetPlayerBot(guid);
if (!bot)
bot = sRandomPlayerbotMgr->GetPlayerBot(guid);
bot = sRandomPlayerbotMgr.GetPlayerBot(guid);
if (!bot)
return "bot not found";
bool addClassBot = sRandomPlayerbotMgr->IsAddclassBot(guid.GetCounter());
bool addClassBot = sRandomPlayerbotMgr.IsAddclassBot(guid.GetCounter());
if (!addClassBot)
return "ERROR: You can not use this command on non-addclass bot.";
@@ -771,7 +781,7 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
{
if (Player* master = GET_PLAYERBOT_AI(bot)->GetMaster())
{
if (master->GetSession()->GetSecurity() <= SEC_PLAYER && sPlayerbotAIConfig->autoInitOnly &&
if (master->GetSession()->GetSecurity() <= SEC_PLAYER && sPlayerbotAIConfig.autoInitOnly &&
cmd != "init=auto")
{
return "The command is not allowed, use init=auto instead.";
@@ -818,7 +828,7 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
else if (cmd == "init=auto")
{
uint32 mixedGearScore = PlayerbotAI::GetMixedGearScore(master, true, false, 12) *
sPlayerbotAIConfig->autoInitEquipLevelLimitRatio;
sPlayerbotAIConfig.autoInitEquipLevelLimitRatio;
// work around: distinguish from 0 if no gear
if (mixedGearScore == 0)
mixedGearScore = 1;
@@ -858,7 +868,7 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
}
else if (cmd == "random")
{
sRandomPlayerbotMgr->Randomize(bot);
sRandomPlayerbotMgr.Randomize(bot);
return "ok";
}
else if (cmd == "quests")
@@ -886,7 +896,7 @@ static uint8 GetOfflinePlayerGender(ObjectGuid guid)
bool PlayerbotMgr::HandlePlayerbotMgrCommand(ChatHandler* handler, char const* args)
{
if (!sPlayerbotAIConfig->enabled)
if (!sPlayerbotAIConfig.enabled)
{
handler->PSendSysMessage("|cffff0000Playerbot system is currently disabled!");
return false;
@@ -1052,7 +1062,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
sPlayerbotAIConfig->Initialize();
sPlayerbotAIConfig.Initialize();
messages.push_back("Config reloaded.");
return messages;
}
@@ -1065,11 +1075,11 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
if (!strcmp(cmd, "tweak"))
{
sPlayerbotAIConfig->tweakValue = sPlayerbotAIConfig->tweakValue++;
if (sPlayerbotAIConfig->tweakValue > 2)
sPlayerbotAIConfig->tweakValue = 0;
sPlayerbotAIConfig.tweakValue = sPlayerbotAIConfig.tweakValue++;
if (sPlayerbotAIConfig.tweakValue > 2)
sPlayerbotAIConfig.tweakValue = 0;
messages.push_back("Set tweakvalue to " + std::to_string(sPlayerbotAIConfig->tweakValue));
messages.push_back("Set tweakvalue to " + std::to_string(sPlayerbotAIConfig.tweakValue));
return messages;
}
@@ -1080,14 +1090,14 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
messages.push_back("Disable player botAI");
delete GET_PLAYERBOT_AI(master);
}
else if (sPlayerbotAIConfig->selfBotLevel == 0)
else if (sPlayerbotAIConfig.selfBotLevel == 0)
messages.push_back("Self-bot is disabled");
else if (sPlayerbotAIConfig->selfBotLevel == 1 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
else if (sPlayerbotAIConfig.selfBotLevel == 1 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
messages.push_back("You do not have permission to enable player botAI");
else
{
messages.push_back("Enable player botAI");
sPlayerbotsMgr->AddPlayerbotData(master, true);
PlayerbotsMgr::instance().AddPlayerbotData(master, true);
GET_PLAYERBOT_AI(master)->SetMaster(master);
}
@@ -1102,7 +1112,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
if (!strcmp(cmd, "addclass"))
{
if (sPlayerbotAIConfig->addClassCommand == 0 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
if (sPlayerbotAIConfig.addClassCommand == 0 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER)
{
messages.push_back("You do not have permission to create bot by addclass command");
return messages;
@@ -1183,7 +1193,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
return messages;
}
uint8 teamId = master->GetTeamId(true);
const std::unordered_set<ObjectGuid> &guidCache = sRandomPlayerbotMgr->addclassCache[RandomPlayerbotMgr::GetTeamClassIdx(teamId == TEAM_ALLIANCE, claz)];
const std::unordered_set<ObjectGuid> &guidCache = sRandomPlayerbotMgr.addclassCache[RandomPlayerbotMgr::GetTeamClassIdx(teamId == TEAM_ALLIANCE, claz)];
for (const ObjectGuid &guid: guidCache)
{
// If the user requested a specific gender, skip any character that doesn't match.
@@ -1194,7 +1204,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
if (ObjectAccessor::FindConnectedPlayer(guid))
continue;
uint32 guildId = sCharacterCache->GetCharacterGuildIdByGuid(guid);
if (guildId && sPlayerbotGuildMgr->IsRealGuild(guildId))
if (guildId && PlayerbotGuildMgr::instance().IsRealGuild(guildId))
continue;
AddPlayerBot(guid, master->GetSession()->GetAccountId());
messages.push_back("Add class " + std::string(charname));
@@ -1424,7 +1434,7 @@ std::string const PlayerbotHolder::ListBots(Player* master)
for (Group::member_citerator itr = groupSlot.begin(); itr != groupSlot.end(); itr++)
{
Player* member = ObjectAccessor::FindPlayer(itr->guid);
if (member && sRandomPlayerbotMgr->IsRandomBot(member))
if (member && sRandomPlayerbotMgr.IsRandomBot(member))
{
std::string const name = member->GetName();
@@ -1494,12 +1504,12 @@ PlayerbotMgr::PlayerbotMgr(Player* const master) : PlayerbotHolder(), master(mas
PlayerbotMgr::~PlayerbotMgr()
{
if (master)
sPlayerbotsMgr->RemovePlayerBotData(master->GetGUID(), false);
PlayerbotsMgr::instance().RemovePlayerBotData(master->GetGUID(), false);
}
void PlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
{
SetNextCheckDelay(sPlayerbotAIConfig->reactDelay);
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
CheckTellErrors(elapsed);
}
@@ -1509,10 +1519,10 @@ void PlayerbotMgr::HandleCommand(uint32 type, std::string const text)
if (!master)
return;
if (text.find(sPlayerbotAIConfig->commandSeparator) != std::string::npos)
if (text.find(sPlayerbotAIConfig.commandSeparator) != std::string::npos)
{
std::vector<std::string> commands;
split(commands, text, sPlayerbotAIConfig->commandSeparator.c_str());
split(commands, text, sPlayerbotAIConfig.commandSeparator.c_str());
for (std::vector<std::string>::iterator i = commands.begin(); i != commands.end(); ++i)
{
HandleCommand(type, *i);
@@ -1529,8 +1539,8 @@ void PlayerbotMgr::HandleCommand(uint32 type, std::string const text)
botAI->HandleCommand(type, text, master);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin();
it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr.GetPlayerBotsBegin();
it != sRandomPlayerbotMgr.GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
@@ -1551,8 +1561,8 @@ void PlayerbotMgr::HandleMasterIncomingPacket(WorldPacket const& packet)
botAI->HandleMasterIncomingPacket(packet);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin();
it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr.GetPlayerBotsBegin();
it != sRandomPlayerbotMgr.GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
@@ -1587,8 +1597,8 @@ void PlayerbotMgr::HandleMasterOutgoingPacket(WorldPacket const& packet)
botAI->HandleMasterOutgoingPacket(packet);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin();
it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr.GetPlayerBotsBegin();
it != sRandomPlayerbotMgr.GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
@@ -1605,8 +1615,8 @@ void PlayerbotMgr::SaveToDB()
bot->SaveToDB(false, false);
}
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr->GetPlayerBotsBegin();
it != sRandomPlayerbotMgr->GetPlayerBotsEnd(); ++it)
for (PlayerBotMap::const_iterator it = sRandomPlayerbotMgr.GetPlayerBotsBegin();
it != sRandomPlayerbotMgr.GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
if (GET_PLAYERBOT_AI(bot) && GET_PLAYERBOT_AI(bot)->GetMaster() == GetMaster())
@@ -1648,12 +1658,12 @@ void PlayerbotMgr::OnPlayerLogin(Player* player)
usedLocale = LOCALE_enUS; // fallback
// set locale priority for bot texts
sPlayerbotTextMgr->AddLocalePriority(usedLocale);
PlayerbotTextMgr::instance().AddLocalePriority(usedLocale);
if (sPlayerbotAIConfig->selfBotLevel > 2)
if (sPlayerbotAIConfig.selfBotLevel > 2)
HandlePlayerbotCommand("self", player);
if (!sPlayerbotAIConfig->botAutologin)
if (!sPlayerbotAIConfig.botAutologin)
return;
uint32 accountId = session->GetAccountId();
@@ -1693,7 +1703,7 @@ void PlayerbotMgr::TellError(std::string const botName, std::string const text)
void PlayerbotMgr::CheckTellErrors(uint32 elapsed)
{
time_t now = time(nullptr);
if ((now - lastErrorTell) < sPlayerbotAIConfig->errorDelay / 1000)
if ((now - lastErrorTell) < sPlayerbotAIConfig.errorDelay / 1000)
return;
lastErrorTell = now;
@@ -1777,7 +1787,7 @@ void PlayerbotsMgr::RemovePlayerBotData(ObjectGuid const& guid, bool is_AI)
PlayerbotAI* PlayerbotsMgr::GetPlayerbotAI(Player* player)
{
if (!(sPlayerbotAIConfig->enabled) || !player)
if (!(sPlayerbotAIConfig.enabled) || !player)
{
return nullptr;
}
@@ -1797,7 +1807,7 @@ PlayerbotAI* PlayerbotsMgr::GetPlayerbotAI(Player* player)
PlayerbotMgr* PlayerbotsMgr::GetPlayerbotMgr(Player* player)
{
if (!(sPlayerbotAIConfig->enabled) || !player)
if (!(sPlayerbotAIConfig.enabled) || !player)
{
return nullptr;
}

View File

@@ -6,12 +6,9 @@
#ifndef _PLAYERBOT_PLAYERBOTMGR_H
#define _PLAYERBOT_PLAYERBOTMGR_H
#include "Common.h"
#include "ObjectGuid.h"
#include "Player.h"
#include "PlayerbotAIBase.h"
#include "QueryHolder.h"
#include "QueryResult.h"
class ChatHandler;
class PlayerbotAI;
@@ -101,13 +98,10 @@ private:
class PlayerbotsMgr
{
public:
PlayerbotsMgr() {}
~PlayerbotsMgr() {}
static PlayerbotsMgr* instance()
static PlayerbotsMgr& instance()
{
static PlayerbotsMgr instance;
return &instance;
return instance;
}
void AddPlayerbotData(Player* player, bool isBotAI);
@@ -117,6 +111,15 @@ public:
PlayerbotMgr* GetPlayerbotMgr(Player* player);
private:
PlayerbotsMgr() = default;
~PlayerbotsMgr() = default;
PlayerbotsMgr(const PlayerbotsMgr&) = delete;
PlayerbotsMgr& operator=(const PlayerbotsMgr&) = delete;
PlayerbotsMgr(PlayerbotsMgr&&) = delete;
PlayerbotsMgr& operator=(PlayerbotsMgr&&) = delete;
std::unordered_map<ObjectGuid, PlayerbotAIBase*> _playerbotsAIMap;
std::unordered_map<ObjectGuid, PlayerbotAIBase*> _playerbotsMgrMap;
};

File diff suppressed because it is too large Load Diff

View File

@@ -10,6 +10,7 @@
#include "ObjectGuid.h"
#include "PlayerbotMgr.h"
#include "GameTime.h"
#include "PlayerbotCommandServer.h"
struct BattlegroundInfo
{
@@ -88,12 +89,11 @@ private:
class RandomPlayerbotMgr : public PlayerbotHolder
{
public:
RandomPlayerbotMgr();
virtual ~RandomPlayerbotMgr();
static RandomPlayerbotMgr* instance()
static RandomPlayerbotMgr& instance()
{
static RandomPlayerbotMgr instance;
return &instance;
return instance;
}
void LogPlayerLocation();
@@ -192,6 +192,43 @@ protected:
void OnBotLoginInternal(Player* const bot) override;
private:
RandomPlayerbotMgr() : PlayerbotHolder(), processTicks(0)
{
this->playersLevel = sPlayerbotAIConfig.randombotStartingLevel;
if (sPlayerbotAIConfig.enabled || sPlayerbotAIConfig.randomBotAutologin)
{
PlayerbotCommandServer::instance().Start();
}
BattlegroundData.clear(); // Clear here and here only.
// Cleanup on server start: orphaned pet data that's often left behind by bot pets that no longer exist in the DB
CharacterDatabase.Execute("DELETE FROM pet_aura WHERE guid NOT IN (SELECT id FROM character_pet)");
CharacterDatabase.Execute("DELETE FROM pet_spell WHERE guid NOT IN (SELECT id FROM character_pet)");
CharacterDatabase.Execute("DELETE FROM pet_spell_cooldown WHERE guid NOT IN (SELECT id FROM character_pet)");
for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
{
for (int queueType = BATTLEGROUND_QUEUE_AV; queueType < MAX_BATTLEGROUND_QUEUE_TYPES; ++queueType)
{
this->BattlegroundData[queueType][bracket] = BattlegroundInfo();
}
}
this->BgCheckTimer = 0;
this->LfgCheckTimer = 0;
this->PlayersCheckTimer = 0;
}
~RandomPlayerbotMgr() = default;
RandomPlayerbotMgr(const RandomPlayerbotMgr&) = delete;
RandomPlayerbotMgr& operator=(const RandomPlayerbotMgr&) = delete;
RandomPlayerbotMgr(RandomPlayerbotMgr&&) = delete;
RandomPlayerbotMgr& operator=(RandomPlayerbotMgr&&) = delete;
// pid values are set in constructor
botPID pid = botPID(1, 50, -50, 0, 0, 0);
float activityMod = 0.25;