towerdef/docs/NEXT.md
Claude b4ae6cb57d Difficulty picker (Easy/Normal/Hard) and a balance pass
Difficulty:
- TD.DIFFICULTIES (starting credits, lives, enemy hp/shield, kill reward), validated
  create-room / newgame option, state carries it; solo menu picker and co-op lobby
  picker (44px segmented control, reachable on every layout), HUD/room/end-screen
  labels, best-wave record per map AND difficulty (Normal keeps the legacy key),
  Play again keeps the running game's difficulty for host and guest

Balance (12 bot runs, deterministic, 48/48 games replay identically in QA):
- Normal ~71% bot wins at wave 30 (was 94%), Easy 100%, Hard 25% on open
- credits tamed: reward growth 3% -> 2% per wave, clear bonus 10+2n -> 10+n, hp scaling
  eased, Rootkit pays 60 (was 100) but is tougher, flyers slower; unspent credits at
  wave 30: 1309 -> 335
- IDS Sniper is now a slow heavy hitter (essential, no longer sufficient: IDS-only
  dies by wave 7); Mortar, Arc and Filter buffed
- Orbital Uplink price step per owned unit 30% (buy and upgrade)
- remaining imbalances documented in docs/BALANCE.md

Tests: difficulty (19) and balance (8) unit suites, 14-difficulty e2e, layout matrix
reachability of the picker. 156 unit tests, 17 e2e scenarios.

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

9.4 KiB

Where to pick up (written 2026-10-09)

Netwall is playable and pushed: solo (desktop + phone), two-player co-op through the Node server, music, PWA, deploy docs. Development was paused on purpose before the fix stage. This file is the entry point for the next session.

State of the repo (2026-10-11)

Area State
public/js/sim.js Shared rules: 7 maps, 9 towers (Sandbox, Load Balancer, 4-level Orbital Uplink with escalating prices), 9 enemy kinds, Easy/Normal/Hard. Balance tuned once (Normal ~71% bot wins, see docs/BALANCE.md); remaining imbalances are listed there.
server/ Adversarially reviewed (pid leak, room flood, XFF, ...) and proxy-tested against real nginx with Proxy Manager's config. Co-op robustness fixed (stalls, half-open sockets, idempotent commands).
public/ client Phone-first layout (action bars, scrollable palette, pinned overlay footers), touch precision (nothing commits on pointerdown, nudge arrows), a11y/audio fixes, difficulty picker. Tested across 33 viewports incl. tablets and foldables (emulated).
e2e/ npm run e2e: 17 scenarios (smoke, touch, touch precision, select/sell, info-panel stability, UI states, a11y, audio, content gallery, co-op chaos, session UI, Uplink price, difficulty, 33-layout matrix ~8 min). Timing checks can flake on a loaded machine: rerun a scenario alone before concluding anything.
tools/bot.js Headless defender bot (dev tool; deterministic). Does not build Sandbox / Load Balancer / Uplink.
Deploy docs/DEPLOY.md, deploy/netwall.service, README setup guide; proxy behaviour verified against nginx 1.26 with Proxy Manager v2.16's rendered config (not the NPM app itself, not a real LXC).

npm test = 156 passing.

Fixed since this was written

  • 2026-10-10: selecting a placed Firewall no longer throws (walls can be sold again; e2e scenario 06-select-sell).

Roadmap (decided with the user, 2026-10-10)

The user playtested ("fun, mostly usable") and chose: maze stays strong (no wall price rule), an Easy/Normal/Hard picker, and these features after the fixes: more maps, new towers and enemies, server leaderboard, room list / quick match. Later requests: an endgame tower (Orbital Uplink, in the sim already), attack-vs-defend multiplayer (docs/VERSUS.md), and a check that the layout holds on tablets and foldables.

Wave Content State
1 Phone panels/layout + touch precision, proxy/server doc fixes, QA done 2026-10-10
2 Co-op robustness (stalled-render tower loss, half-open sockets, idempotent upgrade/wave, restart message), audio + keyboard + a11y done 2026-10-10 (QA passed)
3 New enemies (Daemon healer, Proxy shielded, Botnet swarm) and towers (Sandbox stun, Load Balancer buff), glyphs/shapes, gallery e2e; Orbital Uplink (4 levels, priced 1500 + 25% per owned, upgrades scale equally; ); 4 new maps done 2026-10-10 (QA passed)
4 Difficulty picker (Easy/Normal/Hard) + ONE time-boxed balance pass (IDS no longer sufficient, credit snowball tamed, Mortar/Arc/Filter buffed, flyers slower); Uplink price step set to 30% per owned done 2026-10-11 (QA passed)
5 Attack-vs-defend versus mode, bots for both sides design in docs/VERSUS.md, workflow drafted
6 Server leaderboard (needs StateDirectory=netwall + DATA_DIR; solo scores are client-reported) and an opt-in public room list after 5
any Fold/tablet real-device check; open items below

Open items from wave 2 QA (all minor)

  • The loser of a simultaneous Sell sees a red toast ("That tower no longer exists"); the loser of a simultaneous Keep going sees "Nothing to continue". Silence them like the stale upgrade/wave.
  • A host who closes the tab (no Leave) stays host for the whole grace period (60 s), so the guest on the end screen waits that long for Play again.
  • room.js checks the 1500-unit 'busy' cap before the sim's stale check; main.js has no wording for 'busy'.
  • Any no_room after a successful join says "The server restarted..." even if the room merely expired (a lone sleeping phone); the tests pin the string.
  • Tablet/fold polish: the co-op top bar wraps to two rows at 690x830; at 1180x820 the board letterboxes (~249 px dead band); the Players panel (Invite, Leave) is below the fold on stacked layouts; "Waiting for the host" sits flush under the Menu button.
  • Test strength: the e2e 'stall' scenario passes even without the _carryTw fix (the sync backstop heals it; unit tests pin it); the audio fade-supersede guard is not pinned by 09-audio.
  • If room codes ever get longer than 4 characters, boot's regex and the inCode maxlength must change together.

Suggested order of work

  1. The wall bug above, then the other confirmed high/medium client bugs:
    • code-2: the info panel is rebuilt with innerHTML on every view.rev change, so an Upgrade/Sell/Target tap that lands during a rebuild is lost (worse in co-op, where the partner's actions bump rev). Update in place or rebuild only when this tower's signature changes.
    • coop-1 / code-1: RemoteController keeps only the last 10 snapshots; a render stall of ~0.5 to 1 s drops snapshots that carry tw (tower list) before they are displayed, so the partner's new towers are lost until a resync. Never discard an entry whose tw has not been applied (or apply tw to the mirror on arrival and only delay the drawn list).
    • touch-1, touch-2: with a wall armed, the first finger of a pinch builds a wall immediately; with a turret armed it moves the pending placement. Defer the first placement to pointerup/first real move and cancel on a second pointer.
    • Phone layout: after tapping a tower the Upgrade/Sell/Target buttons are below the fold (visual-2, touch-3); on small phones the first-run Help has no visible "Got it" (visual-3) and the co-op room code and Invite button are not visible while waiting for a partner (visual-4, touch-8). Likely fix: show the selected-tower panel as a bottom sheet over the palette, put room code/invite in the top bar or a toast, make overlays scroll with a sticky button row.
    • coop-2: after a half-open connection (Wi-Fi/cell switch) the UI looks alive but frozen for 47 to 65 s; show the reconnect overlay as soon as the watchdog fires and open a new socket without waiting for the old one to close.
  2. Co-op correctness: simultaneous Upgrade / Next Wave from both players are applied twice (coop-5: make upgrade idempotent, e.g. send the expected level; ignore a wave command within ~1 s of another), host-leaves-while-end-screen (coop-3, code-11), failed join from the menu kills the live game (coop-4), controller races (code-3, code-4).
  3. Smaller UX/a11y: reduced-motion hides every toast (touch-5, visual-6), Space held launches ~20 waves (code-6: ignore e.repeat), co-op music/stinger after Play again (code-5, code-7, code-12), touch target sizes, safe-area double padding, contrast, colour-only enemy legend, pause not obvious.
  4. Proxy docs/behaviour (proxy-* in the findings): 403 when the public URL has a non-default port (Origin vs Host port handling), DEPLOY.md claims NPM can send X-Forwarded-Host from the Advanced tab (it cannot), NPM's default read timeout is 90 s not 60 s, service worker serves nginx's 502 page instead of the cached app, path-prefix instructions for NPM.
  5. Balance (docs/BALANCE.md): the baseline shows the game is currently too easy and IDS Sniper dominates.
  6. Real-world checks that were never possible in the sandbox: a real phone (iOS Safari audio unlock, safe areas, wake lock), real nginx Proxy Manager with Let's Encrypt, a Proxmox LXC with the systemd unit.

Findings marked UNVERIFIED were reported with a reproduction but not yet independently re-checked (the verification stage was stopped); re-run the repro from docs/review-2026-10-09/repro-scripts.tgz before fixing.

Decisions waiting for the user

  • Maze exploit. A long serpentine of cheap walls (5 credits) makes routes about 5 to 6 times longer than the direct path. Options: escalating wall price, a wall cap, or faster/tougher waves. See docs/BALANCE.md.
  • Room codes are 4 characters (about 1M); a stranger could guess an open room. Options: 6 characters, an optional room password, per-IP rate limit on failed joins.
  • Music size. battle/boss/menu are 3 to 8 MB each and downloaded whole on first use; fine on Wi-Fi, heavy on mobile data. Could re-encode to mono ~48 kbps.

Dev environment (what the session used, none of it is in the repo)

  • The sandbox had no Node and no root. The user's machine can install anything: apt install nodejs npm, npm install, npx playwright-core install chromium-headless-shell (plus npx playwright-core install-deps as root) and npm run e2e is all that is needed.
  • The review pipeline (5 reviewers, a verifier per finding, one fixer, a final QA) was a Workflow script; a copy is in docs/review-2026-10-09/phase2-workflow.js and can be re-run (re-point its scratch paths) to verify the UNVERIFIED findings and to run the fix stage.
  • Conventions: public/js/sim.js must stay pure and DOM-free (it runs in the browser for solo and in Node for co-op); ws is the only runtime dependency; the client uses only relative URLs (works under a proxy path prefix); test/ may only hold real test files (plain node --test runs everything there).
  • Git: commit and push at milestones is pre-authorised for this project.