diff --git a/playerbot/PlayerbotAIConfig.cpp b/playerbot/PlayerbotAIConfig.cpp index d3c18388..8fc67f47 100644 --- a/playerbot/PlayerbotAIConfig.cpp +++ b/playerbot/PlayerbotAIConfig.cpp @@ -179,7 +179,7 @@ bool PlayerbotAIConfig::Initialize() LoadList >(config.GetStringDefault("AiPlayerbot.RandomBotQuestIds", "7848,3802,5505,6502,7761,9378"), randomBotQuestIds); LoadList >(config.GetStringDefault("AiPlayerbot.ImmuneSpellIds", ""), immuneSpellIds); - botAutologin = config.GetIntDefault("AiPlayerbot.BotAutologin", false); + botAutologin = BotAutoLogin(config.GetIntDefault("AiPlayerbot.BotAutologin", 0)); randomBotAutologin = config.GetBoolDefault("AiPlayerbot.RandomBotAutologin", true); minRandomBots = config.GetIntDefault("AiPlayerbot.MinRandomBots", 50); maxRandomBots = config.GetIntDefault("AiPlayerbot.MaxRandomBots", 200); @@ -602,7 +602,7 @@ bool PlayerbotAIConfig::Initialize() } sLog.outString("Loading free bots."); - selfBotLevel = config.GetIntDefault("AiPlayerbot.SelfBotLevel", 1); + selfBotLevel = BotSelfBotLevel(config.GetIntDefault("AiPlayerbot.SelfBotLevel", uint32(BotSelfBotLevel::GM_ONLY))); LoadListString>(config.GetStringDefault("AiPlayerbot.ToggleAlwaysOnlineAccounts", ""), toggleAlwaysOnlineAccounts); LoadListString>(config.GetStringDefault("AiPlayerbot.ToggleAlwaysOnlineChars", ""), toggleAlwaysOnlineChars); @@ -753,7 +753,7 @@ void PlayerbotAIConfig::SetValue(std::string name, std::string value) void PlayerbotAIConfig::loadFreeAltBotAccounts() { - bool allCharsOnline = (selfBotLevel > 3); + bool allCharsOnline = (selfBotLevel == BotSelfBotLevel::ALWAYS_ACTIVE); freeAltBots.clear(); @@ -762,14 +762,14 @@ void PlayerbotAIConfig::loadFreeAltBotAccounts() { do { - bool accountAlwaysOnline = allCharsOnline; + bool accountToggle = false; Field* fields = results->Fetch(); std::string accountName = fields[0].GetString(); uint32 accountId = fields[1].GetUInt32(); if (std::find(toggleAlwaysOnlineAccounts.begin(), toggleAlwaysOnlineAccounts.end(), accountName) != toggleAlwaysOnlineAccounts.end()) - accountAlwaysOnline = !accountAlwaysOnline; + accountToggle = true; auto result = CharacterDatabase.PQuery("SELECT name, guid FROM characters WHERE account = '%u'", accountId); if (!result) @@ -777,22 +777,30 @@ void PlayerbotAIConfig::loadFreeAltBotAccounts() do { - bool charAlwaysOnline = allCharsOnline; + bool charToggle = false; Field* fields = result->Fetch(); std::string charName = fields[0].GetString(); uint32 guid = fields[1].GetUInt32(); - uint32 always = sRandomPlayerbotMgr.GetValue(guid, "always"); + BotAlwaysOnline always = BotAlwaysOnline(sRandomPlayerbotMgr.GetValue(guid, "always")); - if (always == 2) + if (always == BotAlwaysOnline::DISABLED_BY_COMMAND) continue; if (std::find(toggleAlwaysOnlineChars.begin(), toggleAlwaysOnlineChars.end(), charName) != toggleAlwaysOnlineChars.end()) - charAlwaysOnline = !charAlwaysOnline; + charToggle = true; - if(charAlwaysOnline || accountAlwaysOnline || always) + bool thisCharAlwaysOnline = allCharsOnline; + + if (accountToggle || charToggle) + thisCharAlwaysOnline = !thisCharAlwaysOnline; + + if ((thisCharAlwaysOnline && always != BotAlwaysOnline::DISABLED_BY_COMMAND) || always == BotAlwaysOnline::ACTIVE) + { + sLog.outString("Enabling always online for %s", charName.c_str()); freeAltBots.push_back(std::make_pair(accountId, guid)); + } } while (result->NextRow()); diff --git a/playerbot/PlayerbotAIConfig.h b/playerbot/PlayerbotAIConfig.h index 7ffd72d1..a6b4317b 100644 --- a/playerbot/PlayerbotAIConfig.h +++ b/playerbot/PlayerbotAIConfig.h @@ -25,6 +25,29 @@ enum class BotCheatMask : uint32 maxMask = 1 << 11 }; +enum class BotAutoLogin : uint32 +{ + DISABLED = 0, + LOGIN_ALL_WITH_MASTER = 1, + LOGIN_ONLY_ALWAYS_ACTIVE = 2 +}; + +enum class BotSelfBotLevel : uint32 +{ + DISABLED = 0, + GM_ONLY = 1, + ACTIVE_BY_COMMAND = 2, + ACTIVE_BY_LOGIN = 3, + ALWAYS_ACTIVE = 4 +}; + +enum class BotAlwaysOnline : uint32 +{ + DISABLED = 0, + ACTIVE = 1, + DISABLED_BY_COMMAND = 2 +}; + #define MAX_GEAR_PROGRESSION_LEVEL 6 class ConfigAccess @@ -71,7 +94,7 @@ class PlayerbotAIConfig uint32 openGoSpell; bool randomBotAutologin; - uint32 botAutologin; + BotAutoLogin botAutologin; std::string randomBotMapsAsString; std::vector randomBotMaps; std::list randomBotQuestItems; @@ -245,7 +268,7 @@ class PlayerbotAIConfig bool talentsInPublicNote; bool nonGmFreeSummon; - uint32 selfBotLevel; + BotSelfBotLevel selfBotLevel; uint32 iterationsPerTick; std::string autoPickReward; diff --git a/playerbot/PlayerbotMgr.cpp b/playerbot/PlayerbotMgr.cpp index 2ad2c812..cb2e4996 100644 --- a/playerbot/PlayerbotMgr.cpp +++ b/playerbot/PlayerbotMgr.cpp @@ -775,17 +775,17 @@ std::list PlayerbotHolder::HandlePlayerbotCommand(char const* args, if (!strcmp(cmd, "always")) { - if (sPlayerbotAIConfig.selfBotLevel == 0) + if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::DISABLED) { messages.push_back("Self-bot is disabled"); return messages; } - else if (sPlayerbotAIConfig.selfBotLevel == 1 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) + else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::GM_ONLY && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) { messages.push_back("You do not have permission to enable player ai"); return messages; } - else if (sPlayerbotAIConfig.selfBotLevel == 2 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) + else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::ACTIVE_BY_COMMAND && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) { messages.push_back("Player ai is only available while online"); return messages; @@ -821,17 +821,36 @@ std::list PlayerbotHolder::HandlePlayerbotCommand(char const* args, alwaysName = charname; } - uint32 always = sRandomPlayerbotMgr.GetValue(guid.GetCounter(), "always"); + BotAlwaysOnline always = BotAlwaysOnline(sRandomPlayerbotMgr.GetValue(guid.GetCounter(), "always")); - if (!always || always == 2) + if (always == BotAlwaysOnline::DISABLED || always == BotAlwaysOnline::DISABLED_BY_COMMAND) { - sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", 1); + sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", (uint32)BotAlwaysOnline::ACTIVE); messages.push_back("Enable offline player ai for " + alwaysName); sPlayerbotAIConfig.freeAltBots.push_back(std::make_pair(accountId, guid.GetCounter())); + + if (!charname) + { + if (!master->GetPlayerbotAI()) + OnBotLogin(master); + } + else + { + Player* bot = sRandomPlayerbotMgr.GetPlayerBot(guid); + + if (bot) + { + ProcessBotCommand("add", guid, + master->GetObjectGuid(), + master->GetSession()->GetSecurity() >= SEC_GAMEMASTER, + master->GetSession()->GetAccountId(), + master->GetGuildId()); + } + } } else { - sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", 2); + sRandomPlayerbotMgr.SetValue(guid.GetCounter(), "always", (uint32)BotAlwaysOnline::DISABLED_BY_COMMAND); messages.push_back("Disable offline player ai for " + alwaysName); if (guid != master->GetObjectGuid()) @@ -862,14 +881,14 @@ std::list PlayerbotHolder::HandlePlayerbotCommand(char const* args, if (sRandomPlayerbotMgr.GetValue(master->GetObjectGuid().GetCounter(), "selfbot")) { messages.push_back("Disable player ai (on login)"); - sRandomPlayerbotMgr.SetValue(master->GetObjectGuid().GetCounter(), "selfbot", 0); + sRandomPlayerbotMgr.SetValue(master->GetObjectGuid().GetCounter(), "selfbot", (uint32)BotAlwaysOnline::DISABLED); } else messages.push_back("Disable player ai"); } - else if (sPlayerbotAIConfig.selfBotLevel == 0) + else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::DISABLED) messages.push_back("Self-bot is disabled"); - else if (sPlayerbotAIConfig.selfBotLevel == 1 && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) + else if (sPlayerbotAIConfig.selfBotLevel == BotSelfBotLevel::GM_ONLY && master->GetSession()->GetSecurity() < SEC_GAMEMASTER) messages.push_back("You do not have permission to enable player ai"); else { @@ -1287,14 +1306,18 @@ void PlayerbotMgr::OnPlayerLogin(Player* player) sPlayerbotTextMgr.AddLocalePriority(player->GetSession()->GetSessionDbLocaleIndex()); sLog.outBasic("Player %s logged in, localeDbc %i, localeDb %i", player->GetName(), (uint32)(player->GetSession()->GetSessionDbcLocale()), player->GetSession()->GetSessionDbLocaleIndex()); - if(sPlayerbotAIConfig.selfBotLevel > 2 || sPlayerbotAIConfig.IsFreeAltBot(player) || sRandomPlayerbotMgr.GetValue(master->GetObjectGuid().GetCounter(), "selfbot")) + if (sPlayerbotAIConfig.IsFreeAltBot(player)) + { + sLog.outString("Enabling selfbot on login for %s", player->GetName()); HandlePlayerbotCommand("self", player); + } + if (player->GetSession() != player->GetPlayerMenu()->GetGossipMenu().GetMenuSession()) { player->GetPlayerMenu()->GetGossipMenu() = GossipMenu(player->GetSession()); } - if (!sPlayerbotAIConfig.botAutologin) + if (sPlayerbotAIConfig.botAutologin == BotAutoLogin::DISABLED) return; uint32 accountId = player->GetSession()->GetAccountId(); @@ -1309,7 +1332,7 @@ void PlayerbotMgr::OnPlayerLogin(Player* player) { Field* fields = results->Fetch(); if (first) first = false; else out << ","; - if(sPlayerbotAIConfig.botAutologin == 2 && !sPlayerbotAIConfig.IsFreeAltBot(fields[0].GetUInt32())) continue; + if(sPlayerbotAIConfig.botAutologin == BotAutoLogin::LOGIN_ONLY_ALWAYS_ACTIVE && !sPlayerbotAIConfig.IsFreeAltBot(fields[0].GetUInt32())) continue; out << fields[1].GetString(); } while (results->NextRow()); diff --git a/playerbot/RandomPlayerbotMgr.cpp b/playerbot/RandomPlayerbotMgr.cpp index db7b2dea..9f41d4da 100644 --- a/playerbot/RandomPlayerbotMgr.cpp +++ b/playerbot/RandomPlayerbotMgr.cpp @@ -755,7 +755,7 @@ void RandomPlayerbotMgr::ScaleBotActivity() void RandomPlayerbotMgr::LoginFreeBots() { - if (!sPlayerbotAIConfig.freeAltBots.empty() && sPlayerbotAIConfig.botAutologin != 2) + if (!sPlayerbotAIConfig.freeAltBots.empty() && sPlayerbotAIConfig.botAutologin != BotAutoLogin::LOGIN_ONLY_ALWAYS_ACTIVE) { for (auto bot : sPlayerbotAIConfig.freeAltBots) {