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
|
|
@ -23,7 +23,7 @@ const PID_RE = /^[A-Za-z0-9_-]{8,40}$/;
|
|||
const ROOM_RE = /^[A-Za-z0-9]{4}$/;
|
||||
const NAME_STRIP = new RegExp('[\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2066-\\u2069\\ufeff]', 'g');
|
||||
// Close codes for a failed join (the 'error' message carries the machine-readable code).
|
||||
const JOIN_CLOSE = { bad_request: 4400, bad_map: 4400, no_room: 4404, full: 4409, too_many_rooms: 4503 };
|
||||
const JOIN_CLOSE = { bad_request: 4400, bad_map: 4400, bad_difficulty: 4400, no_room: 4404, full: 4409, too_many_rooms: 4503 };
|
||||
|
||||
const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
||||
const noop = () => {};
|
||||
|
|
@ -202,7 +202,12 @@ async function createServer(userOpts) {
|
|||
if (typeof msg.map !== 'string' || !hasOwn(TD.MAPS, msg.map)) return failJoin(ctx, 'bad_map', 'unknown map');
|
||||
map = msg.map;
|
||||
}
|
||||
room = manager.create(map);
|
||||
let difficulty = TD.DEFAULT_DIFFICULTY; // like the map, only a creating join carries it (a join to a room takes the room's)
|
||||
if (msg.difficulty !== undefined && msg.difficulty !== null) {
|
||||
if (!TD.isDifficulty(msg.difficulty)) return failJoin(ctx, 'bad_difficulty', 'unknown difficulty');
|
||||
difficulty = msg.difficulty;
|
||||
}
|
||||
room = manager.create(map, difficulty);
|
||||
if (!room) return failJoin(ctx, 'too_many_rooms', 'the server has reached its room limit');
|
||||
why = 'created';
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ function sendRaw(conn, str) {
|
|||
}
|
||||
|
||||
class Room {
|
||||
constructor(manager, code, mapId) {
|
||||
constructor(manager, code, mapId, difficulty) {
|
||||
this.manager = manager;
|
||||
this.code = code;
|
||||
this.sim = new TD.Sim({ map: mapId });
|
||||
this.sim = new TD.Sim({ map: mapId, difficulty });
|
||||
this.speed = 1;
|
||||
this.paused = false;
|
||||
this.seq = 0;
|
||||
|
|
@ -248,10 +248,12 @@ class Room {
|
|||
if (!p.host) { this.reject(p, 'newgame', 'not_host'); return true; }
|
||||
const map = msg.map === undefined || msg.map === null ? this.sim.mapId : msg.map;
|
||||
if (typeof map !== 'string' || !hasOwn(TD.MAPS, map)) { this.reject(p, 'newgame', 'bad_map'); return true; }
|
||||
this.sim = new TD.Sim({ map });
|
||||
const difficulty = msg.difficulty === undefined || msg.difficulty === null ? this.sim.difficulty : msg.difficulty; // absent: keep the room's
|
||||
if (!TD.isDifficulty(difficulty)) { this.reject(p, 'newgame', 'bad_difficulty'); return true; }
|
||||
this.sim = new TD.Sim({ map, difficulty });
|
||||
this.speed = 1; this.paused = false; this.acc = 0;
|
||||
this.lastSentRev = this.sim.rev; // the 'state' below carries the tower list
|
||||
this.log('new game on map ' + map + ' started by ' + p.name);
|
||||
this.log('new game on map ' + map + ' (' + difficulty + ') started by ' + p.name);
|
||||
this.broadcast(this.stateMsg({ newgame: true }));
|
||||
return true;
|
||||
}
|
||||
|
|
@ -363,7 +365,7 @@ class RoomManager {
|
|||
// null when the room limit is reached. A full table first drops a room that nobody is online in (it is only
|
||||
// being held for its grace period): otherwise one client could fill all slots for a minute at a time by
|
||||
// creating rooms and closing the sockets, which costs nothing and is not limited by any per-IP socket cap.
|
||||
create(mapId) {
|
||||
create(mapId, difficulty) {
|
||||
if (this.closed) return null;
|
||||
if (this.rooms.size >= this.maxRooms) {
|
||||
const victim = this.abandonedRoom();
|
||||
|
|
@ -372,9 +374,9 @@ class RoomManager {
|
|||
}
|
||||
const code = this.newCode();
|
||||
if (!code) return null;
|
||||
const room = new Room(this, code, mapId);
|
||||
const room = new Room(this, code, mapId, difficulty);
|
||||
this.rooms.set(code, room);
|
||||
room.log('created (map ' + mapId + '); ' + this.rooms.size + ' room(s)');
|
||||
room.log('created (map ' + mapId + ', ' + room.sim.difficulty + '); ' + this.rooms.size + ' room(s)');
|
||||
this.startLoop();
|
||||
return room;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue