mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Feature: Have bots auto join/start all supported BG's (if enabled) (#877)
* Update RandomPlayerbotMgr.cpp * Update playerbots.conf.dist * Update PlayerbotAIConfig.h * Update PlayerbotAIConfig.cpp * Update playerbots.conf.dist * Update playerbots.conf.dist * Updated information * Update RandomPlayerbotMgr.cpp Avoid reverting https://github.com/liyunfan1223/mod-playerbots/pull/870/files * Update playerbots.conf.dist set capitals on Random * Final update on settings documentation * Update playerbots.conf.dist * Fix bots loving to do BG's a bit too much * Final fix bots over-queuing * pt2 - Limit over-queuing to ~1 instance Try and prevent over-queuing to a max of 1 instance. * Add new queue instead of instance if necessary * Update RandomPlayerbotMgr.cpp * Final commit * Update RandomPlayerbotMgr.cpp * Fix timer * Updated docu * Update playerbots.conf.dist * Update RandomPlayerbotMgr.cpp Set BgCheckTimer to 45 as it is sufficient.
This commit is contained in:
@@ -278,9 +278,21 @@ bool PlayerbotAIConfig::Initialize()
|
||||
|
||||
randomBotJoinBG = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotJoinBG", true);
|
||||
randomBotAutoJoinBG = sConfigMgr->GetOption<bool>("AiPlayerbot.RandomBotAutoJoinBG", false);
|
||||
randomBotAutoJoinWarsongBracket = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinWarsongBracket", 14);
|
||||
|
||||
randomBotAutoJoinArenaBracket = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinArenaBracket", 7);
|
||||
randomBotAutoJoinBGWarsongCount = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGWarsongCount", 0);
|
||||
|
||||
randomBotAutoJoinICBrackets = sConfigMgr->GetOption<std::string>("AiPlayerbot.RandomBotAutoJoinICBrackets", "0,1");
|
||||
randomBotAutoJoinEYBrackets = sConfigMgr->GetOption<std::string>("AiPlayerbot.RandomBotAutoJoinEYBrackets", "0,1,2");
|
||||
randomBotAutoJoinAVBrackets = sConfigMgr->GetOption<std::string>("AiPlayerbot.RandomBotAutoJoinAVBrackets", "0,1,2,3");
|
||||
randomBotAutoJoinABBrackets = sConfigMgr->GetOption<std::string>("AiPlayerbot.RandomBotAutoJoinABBrackets", "0,1,2,3,4,5,6");
|
||||
randomBotAutoJoinWSBrackets = sConfigMgr->GetOption<std::string>("AiPlayerbot.RandomBotAutoJoinWSBrackets", "0,1,2,3,4,5,6,7");
|
||||
|
||||
randomBotAutoJoinBGICCount = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGICCount", 0);
|
||||
randomBotAutoJoinBGEYCount = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGEYCount", 0);
|
||||
randomBotAutoJoinBGAVCount = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGAVCount", 0);
|
||||
randomBotAutoJoinBGABCount = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGABCount", 0);
|
||||
randomBotAutoJoinBGWSCount = sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGWSCount", 0);
|
||||
|
||||
randomBotAutoJoinBGRatedArena2v2Count =
|
||||
sConfigMgr->GetOption<int32>("AiPlayerbot.RandomBotAutoJoinBGRatedArena2v2Count", 0);
|
||||
randomBotAutoJoinBGRatedArena3v3Count =
|
||||
|
||||
@@ -173,12 +173,25 @@ public:
|
||||
|
||||
bool randomBotJoinBG;
|
||||
bool randomBotAutoJoinBG;
|
||||
uint32 randomBotAutoJoinWarsongBracket;
|
||||
|
||||
std::string randomBotAutoJoinICBrackets;
|
||||
std::string randomBotAutoJoinEYBrackets;
|
||||
std::string randomBotAutoJoinAVBrackets;
|
||||
std::string randomBotAutoJoinABBrackets;
|
||||
std::string randomBotAutoJoinWSBrackets;
|
||||
|
||||
uint32 randomBotAutoJoinBGICCount;
|
||||
uint32 randomBotAutoJoinBGEYCount;
|
||||
uint32 randomBotAutoJoinBGAVCount;
|
||||
uint32 randomBotAutoJoinBGABCount;
|
||||
uint32 randomBotAutoJoinBGWSCount;
|
||||
|
||||
uint32 randomBotAutoJoinArenaBracket;
|
||||
uint32 randomBotAutoJoinBGWarsongCount;
|
||||
|
||||
uint32 randomBotAutoJoinBGRatedArena2v2Count;
|
||||
uint32 randomBotAutoJoinBGRatedArena3v3Count;
|
||||
uint32 randomBotAutoJoinBGRatedArena5v5Count;
|
||||
|
||||
bool randomBotLoginAtStartup;
|
||||
uint32 randomBotTeleLowerLevel, randomBotTeleHigherLevel;
|
||||
bool logInGroupOnly, logValuesPerTick;
|
||||
|
||||
@@ -360,7 +360,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
|
||||
|
||||
if (sPlayerbotAIConfig->randomBotJoinBG /* && !players.empty()*/)
|
||||
{
|
||||
if (time(nullptr) > (BgCheckTimer + 30))
|
||||
if (time(nullptr) > (BgCheckTimer + 45))
|
||||
sRandomPlayerbotMgr->CheckBgQueue();
|
||||
}
|
||||
|
||||
@@ -622,20 +622,39 @@ void RandomPlayerbotMgr::LoadBattleMastersCache()
|
||||
LOG_INFO("playerbots", ">> Loaded {} battlemaster entries", count);
|
||||
}
|
||||
|
||||
std::vector<uint32> parseBrackets(const std::string& str)
|
||||
{
|
||||
std::vector<uint32> brackets;
|
||||
std::stringstream ss(str);
|
||||
std::string item;
|
||||
|
||||
while (std::getline(ss, item, ','))
|
||||
{
|
||||
brackets.push_back(static_cast<uint32>(std::stoi(item)));
|
||||
}
|
||||
|
||||
return brackets;
|
||||
}
|
||||
|
||||
void RandomPlayerbotMgr::CheckBgQueue()
|
||||
{
|
||||
if (!BgCheckTimer)
|
||||
if (!BgCheckTimer) {
|
||||
BgCheckTimer = time(nullptr);
|
||||
return; // Exit immediately after initializing the timer
|
||||
}
|
||||
|
||||
if (time(nullptr) < BgCheckTimer + 30)
|
||||
return;
|
||||
if (time(nullptr) < BgCheckTimer) {
|
||||
return; // No need to proceed if the current time is less than the timer
|
||||
}
|
||||
|
||||
// Update the timer to the current time
|
||||
BgCheckTimer = time(nullptr);
|
||||
|
||||
LOG_DEBUG("playerbots", "Checking BG Queue...");
|
||||
|
||||
BattlegroundData.clear();
|
||||
|
||||
// Initialize Battleground Data
|
||||
for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
|
||||
{
|
||||
for (int queueType = BATTLEGROUND_QUEUE_AV; queueType < MAX_BATTLEGROUND_QUEUE_TYPES; ++queueType)
|
||||
@@ -644,6 +663,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
}
|
||||
}
|
||||
|
||||
// Process players
|
||||
for (Player* player : players)
|
||||
{
|
||||
if (!player->InBattlegroundQueue())
|
||||
@@ -654,6 +674,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
continue;
|
||||
|
||||
TeamId teamId = player->GetTeamId();
|
||||
|
||||
for (uint8 queueType = 0; queueType < PLAYER_MAX_BATTLEGROUND_QUEUES; ++queueType)
|
||||
{
|
||||
BattlegroundQueueTypeId queueTypeId = player->GetBattlegroundQueueTypeId(queueType);
|
||||
@@ -668,7 +689,6 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
continue;
|
||||
|
||||
BattlegroundBracketId bracketId = pvpDiff->GetBracketId();
|
||||
|
||||
BattlegroundData[queueTypeId][bracketId].minLevel = pvpDiff->minLevel;
|
||||
BattlegroundData[queueTypeId][bracketId].maxLevel = pvpDiff->maxLevel;
|
||||
|
||||
@@ -680,12 +700,10 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
|
||||
if (bgQueue.GetPlayerGroupInfoData(player->GetGUID(), &ginfo))
|
||||
{
|
||||
if (ginfo.IsRated)
|
||||
isRated = true;
|
||||
isRated = ginfo.IsRated;
|
||||
}
|
||||
|
||||
if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID()) ||
|
||||
(player->InArena() && player->GetBattleground()->isRated()))
|
||||
if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID()) || (player->InArena() && player->GetBattleground()->isRated()))
|
||||
isRated = true;
|
||||
|
||||
if (isRated)
|
||||
@@ -728,16 +746,10 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
}
|
||||
}
|
||||
|
||||
for (PlayerBotMap::iterator i = playerBots.begin(); i != playerBots.end(); ++i)
|
||||
// Process player bots
|
||||
for (auto& [guid, bot] : playerBots)
|
||||
{
|
||||
Player* bot = i->second;
|
||||
if (!bot || !bot->IsInWorld())
|
||||
continue;
|
||||
|
||||
if (!bot->InBattlegroundQueue())
|
||||
continue;
|
||||
|
||||
if (!IsRandomBot(bot))
|
||||
if (!bot || !bot->IsInWorld() || !bot->InBattlegroundQueue() || !IsRandomBot(bot))
|
||||
continue;
|
||||
|
||||
Battleground* bg = bot->GetBattleground();
|
||||
@@ -760,7 +772,6 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
continue;
|
||||
|
||||
BattlegroundBracketId bracketId = pvpDiff->GetBracketId();
|
||||
|
||||
BattlegroundData[queueTypeId][bracketId].minLevel = pvpDiff->minLevel;
|
||||
BattlegroundData[queueTypeId][bracketId].maxLevel = pvpDiff->maxLevel;
|
||||
|
||||
@@ -772,12 +783,10 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
|
||||
if (bgQueue.GetPlayerGroupInfoData(bot->GetGUID(), &ginfo))
|
||||
{
|
||||
if (ginfo.IsRated)
|
||||
isRated = true;
|
||||
isRated = ginfo.IsRated;
|
||||
}
|
||||
|
||||
if (bgQueue.IsPlayerInvitedToRatedArena(bot->GetGUID()) ||
|
||||
(bot->InArena() && bot->GetBattleground()->isRated()))
|
||||
if (bgQueue.IsPlayerInvitedToRatedArena(bot->GetGUID()) || (bot->InArena() && bot->GetBattleground()->isRated()))
|
||||
isRated = true;
|
||||
|
||||
if (isRated)
|
||||
@@ -818,11 +827,8 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;
|
||||
}
|
||||
|
||||
if (instanceIds)
|
||||
{
|
||||
if (std::find(instanceIds->begin(), instanceIds->end(), instanceId) == instanceIds->end())
|
||||
instanceIds->push_back(instanceId);
|
||||
}
|
||||
if (instanceIds && std::find(instanceIds->begin(), instanceIds->end(), instanceId) == instanceIds->end())
|
||||
instanceIds->push_back(instanceId);
|
||||
|
||||
if (isArena)
|
||||
{
|
||||
@@ -839,39 +845,52 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
||||
}
|
||||
}
|
||||
|
||||
// Increase instance count if Bots are required to autojoin BG/Arenas
|
||||
if (sPlayerbotAIConfig->randomBotAutoJoinBG)
|
||||
// If enabled, wait for all bots to have logged in before queueing for Arena's / BG's
|
||||
if (sPlayerbotAIConfig->randomBotAutoJoinBG && playerBots.size() >= GetMaxAllowedBotCount())
|
||||
{
|
||||
uint32 randomBotAutoJoinArenaBracket = sPlayerbotAIConfig->randomBotAutoJoinArenaBracket;
|
||||
uint32 randomBotAutoJoinWarsongBracket = sPlayerbotAIConfig->randomBotAutoJoinWarsongBracket;
|
||||
uint32 randomBotAutoJoinArenaBracket = sPlayerbotAIConfig->randomBotAutoJoinArenaBracket;
|
||||
uint32 randomBotAutoJoinBGRatedArena2v2Count = sPlayerbotAIConfig->randomBotAutoJoinBGRatedArena2v2Count;
|
||||
uint32 randomBotAutoJoinBGRatedArena3v3Count = sPlayerbotAIConfig->randomBotAutoJoinBGRatedArena3v3Count;
|
||||
uint32 randomBotAutoJoinBGRatedArena5v5Count = sPlayerbotAIConfig->randomBotAutoJoinBGRatedArena5v5Count;
|
||||
uint32 randomBotAutoJoinBGWarsongCount = sPlayerbotAIConfig->randomBotAutoJoinBGWarsongCount;
|
||||
|
||||
BattlegroundData[BATTLEGROUND_QUEUE_2v2][randomBotAutoJoinArenaBracket].ratedArenaInstanceCount =
|
||||
std::max(randomBotAutoJoinBGRatedArena2v2Count,
|
||||
(BattlegroundData[BATTLEGROUND_QUEUE_2v2][randomBotAutoJoinArenaBracket].ratedArenaInstanceCount -
|
||||
randomBotAutoJoinBGRatedArena2v2Count) +
|
||||
randomBotAutoJoinBGRatedArena2v2Count);
|
||||
uint32 randomBotAutoJoinBGICCount = sPlayerbotAIConfig->randomBotAutoJoinBGICCount;
|
||||
uint32 randomBotAutoJoinBGEYCount = sPlayerbotAIConfig->randomBotAutoJoinBGEYCount;
|
||||
uint32 randomBotAutoJoinBGAVCount = sPlayerbotAIConfig->randomBotAutoJoinBGAVCount;
|
||||
uint32 randomBotAutoJoinBGABCount = sPlayerbotAIConfig->randomBotAutoJoinBGABCount;
|
||||
uint32 randomBotAutoJoinBGWSCount = sPlayerbotAIConfig->randomBotAutoJoinBGWSCount;
|
||||
|
||||
BattlegroundData[BATTLEGROUND_QUEUE_3v3][randomBotAutoJoinArenaBracket].ratedArenaInstanceCount =
|
||||
std::max(randomBotAutoJoinBGRatedArena3v3Count,
|
||||
(BattlegroundData[BATTLEGROUND_QUEUE_3v3][randomBotAutoJoinArenaBracket].ratedArenaInstanceCount -
|
||||
randomBotAutoJoinBGRatedArena3v3Count) +
|
||||
randomBotAutoJoinBGRatedArena3v3Count);
|
||||
std::vector<uint32> icBrackets = parseBrackets(sPlayerbotAIConfig->randomBotAutoJoinICBrackets);
|
||||
std::vector<uint32> eyBrackets = parseBrackets(sPlayerbotAIConfig->randomBotAutoJoinEYBrackets);
|
||||
std::vector<uint32> avBrackets = parseBrackets(sPlayerbotAIConfig->randomBotAutoJoinAVBrackets);
|
||||
std::vector<uint32> abBrackets = parseBrackets(sPlayerbotAIConfig->randomBotAutoJoinABBrackets);
|
||||
std::vector<uint32> wsBrackets = parseBrackets(sPlayerbotAIConfig->randomBotAutoJoinWSBrackets);
|
||||
|
||||
BattlegroundData[BATTLEGROUND_QUEUE_5v5][randomBotAutoJoinArenaBracket].ratedArenaInstanceCount =
|
||||
std::max(randomBotAutoJoinBGRatedArena5v5Count,
|
||||
(BattlegroundData[BATTLEGROUND_QUEUE_5v5][randomBotAutoJoinArenaBracket].ratedArenaInstanceCount -
|
||||
randomBotAutoJoinBGRatedArena5v5Count) +
|
||||
randomBotAutoJoinBGRatedArena5v5Count);
|
||||
auto updateRatedArenaInstanceCount = [&](uint32 queueType, uint32 bracket, uint32 minCount) {
|
||||
if (BattlegroundData[queueType][bracket].activeRatedArenaQueue == 0 &&
|
||||
BattlegroundData[queueType][bracket].ratedArenaInstanceCount < minCount)
|
||||
BattlegroundData[queueType][bracket].activeRatedArenaQueue = 1;
|
||||
};
|
||||
|
||||
BattlegroundData[BATTLEGROUND_QUEUE_WS][randomBotAutoJoinWarsongBracket].bgInstanceCount =
|
||||
std::max(randomBotAutoJoinBGWarsongCount,
|
||||
(BattlegroundData[BATTLEGROUND_QUEUE_WS][randomBotAutoJoinWarsongBracket].bgInstanceCount -
|
||||
randomBotAutoJoinBGWarsongCount) +
|
||||
randomBotAutoJoinBGWarsongCount);
|
||||
auto updateBGInstanceCount = [&](uint32 queueType, std::vector<uint32> brackets, uint32 minCount) {
|
||||
for (uint32 bracket : brackets)
|
||||
{
|
||||
if (BattlegroundData[queueType][bracket].activeBgQueue == 0 &&
|
||||
BattlegroundData[queueType][bracket].bgInstanceCount < minCount)
|
||||
BattlegroundData[queueType][bracket].activeBgQueue = 1;
|
||||
}
|
||||
};
|
||||
|
||||
// Update rated arena instance counts
|
||||
updateRatedArenaInstanceCount(BATTLEGROUND_QUEUE_2v2, randomBotAutoJoinArenaBracket, randomBotAutoJoinBGRatedArena2v2Count);
|
||||
updateRatedArenaInstanceCount(BATTLEGROUND_QUEUE_3v3, randomBotAutoJoinArenaBracket, randomBotAutoJoinBGRatedArena3v3Count);
|
||||
updateRatedArenaInstanceCount(BATTLEGROUND_QUEUE_5v5, randomBotAutoJoinArenaBracket, randomBotAutoJoinBGRatedArena5v5Count);
|
||||
|
||||
// Update battleground instance counts
|
||||
updateBGInstanceCount(BATTLEGROUND_QUEUE_IC, icBrackets, randomBotAutoJoinBGICCount);
|
||||
updateBGInstanceCount(BATTLEGROUND_QUEUE_EY, eyBrackets, randomBotAutoJoinBGEYCount);
|
||||
updateBGInstanceCount(BATTLEGROUND_QUEUE_AV, avBrackets, randomBotAutoJoinBGAVCount);
|
||||
updateBGInstanceCount(BATTLEGROUND_QUEUE_AB, abBrackets, randomBotAutoJoinBGABCount);
|
||||
updateBGInstanceCount(BATTLEGROUND_QUEUE_WS, wsBrackets, randomBotAutoJoinBGWSCount);
|
||||
}
|
||||
|
||||
LogBattlegroundInfo();
|
||||
|
||||
Reference in New Issue
Block a user