24 Commits

Author SHA1 Message Date
Dustin Hendrickson
3f64862503 Merge pull request #76 from DustinHendrickson/Dustin/BugFixes
Adding in world check
2025-12-11 10:06:45 -06:00
Dustin Hendrickson
6a33cb3257 Adding in world check 2025-12-11 10:06:18 -06:00
Dustin Hendrickson
a926792857 Merge pull request #75 from DustinHendrickson/Dustin/BugFixes
Dustin/bug fixes
2025-12-11 09:57:24 -06:00
Dustin Hendrickson
1faa24cf15 Adding in world check 2025-12-11 09:34:18 -06:00
Dustin Hendrickson
11dc0941fd Adding group check 2025-12-11 09:29:02 -06:00
Dustin Hendrickson
6152f9e77e Merge pull request #73 from DustinHendrickson/Dustin/BugFixes
Fixing a DK edgecase
2025-12-04 16:07:23 -06:00
Dustin Hendrickson
a33f0ca354 Fixing a DK edgecase 2025-12-04 16:05:06 -06:00
Dustin Hendrickson
10c47670cf Merge pull request #71 from DustinHendrickson/Dustin/BugFixes
Dustin/bug fixes
2025-11-16 10:37:03 -06:00
Dustin Hendrickson
d3ab2c899f Adding Arena Team exclusion, on by default 2025-11-16 10:32:58 -06:00
Dustin Hendrickson
d45213c360 Fixing persistance esge case issue 2025-11-16 10:22:20 -06:00
Dustin Hendrickson
93989a902f Merge pull request #66 from DustinHendrickson/Dustin/FixesAndReload
Dustin/fixes and reload
2025-10-18 14:48:12 -05:00
Dustin Hendrickson
0d78babe57 Cleanup 2025-10-18 14:45:13 -05:00
Dustin Hendrickson
82d83f64a4 Urand fix 2025-10-18 14:42:22 -05:00
Dustin Hendrickson
ba34ee7908 Urand fix 2025-10-18 14:36:06 -05:00
Dustin Hendrickson
4205db2b0f Urand fix 2025-10-18 14:29:40 -05:00
Dustin Hendrickson
db5499ee72 Urand fix 2025-10-18 14:26:51 -05:00
Dustin Hendrickson
d2e3ad166c Urand fix 2025-10-18 14:22:16 -05:00
Dustin Hendrickson
e8bf099b03 Urand fix 2025-10-18 14:14:25 -05:00
Dustin Hendrickson
74fb4876f5 Adding reload command 2025-10-18 14:09:37 -05:00
Dustin Hendrickson
8669a4dbcb Adding some fixes 2025-10-18 14:08:01 -05:00
Dustin Hendrickson
a5eb4c6855 Merge pull request #63 from DustinHendrickson/revert-62-feat/ignore_arena_team
Revert "feat: ignore arena team for downgrade"

Players reporting this broke processing. Noticed some weird stuff when I re-reviewed it. Reverting.
2025-10-11 22:22:20 -05:00
Dustin Hendrickson
af1ee91c17 Revert "feat: ignore arena team for downgrade" 2025-10-11 22:21:15 -05:00
Dustin Hendrickson
827ae6ac12 Merge pull request #62 from jl178/feat/ignore_arena_team
feat: ignore arena team for downgrade
2025-10-03 09:13:51 -05:00
Jered Little
402556fc36 feat: ignore arena team for downgrade 2025-10-02 09:23:31 -06:00
3 changed files with 176 additions and 44 deletions

View File

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

View File

@@ -51,6 +51,15 @@ BotLevelBrackets.FlaggedProcessLimit = 5
# Valid values: 0 (disabled) / 1 (enabled)
BotLevelBrackets.IgnoreGuildBotsWithRealPlayers = 1
#
# BotLevelBrackets.IgnoreArenaTeamBots
# Description: When enabled, bots that are members of arena teams are excluded from bot bracket calculations
# and will not be level changed or flagged. This prevents bots in arena teams from being
# changed, which would break team compositions.
# Default: 1 (enabled)
# Valid values: 0 (disabled) / 1 (enabled)
BotLevelBrackets.IgnoreArenaTeamBots = 1
#
# BotLevelBrackets.GuildTrackerUpdateFrequency
# Description: The frequency (in seconds) at which the persistent guild tracker database is updated.
@@ -85,7 +94,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 +104,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:

View File

@@ -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"
@@ -19,6 +20,10 @@
#include "QueryResult.h"
#include <string>
#include "Player.h"
#include "PlayerbotAIConfig.h"
#include "ArenaTeamMgr.h"
using namespace Acore::ChatCommands;
// Forward declarations.
class Guild;
@@ -48,6 +53,8 @@ static uint8 g_RandomBotMaxLevel = 80;
static bool g_BotLevelBracketsEnabled = true;
// Ignore bots in guilds with a real player online. Default is true.
static bool g_IgnoreGuildBotsWithRealPlayers = true;
// Ignore bots in arena teams. Default is true.
static bool g_IgnoreArenaTeamBots = true;
// Use vectors to store the level ranges.
static std::vector<LevelRangeConfig> g_AllianceLevelRanges;
@@ -71,7 +78,7 @@ static float g_RealPlayerWeight = 1.0f;
static bool g_SyncFactions = false;
// Array for character social list friends
std::vector<int> g_SocialFriendsList;
std::vector<uint64> g_SocialFriendsList;
// Array for excluded bot names.
static std::vector<std::string> g_ExcludeBotNames;
@@ -108,6 +115,7 @@ static void LoadBotLevelBracketsConfig()
{
g_BotLevelBracketsEnabled = sConfigMgr->GetOption<bool>("BotLevelBrackets.Enabled", true);
g_IgnoreGuildBotsWithRealPlayers = sConfigMgr->GetOption<bool>("BotLevelBrackets.IgnoreGuildBotsWithRealPlayers", true);
g_IgnoreArenaTeamBots = sConfigMgr->GetOption<bool>("BotLevelBrackets.IgnoreArenaTeamBots", true);
g_BotDistFullDebugMode = sConfigMgr->GetOption<bool>("BotLevelBrackets.FullDebugMode", false);
g_BotDistLiteDebugMode = sConfigMgr->GetOption<bool>("BotLevelBrackets.LiteDebugMode", false);
@@ -251,39 +259,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<uint8, uint32> 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.
*
@@ -338,7 +313,7 @@ static void LoadSocialFriendList()
do
{
uint32 socialFriendGUID = result->Fetch()->Get<uint32>();
g_SocialFriendsList.push_back(socialFriendGUID);
g_SocialFriendsList.push_back(static_cast<uint64>(socialFriendGUID));
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.load", "[BotLevelBrackets] Adding GUID {} to Social Friend List", socialFriendGUID);
@@ -664,16 +639,40 @@ static void AdjustBotToRange(Player* bot, int targetRangeIndex, const LevelRange
{
lowerBound = 55;
}
if (lowerBound > upperBound)
{
return;
}
newLevel = urand(lowerBound, upperBound);
}
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);
newFactory.Randomize(false);
// Force reset talents if equipment persistence is enabled and bot rolled to max level
// This is to fix an issue with Playerbots and how Randomization works with Equipment Persistence
if (newLevel == g_RandomBotMaxLevel && sPlayerbotAIConfig->equipmentPersistence)
{
PlayerbotFactory tempFactory(bot, newLevel);
tempFactory.InitTalentsTree(false, true, true);
}
if (g_BotDistFullDebugMode)
{
PlayerbotAI* botAI = sPlayerbotsMgr->GetPlayerbotAI(bot);
@@ -749,6 +748,30 @@ static bool BotInFriendList(Player* bot)
}
/**
* @brief Checks if the given bot is a member of any arena team.
*
* This function verifies that the provided Player pointer is valid and
* checks all arena team slots to see if the bot is in any arena team.
*
* @param bot Pointer to the Player object representing the bot.
* @return true if the bot is in an arena team, false otherwise.
*/
static bool BotInArenaTeam(Player* bot)
{
if (!bot)
return false;
for (uint32 slot = 0; slot < MAX_ARENA_SLOT; ++slot)
{
if (ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(bot->GetArenaTeamId(slot)))
{
return true;
}
}
return false;
}
/**
* @brief Clamps and balances the level brackets for Alliance and Horde bot distributions.
*
@@ -919,7 +942,7 @@ static bool IsBotSafeForLevelReset(Player* bot)
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && !IsPlayerBot(member))
if (member && member->IsInWorld() && !IsPlayerBot(member))
{
if (g_BotDistFullDebugMode)
{
@@ -1028,6 +1051,32 @@ static void ProcessPendingLevelResets()
continue;
}
if (g_IgnoreArenaTeamBots && BotInArenaTeam(bot))
{
it = g_PendingLevelResets.erase(it);
continue;
}
// Check if bot is now in a group with real players
if (Group* group = bot->GetGroup())
{
bool hasRealPlayer = false;
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && member->IsInWorld() && !IsPlayerBot(member))
{
hasRealPlayer = true;
break;
}
}
if (hasRealPlayer)
{
it = g_PendingLevelResets.erase(it);
continue;
}
}
if (bot && bot->IsInWorld() && IsBotSafeForLevelReset(bot))
{
AdjustBotToRange(bot, targetRange, it->factionRanges);
@@ -1063,6 +1112,37 @@ static int GetOrFlagPlayerBracket(Player* player)
return -1;
}
if (IsPlayerBot(player) && g_IgnoreGuildBotsWithRealPlayers && BotInGuildWithRealPlayer(player))
{
return -1;
}
if (IsPlayerBot(player) && g_IgnoreArenaTeamBots && BotInArenaTeam(player))
{
return -1;
}
// Check if bot is in a group with real players - if so, exclude from bracket processing
if (IsPlayerBot(player))
{
if (Group* group = player->GetGroup())
{
for (GroupReference* ref = group->GetFirstMember(); ref; ref = ref->next())
{
Player* member = ref->GetSource();
if (member && member->IsInWorld() && !IsPlayerBot(member))
{
if (g_BotDistFullDebugMode)
{
LOG_INFO("server.loading", "[BotLevelBrackets] GetOrFlagPlayerBracket: Bot {} (Level {}) is in group with real player {} - excluding from bracket processing.",
player->GetName(), player->GetLevel(), member->GetName());
}
return -1;
}
}
}
}
int rangeIndex = GetLevelRangeIndex(player->GetLevel(), player->GetTeamId());
if (rangeIndex >= 0)
{
@@ -1091,6 +1171,13 @@ static int GetOrFlagPlayerBracket(Player* player)
{
continue;
}
// Skip brackets that Death Knights cannot be assigned to (upper bound < 55)
if (player->getClass() == CLASS_DEATH_KNIGHT && factionRanges[i].upper < 55)
{
continue;
}
int diff = 0;
if (player->GetLevel() < factionRanges[i].lower)
{
@@ -1361,6 +1448,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)
{
@@ -1432,6 +1522,10 @@ public:
{
continue;
}
if (g_IgnoreArenaTeamBots && BotInArenaTeam(player))
{
continue;
}
if (IsAlliancePlayerBot(player))
{
totalAllianceBots++;
@@ -1799,18 +1893,47 @@ 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") {}
ChatCommandTable GetCommands() const override
{
static ChatCommandTable commandTable =
{
{ "reload", HandleReloadConfig, SEC_ADMINISTRATOR, Console::No }
};
return commandTable;
}
static bool HandleReloadConfig(ChatHandler* handler)
{
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();
}