Skip to content

Commit

Permalink
Add offline random bots in real groups faster
Browse files Browse the repository at this point in the history
  • Loading branch information
celguar committed Oct 24, 2023
1 parent 7c70432 commit 481529b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
77 changes: 77 additions & 0 deletions playerbot/RandomPlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ RandomPlayerbotMgr::RandomPlayerbotMgr() : PlayerbotHolder(), processTicks(0), l
LfgCheckTimer = 0;
PlayersCheckTimer = 0;
EventTimeSyncTimer = 0;
OfflineGroupBotsTimer = 0;
guildsDeleted = false;
arenaTeamsDeleted = false;

Expand Down Expand Up @@ -587,6 +588,9 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool minimal)
CheckBgQueue();
}

if (time(nullptr) > (OfflineGroupBotsTimer + 5) && players.size())
AddOfflineGroupBots();

uint32 updateBots = sPlayerbotAIConfig.randomBotsPerInterval;
uint32 maxNewBots = sPlayerbotAIConfig.randomBotsMaxLoginsPerInterval;
if (onlineBotCount < sPlayerbotAIConfig.minRandomBots * sPlayerbotAIConfig.loginBoostPercentage / 100)
Expand Down Expand Up @@ -1549,6 +1553,79 @@ void RandomPlayerbotMgr::CheckLfgQueue()
return;
}

void RandomPlayerbotMgr::AddOfflineGroupBots()
{
if (!OfflineGroupBotsTimer || time(NULL) > (OfflineGroupBotsTimer + 5))
OfflineGroupBotsTimer = time(NULL);

uint32 totalCounter = 0;
for (const auto& i : players)
{
Player* player = i.second;

if (!player || !player->IsInWorld() || !player->GetGroup())
continue;

Group* group = player->GetGroup();
if (group && group->IsLeader(player->GetObjectGuid()))
{
vector<uint32> botsToAdd;
Group::MemberSlotList const& slots = group->GetMemberSlots();
for (Group::MemberSlotList::const_iterator i = slots.begin(); i != slots.end(); ++i)
{
ObjectGuid member = i->guid;
if (member == player->GetObjectGuid())
continue;

if (!IsFreeBot(member.GetCounter()))
continue;

if (sObjectMgr.GetPlayer(member))
continue;

if (GetPlayerBot(member))
continue;

botsToAdd.push_back(member.GetCounter());
}

if (botsToAdd.empty())
return;

uint32 maxToAdd = urand(1, 5);
uint32 counter = 0;
for (auto& guid : botsToAdd)
{
if (counter >= maxToAdd)
break;

if (sPlayerbotAIConfig.IsFreeAltBot(guid))
{
for (auto& bot : sPlayerbotAIConfig.freeAltBots)
{
if (bot.second == guid)
{
Player* player = GetPlayerBot(bot.second);
if (!player)
{
AddPlayerBot(bot.second, bot.first);
}
}
}
}
else
AddRandomBot(guid);

counter++;
totalCounter++;
}
}
}

if (totalCounter)
sLog.outBasic("Added %u offline bots from groups", totalCounter);
}

Item* RandomPlayerbotMgr::CreateTempItem(uint32 item, uint32 count, Player const* player, uint32 randomPropertyId)
{
if (count < 1)
Expand Down
2 changes: 2 additions & 0 deletions playerbot/RandomPlayerbotMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class RandomPlayerbotMgr : public PlayerbotHolder
void CheckPlayers();
void SaveCurTime();
void SyncEventTimers();
void AddOfflineGroupBots();
static Item* CreateTempItem(uint32 item, uint32 count, Player const* player, uint32 randomPropertyId = 0);

bool AddRandomBot(uint32 bot);
Expand Down Expand Up @@ -171,6 +172,7 @@ class RandomPlayerbotMgr : public PlayerbotHolder
time_t LfgCheckTimer;
time_t PlayersCheckTimer;
time_t EventTimeSyncTimer;
time_t OfflineGroupBotsTimer;
uint32 AddRandomBots();
bool ProcessBot(uint32 bot);
void ScheduleRandomize(uint32 bot, uint32 time);
Expand Down

0 comments on commit 481529b

Please sign in to comment.