towerdef/docs/VERSUS.md
Claude 28502984ec Co-op robustness, audio/a11y, new towers and enemies, Uplink rebalance
Co-op (QA'd with two to three real browsers, TCP-proxy chaos scenarios):
- partner's tower changes are never dropped after a render stall or snapshot burst
- half-open connections show "reconnecting" in ~6 s instead of 45-65 s
- upgrade and next-wave are idempotent (stale commands refused), restart message,
  promoted host gets Play again, failed joins never kill a live game, listener leaks

Audio / keyboard / a11y:
- one Audio element per track, fade/stinger supersede tokens, play() retry on the
  next gesture, 5 s fallback to the synth, mute works everywhere, dialogs with
  role/aria-modal/focus handling, accessible names for sound/speed/pause

New content:
- enemies: Daemon (healer), Proxy (regenerating shield), Botnet (flyer swarm);
  waves weave them in from wave 9 (waves 1-8 unchanged)
- towers: Sandbox (stun pulse), Load Balancer (fire-rate aura); hotkeys 1-9
- glyphs/shapes, stun/heal effects, gallery e2e that pixel-checks every kind

Orbital Uplink rebalanced after playtesting (was affordable by wave ~6 and buyable
in bulk from boss rewards): 1500 credits, upgrades 1200/2000/3200, and every Uplink
already owned makes the next one 25% dearer to buy AND to upgrade (each tower
remembers its multiplier, carried in the tower list as a 9th field). Shared
TD.priceFor/upgradePrice so the UI shows exactly what the sim charges.

Also: tablet/foldable viewports in the layout matrix (tolerant colour check),
docs (README tower/enemy tables, PROTOCOL shield/stun/pm encodings, NEXT roadmap).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
2026-10-10 21:18:43 +00:00

5.5 KiB

Versus mode: attack vs defend ("play as the Internet")

Requested 2026-10-10. One player defends (builds the maze and turrets, as today); the other attacks (earns credits over time, spends them on spawning packets, upgrades and sabotage). Same board, same rules, one authoritative simulation per room. Decisions made with the user: timed rounds then swap roles; attacker abilities and defender counter-tools; a computer opponent for either side so it can be played alone.

Match structure

  • A match is two rounds with the roles swapped (host picks who starts as what; or random).
  • A round ends when the server falls (attacker wins, the time it took is recorded) or when the round timer runs out (defender wins; default 12 minutes, host can pick 8 / 12 / 16).
  • Match result compares each player's attacking performance: faster fall wins; if neither felled the server, the one who took off more integrity wins; otherwise draw. Show both rounds side by side on the result screen.
  • No pause, no speed control in versus (both would be exploitable). Disconnect: the round freezes up to the 60 s grace; on expiry the other player wins the round.

Attacker economy ("bandwidth")

Rule Starting value (to be tuned with the bot)
Start credits 150
Base income 4 credits/s, rising slowly (+0.02/s per second of the round)
Lifetime bonus every living attacker unit earns cost x 0.004 credits per second alive, capped at 50% of its cost in total
Leak bonus a unit that reaches the server pays back its full cost (and damages integrity)
Unit shop every enemy kind has a buyCost in the sim's ENEMIES table (currently ping 10, worm 6, spam 3, ghost 15, trojan 30, daemon 25, proxy 30, botnet 3, rootkit 300; about 3x the kill reward, to be tuned by the versus balance pass)
Caps at most 250 units alive, 200 staged (performance)

Save up and launch. Units can be bought instantly (spawn) or staged (stage): the price is paid now, the units wait in a convoy and are released together by launch (optionally split over gateways, as a 3 s burst). The defender sees the size of the staged convoy but not its composition. Presets for one tap: Rush (20 pings), Swarm (60 spam), Siege (4 trojans + a healer), Air raid (10 ghosts), Boss (rootkit).

Tech upgrades (permanent for the round, apply to units spawned afterwards): Armor (+1 per level, 5 levels), Speed (+8%), Health (+15%), Regeneration (+1% hp/s), Shield (absorbs damage), Stealth (towers cannot acquire a unit for its first second on the map, 3 levels), Encryption (resists slows). Costs double per level.

Sabotage abilities (credits + cooldown): EMP disables one turret for 6 s; Decoy a harmless packet every turret prioritises for 5 s; Surge all units +40% speed for 6 s; DDoS all turrets fire 40% slower for 4 s (long cooldown).

Defender economy and counter-tools

  • Start credits 250, kill rewards (scaled by unit cost), plus a small trickle (2/s), so the defender can adapt before the first rush.
  • Builds, upgrades and sells as today (walls still can never seal the route).
  • Counter-tools: Scan (reveals stealth for a few seconds and clears EMP on turrets in an area), Patch (instantly re-enable an EMPed turret), Repair (restore 3 integrity, long cooldown, costs credits), Quarantine (freeze every unit on the board for 2 s, very long cooldown).

More suggestions (not decided yet)

  • Gateway choice per spawn on multi-gateway maps; attacker sees a faint heat-map of where the defender's fire is strongest.
  • A short ready/countdown before each round so both players are present; a rematch button that swaps roles.
  • Spectators (third connection, read-only) later.
  • Handicap sliders in the lobby (attacker income, defender start credits) for mixed-skill pairs.
  • Per-map, per-difficulty leaderboard of attack times once the server leaderboard exists.
  • The bot defender is the maze builder from tools/bot.js moved into shared code; the bot attacker is a budgeted spender that reacts to the tower mix (flyers if there is no anti-air, armoured trojans against filters, saves for a convoy).

Implementation plan

  1. Sim (public/js/sim.js, pure, with unit tests): mode: 'versus', attacker state (credits, income, tech levels, staged convoy, cooldowns), commands spawn, stage, launch, tech, ability, defender tools, round timer and result, role checks (a command carries the issuer's role; the sim refuses cross-role commands). Add buyCost to the enemy table. No automatic waves.
  2. Bots shared by browser and server (public/js/bot.js), driven only through the public sim API.
  3. Server (server/room.js, protocol): room option mode: 'coop' | 'versus', role assignment, ready/countdown, rounds and swap, per-role command whitelist, attacker data in snapshots, match result message, bot seat. Update docs/PROTOCOL.md and tests.
  4. Client: lobby (mode, role, limit, bot), role-aware HUD: attacker gets the unit shop (the palette becomes the shop), tech panel, abilities, convoy and Launch, income readout, round timer; defender keeps the build palette plus counter-tools. Phone layout first (the action bar pattern), same canvas renderer.
  5. Balance with bot-versus-bot matches over the maps (like tools/bot.js does for solo): neither side should win more than about 60% of rounds on any map.
  6. e2e: two browsers play a round each way; one bot match.

Depends on the content wave (new enemy kinds become shop items) and on the difficulty/economy constants, so it comes after them.