Run clang-format

This commit is contained in:
Yunfan Li
2024-08-04 10:23:36 +08:00
parent 44da167492
commit 53611c9040
835 changed files with 35085 additions and 31861 deletions

View File

@@ -1,7 +1,16 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
* and/or modify it under version 2 of the License, or (at your option), any later version.
*/
#include "PlayerbotMgr.h"
#include <cstdio>
#include <cstring>
#include <istream>
#include <string>
#include "ChannelMgr.h"
#include "CharacterCache.h"
#include "CharacterPackets.h"
#include "Common.h"
@@ -11,35 +20,29 @@
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "PlayerbotAIConfig.h"
#include "PlayerbotMgr.h"
#include "PlayerbotSecurity.h"
#include "Playerbots.h"
#include "PlayerbotDbStore.h"
#include "PlayerbotFactory.h"
#include "PlayerbotSecurity.h"
#include "Playerbots.h"
#include "SharedDefines.h"
#include "WorldSession.h"
#include "ChannelMgr.h"
#include <cstdio>
#include <cstring>
#include <istream>
#include <string>
PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false)
{
}
PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) {}
class PlayerbotLoginQueryHolder : public LoginQueryHolder
{
private:
uint32 masterAccountId;
PlayerbotHolder* playerbotHolder;
private:
uint32 masterAccountId;
PlayerbotHolder* playerbotHolder;
public:
PlayerbotLoginQueryHolder(PlayerbotHolder* playerbotHolder, uint32 masterAccount, uint32 accountId, ObjectGuid guid)
: LoginQueryHolder(accountId, guid), masterAccountId(masterAccount), playerbotHolder(playerbotHolder) { }
public:
PlayerbotLoginQueryHolder(PlayerbotHolder* playerbotHolder, uint32 masterAccount, uint32 accountId, ObjectGuid guid)
: LoginQueryHolder(accountId, guid), masterAccountId(masterAccount), playerbotHolder(playerbotHolder)
{
}
uint32 GetMasterAccountId() const { return masterAccountId; }
PlayerbotHolder* GetPlayerbotHolder() { return playerbotHolder; }
uint32 GetMasterAccountId() const { return masterAccountId; }
PlayerbotHolder* GetPlayerbotHolder() { return playerbotHolder; }
};
void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId)
@@ -53,7 +56,8 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
if (!accountId)
return;
std::shared_ptr<PlayerbotLoginQueryHolder> holder = std::make_shared<PlayerbotLoginQueryHolder>(this, masterAccountId, accountId, playerGuid);
std::shared_ptr<PlayerbotLoginQueryHolder> holder =
std::make_shared<PlayerbotLoginQueryHolder>(this, masterAccountId, accountId, playerGuid);
if (!holder->Initialize())
{
return;
@@ -61,17 +65,15 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
if (WorldSession* masterSession = sWorld->FindSession(masterAccountId))
{
masterSession->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder)).AfterComplete([this](SQLQueryHolderBase const& holder)
{
HandlePlayerBotLoginCallback(static_cast<PlayerbotLoginQueryHolder const&>(holder));
});
masterSession->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder))
.AfterComplete([this](SQLQueryHolderBase const& holder)
{ HandlePlayerBotLoginCallback(static_cast<PlayerbotLoginQueryHolder const&>(holder)); });
}
else
{
sWorld->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder)).AfterComplete([this](SQLQueryHolderBase const& holder)
{
HandlePlayerBotLoginCallback(static_cast<PlayerbotLoginQueryHolder const&>(holder));
});
sWorld->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder))
.AfterComplete([this](SQLQueryHolderBase const& holder)
{ HandlePlayerBotLoginCallback(static_cast<PlayerbotLoginQueryHolder const&>(holder)); });
}
}
@@ -79,23 +81,27 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
{
// has bot already been added?
Player* loginBot = ObjectAccessor::FindConnectedPlayer(holder.GetGuid());
if (loginBot && loginBot->IsInWorld()) {
if (loginBot && loginBot->IsInWorld())
{
return;
}
uint32 botAccountId = holder.GetAccountId();
// At login DBC locale should be what the server is set to use by default (as spells etc are hardcoded to ENUS this allows channels to work as intended)
WorldSession* botSession = new WorldSession(botAccountId, "", nullptr, SEC_PLAYER, EXPANSION_WRATH_OF_THE_LICH_KING, time_t(0), sWorld->GetDefaultDbcLocale(), 0, false, false, 0, true);
// At login DBC locale should be what the server is set to use by default (as spells etc are hardcoded to ENUS this
// allows channels to work as intended)
WorldSession* botSession = new WorldSession(botAccountId, "", nullptr, SEC_PLAYER, EXPANSION_WRATH_OF_THE_LICH_KING,
time_t(0), sWorld->GetDefaultDbcLocale(), 0, false, false, 0, true);
botSession->HandlePlayerLoginFromDB(holder); // will delete lqh
botSession->HandlePlayerLoginFromDB(holder); // will delete lqh
Player* bot = botSession->GetPlayer();
if (!bot)
{
botSession->LogoutPlayer(true);
delete botSession;
// LOG_ERROR("playerbots", "Error logging in bot {}, please try to reset all random bots", holder.GetGuid().ToString().c_str());
// LOG_ERROR("playerbots", "Error logging in bot {}, please try to reset all random bots",
// holder.GetGuid().ToString().c_str());
return;
}
@@ -103,25 +109,37 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
WorldSession* masterSession = masterAccount ? sWorld->FindSession(masterAccount) : nullptr;
std::ostringstream out;
bool allowed = false;
if (botAccountId == masterAccount) {
if (botAccountId == masterAccount)
{
allowed = true;
} else if (masterSession && sPlayerbotAIConfig->allowGuildBots && bot->GetGuildId() != 0 && bot->GetGuildId() == masterSession->GetPlayer()->GetGuildId()) {
}
else if (masterSession && sPlayerbotAIConfig->allowGuildBots && bot->GetGuildId() != 0 &&
bot->GetGuildId() == masterSession->GetPlayer()->GetGuildId())
{
allowed = true;
} else if (sPlayerbotAIConfig->IsInRandomAccountList(botAccountId)) {
}
else if (sPlayerbotAIConfig->IsInRandomAccountList(botAccountId))
{
allowed = true;
} else {
}
else
{
allowed = false;
out << "Failure: You are not allowed to control bot " << bot->GetName().c_str();
}
if (allowed && masterSession) {
if (allowed && masterSession)
{
Player* player = masterSession->GetPlayer();
PlayerbotMgr *mgr = GET_PLAYERBOT_MGR(player);
PlayerbotMgr* mgr = GET_PLAYERBOT_MGR(player);
uint32 count = mgr->GetPlayerbotsCount();
uint32 cls_count = mgr->GetPlayerbotsCountByClass(bot->getClass());
if (count >= sPlayerbotAIConfig->maxAddedBots) {
if (count >= sPlayerbotAIConfig->maxAddedBots)
{
allowed = false;
out << "Failure: You have added too many bots";
} else if (cls_count >= sPlayerbotAIConfig->maxAddedBotsPerClass) {
}
else if (cls_count >= sPlayerbotAIConfig->maxAddedBotsPerClass)
{
allowed = false;
out << "Failure: You have added too many bots for this class";
}
@@ -143,7 +161,8 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
// OnBotLogin(bot);
// LogoutPlayerBot(bot->GetGUID());
// LOG_ERROR("playerbots", "Attempt to add not allowed bot {}, please try to reset all random bots", bot->GetName());
// LOG_ERROR("playerbots", "Attempt to add not allowed bot {}, please try to reset all random bots",
// bot->GetName());
}
}
@@ -155,7 +174,8 @@ void PlayerbotHolder::UpdateSessions()
if (bot->IsBeingTeleported())
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (botAI) {
if (botAI)
{
botAI->HandleTeleportAck();
}
}
@@ -229,7 +249,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);
@@ -289,14 +310,16 @@ void PlayerbotHolder::LogoutPlayerBot(ObjectGuid guid)
logout = true;
}
if (master && (master->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || master->HasUnitState(UNIT_STATE_IN_FLIGHT) ||
(masterWorldSessionPtr && masterWorldSessionPtr->GetSecurity() >= (AccountTypes)sWorld->getIntConfig(CONFIG_INSTANT_LOGOUT))))
if (master &&
(master->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || master->HasUnitState(UNIT_STATE_IN_FLIGHT) ||
(masterWorldSessionPtr &&
masterWorldSessionPtr->GetSecurity() >= (AccountTypes)sWorld->getIntConfig(CONFIG_INSTANT_LOGOUT))))
{
logout = true;
}
TravelTarget* target = nullptr;
if (botAI->GetAiObjectContext()) //Maybe some day re-write to delate all pointer values.
if (botAI->GetAiObjectContext()) // Maybe some day re-write to delate all pointer values.
{
target = botAI->GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get();
}
@@ -325,19 +348,19 @@ void PlayerbotHolder::LogoutPlayerBot(ObjectGuid guid)
}
else
{
playerBots.erase(guid); // deletes bot player ptr inside this WorldSession PlayerBotMap
playerBots.erase(guid); // deletes bot player ptr inside this WorldSession PlayerBotMap
delete botWorldSessionPtr; // finally delete the bot's WorldSession
if (target)
delete target;
}
return;
} // if instant logout possible, do it
} // if instant logout possible, do it
else if (bot && (logout || !botWorldSessionPtr->isLogingOut()))
{
botAI->TellMaster("Goodbye!");
playerBots.erase(guid); // deletes bot player ptr inside this WorldSession PlayerBotMap
botWorldSessionPtr->LogoutPlayer(true); // this will delete the bot Player object and PlayerbotAI object
delete botWorldSessionPtr; // finally delete the bot's WorldSession
playerBots.erase(guid); // deletes bot player ptr inside this WorldSession PlayerBotMap
botWorldSessionPtr->LogoutPlayer(true); // this will delete the bot Player object and PlayerbotAI object
delete botWorldSessionPtr; // finally delete the bot's WorldSession
}
}
}
@@ -347,7 +370,8 @@ void PlayerbotHolder::DisablePlayerBot(ObjectGuid guid)
if (Player* bot = GetPlayerBot(guid))
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
if (!botAI)
{
return;
}
botAI->TellMaster("Goodbye!");
@@ -364,14 +388,14 @@ void PlayerbotHolder::DisablePlayerBot(ObjectGuid guid)
bot->SaveToDB(false, false);
if (botAI->GetAiObjectContext()) //Maybe some day re-write to delate all pointer values.
if (botAI->GetAiObjectContext()) // Maybe some day re-write to delate all pointer values.
{
TravelTarget* target = botAI->GetAiObjectContext()->GetValue<TravelTarget*>("travel target")->Get();
if (target)
delete target;
}
playerBots.erase(guid); // deletes bot player ptr inside this WorldSession PlayerBotMap
playerBots.erase(guid); // deletes bot player ptr inside this WorldSession PlayerBotMap
delete botAI;
}
@@ -393,7 +417,8 @@ Player* PlayerbotHolder::GetPlayerBot(ObjectGuid::LowType lowGuid) const
void PlayerbotHolder::OnBotLogin(Player* const bot)
{
// Prevent duplicate login
if (playerBots.find(bot->GetGUID()) != playerBots.end()) {
if (playerBots.find(bot->GetGUID()) != playerBots.end())
{
return;
}
@@ -401,16 +426,16 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
playerBots[bot->GetGUID()] = bot;
OnBotLoginInternal(bot);
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
if (!botAI)
{
return;
}
Player* master = botAI->GetMaster();
if (master)
{
ObjectGuid masterGuid = master->GetGUID();
if (master->GetGroup() && ! master->GetGroup()->IsLeader(masterGuid))
if (master->GetGroup() && !master->GetGroup()->IsLeader(masterGuid))
master->GetGroup()->ChangeLeader(masterGuid);
}
@@ -475,19 +500,27 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
botAI->TellMaster("Hello!", PLAYERBOT_SECURITY_TALK);
if (master && master->GetGroup() && !group) {
if (master && master->GetGroup() && !group)
{
Group* mgroup = master->GetGroup();
if (mgroup->GetMembersCount() >= 5) {
if (!mgroup->isRaidGroup() && !mgroup->isLFGGroup() && !mgroup->isBGGroup() && !mgroup->isBFGroup()) {
if (mgroup->GetMembersCount() >= 5)
{
if (!mgroup->isRaidGroup() && !mgroup->isLFGGroup() && !mgroup->isBGGroup() && !mgroup->isBFGroup())
{
mgroup->ConvertToRaid();
}
if (mgroup->isRaidGroup()) {
if (mgroup->isRaidGroup())
{
mgroup->AddMember(bot);
}
} else {
}
else
{
mgroup->AddMember(bot);
}
} else if (master && !group) {
}
else if (master && !group)
{
Group* newGroup = new Group();
newGroup->Create(master);
sGroupMgr->AddGroup(newGroup);
@@ -497,30 +530,36 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
uint32 accountId = bot->GetSession()->GetAccountId();
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);
if (master && isRandomAccount && master->GetLevel() < bot->GetLevel()) {
if (master && isRandomAccount && master->GetLevel() < bot->GetLevel())
{
// PlayerbotFactory factory(bot, master->GetLevel());
// factory.Randomize(false);
uint32 mixedGearScore = PlayerbotAI::GetMixedGearScore(master, true, false, 12) * sPlayerbotAIConfig->autoInitEquipLevelLimitRatio;
uint32 mixedGearScore =
PlayerbotAI::GetMixedGearScore(master, true, false, 12) * sPlayerbotAIConfig->autoInitEquipLevelLimitRatio;
PlayerbotFactory factory(bot, master->GetLevel(), ITEM_QUALITY_LEGENDARY, mixedGearScore);
factory.Randomize(false);
}
// bots join World chat if not solo oriented
if (bot->GetLevel() >= 10 && sRandomPlayerbotMgr->IsRandomBot(bot) && GET_PLAYERBOT_AI(bot) && GET_PLAYERBOT_AI(bot)->GetGrouperType() != GrouperType::SOLO)
if (bot->GetLevel() >= 10 && sRandomPlayerbotMgr->IsRandomBot(bot) && GET_PLAYERBOT_AI(bot) &&
GET_PLAYERBOT_AI(bot)->GetGrouperType() != GrouperType::SOLO)
{
// TODO make action/config
// Make the bot join the world channel for chat
WorldPacket pkt(CMSG_JOIN_CHANNEL);
pkt << uint32(0) << uint8(0) << uint8(0);
pkt << std::string("World");
pkt << ""; // Pass
pkt << ""; // Pass
bot->GetSession()->HandleJoinChannel(pkt);
}
// join standard channels
@@ -533,7 +572,8 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
{
ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(i);
if (!channel) continue;
if (!channel)
continue;
bool isLfg = (channel->flags & CHANNEL_DBC_FLAG_LFG) != 0;
@@ -551,7 +591,8 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
else
{
char new_channel_name_buf[100];
snprintf(new_channel_name_buf, 100, channel->pattern[sWorld->GetDefaultDbcLocale()], current_zone_name.c_str());
snprintf(new_channel_name_buf, 100, channel->pattern[sWorld->GetDefaultDbcLocale()],
current_zone_name.c_str());
new_channel = cMgr->GetJoinChannel(new_channel_name_buf, channel->ChannelID);
}
if (new_channel && new_channel->GetName().length() > 0)
@@ -560,7 +601,8 @@ 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)
std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, ObjectGuid guid, ObjectGuid masterguid,
bool admin, uint32 masterAccountId, uint32 masterGuildId)
{
if (!sPlayerbotAIConfig->enabled || guid.IsEmpty())
return "bot system is disabled";
@@ -573,7 +615,8 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
if (!isRandomAccount && !isMasterAccount && !admin && masterguid)
{
Player* master = ObjectAccessor::FindConnectedPlayer(masterguid);
if (master && (!sPlayerbotAIConfig->allowGuildBots || !masterGuildId || (masterGuildId && sCharacterCache->GetCharacterGuildIdByGuid(guid) != masterGuildId)))
if (master && (!sPlayerbotAIConfig->allowGuildBots || !masterGuildId ||
(masterGuildId && sCharacterCache->GetCharacterGuildIdByGuid(guid) != masterGuildId)))
return "not in your guild or account";
}
@@ -609,21 +652,27 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
if (!bot)
return "bot not found";
if (!isRandomAccount || isRandomBot) {
if (!isRandomAccount || isRandomBot)
{
return "ERROR: You can not use this command on non-summoned random bot.";
}
if (!admin) {
if (!admin)
{
Player* master = ObjectAccessor::FindConnectedPlayer(masterguid);
if (master && (master->IsInCombat() || bot->IsInCombat())) {
if (master && (master->IsInCombat() || bot->IsInCombat()))
{
return "ERROR: You can not use this command during combat.";
}
}
if (GET_PLAYERBOT_AI(bot)) {
if (GET_PLAYERBOT_AI(bot))
{
if (Player* master = GET_PLAYERBOT_AI(bot)->GetMaster())
{
if (master->GetSession()->GetSecurity() <= SEC_PLAYER && sPlayerbotAIConfig->autoInitOnly && cmd != "init=auto") {
if (master->GetSession()->GetSecurity() <= SEC_PLAYER && sPlayerbotAIConfig->autoInitOnly &&
cmd != "init=auto")
{
return "The command is not allowed, use init=auto instead.";
}
int gs;
@@ -659,10 +708,12 @@ 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;
uint32 mixedGearScore = PlayerbotAI::GetMixedGearScore(master, true, false, 12) *
sPlayerbotAIConfig->autoInitEquipLevelLimitRatio;
PlayerbotFactory factory(bot, master->GetLevel(), ITEM_QUALITY_LEGENDARY, mixedGearScore);
factory.Randomize(false);
return "ok, gear score limit: " + std::to_string(mixedGearScore / (ITEM_QUALITY_EPIC + 1)) + "(for epic)";
return "ok, gear score limit: " + std::to_string(mixedGearScore / (ITEM_QUALITY_EPIC + 1)) +
"(for epic)";
}
else if (cmd.starts_with("init=") && sscanf(cmd.c_str(), "init=%d", &gs) != -1)
{
@@ -673,7 +724,7 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
}
if (cmd == "refresh=raid")
{ // TODO: This function is not perfect yet. If you are already in a raid,
{ // TODO: This function is not perfect yet. If you are already in a raid,
// after the command is executed, the AI needs to go back online or exit the raid and re-enter.
PlayerbotFactory factory(bot, bot->GetLevel());
factory.UnbindInstance();
@@ -698,7 +749,8 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje
sRandomPlayerbotMgr->Randomize(bot);
return "ok";
}
else if (cmd == "quests"){
else if (cmd == "quests")
{
PlayerbotFactory factory(bot, bot->GetLevel());
factory.InitInstanceQuests();
return "Initialization quests";
@@ -754,61 +806,78 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
return messages;
}
char* cmd = strtok ((char*)args, " ");
char* charname = strtok (nullptr, " ");
char* cmd = strtok((char*)args, " ");
char* charname = strtok(nullptr, " ");
if (!cmd)
{
messages.push_back("usage: list/reload/tweak/self or add/init/remove PLAYERNAME or addclass CLASSNAME");
return messages;
}
if (!strcmp(cmd, "initself")) {
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER) {
if (!strcmp(cmd, "initself"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_EPIC);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
} else {
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
if (!strncmp(cmd, "initself=", 9)) {
if (!strcmp(cmd, "initself=rare")) {
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER) {
if (!strncmp(cmd, "initself=", 9))
{
if (!strcmp(cmd, "initself=rare"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_RARE);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
} else {
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
if (!strcmp(cmd, "initself=epic")) {
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER) {
if (!strcmp(cmd, "initself=epic"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_EPIC);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
} else {
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
int32 gs;
if (sscanf(cmd, "initself=%d", &gs) != -1) {
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER) {
if (sscanf(cmd, "initself=%d", &gs) != -1)
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_LEGENDARY, gs);
factory.Randomize(false);
messages.push_back("initself ok, gs = " + std::to_string(gs));
return messages;
} else {
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
@@ -867,12 +936,15 @@ 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;
}
if (!charname) {
messages.push_back("addclass: invalid CLASSNAME(warrior/paladin/hunter/rogue/priest/shaman/mage/warlock/druid/dk)");
if (!charname)
{
messages.push_back(
"addclass: invalid CLASSNAME(warrior/paladin/hunter/rogue/priest/shaman/mage/warlock/druid/dk)");
return messages;
}
uint8 claz;
@@ -942,10 +1014,13 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
}
uint32 maxAccountId = sPlayerbotAIConfig->randomBotAccounts.back();
// find a bot fit conditions and not in any guild
QueryResult results = CharacterDatabase.Query("SELECT guid FROM characters "
"WHERE name IN (SELECT name FROM playerbots_names) AND class = '{}' AND online = 0 AND race IN ({}) AND guid NOT IN ( SELECT guid FROM guild_member ) "
QueryResult results = CharacterDatabase.Query(
"SELECT guid FROM characters "
"WHERE name IN (SELECT name FROM playerbots_names) AND class = '{}' AND online = 0 AND race IN ({}) AND "
"guid NOT IN ( SELECT guid FROM guild_member ) "
"AND account <= {} "
"ORDER BY account DESC LIMIT 1", claz, race_limit, maxAccountId);
"ORDER BY account DESC LIMIT 1",
claz, race_limit, maxAccountId);
if (results)
{
Field* fields = results->Fetch();
@@ -966,13 +1041,18 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
std::string name;
bool isPlayer = sCharacterCache->GetCharacterNameByGuid(master->GetTarget(), name);
// Player* tPlayer = ObjectAccessor::FindConnectedPlayer(master->GetTarget());
if (isPlayer) {
if (isPlayer)
{
charnameStr = name;
} else {
}
else
{
messages.push_back("usage: list/reload/tweak/self or add/init/remove PLAYERNAME");
return messages;
}
} else {
}
else
{
charnameStr = charname;
}
@@ -1050,7 +1130,9 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
}
else if (master && member != master->GetGUID())
{
out << ProcessBotCommand(cmdStr, member, master->GetGUID(), master->GetSession()->GetSecurity() >= SEC_GAMEMASTER, master->GetSession()->GetAccountId(), master->GetGuildId());
out << ProcessBotCommand(cmdStr, member, master->GetGUID(),
master->GetSession()->GetSecurity() >= SEC_GAMEMASTER,
master->GetSession()->GetAccountId(), master->GetGuildId());
}
else if (!master)
{
@@ -1063,10 +1145,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
return messages;
}
uint32 PlayerbotHolder::GetAccountId(std::string const name)
{
return AccountMgr::GetId(name);
}
uint32 PlayerbotHolder::GetAccountId(std::string const name) { return AccountMgr::GetId(name); }
uint32 PlayerbotHolder::GetAccountId(ObjectGuid guid)
{
@@ -1122,7 +1201,8 @@ std::string const PlayerbotHolder::ListBots(Player* master)
if (master)
{
QueryResult results = CharacterDatabase.Query("SELECT class, name FROM characters WHERE account = {}", master->GetSession()->GetAccountId());
QueryResult results = CharacterDatabase.Query("SELECT class, name FROM characters WHERE account = {}",
master->GetSession()->GetAccountId());
if (results)
{
do
@@ -1147,7 +1227,7 @@ std::string const PlayerbotHolder::ListBots(Player* master)
Group::MemberSlotList const& groupSlot = group->GetMemberSlots();
for (Group::member_citerator itr = groupSlot.begin(); itr != groupSlot.end(); itr++)
{
Player *member = ObjectAccessor::FindPlayer(itr->guid);
Player* member = ObjectAccessor::FindPlayer(itr->guid);
if (member && sRandomPlayerbotMgr->IsRandomBot(member))
{
std::string const name = member->GetName();
@@ -1192,7 +1272,8 @@ std::string const PlayerbotHolder::LookupBots(Player* master)
messages.push_back("DK");
messages.push_back("(Usage: .bot lookup CLASS)");
std::string ret_msg;
for (std::string msg: messages) {
for (std::string msg : messages)
{
ret_msg += msg + "\n";
}
return ret_msg;
@@ -1204,16 +1285,15 @@ uint32 PlayerbotHolder::GetPlayerbotsCountByClass(uint32 cls)
for (PlayerBotMap::const_iterator it = GetPlayerBotsBegin(); it != GetPlayerBotsEnd(); ++it)
{
Player* const bot = it->second;
if (bot->getClass() == cls) {
if (bot->getClass() == cls)
{
count++;
}
}
return count;
}
PlayerbotMgr::PlayerbotMgr(Player* const master) : PlayerbotHolder(), master(master), lastErrorTell(0)
{
}
PlayerbotMgr::PlayerbotMgr(Player* const master) : PlayerbotHolder(), master(master), lastErrorTell(0) {}
PlayerbotMgr::~PlayerbotMgr()
{
@@ -1253,7 +1333,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);
@@ -1274,7 +1355,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);
@@ -1309,7 +1391,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);
@@ -1326,7 +1409,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())
@@ -1334,10 +1418,11 @@ void PlayerbotMgr::SaveToDB()
}
}
void PlayerbotMgr::OnBotLoginInternal(Player * const bot)
void PlayerbotMgr::OnBotLoginInternal(Player* const bot)
{
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
if (!botAI) {
if (!botAI)
{
return;
}
botAI->SetMaster(master);
@@ -1431,7 +1516,7 @@ void PlayerbotsMgr::AddPlayerbotData(Player* player, bool isBotAI)
return;
}
// If the guid already exists in the map, remove it
if (!isBotAI)
{
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsMgrMap.find(player->GetGUID());
@@ -1458,13 +1543,16 @@ void PlayerbotsMgr::AddPlayerbotData(Player* player, bool isBotAI)
void PlayerbotsMgr::RemovePlayerBotData(ObjectGuid const& guid, bool is_AI)
{
if (is_AI) {
if (is_AI)
{
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsAIMap.find(guid);
if (itr != _playerbotsAIMap.end())
{
_playerbotsAIMap.erase(itr);
}
} else {
}
else
{
std::unordered_map<ObjectGuid, PlayerbotAIBase*>::iterator itr = _playerbotsMgrMap.find(guid);
if (itr != _playerbotsMgrMap.end())
{