Added Option to Enable/Disable Mod

This commit is contained in:
jimm0thy
2025-02-24 18:07:59 -05:00
parent 5a6c54eab4
commit 69e346e357
2 changed files with 576 additions and 559 deletions

View File

@@ -3,6 +3,12 @@
############################################## ##############################################
# mod-player-bot-level-brackets configuration # mod-player-bot-level-brackets configuration
############################################## ##############################################
# BotLevelBrackets.ModEnabled
# Description: Turns module on/on
# Default: 1 (enabled)
# Valid Values: 0 (off) / 1 (on)
BotLevelBrackets.ModEnabled = 1
# #
# BotLevelBrackets.DebugMode # BotLevelBrackets.DebugMode
# Description: Enables debug logging for the Bot Level Brackets module. # Description: Enables debug logging for the Bot Level Brackets module.

View File

@@ -51,6 +51,7 @@ static uint32 g_BotDistFlaggedCheckFrequency = 15; // in seconds
static bool g_BotDistDebugMode = false; static bool g_BotDistDebugMode = false;
static bool g_UseDynamicDistribution = false; static bool g_UseDynamicDistribution = false;
static bool g_IgnoreFriendListed = true; static bool g_IgnoreFriendListed = true;
static bool g_EnableMod = true;
// Real player weight to boost bracket contributions. // Real player weight to boost bracket contributions.
static float g_RealPlayerWeight = 1.0f; static float g_RealPlayerWeight = 1.0f;
@@ -64,6 +65,7 @@ static void LoadBotLevelBracketsConfig()
g_UseDynamicDistribution = sConfigMgr->GetOption<bool>("BotLevelBrackets.UseDynamicDistribution", false); g_UseDynamicDistribution = sConfigMgr->GetOption<bool>("BotLevelBrackets.UseDynamicDistribution", false);
g_RealPlayerWeight = sConfigMgr->GetOption<float>("BotLevelBrackets.RealPlayerWeight", 1.0f); g_RealPlayerWeight = sConfigMgr->GetOption<float>("BotLevelBrackets.RealPlayerWeight", 1.0f);
g_IgnoreFriendListed = sConfigMgr->GetOption<bool>("BotLevelBrackets.IgnoreFriendListed", true); g_IgnoreFriendListed = sConfigMgr->GetOption<bool>("BotLevelBrackets.IgnoreFriendListed", true);
g_EnableMod = sConfigMgr->GetOption<bool>("BotLevelBrackets.ModEnabled", true);
// Load the bot level restrictions. // Load the bot level restrictions.
g_RandomBotMinLevel = static_cast<uint8>(sConfigMgr->GetOption<uint32>("AiPlayerbot.RandomBotMinLevel", 1)); g_RandomBotMinLevel = static_cast<uint8>(sConfigMgr->GetOption<uint32>("AiPlayerbot.RandomBotMinLevel", 1));
@@ -98,11 +100,13 @@ static void LoadBotLevelBracketsConfig()
// If the bot is out of range, it returns -1 // If the bot is out of range, it returns -1
static int GetLevelRangeIndex(uint8 level, uint8 teamID) static int GetLevelRangeIndex(uint8 level, uint8 teamID)
{ {
if (g_EnableMod)
{
// If the bot's level is outside the allowed global bounds, signal an invalid bracket. // If the bot's level is outside the allowed global bounds, signal an invalid bracket.
if (level < g_RandomBotMinLevel || level > g_RandomBotMaxLevel) if (level < g_RandomBotMinLevel || level > g_RandomBotMaxLevel)
return -1; return -1;
if(teamID == TEAM_ALLIANCE) if (teamID == TEAM_ALLIANCE)
{ {
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
@@ -111,7 +115,7 @@ static int GetLevelRangeIndex(uint8 level, uint8 teamID)
} }
} }
if(teamID == TEAM_HORDE) if (teamID == TEAM_HORDE)
{ {
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
@@ -121,6 +125,7 @@ static int GetLevelRangeIndex(uint8 level, uint8 teamID)
} }
return -1; return -1;
}
} }
// Returns a random level within the provided range. // Returns a random level within the provided range.
@@ -238,6 +243,8 @@ static void LogAllBotLevels()
static void ClampAndBalanceBrackets() static void ClampAndBalanceBrackets()
{ {
if (g_EnableMod)
{
// First, adjust Alliance brackets. // First, adjust Alliance brackets.
for (uint8 i = 0; i < NUM_RANGES; ++i) for (uint8 i = 0; i < NUM_RANGES; ++i)
{ {
@@ -268,17 +275,17 @@ static void ClampAndBalanceBrackets()
totalHorde += g_HordeLevelRanges[i].desiredPercent; totalHorde += g_HordeLevelRanges[i].desiredPercent;
} }
// If totals are not 100, then distribute the missing percent among valid brackets. // If totals are not 100, then distribute the missing percent among valid brackets.
if(totalAlliance != 100 && totalAlliance > 0) if (totalAlliance != 100 && totalAlliance > 0)
{ {
LOG_INFO("server.loading", "[BotLevelBrackets] Alliance: Sum of percentages is {} (expected 100). Auto adjusting.", totalAlliance); LOG_INFO("server.loading", "[BotLevelBrackets] Alliance: Sum of percentages is {} (expected 100). Auto adjusting.", totalAlliance);
int missing = 100 - totalAlliance; int missing = 100 - totalAlliance;
while(missing > 0) while (missing > 0)
{ {
for (uint8 i = 0; i < NUM_RANGES && missing > 0; ++i) for (uint8 i = 0; i < NUM_RANGES && missing > 0; ++i)
{ {
if(g_AllianceLevelRanges[i].lower <= g_AllianceLevelRanges[i].upper && if (g_AllianceLevelRanges[i].lower <= g_AllianceLevelRanges[i].upper &&
g_AllianceLevelRanges[i].desiredPercent > 0) g_AllianceLevelRanges[i].desiredPercent > 0)
{ {
g_AllianceLevelRanges[i].desiredPercent++; g_AllianceLevelRanges[i].desiredPercent++;
@@ -287,17 +294,17 @@ static void ClampAndBalanceBrackets()
} }
} }
} }
if(totalHorde != 100 && totalHorde > 0) if (totalHorde != 100 && totalHorde > 0)
{ {
LOG_INFO("server.loading", "[BotLevelBrackets] Horde: Sum of percentages is {} (expected 100). Auto adjusting.", totalHorde); LOG_INFO("server.loading", "[BotLevelBrackets] Horde: Sum of percentages is {} (expected 100). Auto adjusting.", totalHorde);
int missing = 100 - totalHorde; int missing = 100 - totalHorde;
while(missing > 0) while (missing > 0)
{ {
for (uint8 i = 0; i < NUM_RANGES && missing > 0; ++i) for (uint8 i = 0; i < NUM_RANGES && missing > 0; ++i)
{ {
if(g_HordeLevelRanges[i].lower <= g_HordeLevelRanges[i].upper && if (g_HordeLevelRanges[i].lower <= g_HordeLevelRanges[i].upper &&
g_HordeLevelRanges[i].desiredPercent > 0) g_HordeLevelRanges[i].desiredPercent > 0)
{ {
g_HordeLevelRanges[i].desiredPercent++; g_HordeLevelRanges[i].desiredPercent++;
@@ -306,6 +313,7 @@ static void ClampAndBalanceBrackets()
} }
} }
} }
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@@ -395,7 +403,7 @@ static void ProcessPendingLevelResets()
Player* bot = it->bot; Player* bot = it->bot;
int targetRange = it->targetRange; int targetRange = it->targetRange;
if (bot && bot->IsInWorld() && IsBotSafeForLevelReset(bot)) if (bot && bot->IsInWorld() && IsBotSafeForLevelReset(bot) && g_EnableMod)
{ {
AdjustBotToRange(bot, targetRange, it->factionRanges); AdjustBotToRange(bot, targetRange, it->factionRanges);
LOG_INFO("server.loading", "[BotLevelBrackets] Bot '{}' successfully reset to level range {}-{}.", LOG_INFO("server.loading", "[BotLevelBrackets] Bot '{}' successfully reset to level range {}-{}.",
@@ -496,6 +504,8 @@ public:
} }
void OnUpdate(uint32 diff) override void OnUpdate(uint32 diff) override
{
if (g_EnableMod)
{ {
m_timer += diff; m_timer += diff;
m_flaggedTimer += diff; m_flaggedTimer += diff;
@@ -516,8 +526,8 @@ public:
// Dynamic distribution: recalc desired percentages based on non-bot players. // Dynamic distribution: recalc desired percentages based on non-bot players.
if (g_UseDynamicDistribution) if (g_UseDynamicDistribution)
{ {
int allianceRealCounts[NUM_RANGES] = {0}; int allianceRealCounts[NUM_RANGES] = { 0 };
int hordeRealCounts[NUM_RANGES] = {0}; int hordeRealCounts[NUM_RANGES] = { 0 };
uint32 totalAllianceReal = 0; uint32 totalAllianceReal = 0;
uint32 totalHordeReal = 0; uint32 totalHordeReal = 0;
// Iterate over all players and count non-bot players. // Iterate over all players and count non-bot players.
@@ -546,8 +556,8 @@ public:
const float baseline = 1.0f; const float baseline = 1.0f;
float allianceTotalWeight = 0.0f; float allianceTotalWeight = 0.0f;
float hordeTotalWeight = 0.0f; float hordeTotalWeight = 0.0f;
float allianceWeights[NUM_RANGES] = {0}; float allianceWeights[NUM_RANGES] = { 0 };
float hordeWeights[NUM_RANGES] = {0}; float hordeWeights[NUM_RANGES] = { 0 };
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
// Only count valid brackets. // Only count valid brackets.
@@ -664,12 +674,12 @@ public:
// Containers for Alliance bots. // Containers for Alliance bots.
uint32 totalAllianceBots = 0; uint32 totalAllianceBots = 0;
int allianceActualCounts[NUM_RANGES] = {0}; int allianceActualCounts[NUM_RANGES] = { 0 };
std::vector<Player*> allianceBotsByRange[NUM_RANGES]; std::vector<Player*> allianceBotsByRange[NUM_RANGES];
// Containers for Horde bots. // Containers for Horde bots.
uint32 totalHordeBots = 0; uint32 totalHordeBots = 0;
int hordeActualCounts[NUM_RANGES] = {0}; int hordeActualCounts[NUM_RANGES] = { 0 };
std::vector<Player*> hordeBotsByRange[NUM_RANGES]; std::vector<Player*> hordeBotsByRange[NUM_RANGES];
// Iterate only over player bots. // Iterate only over player bots.
@@ -749,7 +759,7 @@ public:
if (totalAllianceBots > 0) if (totalAllianceBots > 0)
{ {
LOG_INFO("server.loading", "[BotLevelBrackets] ========================================="); LOG_INFO("server.loading", "[BotLevelBrackets] =========================================");
int allianceDesiredCounts[NUM_RANGES] = {0}; int allianceDesiredCounts[NUM_RANGES] = { 0 };
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
allianceDesiredCounts[i] = static_cast<int>(round((g_AllianceLevelRanges[i].desiredPercent / 100.0) * totalAllianceBots)); allianceDesiredCounts[i] = static_cast<int>(round((g_AllianceLevelRanges[i].desiredPercent / 100.0) * totalAllianceBots));
@@ -872,7 +882,7 @@ public:
} }
if (!alreadyFlagged) if (!alreadyFlagged)
{ {
g_PendingLevelResets.push_back({bot, targetRange, g_AllianceLevelRanges}); g_PendingLevelResets.push_back({ bot, targetRange, g_AllianceLevelRanges });
LOG_INFO("server.loading", "[BotLevelBrackets] Alliance bot '{}' flagged for pending level reset to range {}-{}.", LOG_INFO("server.loading", "[BotLevelBrackets] Alliance bot '{}' flagged for pending level reset to range {}-{}.",
bot->GetName(), g_AllianceLevelRanges[targetRange].lower, g_AllianceLevelRanges[targetRange].upper); bot->GetName(), g_AllianceLevelRanges[targetRange].lower, g_AllianceLevelRanges[targetRange].upper);
} }
@@ -884,7 +894,7 @@ public:
if (totalHordeBots > 0) if (totalHordeBots > 0)
{ {
LOG_INFO("server.loading", "[BotLevelBrackets] ========================================="); LOG_INFO("server.loading", "[BotLevelBrackets] =========================================");
int hordeDesiredCounts[NUM_RANGES] = {0}; int hordeDesiredCounts[NUM_RANGES] = { 0 };
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
hordeDesiredCounts[i] = static_cast<int>(round((g_HordeLevelRanges[i].desiredPercent / 100.0) * totalHordeBots)); hordeDesiredCounts[i] = static_cast<int>(round((g_HordeLevelRanges[i].desiredPercent / 100.0) * totalHordeBots));
@@ -1006,7 +1016,7 @@ public:
} }
if (!alreadyFlagged) if (!alreadyFlagged)
{ {
g_PendingLevelResets.push_back({bot, targetRange, g_HordeLevelRanges}); g_PendingLevelResets.push_back({ bot, targetRange, g_HordeLevelRanges });
LOG_INFO("server.loading", "[BotLevelBrackets] Horde bot '{}' flagged for pending level reset to range {}-{}.", LOG_INFO("server.loading", "[BotLevelBrackets] Horde bot '{}' flagged for pending level reset to range {}-{}.",
bot->GetName(), g_HordeLevelRanges[targetRange].lower, g_HordeLevelRanges[targetRange].upper); bot->GetName(), g_HordeLevelRanges[targetRange].lower, g_HordeLevelRanges[targetRange].upper);
} }
@@ -1023,7 +1033,7 @@ public:
LOG_INFO("server.loading", "[BotLevelBrackets] ========================================="); LOG_INFO("server.loading", "[BotLevelBrackets] =========================================");
LogAllBotLevels(); LogAllBotLevels();
LOG_INFO("server.loading", "[BotLevelBrackets] ========================================="); LOG_INFO("server.loading", "[BotLevelBrackets] =========================================");
int allianceDesiredCounts[NUM_RANGES] = {0}; int allianceDesiredCounts[NUM_RANGES] = { 0 };
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
allianceDesiredCounts[i] = static_cast<int>(round((g_AllianceLevelRanges[i].desiredPercent / 100.0) * totalAllianceBots)); allianceDesiredCounts[i] = static_cast<int>(round((g_AllianceLevelRanges[i].desiredPercent / 100.0) * totalAllianceBots));
@@ -1032,7 +1042,7 @@ public:
allianceDesiredCounts[i], allianceActualCounts[i]); allianceDesiredCounts[i], allianceActualCounts[i]);
} }
LOG_INFO("server.loading", "[BotLevelBrackets] ----------------------------------------"); LOG_INFO("server.loading", "[BotLevelBrackets] ----------------------------------------");
int hordeDesiredCounts[NUM_RANGES] = {0}; int hordeDesiredCounts[NUM_RANGES] = { 0 };
for (int i = 0; i < NUM_RANGES; ++i) for (int i = 0; i < NUM_RANGES; ++i)
{ {
hordeDesiredCounts[i] = static_cast<int>(round((g_HordeLevelRanges[i].desiredPercent / 100.0) * totalHordeBots)); hordeDesiredCounts[i] = static_cast<int>(round((g_HordeLevelRanges[i].desiredPercent / 100.0) * totalHordeBots));
@@ -1044,6 +1054,7 @@ public:
} }
} }
}
private: private:
uint32 m_timer; // For distribution adjustments uint32 m_timer; // For distribution adjustments