From 8669a4dbcb615748f2f79e180a17a1969d6609b7 Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:08:01 -0500 Subject: [PATCH 1/9] Adding some fixes --- README.md | 4 ++-- conf/mod_player_bot_level_brackets.conf.dist | 8 ++++---- src/mod-player-bot-level-brackets.cpp | 7 +++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7fea691..ddf9e28 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,8 @@ BotLevelBrackets.LiteDebugMode | Enables lite debug logging for th BotLevelBrackets.CheckFrequency | Frequency (in seconds) at which the bot level distribution check is performed. | 300 | Positive Integer BotLevelBrackets.CheckFlaggedFrequency | Frequency (in seconds) at which the bot level reset is performed for flagged bots that initially failed safety checks. | 15 | Positive Integer BotLevelBrackets.FlaggedProcessLimit | Maximum number of flagged bots to process per pending level change step. | 5 | Positive Integer -BotLevelBrackets.Dynamic.UseDynamicDistribution | Enables dynamic bot distribution: when on, brackets with more real players get a higher share of bots, based on the weight below. | 0 | 0 (off) / 1 (on) -BotLevelBrackets.Dynamic.RealPlayerWeight | Controls how much bots "follow" real player activity when dynamic distribution is enabled. 0.0 = bots always spread evenly; 1.0 = mild effect; higher values = more bots go where players are, but the effect is scaled. | 1.0 | ≥ 0.0 (float) +BotLevelBrackets.Dynamic.UseDynamicDistribution | Enables dynamic bot distribution: when on, brackets with more real players get a higher share of bots in their level bracket, based on the weight below. | 0 | 0 (off) / 1 (on) +BotLevelBrackets.Dynamic.RealPlayerWeight | Controls how much bots "follow" real player activity when dynamic distribution is enabled. 0.0 = bots always spread evenly; 1.0 = minimal effect; 10.0 = heavy effect; higher values = more bots go where players are, but the effect is scaled. | 10.0 | ≥ 0.0 (float) BotLevelBrackets.Dynamic.SyncFactions | Enables synchronized brackets and weighting between Alliance and Horde factions when Dynamic Distribution is also enabled. | 0 | 0 (off) / 1 (on) BotLevelBrackets.IgnoreFriendListed | Ignores bots that are on real players' friend lists from any bracket calculations. | 1 | 0 (off) / 1 (on) BotLevelBrackets.IgnoreGuildBotsWithRealPlayers | Excludes bots in a guild with at least one real (non-bot) player from adjustments. Uses persistent database tracking for both online and offline real players. | 1 | 0 (disabled) / 1 (enabled) diff --git a/conf/mod_player_bot_level_brackets.conf.dist b/conf/mod_player_bot_level_brackets.conf.dist index efa582b..d8ca1ea 100644 --- a/conf/mod_player_bot_level_brackets.conf.dist +++ b/conf/mod_player_bot_level_brackets.conf.dist @@ -85,7 +85,7 @@ BotLevelBrackets.NumRanges = 9 # # BotLevelBrackets.Dynamic.UseDynamicDistribution # Description: Enables dynamic recalculation of bot distribution percentages based on the number of non-bot players -# present in each level bracket. +# present in each level bracket. This overrides any custom brackets in the conf. # Default: 0 (disabled) # Valid values: 0 (off) / 1 (on) BotLevelBrackets.Dynamic.UseDynamicDistribution = 0 @@ -95,7 +95,7 @@ BotLevelBrackets.Dynamic.UseDynamicDistribution = 0 # The higher you set this value, the more bots will move to the same level brackets where real players are found, but the effect is *gentle*, not extreme. # A value of 0.0 means bots always distribute evenly across all brackets, regardless of where players are. The default value of 1.0 gives a mild, balanced effect. # Raising this to 3.0, 5.0, or higher will make bots concentrate more in brackets with real players. -# The value is a multiplier (not a percent): 0.0 = no extra effect, 1.0 = default, 3.0 = stronger, 5.0 = strong but not extreme. +# The value is a multiplier (not a percent): 0.0 = no extra effect, 1.0 = minimal, 3.0 = stronger, 5.0 = strong but not extreme. # Experiment based on your total bot count and real player counts to find a good number for your server. # If you want a large congestion of bots in your level bracket for solo play I recommend 10-15 for RealPlayerWeight. # What to expect: @@ -107,8 +107,8 @@ BotLevelBrackets.Dynamic.UseDynamicDistribution = 0 # Formula (per bracket): # bracket_weight = 1.0 + (RealPlayerWeight × (1 / TotalRealPlayers) × log(1 + RealPlayersInBracket)) # All bracket weights are normalized to total 100%. -# Default: 1.0 -BotLevelBrackets.Dynamic.RealPlayerWeight = 1.0 +# Default: 10.0 +BotLevelBrackets.Dynamic.RealPlayerWeight = 10.0 # # BotLevelBrackets.Dynamic.SyncFactions diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 87dda4b..48ca132 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -664,6 +664,10 @@ static void AdjustBotToRange(Player* bot, int targetRangeIndex, const LevelRange { lowerBound = 55; } + if (lowerBound > upperBound) + { + return; + } newLevel = urand(lowerBound, upperBound); } else @@ -1361,6 +1365,9 @@ public: applyWeights(g_AllianceLevelRanges, allianceWeights); applyWeights(g_HordeLevelRanges, hordeWeights); + // Ensure brackets respect global min/max levels and percentages sum to 100 + ClampAndBalanceBrackets(); + // Debug output for new bracket percentages after normalization if (g_BotDistFullDebugMode || g_BotDistLiteDebugMode) { From 74fb4876f54fd9d0560723f6b8efe1a427e5cb1f Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:09:37 -0500 Subject: [PATCH 2/9] Adding reload command --- README.md | 2 +- conf/mod_player_bot_level_brackets.conf.dist | 4 +- src/mod-player-bot-level-brackets.cpp | 39 ++++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ddf9e28..2de5816 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ BotLevelBrackets.CheckFrequency | Frequency (in seconds) at which t BotLevelBrackets.CheckFlaggedFrequency | Frequency (in seconds) at which the bot level reset is performed for flagged bots that initially failed safety checks. | 15 | Positive Integer BotLevelBrackets.FlaggedProcessLimit | Maximum number of flagged bots to process per pending level change step. | 5 | Positive Integer BotLevelBrackets.Dynamic.UseDynamicDistribution | Enables dynamic bot distribution: when on, brackets with more real players get a higher share of bots in their level bracket, based on the weight below. | 0 | 0 (off) / 1 (on) -BotLevelBrackets.Dynamic.RealPlayerWeight | Controls how much bots "follow" real player activity when dynamic distribution is enabled. 0.0 = bots always spread evenly; 1.0 = minimal effect; 10.0 = heavy effect; higher values = more bots go where players are, but the effect is scaled. | 10.0 | ≥ 0.0 (float) +BotLevelBrackets.Dynamic.RealPlayerWeight | Controls how much bots "follow" real player activity when dynamic distribution is enabled. 0.0 = bots always spread evenly; 1.0 = minimal effect; 10.0 = heavy effect; higher values = more bots go where players are, but the effect is scaled. | 1.0 | ≥ 0.0 (float) BotLevelBrackets.Dynamic.SyncFactions | Enables synchronized brackets and weighting between Alliance and Horde factions when Dynamic Distribution is also enabled. | 0 | 0 (off) / 1 (on) BotLevelBrackets.IgnoreFriendListed | Ignores bots that are on real players' friend lists from any bracket calculations. | 1 | 0 (off) / 1 (on) BotLevelBrackets.IgnoreGuildBotsWithRealPlayers | Excludes bots in a guild with at least one real (non-bot) player from adjustments. Uses persistent database tracking for both online and offline real players. | 1 | 0 (disabled) / 1 (enabled) diff --git a/conf/mod_player_bot_level_brackets.conf.dist b/conf/mod_player_bot_level_brackets.conf.dist index d8ca1ea..35277a5 100644 --- a/conf/mod_player_bot_level_brackets.conf.dist +++ b/conf/mod_player_bot_level_brackets.conf.dist @@ -107,8 +107,8 @@ BotLevelBrackets.Dynamic.UseDynamicDistribution = 0 # Formula (per bracket): # bracket_weight = 1.0 + (RealPlayerWeight × (1 / TotalRealPlayers) × log(1 + RealPlayersInBracket)) # All bracket weights are normalized to total 100%. -# Default: 10.0 -BotLevelBrackets.Dynamic.RealPlayerWeight = 10.0 +# Default: 1.0 +BotLevelBrackets.Dynamic.RealPlayerWeight = 1.0 # # BotLevelBrackets.Dynamic.SyncFactions diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 48ca132..b1ac876 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -1806,18 +1806,51 @@ public: } }; +/** + * @class BotLevelBracketsCommandScript + * @brief Handles chat commands for the Player Bot Level Brackets module. + * + * This script provides administrative commands to manage the bot level brackets configuration. + */ +class BotLevelBracketsCommandScript : public CommandScript +{ +public: + BotLevelBracketsCommandScript() : CommandScript("BotLevelBracketsCommandScript") {} + + std::vector GetCommands() const override + { + static std::vector commandTable = + { + { "reload", SEC_ADMINISTRATOR, false, &HandleReloadConfig, "" } + }; + static std::vector commandTableMain = + { + { "botlevelbrackets", SEC_ADMINISTRATOR, true, nullptr, "", commandTable } + }; + return commandTableMain; + } + + static bool HandleReloadConfig(ChatHandler* handler, const char* args) + { + LoadBotLevelBracketsConfig(); + handler->SendSysMessage("Bot level brackets config reloaded."); + return true; + } +}; // ----------------------------------------------------------------------------- // ENTRY POINT: Register the Bot Level Distribution Module // ----------------------------------------------------------------------------- /** - * @brief Registers the world and player scripts for the Player Bot Level Brackets module. + * @brief Registers the world, player, and command scripts for the Player Bot Level Brackets module. * - * This function instantiates and adds the BotLevelBracketsWorldScript and BotLevelBracketsPlayerScript - * to the script system, enabling custom logic for player bot level brackets within the game world. + * This function instantiates and adds the BotLevelBracketsWorldScript, BotLevelBracketsPlayerScript, + * and BotLevelBracketsCommandScript to the script system, enabling custom logic and commands + * for player bot level brackets within the game world. */ void Addmod_player_bot_level_bracketsScripts() { new BotLevelBracketsWorldScript(); new BotLevelBracketsPlayerScript(); + new BotLevelBracketsCommandScript(); } From e8bf099b036b1d733175e61b6283dba2bed2308b Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:14:25 -0500 Subject: [PATCH 3/9] Urand fix --- src/mod-player-bot-level-brackets.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index b1ac876..1f93ef9 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -672,7 +672,19 @@ static void AdjustBotToRange(Player* bot, int targetRangeIndex, const LevelRange } else { - newLevel = GetRandomLevelInRange(factionRanges[targetRangeIndex]); + const LevelRangeConfig& range = factionRanges[targetRangeIndex]; + if (range.lower > range.upper) + { + if (g_BotDistFullDebugMode) + { + std::string playerFaction = IsAlliancePlayerBot(bot) ? "Alliance" : "Horde"; + LOG_INFO("server.loading", + "[BotLevelBrackets] AdjustBotToRange: Invalid range {}-{} for {} bot '{}'.", + range.lower, range.upper, playerFaction, bot->GetName()); + } + return; + } + newLevel = GetRandomLevelInRange(range); } PlayerbotFactory newFactory(bot, newLevel); From d2e3ad166ce95d88dccfb1daf875383bcf6cc189 Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:22:16 -0500 Subject: [PATCH 4/9] Urand fix --- src/mod-player-bot-level-brackets.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 1f93ef9..16e6b21 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -1829,13 +1829,13 @@ class BotLevelBracketsCommandScript : public CommandScript public: BotLevelBracketsCommandScript() : CommandScript("BotLevelBracketsCommandScript") {} - std::vector GetCommands() const override + ChatCommandTable GetCommands() const override { - static std::vector commandTable = + static ChatCommandTable commandTable = { { "reload", SEC_ADMINISTRATOR, false, &HandleReloadConfig, "" } }; - static std::vector commandTableMain = + static ChatCommandTable commandTableMain = { { "botlevelbrackets", SEC_ADMINISTRATOR, true, nullptr, "", commandTable } }; From db5499ee72546313dc95866faefc5c6c7312e25a Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:26:51 -0500 Subject: [PATCH 5/9] Urand fix --- src/mod-player-bot-level-brackets.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 16e6b21..23814b6 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -71,7 +71,7 @@ static float g_RealPlayerWeight = 1.0f; static bool g_SyncFactions = false; // Array for character social list friends -std::vector g_SocialFriendsList; +std::vector g_SocialFriendsList; // Array for excluded bot names. static std::vector g_ExcludeBotNames; @@ -338,7 +338,7 @@ static void LoadSocialFriendList() do { uint32 socialFriendGUID = result->Fetch()->Get(); - g_SocialFriendsList.push_back(socialFriendGUID); + g_SocialFriendsList.push_back(static_cast(socialFriendGUID)); if (g_BotDistFullDebugMode) { LOG_INFO("server.load", "[BotLevelBrackets] Adding GUID {} to Social Friend List", socialFriendGUID); @@ -1829,13 +1829,13 @@ class BotLevelBracketsCommandScript : public CommandScript public: BotLevelBracketsCommandScript() : CommandScript("BotLevelBracketsCommandScript") {} - ChatCommandTable GetCommands() const override + Acore::ChatCommands::ChatCommandTable GetCommands() const override { - static ChatCommandTable commandTable = + static Acore::ChatCommands::ChatCommandTable commandTable = { { "reload", SEC_ADMINISTRATOR, false, &HandleReloadConfig, "" } }; - static ChatCommandTable commandTableMain = + static Acore::ChatCommands::ChatCommandTable commandTableMain = { { "botlevelbrackets", SEC_ADMINISTRATOR, true, nullptr, "", commandTable } }; From 4205db2b0f27a7f004cfbefc82997b4fdc494f24 Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:29:40 -0500 Subject: [PATCH 6/9] Urand fix --- src/mod-player-bot-level-brackets.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 23814b6..7030e84 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -2,6 +2,7 @@ #include "Player.h" #include "ObjectMgr.h" #include "Chat.h" +#include "CommandScript.h" #include "Log.h" #include "PlayerbotAI.h" #include "PlayerbotMgr.h" @@ -1829,13 +1830,13 @@ class BotLevelBracketsCommandScript : public CommandScript public: BotLevelBracketsCommandScript() : CommandScript("BotLevelBracketsCommandScript") {} - Acore::ChatCommands::ChatCommandTable GetCommands() const override + ChatCommandTable GetCommands() const override { - static Acore::ChatCommands::ChatCommandTable commandTable = + static ChatCommandTable commandTable = { { "reload", SEC_ADMINISTRATOR, false, &HandleReloadConfig, "" } }; - static Acore::ChatCommands::ChatCommandTable commandTableMain = + static ChatCommandTable commandTableMain = { { "botlevelbrackets", SEC_ADMINISTRATOR, true, nullptr, "", commandTable } }; From ba34ee7908166d7e1275e70b403aa9dce1d1bfb3 Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:36:06 -0500 Subject: [PATCH 7/9] Urand fix --- src/mod-player-bot-level-brackets.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 7030e84..4925f31 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -21,6 +21,10 @@ #include #include "Player.h" +using namespace Acore::ChatCommands; + +using ChatCommandTable = std::vector; + // Forward declarations. class Guild; static bool IsAlliancePlayerBot(Player* bot); From 82d83f64a493a27aa43af4a9d513e31e93405c9a Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:42:22 -0500 Subject: [PATCH 8/9] Urand fix --- src/mod-player-bot-level-brackets.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 4925f31..7174bf2 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -23,8 +23,6 @@ using namespace Acore::ChatCommands; -using ChatCommandTable = std::vector; - // Forward declarations. class Guild; static bool IsAlliancePlayerBot(Player* bot); @@ -1838,16 +1836,12 @@ public: { static ChatCommandTable commandTable = { - { "reload", SEC_ADMINISTRATOR, false, &HandleReloadConfig, "" } + { "reload", HandleReloadConfig, SEC_ADMINISTRATOR, Console::No } }; - static ChatCommandTable commandTableMain = - { - { "botlevelbrackets", SEC_ADMINISTRATOR, true, nullptr, "", commandTable } - }; - return commandTableMain; + return commandTable; } - static bool HandleReloadConfig(ChatHandler* handler, const char* args) + static bool HandleReloadConfig(ChatHandler* handler) { LoadBotLevelBracketsConfig(); handler->SendSysMessage("Bot level brackets config reloaded."); From 0d78babe57411550b8d99b4f7482017df42cb9de Mon Sep 17 00:00:00 2001 From: Dustin Hendrickson Date: Sat, 18 Oct 2025 14:45:13 -0500 Subject: [PATCH 9/9] Cleanup --- src/mod-player-bot-level-brackets.cpp | 33 --------------------------- 1 file changed, 33 deletions(-) diff --git a/src/mod-player-bot-level-brackets.cpp b/src/mod-player-bot-level-brackets.cpp index 7174bf2..9733e62 100644 --- a/src/mod-player-bot-level-brackets.cpp +++ b/src/mod-player-bot-level-brackets.cpp @@ -254,39 +254,6 @@ static bool IsHordePlayerBot(Player* bot) } -/** - * @brief Logs the number of player bots at each level if full debug mode is enabled. - * - * This function iterates through all players in the world, counts the number of bots at each level, - * and logs the results. Only bots that are currently in the world are considered. The logging occurs - * only if the global debug mode flag `g_BotDistFullDebugMode` is set to true. - */ -static void LogAllBotLevels() -{ - if (g_BotDistFullDebugMode) - { - std::map botLevelCount; - for (auto const& itr : ObjectAccessor::GetPlayers()) - { - Player* player = itr.second; - if (!player || !player->IsInWorld()) - { - continue; - } - if (!IsPlayerBot(player)) - { - continue; - } - botLevelCount[player->GetLevel()]++; - } - for (const auto& entry : botLevelCount) - { - LOG_INFO("server.loading", "[BotLevelBrackets] Level {}: {} bots", entry.first, entry.second); - } - } -} - - /** * @brief Removes a bot from the list of pending level resets. *