From 1c22a9a9ffabeafaccac3157055c513fef0f6386 Mon Sep 17 00:00:00 2001 From: Yunfan Li <56597220+liyunfan1223@users.noreply.github.com> Date: Thu, 26 Dec 2024 03:42:35 +0800 Subject: [PATCH] Add ratio config for alliance and horde rndbots (#818) --- conf/playerbots.conf.dist | 5 +++++ src/PlayerbotAIConfig.cpp | 2 ++ src/PlayerbotAIConfig.h | 2 ++ src/RandomPlayerbotMgr.cpp | 31 +++++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 71c3a051..18d1e527 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -495,6 +495,11 @@ AiPlayerbot.PreQuests = 0 # Enable LFG for random bots AiPlayerbot.RandomBotJoinLfg = 1 +# Percentage ratio of alliance and horde +# Need to reset rndbot after changing the setting (.playerbot rndbot reset) +AiPlayerbot.RandomBotAllianceRatio = 50 +AiPlayerbot.RandomBotHordeRatio = 50 + # Disable death knight for bots login # Need to reset rndbot after changing the setting (.playerbot rndbot reset) AiPlayerbot.DisableDeathKnightLogin = 0 diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index df0dd650..2b4c17ee 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -468,6 +468,8 @@ bool PlayerbotAIConfig::Initialize() autoGearScoreLimit = sConfigMgr->GetOption("AiPlayerbot.AutoGearScoreLimit", 0); playerbotsXPrate = sConfigMgr->GetOption("AiPlayerbot.KillXPRate", 1); + randomBotAllianceRatio = sConfigMgr->GetOption("AiPlayerbot.RandomBotAllianceRatio", 50); + randomBotHordeRatio = sConfigMgr->GetOption("AiPlayerbot.RandomBotHordeRatio", 50); disableDeathKnightLogin = sConfigMgr->GetOption("AiPlayerbot.DisableDeathKnightLogin", 0); botActiveAlone = sConfigMgr->GetOption("AiPlayerbot.BotActiveAlone", 100); BotActiveAloneForceWhenInRadius = sConfigMgr->GetOption("AiPlayerbot.BotActiveAloneForceWhenInRadius", 150); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index f8d36152..b5049dbb 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -262,6 +262,8 @@ public: bool randomBotFixedLevel; bool disableRandomLevels; uint32 playerbotsXPrate; + uint32 randomBotAllianceRatio; + uint32 randomBotHordeRatio; bool disableDeathKnightLogin; uint32 botActiveAlone; uint32 BotActiveAloneForceWhenInRadius; diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 18b6ab3a..c1f7aabb 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -464,6 +464,9 @@ uint32 RandomPlayerbotMgr::AddRandomBots() maxAllowedBotCount -= currentBots.size(); maxAllowedBotCount = std::min(sPlayerbotAIConfig->randomBotsPerInterval, maxAllowedBotCount); + uint32 allowedAllianceCount = maxAllowedBotCount * (sPlayerbotAIConfig->randomBotAllianceRatio) / (sPlayerbotAIConfig->randomBotAllianceRatio + sPlayerbotAIConfig->randomBotHordeRatio); + uint32 allowedHordeCount = maxAllowedBotCount - allowedAllianceCount; + for (std::vector::iterator i = sPlayerbotAIConfig->randomBotAccounts.begin(); i != sPlayerbotAIConfig->randomBotAccounts.end(); i++) { @@ -500,18 +503,30 @@ uint32 RandomPlayerbotMgr::AddRandomBots() if (sPlayerbotAIConfig->disableDeathKnightLogin) { - QueryResult result = CharacterDatabase.Query("Select class from characters where guid = {}", guid); - if (!result) - { - continue; - } - Field* fields = result->Fetch(); - uint32 rClass = fields[0].Get(); + uint32 rClass = fields[1].Get(); if (rClass == CLASS_DEATH_KNIGHT) { continue; } } + uint32 rRace = fields[2].Get(); + uint32 isAlliance = IsAlliance(rRace); + if (!allowedAllianceCount && isAlliance) + { + continue; + } + if (!allowedHordeCount && !isAlliance) + { + continue; + } + if (isAlliance) + { + allowedAllianceCount--; + } + else + { + allowedHordeCount--; + } guids.push_back(guid); } while (result->NextRow()); @@ -540,7 +555,7 @@ uint32 RandomPlayerbotMgr::AddRandomBots() if (maxAllowedBotCount) LOG_ERROR("playerbots", - "Not enough random bot accounts available. Need {} more, try to increase RandomBotAccountCount " + "Not enough random bot accounts available. Try to increase RandomBotAccountCount " "in your conf file", ceil(maxAllowedBotCount / 10)); }