PlayerbotV2: bot pickup groups break up again

Two world bots that grouped on their own (idle:invite_nearby_player) stayed
grouped until the next restart: grouped bots counted as tied up, outside
the world cap, the spawner never logged them out and the runtime group
hygiene left every pure-bot group alone, so the grouped count only grew
(GitHub #345).

A group a bot's own invite made is now noted as a pickup group
(Fleet/PickupGroups.h). Its bots count toward Playerbot.World.MaxBots, the
spawner breaks it up once none of its bots is near a player (they are then
logged out like any far world bot), and the group hygiene breaks it up at
the end of its 10 to 20 minute life. Never while a member fights, is being
teleported or is in an instance, and a group a player joined is his.
The [world] line counts pickup_groups and how many were broken up.
This commit is contained in:
Karrz1
2026-11-16 09:57:46 +00:00
parent 7b847dd3ec
commit d70d3ee5b6
7 changed files with 178 additions and 6 deletions
@@ -64,6 +64,8 @@
#include "FollowDrop.h" // follow_drop: ledge plan toward an owner who dropped or jumped down
#include "Fleet/CityLayer.h" // same-level moves across a drop, NoPath storm
#include "Fleet/BotPool.h" // Pool::IsScenarioBot: a test character trades with nobody
#include "Fleet/BotIdentityRegistry.h" // Lifecycle().is_bot: a bot's own invite made the group
#include "Fleet/PickupGroups.h" // a bot-made pickup group is noted so it breaks up again
#include "Bot/World/ZonePicker.h" // IsVanillaCapitalZone
#include "Fleet/InstanceEntry.h" // PrepareInstanceEntry: a stale raid lock must not keep a companion out of its owner's instance
#include "PartialRouteStall.h"
@@ -5490,6 +5492,7 @@ Result API::accept_group_invite()
if (g->GetLeaderGUID() == p_->GetGUID()) return Result::Other;
if (g->IsFull()) return Result::ServerRefused;
bool formed_by_bot = false;
if (!g->IsCreated())
{
Player* leader = ObjectAccessor::FindPlayer(g->GetLeaderGUID());
@@ -5497,9 +5500,13 @@ Result API::accept_group_invite()
g->RemoveInvite(leader);
g->Create(leader);
sGroupMgr->AddGroup(g);
// A world bot's own invite made this group (idle:invite_nearby_player): a pickup group, which breaks up again (Fleet/PickupGroups.h).
formed_by_bot = Services::Lifecycle().is_bot(leader->GetGUID().GetCounter());
}
g->RemoveInvite(p_);
if (!g->AddMember(p_)) return Result::ServerRefused;
if (formed_by_bot)
::Playerbot::V2::PickupGroups::Note(g->GetGUID().GetCounter(), GameTime::GetGameTimeMS());
g->BroadcastGroupUpdate();
return Result::Ok;
}
@@ -0,0 +1,71 @@
// PickupGroups - the game groups two world bots form on their own (idle:invite_nearby_player, Playerbot.Behavior.InvitePassingBots).
//
// Such a group used to last until the server restarted: its members counted as "tied up" (outside the world cap, like a dungeon group),
// the spawner never logged a grouped bot out, and the runtime group hygiene left every pure-bot group alone. Bots paired off as they
// logged in and the grouped count only grew, 59 -> 191 in 13 minutes on a 300-bot realm until memory ran out (GitHub #345).
// A pickup group is now a world thing like a BotParties party:
// - its members count toward Playerbot.World.MaxBots (WorldBotSpawner::DriveDespawn);
// - it breaks up once no member is near a player any more (the spawner then logs them out as it does any far world bot);
// - and it breaks up after its life, the way strangers team up for a few kills and go their own ways (module group hygiene).
// Only groups made through API::accept_group_invite with a bot as the new leader are noted; a group with a real player in it is a
// player's group and is forgotten here.
//
// World thread only (the intent executor and the world tick).
#pragma once
#include <cstdint>
#include <unordered_map>
namespace Playerbot::V2::PickupGroups
{
// How long a pickup group lasts: 10 to 20 minutes, spread by group id so the pairs do not all break up at once.
constexpr std::uint32_t kLifeMinMs = 10u * 60u * 1000u;
constexpr std::uint32_t kLifeSpreadMs = 10u * 60u * 1000u;
struct Entry
{
std::uint32_t formed_ms = 0;
std::uint32_t life_ms = kLifeMinMs;
};
inline std::unordered_map<std::uint64_t, Entry>& Table()
{
static std::unordered_map<std::uint64_t, Entry> table;
return table;
}
inline std::uint32_t LifeFor(std::uint64_t group_id)
{
return kLifeMinMs + std::uint32_t((group_id * 2654435761ull) % kLifeSpreadMs);
}
inline void Note(std::uint64_t group_id, std::uint32_t now_ms)
{
Table()[group_id] = Entry{ now_ms, LifeFor(group_id) };
}
inline bool Has(std::uint64_t group_id) { return Table().contains(group_id); }
inline void Forget(std::uint64_t group_id) { Table().erase(group_id); }
// Its life is over (wrap-safe on the 32-bit millisecond clock).
inline bool Expired(Entry const& e, std::uint32_t now_ms)
{
return std::uint32_t(now_ms - e.formed_ms) >= e.life_ms;
}
// What the spawner saw of one pickup group's online members this pass.
struct Seen
{
bool near_player = false; // a member stands within DespawnRadius of a player (or in his bubble by the spawner's other tests)
bool busy = false; // a member fights, is being teleported, or stands in an instance / battleground / its queue
};
// The spawner breaks a group up when nobody of it is near a player and nobody of it is busy: logging a bot out mid-fight or
// mid-teleport would break the fight or the move, and the next pass looks again.
inline bool BreakUpForDistance(Seen const& s)
{
return !s.near_player && !s.busy;
}
} // namespace Playerbot::V2::PickupGroups
@@ -58,6 +58,8 @@
#include "GameTime.h"
#include "DatabaseEnv.h"
#include "Group.h"
#include "GroupMgr.h"
#include "PickupGroups.h"
#include "Log.h"
#include "DB2Stores.h"
#include "DB2Structure.h"
@@ -586,8 +588,9 @@ std::string WorldBotSpawner::Report() const
if (t.m.moving) ++riders;
line += Trinity::StringFormat(" | moving riders={} placed_ahead={} woken_ahead={} left_behind={}", riders, n_moving_placed_, n_moving_woken_, n_left_behind_);
}
line += Trinity::StringFormat(" | split world={} (cap {}) tied_up={} (group/BG/instance) owned={} (companions) soak_anchors={} evicted_for_room={} | walked_in={} walked_out={} leaving={} idle_swaps={}",
ambient_online_, cfg_.max_bots, tied_online_, owned_online_, soak_anchors_, n_evicted_, n_arrived_walking_, n_left_walking_, leaving_.size(), n_idle_swaps_);
line += Trinity::StringFormat(" | split world={} (cap {}) tied_up={} (group/BG/instance, not pickup groups) owned={} (companions) soak_anchors={} evicted_for_room={} | walked_in={} walked_out={} leaving={} idle_swaps={} pickup_groups={} (broken up {})",
ambient_online_, cfg_.max_bots, tied_online_, owned_online_, soak_anchors_, n_evicted_, n_arrived_walking_, n_left_walking_, leaving_.size(), n_idle_swaps_,
PickupGroups::Table().size(), n_pickup_broken_);
{
auto& tl = ::Playerbot::V2::TownLife::Counters();
line += Trinity::StringFormat(" | town_life inn_ticks={} inn_walk={} inn_none={} inn_stuck={} mailbox_ticks={} duels={} campfires={} lfg_calls={} idle_strikes town={} field={} gate_duels={} gate_challenges={} errands={} errand_gave_up={} inn_full={} mailbox_full={} player_nudges={}",
@@ -1581,6 +1584,7 @@ void WorldBotSpawner::DriveDespawn(uint32 now_ms, std::vector<Anchor> const& anc
uint32 all_bots = 0;
uint32 owned_bots = 0; // companions and a player's own bots: never part of the world cap
uint32 tied_bots = 0; // ambient bots in a group, instance or battleground: not part of the world cap either
std::unordered_map<uint64, PickupGroups::Seen> pickup_seen; // the bots' own pickup groups seen this pass
Services::Registry().for_each([&](BotId id, BotRegistryEntry const&)
{
ObjectGuid const g = ObjectGuid::Create<HighGuid::Player>(id);
@@ -1588,16 +1592,31 @@ void WorldBotSpawner::DriveDespawn(uint32 now_ms, std::vector<Anchor> const& anc
if (!p || !p->IsInWorld()) return;
++all_bots;
if (!owner_.IsAmbientBot(id, p)) { ++owned_bots; return; }
// Two world bots' own pickup group (Fleet/PickupGroups.h) is world population: its members count toward the world cap and the
// group breaks up below once none of them is near a player (GitHub #345: these pairs piled up "tied up" until memory ran out).
Group const* const grp = p->GetGroup();
uint64 const pickup_id = grp && PickupGroups::Has(grp->GetGUID().GetCounter()) ? grp->GetGUID().GetCounter() : 0;
PickupGroups::Seen* const pickup = pickup_id ? &pickup_seen[pickup_id] : nullptr;
// Bots queued for / inside a battleground, in a group or in an instance are not part of the open-world population.
if (p->InBattleground() || p->InBattlegroundQueue() || p->GetGroup()
if (p->InBattleground() || p->InBattlegroundQueue() || (grp && !pickup)
|| (p->GetMap() && (p->GetMap()->IsDungeon() || p->GetMap()->IsBattlegroundOrArena())))
{
if (pickup) pickup->busy = true;
++tied_bots;
return;
}
++ambient;
if (pending_.contains(uint64(id)) || seeding_.contains(uint64(id)) || leaving_.contains(uint64(id))) return;
if (::Playerbot::V2::Travel::SoakBoard::Instance().Has(uint64(id))) return; // a soak runner is far from every anchor on purpose
if (pickup && (p->IsInCombat() || p->IsBeingTeleported())) pickup->busy = true;
if (pending_.contains(uint64(id)) || seeding_.contains(uint64(id)) || leaving_.contains(uint64(id)))
{
if (pickup && !leaving_.contains(uint64(id))) pickup->busy = true; // still being placed: its distance says nothing yet
return;
}
if (::Playerbot::V2::Travel::SoakBoard::Instance().Has(uint64(id))) // a soak runner is far from every anchor on purpose
{
if (pickup) pickup->busy = true;
return;
}
// Distance to the nearest anchor on the bot's own map.
float nearest = 1e9f;
@@ -1637,6 +1656,7 @@ void WorldBotSpawner::DriveDespawn(uint32 now_ms, std::vector<Anchor> const& anc
emptied = !place_seen_ms_.contains(::Playerbot::V2::Fleet::PlaceKey(p->GetMapId(), bot_zone));
// A misfit goes as an orphan does: a level 25 human priest in Deathknell takes the new player's mobs (PC 26 Oct).
bool const orphan = nearest > cfg_.despawn_radius || misfit || trail || emptied;
if (pickup && !orphan) pickup->near_player = true;
// A bot behind the player (past ActivityRadius, inside DespawnRadius) can be recycled early when the world cap is full and a
// player's bubble still lacks bots; otherwise only orphans go.
if (!orphan && nearest <= cfg_.activity_radius)
@@ -1660,6 +1680,23 @@ void WorldBotSpawner::DriveDespawn(uint32 now_ms, std::vector<Anchor> const& anc
owned_online_ = owned_bots;
tied_online_ = tied_bots;
// A pickup group with nobody near a player breaks up; its bots are then far world bots, logged out by the next passes.
for (auto const& [gid, seen] : pickup_seen)
{
if (!PickupGroups::BreakUpForDistance(seen)) continue;
Group* const g = sGroupMgr->GetGroupByGUID(ObjectGuid::Create<HighGuid::Party>(gid));
PickupGroups::Forget(gid);
if (!g) continue;
// A player who joined it made it his group: it stays (the group hygiene forgets it as a pickup group too).
bool player_in = false;
for (Group::MemberSlot const& slot : g->GetMemberSlots())
if (!Services::Lifecycle().is_bot(slot.guid.GetCounter())) { player_in = true; break; }
if (player_in) continue;
TC_LOG_INFO("playerbot.v2", "[group_hygiene] disbanding bot pickup group {} reason=no-player-near ({} members)", gid, g->GetMembersCount());
g->Disband();
++n_pickup_broken_;
}
// The bubbles' shortfall: how many bots the players' targets still lack.
uint32 deficit = 0;
for (Anchor const& a : anchors)
@@ -341,6 +341,7 @@ private:
uint64 n_arrived_walking_ = 0;
uint64 n_left_walking_ = 0;
uint64 n_idle_swaps_ = 0;
uint64 n_pickup_broken_ = 0; // bots' own pickup groups broken up with no player near (Fleet/PickupGroups.h)
uint32 last_swap_pass_ms_ = 0;
std::unordered_map<uint64, uint32> swap_ms_; // per bot: when it was last swapped
uint32 swap_burst_until_ms_ = 0; // module ms until which a jump (teleport / hearth) swaps the bubble at a higher rate
+28 -1
View File
@@ -33,6 +33,7 @@
#include "Fleet/CraftOrderBoard.h"
#include "Fleet/PlayerCraftOrders.h"
#include "Fleet/BotQueueFiller.h"
#include "Fleet/PickupGroups.h" // the bots' own pickup groups break up at the end of their life
#include "Fleet/JunkQuestResolver.h"
#include "Bot/ClassTables.h" // MaxPlayerLevel()
#include "Bot/Battleground/BgTeamCoordinator.h"
@@ -1057,7 +1058,8 @@ namespace
// survive a crash). Human groups are left intact.
// purge_pure_bot=false → runtime pass: leave pure-bot groups (legit dungeon
// / BG / quest groups) and only disband human groups
// whose human member(s) have ALL been offline ≥30min.
// whose human member(s) have ALL been offline ≥30min,
// and the bots' own pickup groups whose life is over.
//
// only_these (boot purge): the group ids that existed when the module's first tick ran. The purge runs when the boot gate opens,
// which with no human logged in is 60 s later, and a group formed in that minute is live, not persisted. 2026-10-09: the
@@ -1092,6 +1094,27 @@ namespace
if (!has_bot)
continue;
// Two world bots' own pickup group (Fleet/PickupGroups.h): once a player is in it, it is his group; otherwise it breaks up at
// the end of its life, when no member is fighting, being teleported or in an instance (the spawner breaks it up sooner when
// no player is near).
if (PickupGroups::Has(gid))
{
if (has_human)
PickupGroups::Forget(gid);
else if (!purge_pure_bot && PickupGroups::Expired(PickupGroups::Table().at(gid), now_ms))
{
bool busy = false;
for (auto const& slot : group->GetMemberSlots())
if (Player* m = ObjectAccessor::FindConnectedPlayer(slot.guid))
if (m->IsInCombat() || m->IsBeingTeleported() || (m->GetMap() && m->GetMap()->Instanceable()))
{ busy = true; break; }
if (!busy)
{
to_disband.emplace_back(group, "pickup-life-over");
continue;
}
}
}
if (!has_human)
{
g_group_humans_offline_since.erase(gid);
@@ -1135,9 +1158,13 @@ namespace
to_disband.emplace_back(group, "human-afk-30min");
}
// Disband AFTER iterating — Group::Disband() mutates the GroupStore.
// A pickup group that is gone (it broke up, or its last member left it) is forgotten.
std::erase_if(PickupGroups::Table(),
[](auto const& kv) { return !sGroupMgr->GetGroupByGUID(ObjectGuid::Create<HighGuid::Party>(kv.first)); });
for (auto const& [g, reason] : to_disband)
{
g_group_humans_offline_since.erase(g->GetGUID().GetCounter());
PickupGroups::Forget(g->GetGUID().GetCounter());
TC_LOG_INFO("playerbot.v2",
"[group_hygiene] disbanding bot group {} reason={}",
g->GetGUID().GetCounter(), reason);
@@ -1004,6 +1004,8 @@ Playerbot.Behavior.PoliteWorldBots = 1
Playerbot.Behavior.InvitePassingPlayers = 0
# InvitePassingBots 1 (default) = a world bot (as above) may invite another world bot near it to a pickup group. 0 = it
# does not. With both InvitePassing keys at 0 no world bot sends an invite nobody asked for.
# Such a pickup group counts toward MaxBots and breaks up again after 10 to 20 minutes, or sooner once
# none of its bots is within DespawnRadius of a player (the spawner then logs them out as usual).
Playerbot.Behavior.InvitePassingBots = 1
# QuestAccept a companion (a bot grouped with its owner) quests with him like a party member: it accepts a quest
# its group shares with it, and when its owner takes a quest from an NPC beside it, it walks up to the
+27
View File
@@ -17,6 +17,7 @@
#include "tc_catch2.h"
#include "../../src/modules/PlayerbotV2/Fleet/BotParties.h"
#include "../../src/modules/PlayerbotV2/Fleet/PickupGroups.h"
using namespace Playerbot::V2::Parties;
@@ -125,3 +126,29 @@ TEST_CASE("A mate's fight is in the link", "[ClassicBotParties]")
REQUIRE(links[2].mates[0].in_combat);
REQUIRE(links[2].mates[0].target == 4242);
}
// Pickup groups (GitHub #345): two world bots' own game group breaks up again.
TEST_CASE("A bot pickup group lasts 10 to 20 minutes and breaks up only when nobody of it is near a player or busy", "[ClassicBotParties]")
{
namespace PG = Playerbot::V2::PickupGroups;
for (std::uint64_t id : { 1ull, 2ull, 77ull, 123456ull, 0xFFFFFFFFull })
{
std::uint32_t const life = PG::LifeFor(id);
CHECK(life >= PG::kLifeMinMs);
CHECK(life < PG::kLifeMinMs + PG::kLifeSpreadMs);
}
CHECK(PG::LifeFor(1) != PG::LifeFor(2)); // the pairs do not all break up at once
PG::Entry const e{ 0xFFFFF000u, PG::kLifeMinMs }; // formed just before the 32-bit clock wraps
CHECK_FALSE(PG::Expired(e, 0xFFFFF000u + 1000u));
CHECK(PG::Expired(e, 0xFFFFF000u + PG::kLifeMinMs));
CHECK(PG::BreakUpForDistance(PG::Seen{ false, false }));
CHECK_FALSE(PG::BreakUpForDistance(PG::Seen{ true, false })); // a member is near a player
CHECK_FALSE(PG::BreakUpForDistance(PG::Seen{ false, true })); // a member fights or is in an instance
PG::Note(42, 1000);
CHECK(PG::Has(42));
PG::Forget(42);
CHECK_FALSE(PG::Has(42));
}