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
This commit is contained in:
parent
28502984ec
commit
b4ae6cb57d
19 changed files with 1348 additions and 156 deletions
|
|
@ -78,16 +78,20 @@ at a domain root and under a path prefix the proxy strips.
|
|||
Client's first message:
|
||||
|
||||
```
|
||||
{ t:'join', pid, name, room?, map? }
|
||||
{ t:'join', pid, name, room?, map?, difficulty? }
|
||||
```
|
||||
* `pid` `^[A-Za-z0-9_-]{8,40}$` - random, generated by the client, kept in `sessionStorage` (stable across reloads).
|
||||
* `name` any string; server trims, strips control chars, caps at 16 chars, default `"Player"`.
|
||||
* `room` absent -> **create** a room. `map` must be a key of `TD.MAPS` (default `'open'`).
|
||||
* `room` absent -> **create** a room. `map` must be a key of `TD.MAPS` (default `'open'`). `difficulty` must be a key of
|
||||
`TD.DIFFICULTIES` (`'easy'`, `'normal'`, `'hard'`; default `'normal'`, `null` counts as absent), see "Difficulty" below.
|
||||
Server generates a 4 character code from `ABCDEFGHJKLMNPQRSTUVWXYZ23456789`, unique among rooms.
|
||||
* `room` present (`^[A-Za-z0-9]{4}$`, case-insensitive -> upper-cased) -> **join**.
|
||||
* `room` present (`^[A-Za-z0-9]{4}$`, case-insensitive -> upper-cased) -> **join**. `map` and `difficulty` are ignored on a join (not even
|
||||
validated): the joiner gets the room's, in `state.map` / `state.difficulty` of the `joined` message. A reconnect (same `pid`) is a join.
|
||||
|
||||
Failure: `{ t:'error', code, msg }` then the server closes the socket (code 4000+).
|
||||
Codes: `bad_request`, `no_room`, `full` (two *other* pids already hold the slots), `too_many_rooms`, `bad_map`.
|
||||
Codes: `bad_request`, `no_room`, `full` (two *other* pids already hold the slots), `too_many_rooms`, `bad_map`, `bad_difficulty`
|
||||
(a creating join whose `difficulty` is not one of the table's keys: wrong type, `'toString'`, `'__proto__'`, ... all refused, no room is
|
||||
created, the socket closes with 4400; a bad `map` is checked first).
|
||||
|
||||
Success: reply to the joiner
|
||||
|
||||
|
|
@ -121,7 +125,7 @@ pid for the viewer's own entry and an opaque, stable per-room alias for the othe
|
|||
| `{t:'mark', x, y}` | map ping; at most 1 per 400 ms per player; server broadcasts `mark` (below) |
|
||||
| `{t:'rtt', ts}` | latency probe; reply immediately with the same `ts` |
|
||||
| `{t:'sync'}` | ask for a full state resend |
|
||||
| `{t:'newgame', map}` | **host only**: replace the sim with a fresh `new Sim({map})`; resets pause/speed |
|
||||
| `{t:'newgame', map?, difficulty?}` | **host only**: replace the sim with a fresh `new Sim({map, difficulty})`; resets pause/speed. An absent (or `null`) `map` / `difficulty` keeps the room's current one, so a plain `{t:'newgame'}` is "play again" |
|
||||
| `{t:'leave'}` | leave now |
|
||||
|
||||
**Idempotent `upgrade` and `wave`.** Two players who press Upgrade (or Next wave) at the same moment both send the command; without
|
||||
|
|
@ -137,7 +141,8 @@ Command validation is the server's job: `t:'cmd'` must carry a string `c` in the
|
|||
`c`, non-object, etc. count as malformed. A command the sim refuses (`{ok:false, reason}`) gets
|
||||
`{ t:'reject', c, reason, x?, y?, id? }` sent **to the sender only** (echo `x,y`/`id` when present).
|
||||
Successful commands send nothing extra; the effect arrives via `snap`.
|
||||
`newgame` from a non-host -> `reject` with `reason:'not_host'`; `newgame` with a bad map -> `reject` `bad_map`.
|
||||
`newgame` from a non-host -> `reject` with `reason:'not_host'`; `newgame` with a bad map -> `reject` `bad_map`; with a bad difficulty
|
||||
-> `reject` `bad_difficulty` (checked in the order not_host, bad_map, bad_difficulty; a rejected `newgame` changes nothing and sends no `state`).
|
||||
|
||||
## Client behaviour that the protocol relies on
|
||||
|
||||
|
|
@ -167,6 +172,9 @@ Successful commands send nothing extra; the effect arrives via `snap`.
|
|||
{ t:'reject', c, reason, ... }
|
||||
{ t:'error', code, msg }
|
||||
```
|
||||
* `state.difficulty` (also in the `joined` message) is the room's difficulty id. It is a field of `fullState()`, added next to `map`,
|
||||
`rev`, `towers`, `winWave` and `maxLives`; an older server sends none and a client then assumes `'normal'`. The per-tick `snap` does
|
||||
not repeat it: it cannot change without a `state` message (only the host's `newgame` changes it, and that sends one).
|
||||
* `seq` increments by 1 per snapshot per room.
|
||||
* Snapshots are sent every `1000/snapshotHz` ms **whether or not** the sim advanced (paused rooms still send, so
|
||||
cursors keep moving) but only to online players, and only if at least one player is online.
|
||||
|
|
@ -183,6 +191,21 @@ Successful commands send nothing extra; the effect arrives via `snap`.
|
|||
* Because WebSocket is reliable and ordered, `tw` deltas cannot be lost; `snap.rev` lets a client detect a
|
||||
bug/desync (`rev` differs from the `rev` it last applied and no `tw` came along) and ask for `sync`.
|
||||
|
||||
## Difficulty
|
||||
|
||||
`TD.DIFFICULTIES` (`sim.js`) has one row per difficulty, `{ id, name, gold, lives, hp, reward }`, every number a multiplier on the normal
|
||||
game; `TD.DIFFICULTY_ORDER` is `['easy', 'normal', 'hard']` (append-only: the ids are on the wire). `new Sim({ map, difficulty })`:
|
||||
|
||||
* `gold`, `lives`: the starting credits and integrity are `START_GOLD` / `START_LIVES` times it (rounded, integrity at least 1;
|
||||
`state.maxLives` follows). An explicit `gold` / `lives` option of the Sim (tests, the balance bot) is used as given.
|
||||
* `hp`: the hit points of every enemy **and its shield**, so the snapshot's `hp + shield` / `maxhp + maxShield` encoding (the client splits
|
||||
the two by the kind's base ratio) stays right.
|
||||
* `reward`: what a kill pays (at least 1). The wave clear bonus and the tower prices do not change.
|
||||
* An unknown value in `new Sim` is `'normal'`; the server refuses it (`bad_difficulty`) instead.
|
||||
|
||||
Normal is all 1: it plays the base tables of `sim.js` as they are (those tables were retuned in the wave 4 balance pass, see `docs/BALANCE.md`). The room's difficulty is fixed for a game: the host picks
|
||||
it when creating the room (`join.difficulty`) or when starting a new game (`newgame.difficulty`).
|
||||
|
||||
## Tick loop
|
||||
|
||||
Fixed step `TD.STEP` (1/60 s) with an accumulator driven by `process.hrtime.bigint()`; real time elapsed is
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue