AI companions that are real heroes in the sim
Recruitable AI party members that are ordinary SimPlayers driven by a 5 Hz brain sending client commands, yielding to real players, at 0.3 ms a tick for 120 of them.

Contents
When nobody else is online, a solo hero still gets the party game: a Warden holding the pack, a Stalker raining arrows, an Emberwright dropping Starfall on the elite, four names in the party frame. Diablo II's answer was one hireling; Duskbound's is three real heroes in the sim.
Real heroes, not a new entity
| Option | Problem |
|---|---|
| Bot clients (account, row, socket each) | 120 extra sockets in one Bun process to simulate what's already in memory |
| New entity type | a second branch in every combat path, skill, aura, buff, nameplate, animation and transfer, forever |
A SimPlayer with one extra field |
none |
bot: { ownerId: string }- Lives in
world.playersandstate.playersascmp_<entryId>; combat, skills, animations, auras, transfers and nameplates just work - No session, so per-player events, saves and the private
selfsheet skip it naturally PlayerState.ownerlets clients draw ally plates and party-frame rows

Recruit in the Party panel: class, name, Recruit. Three per hero, saved on the character.
- Always at the owner's level; rebuilt on level-up; no inventory
- Fixed skill build and attribute split per class
- Gear rolled deterministically from id, level and difficulty: white under 5, magic from 5, rare weapon and chest from 15, all rares in Nightmare and Hell
A brain that presses the same buttons you do
The AI never touches state. It calls runCommand with move, attackTarget or cast, the same commands a client sends, so mana, cooldowns, weapon requirements and line of sight apply unchanged. It thinks every 200 ms, staggered across ticks:
- Stay close. More than 25 tiles from the owner, or stuck for 2.5 s: blink to a formation spot behind them (doors, cliffs, waypoints)
- Pick a target within 12 tiles of the owner; drop the fight beyond 10 tiles from the owner
- Choose an action from the class kit
- Position for range and line of sight, then send

let score = Math.hypot(m.x - bot.x, m.y - bot.y)
if (m.id === ownerTarget) score -= 100
else if (m.targetId === owner.id) score -= 50
else if (m.targetId === bot.id) score -= 30
if (m.id === brain.targetId) score -= 20Owner's target, then whatever hits the owner, then whatever hits the companion, then nearest, with stickiness against flip-flopping. Sleeping monsters only within 7 tiles of the owner, so companions never wake the next room. Melee companions check for a path first; unreachable targets (across lava, water) are blacklisted for 5 s.
Class kits
Plain if priority lists. The whole Warden:
case 'warden': {
if (lifeFrac < 0.45 && !hasBuff(bot, 'w_aegis') && canUse(w, bot, 'w_aegis')) return cast('w_aegis', true)
if (!hasBuff(bot, 'w_rallying_cry') && canUse(w, bot, 'w_rallying_cry')) return cast('w_rallying_cry', true)
if (!bot.aura && canUse(w, bot, 'w_hallowed_ground')) return cast('w_hallowed_ground', true)
if (near >= 3 && canUse(w, bot, 'w_warcry')) return cast('w_warcry', true)
if (pack >= 2 && canUse(w, bot, 'w_cleave')) return cast('w_cleave')
if (elite(target) && canUse(w, bot, 'w_verdict')) return cast('w_verdict')
if (elite(target) && canUse(w, bot, 'w_shieldbreaker')) return cast('w_shieldbreaker')
if (canUse(w, bot, 'w_twin_cut')) return cast('w_twin_cut')
if (canUse(w, bot, 'w_sunder')) return cast('w_sunder')
return { kind: 'attack' }
}canUse checks learned, cooldown, cost and weapon, so the list works at every level; at level 3 most lines fall through.
- Warden: companion War Cry also taunts everything within 6 tiles. Without it, the tank was melee DPS in plate.
- Stalker: Rain of Barbs on 3+, Volley and Quickdraw on pairs, then Seeker and Barbed Arrow.
- Emberwright: keeps Rime Ward up, saves Starfall for elites and big packs.
- Kiting: ranged classes step back from anything within 2.5 tiles, weighted 2:1 away-from-monster to toward-owner, so they back into the party.
- No potions: mana regenerates 10%/s, life 5%/s out of combat. A companion out of mana mid-fight looks broken, not balanced.
Rules that keep it honest
Companions are a party for a solo hero, not three free farmers. The rules live in one hooks file:
- No loot, no XP: skipped in
lootEligibleand chests - Kills credit the owner, undiluted: splitting XP with companions would punish using them
- Half a player for scaling: monster life is +35% per extra player; a companion counts 0.5, so a full crew adds 52.5% instead of 105%, and bigger monsters pay proportionally more XP
- Cheap death: nothing lost, never hardcore, back up beside the owner after 10 s
- Not on the ladder: rift clears and boss kills record real players only
Stepping aside for real players
Companions fill a party to four heroes; real players can go to eight. When a real player would push it past four, a companion steps aside, and returns when there's room:
while (total > cap) {
const pick = state
.filter((s) => active(s).length > 0)
.sort((a, b) => active(b).length - active(a).length || newest(active(b)) - newest(active(a)) || a.ownerId.localeCompare(b.ownerId))[0]
const c = pick ? active(pick).sort((a, b) => b.since - a.since)[0] : undefined
if (!pick || !c) break
c.active = false
out.push({ kind: 'yield', ownerId: pick.ownerId, id: c.id })
total--
}- The owner with the most active companions yields first, newest companion first: two solo players with three each end up with one each, not three and zero
- Returns a list of changes rather than applying them, so tests are trivial: full crew solo, newest steps aside, biggest crew yields first, four real players leave no room, companions return
- Re-planned about once a second per room; a toast ("Wren steps aside to make room") and a Rejoin button
Private worlds
An Open / Private toggle on the character screen. Private joins carry privateKey = <characterId>, and rooms match on zoneId, difficulty and privateKey, so the hero gets their own instance of every zone, towns included.
onAuth enforces privateWorldAllows: the owner, their party, and anyone partied with someone inside. Invited players still arrive through the normal party transfer. server/game/privacy.test.ts pins it.
What it costs
scripts/companion-perf.ts: 40 owners fighting in the Scorched Dunes for 30 s, then again with three companions each (160 heroes):
| Average tick | p95 | |
|---|---|---|
| 40 heroes | 0.17 ms | 0.51 ms |
| 40 heroes + 120 companions | 0.32 ms | 0.80 ms |
| of which companion AI | 0.09 ms |
Companions don't count toward the 40-client cap (Colyseus counts sockets). The real cost of a crowded room is event fan-out (forty players); there, your own companions' effects are treated like your own casts and always reach you.
Where the brain stops
No model of boss telegraphs: companions don't leave the Architect's warning tiles or switch to the Choir's chiming voice. The data already exists (clients draw every telegraph from server events), so the next rule is a first line in think: if standing in a marked area, move out.