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

@@ -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);