Random bots to fix team jams#49
Conversation
…and delayed leave ## Summary - Prevents random bots from staying in a group when their master logs out, which made them uninvitable on re-login. - When a real player leaves a party that still has other real players, the party is kept: leader is transferred to the next real player and bots get a new master. The party only breaks when the last real player leaves. - When no real player remains in the party, random bots leave after a configurable delay (default 180s) so brief disconnects don’t disband the group. - After a server crash/restart, groups are restored from DB; if a random bot logs in and its group has no connected real player, that group is scheduled for delayed leave so bots don’t stay stuck. ## Changes - **OnPlayerLogout**: For each random bot that had the logging-out player as master, either assign a new master (first connected real player in the group) and transfer party leader to that player, or schedule delayed leave and clear master. If the core did not remove the player on logout (`LeaveGroupOnLogout=0`), transfer leader when possible, then remove the player from the group. - **Delayed leave**: New config `AiPlayerbot.BotLeaveGroupDelayWhenNoRealPlayer` (default 180 seconds). Groups with no real player are scheduled; each tick `ProcessScheduledGroupLeaves` re-checks for a connected real player and, if still none, only **random bots** in that group are forced to leave (alt/addclass bots are not kicked). Delay 0 means leave on the next tick. - **OnBotLoginInternal**: When a random bot logs in and is in a group with no connected real player, schedule that group for delayed leave (avoids stuck/uninvitable bots after crash). - **Scope**: Only 5-man parties are handled; raid, LFG, and battleground are skipped. Logic applies only to random bots managed by RandomPlayerbotMgr. ## Config - `AiPlayerbot.BotLeaveGroupDelayWhenNoRealPlayer` (default: 180) — seconds before random bots leave the group when no real player remains. ## Notes - If `LeaveGroupOnLogout` is enabled in the core, the core removes the player and broadcasts first; bots may leave immediately via `PartyCommandAction(PARTY_OP_LEAVE)`, so the delay does not apply in that case. When `LeaveGroupOnLogout` is disabled, we transfer leader and remove the player ourselves, and the delay applies. - Defensive checks added: `FindFirstRealConnectedPlayerInGroup` validates `GetSession()` and skips logout/invalid members to avoid crashes.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
This is the final PR Bugbot will review for you during this billing cycle
Your free Bugbot reviews will reset on March 26
Details
You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| { | ||
| sRandomPlayerbotMgr.ScheduleGroupDelayedLeave(bot->GetGroup()); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Delay blocks non-random bots from ever leaving group
Medium Severity
The delayed-leave check in PartyCommandAction::Execute is placed outside the IsRandomBot guard, so when botLeaveGroupDelayWhenNoRealPlayer > 0 (default 180), all bot types — including alt/addclass bots — hit return false instead of reaching return Leave(). However, ProcessScheduledGroupLeaves explicitly skips non-random bots (!IsRandomBot(member)), meaning those bots are never actually removed and stay stuck in the group indefinitely. This happens when a real player manually leaves a group containing their alt/addclass bots.


Pull Request
Describe what this change does and why it is needed...
Design Philosophy
We prioritize stability, performance, and predictability over behavioral realism.
Complex player-mimicking logic is intentionally limited due to its negative impact on scalability, maintainability, and
long-term robustness.
Excessive processing overhead can lead to server hiccups, increased CPU usage, and degraded performance for all
participants. Because every action and
decision tree is executed per bot and per trigger, even small increases in logic complexity can scale poorly and
negatively affect both players and
world (random) bots. Bots are not expected to behave perfectly, and perfect simulation of human decision-making is not a
project goal. Increased behavioral
realism often introduces disproportionate cost, reduced predictability, and significantly higher maintenance overhead.
Every additional branch of logic increases long-term responsibility. All decision paths must be tested, validated, and
maintained continuously as the system evolves.
If advanced or AI-intensive behavior is introduced, the default configuration must remain the lightweight decision
model. More complex behavior should only be
available as an explicit opt-in option, clearly documented as having a measurable performance cost.
Principles:
Stability before intelligence
A stable system is always preferred over a smarter one.
Performance is a shared resource
Any increase in bot cost affects all players and all bots.
Simple logic scales better than smart logic
Predictable behavior under load is more valuable than perfect decisions.
Complexity must justify itself
If a feature cannot clearly explain its cost, it should not exist.
Defaults must be cheap
Expensive behavior must always be optional and clearly communicated.
Bots should look reasonable, not perfect
The goal is believable behavior, not human simulation.
Before submitting, confirm that this change aligns with those principles.
Feature Evaluation
Please answer the following:
How to Test the Changes
Complexity & Impact
Does this change add new decision branches?
Does this change increase per-bot or per-tick processing?
Could this logic scale poorly under load?
Defaults & Configuration
Does this change modify default bot behavior?
If this introduces more advanced or AI-heavy logic:
AI Assistance
Was AI assistance (e.g. ChatGPT or similar tools) used while working on this change?
If yes, please specify:
AI assistance is allowed, but all submitted code must be fully understood, reviewed, and owned by the contributor.
Any AI-influenced changes must be verified against existing CORE and PB logic. We expect contributors to be honest
about what they do and do not understand.
Final Checklist
Notes for Reviewers
Anything that significantly improves realism at the cost of stability or performance should be carefully discussed
before merging.
Note
Medium Risk
Touches group/leader handling on player logout/party leave and introduces per-tick processing of scheduled group leaves, which could cause unintended group state changes or performance impact under many groups.
Overview
Prevents random-bot groups from getting stuck without a real leader by introducing delayed group leave and leader transfer to another connected real player when a player logs out or leaves a party.
Adds
AiPlayerbot.BotLeaveGroupDelayWhenNoRealPlayer(default180s) and wires it intoLeaveGroupActionplusRandomPlayerbotMgrto schedule, process, and cancel pending group leaves; on bot login after restart, groups with no connected real player are also scheduled to clear out.Written by Cursor Bugbot for commit bb3a246. This will update automatically on new commits. Configure here.