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
|
|
@ -5,13 +5,14 @@
|
|||
* ctrl.kind 'local' | 'remote'
|
||||
* ctrl.board TD.Board (own for local, a mirror for remote: used for route previews)
|
||||
* ctrl.view render state, refreshed by ctrl.update(nowMs):
|
||||
* gold lives maxLives wave state auto nextWaveIn kills winWave rev queued speed paused
|
||||
* gold lives maxLives wave state auto nextWaveIn kills winWave rev queued speed paused difficulty
|
||||
* towers[{id,type,x,y,level,mode,spent,owner,tgt,kills}]
|
||||
* monsters[{id,kind,x,y,hp,maxhp,slow,air}] bullets[{id,k,x,y}] cursors[{slot,x,y}]
|
||||
* ctrl.send(cmd) place / sell / upgrade / target / wave / auto / continue. An upgrade carries the level the player saw (lv)
|
||||
* and a wave carries the wave it expects to start (n), filled in here from the view: a second player who
|
||||
* pressed the same button at the same moment is refused as 'stale' (see sim.js) instead of paying twice.
|
||||
* ctrl.ctl(c, v) 'pause' | 'speed'
|
||||
* ctrl.difficulty the game's difficulty id (TD.DIFFICULTIES); `newGame(map, difficulty)` keeps the current one when none is given
|
||||
* ctrl.preview(x,y,routes) would a block there be legal, and what does it do to the route?
|
||||
* events ctrl.on('events', list) | 'reject' | 'mark' | 'players' | 'status' | 'joined' | 'newgame' | 'fatal' | 'rtt'
|
||||
*/
|
||||
|
|
@ -55,18 +56,19 @@
|
|||
super();
|
||||
this.kind = 'local';
|
||||
this.mapId = (opts && opts.map) || 'open';
|
||||
this.difficulty = TD.difficultyId(opts && opts.difficulty);
|
||||
this.speed = 1; this.paused = false;
|
||||
this.players = [{ slot: 0, name: 'You', online: true, host: true }];
|
||||
this.you = { slot: 0, host: true };
|
||||
this._fresh();
|
||||
}
|
||||
_fresh() {
|
||||
this.sim = new TD.Sim({ map: this.mapId });
|
||||
this.sim = new TD.Sim({ map: this.mapId, difficulty: this.difficulty });
|
||||
this.board = this.sim.board;
|
||||
this.acc = 0; this.last = 0;
|
||||
this.view = {
|
||||
gold: 0, lives: 0, maxLives: 0, wave: 0, state: 'playing', auto: false, nextWaveIn: -1, kills: 0, winWave: 0, rev: 0, queued: 0,
|
||||
speed: this.speed, paused: this.paused, time: 0,
|
||||
speed: this.speed, paused: this.paused, time: 0, difficulty: this.difficulty,
|
||||
towers: this.sim.towers, monsters: this.sim.monsters, bullets: this.sim.bullets, cursors: [],
|
||||
};
|
||||
this._sync();
|
||||
|
|
@ -76,7 +78,7 @@
|
|||
v.gold = s.gold; v.lives = s.lives; v.maxLives = s.maxLives; v.wave = s.wave; v.state = s.state;
|
||||
v.auto = s.autoWaves; v.nextWaveIn = s.autoWaves ? s.nextWaveIn : -1; v.kills = s.kills;
|
||||
v.winWave = isFinite(s.winWave) ? s.winWave : 0; v.rev = s.rev; v.queued = s.spawnQ.length;
|
||||
v.speed = this.speed; v.paused = this.paused; v.time = s.time;
|
||||
v.speed = this.speed; v.paused = this.paused; v.time = s.time; v.difficulty = s.difficulty;
|
||||
v.towers = s.towers; v.monsters = s.monsters; v.bullets = s.bullets;
|
||||
}
|
||||
update(now) {
|
||||
|
|
@ -102,7 +104,12 @@
|
|||
this._sync();
|
||||
}
|
||||
preview(x, y, routes) { return this.sim.preview(x, y, routes); }
|
||||
newGame(map) { if (map) this.mapId = map; this._fresh(); this.emit('newgame'); }
|
||||
// `difficulty` absent: the same one again ("Play again"); an unknown one is normal (the sim's rule)
|
||||
newGame(map, difficulty) {
|
||||
if (map) this.mapId = map;
|
||||
if (difficulty !== undefined && difficulty !== null) this.difficulty = TD.difficultyId(difficulty);
|
||||
this._fresh(); this.emit('newgame');
|
||||
}
|
||||
sendCursor() {}
|
||||
sendMark(x, y) { this.emit('mark', { slot: 0, x, y }); }
|
||||
requestSync() {}
|
||||
|
|
@ -118,6 +125,7 @@
|
|||
this.pid = opts.pid; this.name = opts.name || 'Player';
|
||||
this.room = opts.room || null; // null => create a room on first connect
|
||||
this.mapId = opts.map || 'open';
|
||||
this.difficulty = TD.difficultyId(opts.difficulty); // what a CREATING join asks for; afterwards whatever the server's state says
|
||||
this.status = 'idle'; // idle | connecting | joined | reconnecting | closed
|
||||
this.ws = null; this.players = []; this.you = null; this.board = null;
|
||||
this.buf = []; this.delay = 120;
|
||||
|
|
@ -132,7 +140,7 @@
|
|||
this.speed = 1; this.paused = false;
|
||||
this.view = {
|
||||
gold: 0, lives: 0, maxLives: 0, wave: 0, state: 'playing', auto: false, nextWaveIn: -1, kills: 0, winWave: 0, rev: 0, queued: 0,
|
||||
speed: 1, paused: false, time: 0, towers: [], monsters: [], bullets: [], cursors: [],
|
||||
speed: 1, paused: false, time: 0, difficulty: this.difficulty, towers: [], monsters: [], bullets: [], cursors: [],
|
||||
};
|
||||
this._onVis = () => { if (!document.hidden) this._wake(); };
|
||||
document.addEventListener('visibilitychange', this._onVis);
|
||||
|
|
@ -154,7 +162,7 @@
|
|||
this.ws = ws;
|
||||
ws.onopen = () => {
|
||||
const j = { t: 'join', pid: this.pid, name: this.name };
|
||||
if (this.room) j.room = this.room; else j.map = this.mapId;
|
||||
if (this.room) j.room = this.room; else { j.map = this.mapId; j.difficulty = this.difficulty; } // only a creating join carries them: a joiner takes the room's
|
||||
this._send(j);
|
||||
};
|
||||
ws.onmessage = (e) => { this.lastMsg = performance.now(); this._onMsg(e.data); };
|
||||
|
|
@ -260,7 +268,7 @@
|
|||
this._die('restarted', this.everJoined ? 'The server restarted, your game was lost.' : 'That co-op game is gone: the server restarted or the room timed out.');
|
||||
break;
|
||||
}
|
||||
const msgs = { no_room: 'That room does not exist (any more).', full: 'That room already has two players.', bad_request: 'The server did not understand the request.', too_many_rooms: 'The server is full right now. Try again in a minute.', bad_map: 'Unknown map.' };
|
||||
const msgs = { no_room: 'That room does not exist (any more).', full: 'That room already has two players.', bad_request: 'The server did not understand the request.', too_many_rooms: 'The server is full right now. Try again in a minute.', bad_map: 'Unknown map.', bad_difficulty: 'Unknown difficulty.' };
|
||||
this._die(m.code || 'error', msgs[m.code] || m.msg || 'Server error.');
|
||||
break;
|
||||
}
|
||||
|
|
@ -282,6 +290,8 @@
|
|||
this._setTowers(state.towers);
|
||||
this.rev = this.recvRev = state.rev;
|
||||
this.maxLives = state.maxLives; this.winWave = state.winWave;
|
||||
this.difficulty = TD.isDifficulty(state.difficulty) ? state.difficulty : 'normal'; // (a server from before difficulties sends none)
|
||||
this.view.difficulty = this.difficulty;
|
||||
this.buf.length = 0; this._carryTw = null; this.monCache.clear(); this.bulCache.clear();
|
||||
if (snap) this._push(snap, true);
|
||||
}
|
||||
|
|
@ -384,7 +394,7 @@
|
|||
for (const m of this.view.monsters) if (!m.air) reserved.add(Math.floor(m.y) * this.board.cols + Math.floor(m.x));
|
||||
return this.board.trial(x, y, reserved, null, routes);
|
||||
}
|
||||
newGame(map) { this._send({ t: 'newgame', map }); }
|
||||
newGame(map, difficulty) { this._send({ t: 'newgame', map, difficulty }); } // (JSON drops an undefined difficulty: the server keeps the room's)
|
||||
// Moves are throttled to one per 70 ms. A clear (x === null) or `force` always goes out, so the final position / the
|
||||
// "cursor gone" message of a touch is never swallowed by the throttle (touch-9).
|
||||
sendCursor(x, y, force) {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
bounds: 'Out of bounds', obstacle: 'That node is dead. Pick another cell', occupied: 'Something is already there', spawn: "Can't build on a gateway",
|
||||
core: "Can't build on the server", monster: 'A packet is in the way', blocks: 'That would seal the route. Leave a path!', gold: 'Not enough credits',
|
||||
over: 'The game is over', no_tower: 'That tower no longer exists', max: 'Already at max level', not_host: 'Only the host can do that',
|
||||
bad_map: 'Unknown map', bad_type: 'Unknown tower', bad_cmd: 'Invalid command', not_won: 'Nothing to continue',
|
||||
bad_map: 'Unknown map', bad_difficulty: 'Unknown difficulty', bad_type: 'Unknown tower', bad_cmd: 'Invalid command', not_won: 'Nothing to continue',
|
||||
};
|
||||
const MODE_NAMES = { first: 'First', last: 'Last', strong: 'Strongest', close: 'Closest' };
|
||||
|
||||
|
|
@ -43,6 +43,7 @@
|
|||
const app = {
|
||||
ctrl: null, renderer: null, screen: 'menu', inGame: false,
|
||||
mapId: store.get('nw.map', 'open'),
|
||||
difficulty: 'normal', // the player's pick for the NEXT game (the running game's is ctrl.view.difficulty); loaded below
|
||||
selType: null, selTower: 0,
|
||||
hover: null, pending: null, preview: null, valid: true, previewDirty: true, lastPreviewAt: 0,
|
||||
zoomed: false, last: {}, names: {}, started: false, lastBossCheck: 0, bossMusic: false,
|
||||
|
|
@ -54,6 +55,7 @@
|
|||
const renderer = new NW.Renderer(canvas);
|
||||
app.renderer = renderer;
|
||||
if (!TD.MAPS[app.mapId]) app.mapId = 'open';
|
||||
{ const d = store.get('nw.difficulty', 'normal'); app.difficulty = TD.isDifficulty(d) ? d : 'normal'; } // (a stored value that is not a difficulty any more is normal)
|
||||
|
||||
// ------------------------------------------------------------------ small UI helpers
|
||||
let lastToast = '', lastToastAt = 0;
|
||||
|
|
@ -149,6 +151,7 @@
|
|||
ctrl.on('newgame', () => {
|
||||
resetSelection(); app.endShown = false; app.last.state = 'playing'; adoptBoard(); $('end').hidden = true;
|
||||
app.bossMusic = false; if (app.inGame) Audio.music('battle'); // a new game starts its music on every client, not only on the one that pressed Play again (code-5)
|
||||
if (ctrl.kind === 'remote') renderPlayers(); // (the room header names the difficulty, which a new game may have changed)
|
||||
});
|
||||
adoptBoard(true);
|
||||
}
|
||||
|
|
@ -171,7 +174,7 @@
|
|||
cancelPending(); // a co-op join that is still connecting must not take this game over (code-3)
|
||||
leaveRemote(true);
|
||||
app.mapId = mapId; store.set('nw.map', mapId);
|
||||
const c = new NW.LocalController({ map: mapId });
|
||||
const c = new NW.LocalController({ map: mapId, difficulty: app.difficulty });
|
||||
useController(c);
|
||||
app.inGame = true; app.started = true; app.endShown = false; app.last = {};
|
||||
resetSelection(); setScreen('playing'); showOverlay(null);
|
||||
|
|
@ -428,14 +431,15 @@
|
|||
|
||||
function renderWavePanel(view) {
|
||||
const n = view.wave + 1;
|
||||
const key = n + ':' + view.state;
|
||||
const dif = viewDifficulty(view);
|
||||
const key = n + ':' + view.state + ':' + dif;
|
||||
if (app.last.waveKey === key) return;
|
||||
app.last.waveKey = key;
|
||||
const box = $('nextwave');
|
||||
if (view.state !== 'playing') { box.textContent = ''; return; }
|
||||
if (n % 10 === 9 || n % 10 === 0) Audio.preload('boss'); // the boss theme is fetched a wave or two ahead, so it starts with the boss instead of seconds later (code-12)
|
||||
const sum = TD.waveSummary(n);
|
||||
let html = '<div class="panel"><h4>Next · wave ' + n + '</h4><div class="wv">';
|
||||
let html = '<div class="panel"><h4>Next · wave ' + n + '<span class="dtag" data-d="' + dif + '" title="Difficulty">' + esc(diffName(dif)) + '</span></h4><div class="wv">';
|
||||
let air = false;
|
||||
for (const g of sum) {
|
||||
const d = TD.ENEMIES[g.k];
|
||||
|
|
@ -467,7 +471,8 @@
|
|||
const ctrl = app.ctrl, box = $('players');
|
||||
if (!ctrl || ctrl.kind !== 'remote') { box.hidden = true; return; }
|
||||
box.hidden = false;
|
||||
let html = '<div class="panel"><h4>Room ' + esc(ctrl.room || '') + ' <span id="plPing" class="muted"></span></h4>'; // (every server string is escaped before it goes into HTML, code-28)
|
||||
const dif = viewDifficulty(ctrl.view);
|
||||
let html = '<div class="panel"><h4>Room ' + esc(ctrl.room || '') + '<span class="dtag" data-d="' + dif + '" title="Difficulty">' + esc(diffName(dif)) + '</span> <span id="plPing" class="muted"></span></h4>'; // (every server string is escaped before it goes into HTML, code-28)
|
||||
for (const p of ctrl.players) {
|
||||
html += '<div class="pl"><span class="dot" style="background:' + slotColor(p.slot) + '"></span><span class="pn"></span>' +
|
||||
(ctrl.you && p.pid === ctrl.you.pid ? '<span class="you">(you)</span>' : '') + (p.host ? '<span class="you">host</span>' : '') + (p.online ? '' : '<span class="off">offline</span>') + '</div>';
|
||||
|
|
@ -551,11 +556,12 @@
|
|||
const won = view.state === 'won';
|
||||
$('endTitle').textContent = won ? 'Server secured!' : 'Breach!';
|
||||
$('endTitle').style.color = won ? 'var(--green)' : 'var(--red)';
|
||||
const best = store.get('nw.best.' + ctrl.board.mapId, 0);
|
||||
if (view.wave > best) store.set('nw.best.' + ctrl.board.mapId, view.wave); // a win counts too (code-25)
|
||||
const dif = viewDifficulty(view), bk = bestKey(ctrl.board.mapId, dif);
|
||||
const best = +store.get(bk, 0) || 0;
|
||||
if (view.wave > best) store.set(bk, view.wave); // a win counts too (code-25)
|
||||
$('endText').textContent = won ? 'You held the line through wave ' + view.wave + '. Every packet was filtered.' : 'The server fell on wave ' + view.wave + '.';
|
||||
const walls = view.towers.filter((t) => t.type === 'wall').length;
|
||||
const rows = [['Wave', view.wave], ['Packets killed', view.kills], ['Turrets', view.towers.length - walls], ['Firewalls', walls], ['Integrity left', view.lives], ['Best (map)', Math.max(best, view.wave)]];
|
||||
const rows = [['Wave', view.wave], ['Packets killed', view.kills], ['Turrets', view.towers.length - walls], ['Firewalls', walls], ['Integrity left', view.lives], ['Difficulty', diffName(dif)], ['Best on ' + diffName(dif), Math.max(best, view.wave)]];
|
||||
$('endStats').innerHTML = rows.map((r) => '<div><span>' + r[0] + '</span><b>' + esc(r[1]) + '</b></div>').join(''); // (in co-op these numbers come from the server)
|
||||
syncEndButtons();
|
||||
$('btnContinue').hidden = !won;
|
||||
|
|
@ -958,6 +964,55 @@
|
|||
$('pausedTag').addEventListener('click', () => { Audio.sfx('click'); app.ctrl.ctl('pause', false); });
|
||||
$('netChip').addEventListener('click', () => { if (app.ctrl && app.ctrl.kind === 'remote') { Audio.sfx('click'); invite(); } }); // room code chip: tap to invite
|
||||
|
||||
// ------------------------------------------------------------------ difficulty
|
||||
// The picker (menu, and the co-op lobby for the host) sets app.difficulty, the pick for the NEXT game, and remembers it. A game that is
|
||||
// running keeps its own (view.difficulty): Play again repeats that one, and every screen about the running game shows it.
|
||||
const diffName = (id) => (TD.DIFFICULTIES[id] ? TD.DIFFICULTIES[id].name : String(id));
|
||||
const viewDifficulty = (view) => (view && TD.isDifficulty(view.difficulty) ? view.difficulty : 'normal');
|
||||
// The best wave per map AND difficulty. Normal keeps the key the game always used (nw.best.<map>), so every record from before
|
||||
// difficulties existed is simply the normal one and nothing is lost or migrated; easy and hard get their own suffix.
|
||||
const bestKey = (map, dif) => 'nw.best.' + map + (dif === 'normal' ? '' : '.' + dif);
|
||||
// What a difficulty changes, worded from the table (so a retune cannot leave this text wrong).
|
||||
function diffSummary(id) {
|
||||
const d = TD.DIFFICULTIES[id], out = [];
|
||||
if (!d) return '';
|
||||
const pct = (m) => Math.round(Math.abs(m - 1) * 100) + '%';
|
||||
if (d.gold !== 1) out.push(pct(d.gold) + (d.gold > 1 ? ' more' : ' fewer') + ' starting credits');
|
||||
if (d.lives !== 1) out.push(pct(d.lives) + (d.lives > 1 ? ' more' : ' less') + ' integrity');
|
||||
if (d.hp !== 1) out.push('packets ' + pct(d.hp) + (d.hp < 1 ? ' weaker' : ' tougher'));
|
||||
if (d.reward !== 1) out.push('kills pay ' + pct(d.reward) + (d.reward > 1 ? ' more' : ' less'));
|
||||
return out.length ? out.join(', ') : 'The standard game.';
|
||||
}
|
||||
const diffBoxes = () => [$('diffPick'), $('lobbyDiff')].filter(Boolean);
|
||||
function buildDiffPickers() {
|
||||
for (const box of diffBoxes()) {
|
||||
box.textContent = '';
|
||||
for (const id of TD.DIFFICULTY_ORDER) {
|
||||
const b = document.createElement('button');
|
||||
b.type = 'button'; b.dataset.diff = id; b.setAttribute('role', 'radio');
|
||||
b.textContent = diffName(id);
|
||||
b.title = diffSummary(id);
|
||||
b.addEventListener('click', () => { Audio.sfx('click'); chooseDifficulty(id); });
|
||||
box.appendChild(b);
|
||||
}
|
||||
}
|
||||
chooseDifficulty(app.difficulty, true);
|
||||
}
|
||||
function chooseDifficulty(id, silent) {
|
||||
if (!TD.isDifficulty(id)) id = 'normal';
|
||||
app.difficulty = id;
|
||||
if (!silent) store.set('nw.difficulty', id);
|
||||
for (const box of diffBoxes()) for (const b of box.children) b.setAttribute('aria-checked', b.dataset.diff === id ? 'true' : 'false');
|
||||
renderDiffNote();
|
||||
}
|
||||
// One line under the picker: what the picked difficulty does; while a game is running, which one that game is on.
|
||||
function renderDiffNote() {
|
||||
const n = $('diffNote'); if (!n) return;
|
||||
const cur = app.inGame && app.ctrl ? viewDifficulty(app.ctrl.view) : null;
|
||||
n.className = 'diffnote' + (cur ? ' live' : '');
|
||||
n.textContent = cur ? 'This game: ' + diffName(cur) + (cur !== app.difficulty ? ' \u00b7 next game: ' + diffName(app.difficulty) : '') : diffSummary(app.difficulty);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ menu / lobby
|
||||
function buildMapPicker() {
|
||||
const box = $('mapPick'); box.textContent = '';
|
||||
|
|
@ -965,7 +1020,7 @@
|
|||
const def = TD.MAPS[id];
|
||||
const b = document.createElement('button');
|
||||
b.type = 'button'; b.className = 'mapcard'; b.dataset.map = id; b.setAttribute('role', 'radio');
|
||||
b.innerHTML = '<canvas width="208" height="128"></canvas><span class="nm"></span><span class="df">DIFFICULTY <b></b></span>';
|
||||
b.innerHTML = '<canvas width="208" height="128"></canvas><span class="nm"></span><span class="df">RATING <b></b></span>';
|
||||
b.querySelector('.nm').textContent = def.name;
|
||||
b.querySelector('.df b').textContent = '●'.repeat(def.difficulty) + '○'.repeat(3 - def.difficulty);
|
||||
drawMapPreview(b.querySelector('canvas'), def);
|
||||
|
|
@ -997,6 +1052,7 @@
|
|||
$('btnCloseMenu').hidden = !app.inGame;
|
||||
$('btnSolo').lastChild.textContent = app.inGame ? 'New solo game' : 'Play solo';
|
||||
showOverlay('menu');
|
||||
renderDiffNote();
|
||||
if (!app.inGame) Audio.music('theme');
|
||||
updateResumeButton();
|
||||
}
|
||||
|
|
@ -1028,8 +1084,9 @@
|
|||
|
||||
$('btnAgain').addEventListener('click', () => {
|
||||
Audio.sfx('click');
|
||||
if (app.ctrl.kind === 'local') { app.ctrl.newGame(app.ctrl.mapId); Audio.music('battle'); }
|
||||
else { app.ctrl.newGame(app.ctrl.board.mapId); }
|
||||
// Play again keeps the difficulty of the game that just ended (not the menu's pick, which is for a NEW game)
|
||||
if (app.ctrl.kind === 'local') { app.ctrl.newGame(app.ctrl.mapId, app.ctrl.difficulty); Audio.music('battle'); }
|
||||
else { app.ctrl.newGame(app.ctrl.board.mapId, app.ctrl.difficulty); }
|
||||
});
|
||||
$('btnContinue').addEventListener('click', () => { app.ctrl.send({ c: 'continue' }); $('end').hidden = true; app.endShown = false; Audio.music('battle'); });
|
||||
$('btnEndMenu').addEventListener('click', () => { if (app.ctrl.kind === 'remote') leaveToMenu(); else { app.inGame = false; previewMap(app.mapId); setScreen('menu'); openMenu(); } });
|
||||
|
|
@ -1045,7 +1102,7 @@
|
|||
$('btnCoop').addEventListener('click', () => { Audio.unlock(); openLobby(); });
|
||||
$('btnLobbyBack').addEventListener('click', () => { cancelPending(); lobbyMsg(''); if (app.inGame) closeOverlayToGame(); else openMenu(); });
|
||||
$('inCode').addEventListener('input', (e) => { e.target.value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 4); });
|
||||
$('btnCreate').addEventListener('click', () => connectRemote({ room: null, map: app.mapId }));
|
||||
$('btnCreate').addEventListener('click', () => connectRemote({ room: null, map: app.mapId, difficulty: app.difficulty }));
|
||||
$('btnJoin').addEventListener('click', () => {
|
||||
const code = $('inCode').value.trim().toUpperCase();
|
||||
if (!/^[A-Z0-9]{4}$/.test(code)) { lobbyMsg('Enter the 4 character room code.', true); return; }
|
||||
|
|
@ -1072,7 +1129,7 @@
|
|||
const name = ($('inName').value || store.get('nw.name', '') || '').trim().slice(0, 16) || 'Player';
|
||||
store.set('nw.name', name);
|
||||
lobbyMsg('Connecting…');
|
||||
const rc = new NW.RemoteController({ pid: getPid(), name, room: opts.room, map: opts.map, resume: !!opts.resume });
|
||||
const rc = new NW.RemoteController({ pid: getPid(), name, room: opts.room, map: opts.map, difficulty: opts.difficulty, resume: !!opts.resume });
|
||||
pendingRc = rc; setLobbyBusy(true);
|
||||
const saveSession = () => { sess.set('nw.room', rc.room); store.set('nw.session', { pid: getPid(), room: rc.room, name, ts: Date.now() }); };
|
||||
let first = true;
|
||||
|
|
@ -1088,7 +1145,7 @@
|
|||
resetSelection(); setScreen('playing'); showOverlay(null);
|
||||
onPlayers(rc.players);
|
||||
try { root.history.replaceState(null, '', root.location.pathname + '?room=' + encodeURIComponent(rc.room)); } catch (e) { /* ignore */ }
|
||||
toast('Room ' + rc.room + (rc.players.length < 2 ? '. Send the invite link to your partner!' : ''), 'good');
|
||||
toast('Room ' + rc.room + ' \u00b7 ' + diffName(viewDifficulty(rc.view)) + (rc.players.length < 2 ? '. Send the invite link to your partner!' : ''), 'good'); // (a joiner learns the host's difficulty here)
|
||||
Audio.music('battle'); requestWakeLock();
|
||||
firstRunHelp(); // an invited player is new to the game too (code-26)
|
||||
} else { toast('Reconnected', 'good'); adoptBoard(); }
|
||||
|
|
@ -1232,7 +1289,7 @@
|
|||
|
||||
// ------------------------------------------------------------------ boot
|
||||
function boot() {
|
||||
buildPalette(); buildMapPicker();
|
||||
buildPalette(); buildMapPicker(); buildDiffPickers();
|
||||
{ const keys = TD.TOWER_ORDER.map((t) => TD.TOWERS[t].key); $('helpKeys').textContent = keys[0] + '\u2013' + keys[keys.length - 1]; }
|
||||
previewMap(app.mapId);
|
||||
setScreen('menu'); showOverlay('menu');
|
||||
|
|
|
|||
|
|
@ -21,6 +21,29 @@
|
|||
const START_LIVES = 20;
|
||||
const SELL_RATIO = 0.7;
|
||||
const WIN_WAVE = 30;
|
||||
// Clearing wave n pays CLEAR_BONUS + CLEAR_BONUS_PER_WAVE * n credits on top of the kills (the same on every difficulty).
|
||||
const CLEAR_BONUS = 10;
|
||||
const CLEAR_BONUS_PER_WAVE = 1;
|
||||
function clearBonus(n) { return CLEAR_BONUS + CLEAR_BONUS_PER_WAVE * n; }
|
||||
|
||||
// ---------------------------------------------------------------- difficulty
|
||||
// One row per difficulty; every number is a multiplier on the base tables below (normal is all 1, so it plays exactly the tuned base game):
|
||||
// gold the starting credits (START_GOLD) lives the starting integrity (START_LIVES), at least 1
|
||||
// hp every enemy's hit points AND its shield reward what a kill pays (a kill always pays at least 1)
|
||||
// The wave clear bonus and the tower prices do not change. Nothing outside this table may hard-code a number from it: tests, the
|
||||
// UI and the balance bot read the table. The ids travel on the wire (create-room option, newgame, fullState), so only ever APPEND.
|
||||
// (Not to be confused with the `difficulty` 1-3 of a MAP below: that is the layout's own rating, drawn as dots on the map cards.)
|
||||
const DIFFICULTY_ORDER = ['easy', 'normal', 'hard'];
|
||||
const DEFAULT_DIFFICULTY = 'normal';
|
||||
const DIFFICULTIES = {
|
||||
easy: { id: 'easy', name: 'Easy', gold: 1.5, lives: 1.5, hp: 0.8, reward: 1.1 },
|
||||
normal: { id: 'normal', name: 'Normal', gold: 1, lives: 1, hp: 1, reward: 1 },
|
||||
hard: { id: 'hard', name: 'Hard', gold: 0.9, lives: 0.85, hp: 1.08, reward: 0.97 },
|
||||
};
|
||||
// Is `v` the id of a difficulty? (own keys only: 'toString' and '__proto__' are not difficulties)
|
||||
function isDifficulty(v) { return typeof v === 'string' && Object.prototype.hasOwnProperty.call(DIFFICULTIES, v); }
|
||||
// `v` if it is a difficulty, otherwise normal (what the Sim does with an unknown value; the server rejects those instead).
|
||||
function difficultyId(v) { return isDifficulty(v) ? v : DEFAULT_DIFFICULTY; }
|
||||
|
||||
// ---------------------------------------------------------------- maps
|
||||
// '.' open, '#' dead node (permanent obstacle), 'S' spawn (internet gateway), 'C' core (the server)
|
||||
|
|
@ -208,6 +231,7 @@
|
|||
// Hotkeys: one unique key 1-9 per tower, in palette order.
|
||||
const TOWER_ORDER = ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc', 'sandbox', 'balancer', 'uplink'];
|
||||
const TARGET_MODES = ['first', 'last', 'strong', 'close'];
|
||||
const UPLINK_GROWTH = 1.3; // each Orbital Uplink you own makes the next one (and its upgrades) this much dearer; was 1.25
|
||||
const TOWERS = {
|
||||
wall: {
|
||||
name: 'Firewall', key: '1', color: '#5aa9ff', refund: 1, role: 'wall',
|
||||
|
|
@ -218,28 +242,28 @@
|
|||
name: 'Packet Filter', key: '2', color: '#35e0a1', role: 'attack', air: true, ground: true,
|
||||
desc: 'Fast, cheap rapid fire. Weak against armour.',
|
||||
levels: [
|
||||
{ cost: 25, dmg: 6, range: 3.2, rate: 3.0 },
|
||||
{ cost: 30, dmg: 9, range: 3.5, rate: 3.4 },
|
||||
{ cost: 55, dmg: 13, range: 3.9, rate: 4.0 },
|
||||
{ cost: 25, dmg: 6, range: 3.5, rate: 3.0 },
|
||||
{ cost: 25, dmg: 9, range: 3.8, rate: 3.4 },
|
||||
{ cost: 45, dmg: 13, range: 4.2, rate: 4.0 },
|
||||
],
|
||||
bulletSpeed: 14,
|
||||
},
|
||||
ids: {
|
||||
name: 'IDS Sniper', key: '3', color: '#b78cff', role: 'attack', air: true, ground: true,
|
||||
desc: 'Long range, hard hitting, slow. Great against armour and bosses.',
|
||||
desc: 'Long range, hard hitting, slow. Great against armour and bosses, poor against swarms.',
|
||||
levels: [
|
||||
{ cost: 60, dmg: 50, range: 6.5, rate: 0.7 },
|
||||
{ cost: 70, dmg: 85, range: 7.2, rate: 0.75 },
|
||||
{ cost: 110, dmg: 150, range: 8.0, rate: 0.8 },
|
||||
{ cost: 70, dmg: 83, range: 6.2, rate: 0.42 },
|
||||
{ cost: 80, dmg: 143, range: 6.8, rate: 0.445 },
|
||||
{ cost: 130, dmg: 250, range: 7.5, rate: 0.48 },
|
||||
],
|
||||
},
|
||||
mortar: {
|
||||
name: 'Flood Mortar', key: '4', color: '#d4f04a', role: 'attack', air: false, ground: true,
|
||||
desc: 'Splash damage against ground swarms. Cannot hit flyers.',
|
||||
levels: [
|
||||
{ cost: 55, dmg: 28, range: 4.8, rate: 0.8, splash: 1.3 },
|
||||
{ cost: 60, dmg: 45, range: 5.2, rate: 0.85, splash: 1.5 },
|
||||
{ cost: 100, dmg: 75, range: 5.6, rate: 0.9, splash: 1.7 },
|
||||
{ cost: 55, dmg: 31, range: 4.9, rate: 0.8, splash: 1.3 },
|
||||
{ cost: 60, dmg: 50, range: 5.3, rate: 0.85, splash: 1.5 },
|
||||
{ cost: 95, dmg: 82, range: 5.7, rate: 0.9, splash: 1.7 },
|
||||
],
|
||||
shellSpeed: 5.5,
|
||||
},
|
||||
|
|
@ -256,9 +280,9 @@
|
|||
name: 'Router Arc', key: '6', color: '#ff7ad9', role: 'attack', air: true, ground: true,
|
||||
desc: 'Chain lightning that jumps between nearby packets.',
|
||||
levels: [
|
||||
{ cost: 75, dmg: 16, range: 3.6, rate: 1.2, chains: 2, chainRange: 1.9, falloff: 0.7 },
|
||||
{ cost: 70, dmg: 24, range: 3.8, rate: 1.25, chains: 3, chainRange: 2.0, falloff: 0.72 },
|
||||
{ cost: 120, dmg: 36, range: 4.2, rate: 1.4, chains: 4, chainRange: 2.2, falloff: 0.75 },
|
||||
{ cost: 70, dmg: 17, range: 3.8, rate: 1.2, chains: 2, chainRange: 1.9, falloff: 0.7 },
|
||||
{ cost: 60, dmg: 26, range: 4.0, rate: 1.25, chains: 3, chainRange: 2.0, falloff: 0.72 },
|
||||
{ cost: 105, dmg: 38, range: 4.4, rate: 1.4, chains: 4, chainRange: 2.2, falloff: 0.75 },
|
||||
],
|
||||
},
|
||||
sandbox: {
|
||||
|
|
@ -281,8 +305,8 @@
|
|||
},
|
||||
uplink: {
|
||||
name: 'Orbital Uplink', key: '9', color: '#ffe27a', role: 'attack', air: true, ground: true,
|
||||
desc: 'Endgame weapon. A piercing orbital beam that ignores armour, scorches everything in its line, blasts and slows the rest around the target, and reaches across most of the map. Extremely expensive to build and to upgrade, and every Uplink you already own makes the next one 25% dearer, and its upgrades too.',
|
||||
priceGrowth: 1.25, // the Nth Uplink costs cost * 1.25^(N-1) to buy AND to upgrade (see priceMult), so kill rewards cannot buy a carpet of them
|
||||
desc: 'Endgame weapon. A piercing orbital beam that ignores armour, scorches everything in its line, blasts and slows the rest around the target, and reaches across most of the map. Extremely expensive to build and to upgrade, and every Uplink you already own makes the next one ' + Math.round((UPLINK_GROWTH - 1) * 100) + '% dearer, and its upgrades too.',
|
||||
priceGrowth: UPLINK_GROWTH, // the Nth Uplink costs cost * UPLINK_GROWTH^(N-1) to buy AND to upgrade (see priceMult), so kill rewards cannot buy a carpet of them
|
||||
levels: [
|
||||
{ cost: 1500, dmg: 260, range: 11, rate: 0.45, width: 0.5, splash: 1.3, slowOnHit: 0.4, slowFor: 1.5 },
|
||||
{ cost: 1200, dmg: 400, range: 12, rate: 0.5, width: 0.55, splash: 1.5, slowOnHit: 0.45, slowFor: 1.75 },
|
||||
|
|
@ -324,16 +348,16 @@
|
|||
const ENEMIES = {
|
||||
ping: { name: 'Ping', hp: 30, speed: 1.5, armor: 0, reward: 3, leak: 1, air: false, r: 0.26, color: '#ff5c7a', buyCost: 10 },
|
||||
worm: { name: 'Worm', hp: 18, speed: 2.8, armor: 0, reward: 2, leak: 1, air: false, r: 0.22, color: '#ff9f43', buyCost: 6 },
|
||||
trojan: { name: 'Trojan', hp: 140, speed: 0.85, armor: 3, reward: 9, leak: 2, air: false, r: 0.38, color: '#c8506b', buyCost: 30 },
|
||||
trojan: { name: 'Trojan', hp: 140, speed: 0.85, armor: 4, reward: 9, leak: 2, air: false, r: 0.38, color: '#c8506b', buyCost: 30 },
|
||||
spam: { name: 'Spam', hp: 7, speed: 2.0, armor: 0, reward: 1, leak: 1, air: false, r: 0.16, color: '#ffd166', buyCost: 3 },
|
||||
ghost: { name: 'Spoof', hp: 40, speed: 1.6, armor: 0, reward: 5, leak: 1, air: true, r: 0.28, color: '#e29bff', buyCost: 15 },
|
||||
rootkit: { name: 'Rootkit', hp: 1400, speed: 0.65, armor: 5, reward: 100, leak: 5, air: false, r: 0.55, color: '#ff3b3b', buyCost: 300, slowRes: 0.5 },
|
||||
ghost: { name: 'Spoof', hp: 40, speed: 1.3, armor: 0, reward: 5, leak: 1, air: true, r: 0.28, color: '#e29bff', buyCost: 15 },
|
||||
rootkit: { name: 'Rootkit', hp: 1400, speed: 0.65, armor: 7, reward: 60, leak: 5, air: false, r: 0.55, color: '#ff3b3b', buyCost: 180, slowRes: 0.5 },
|
||||
// Healer: every HEAL_EVERY s it restores 'heal' of the max hp of every other enemy within healRange (several daemons stack up to HEAL_CAP).
|
||||
daemon: { name: 'Daemon', hp: 70, speed: 1.1, armor: 0, reward: 8, leak: 1, air: false, r: 0.3, color: '#7ee08a', buyCost: 25, heal: 0.06, healRange: 2.2 },
|
||||
// Shielded: 'shield' extra hit points (scaled like hp) that soak damage first and regrow shieldRegen/s of their max after shieldDelay s unhurt.
|
||||
proxy: { name: 'Proxy', hp: 90, speed: 1.0, armor: 1, reward: 10, leak: 1, air: false, r: 0.34, color: '#7aa2ff', buyCost: 30, shield: 120, shieldRegen: 0.1, shieldDelay: 3 },
|
||||
// Swarm flyer.
|
||||
botnet: { name: 'Botnet', hp: 12, speed: 2.6, armor: 0, reward: 1, leak: 1, air: true, r: 0.14, color: '#4dd0c8', buyCost: 3 },
|
||||
botnet: { name: 'Botnet', hp: 12, speed: 2.2, armor: 0, reward: 1, leak: 1, air: true, r: 0.14, color: '#4dd0c8', buyCost: 3 },
|
||||
};
|
||||
const HEAL_EVERY = 1; // seconds between daemon pulses (one global clock, so the 12%/s cap is exact)
|
||||
const HEAL_CAP = 0.12; // most max-hp fraction one enemy can be healed per pulse, however many daemons are near
|
||||
|
|
@ -391,8 +415,10 @@
|
|||
}
|
||||
return out;
|
||||
}
|
||||
function hpScale(n) { return 1 + 0.16 * (n - 1) + 0.022 * (n - 1) * (n - 1); }
|
||||
function rewardScale(n) { return 1 + 0.03 * (n - 1); }
|
||||
// Tuned numbers (docs/BALANCE.md): enemy hit points per wave and what a kill pays. Kill credits grow slower than the packets' hit points,
|
||||
// so credits stay a constraint all game; bosses pay little per hit point (a rootkit is a danger, not a payday).
|
||||
function hpScale(n) { return 1 + 0.145 * (n - 1) + 0.0165 * (n - 1) * (n - 1); }
|
||||
function rewardScale(n) { return 1 + 0.02 * (n - 1); }
|
||||
|
||||
// ---------------------------------------------------------------- path finding
|
||||
class MinHeap {
|
||||
|
|
@ -561,8 +587,11 @@
|
|||
this.board = new Board(opts.map || 'open');
|
||||
this.mapId = this.board.mapId;
|
||||
this.winWave = opts.winWave === undefined ? WIN_WAVE : opts.winWave;
|
||||
this.gold = opts.gold === undefined ? START_GOLD : opts.gold;
|
||||
this.lives = opts.lives === undefined ? START_LIVES : opts.lives;
|
||||
// An explicit `gold` / `lives` (tests, the bot) is used exactly as given; the difficulty scales only the defaults.
|
||||
this.difficulty = difficultyId(opts.difficulty);
|
||||
this.diff = DIFFICULTIES[this.difficulty];
|
||||
this.gold = opts.gold === undefined ? Math.round(START_GOLD * this.diff.gold) : opts.gold;
|
||||
this.lives = opts.lives === undefined ? Math.max(1, Math.round(START_LIVES * this.diff.lives)) : opts.lives;
|
||||
this.maxLives = this.lives;
|
||||
this.collectEvents = opts.events !== false;
|
||||
|
||||
|
|
@ -740,13 +769,14 @@
|
|||
const def = ENEMIES[q.k];
|
||||
const b = this.board;
|
||||
const s = b.spawns[this.spawnRR++ % b.spawns.length];
|
||||
const hp = Math.round(def.hp * hpScale(q.wave));
|
||||
const shield = def.shield ? Math.round(def.shield * hpScale(q.wave)) : 0;
|
||||
const dm = this.diff; // the difficulty scales hit points and shield alike (the wire derives the shield bar from their ratio)
|
||||
const hp = Math.max(1, Math.round(def.hp * hpScale(q.wave) * dm.hp));
|
||||
const shield = def.shield ? Math.max(1, Math.round(def.shield * hpScale(q.wave) * dm.hp)) : 0;
|
||||
const m = {
|
||||
id: this.nid++, kind: q.k, air: !!def.air,
|
||||
x: s.x + 0.5, y: s.y + 0.5, cx: s.x, cy: s.y, tx: -1, ty: -1,
|
||||
hp, maxhp: hp, armor: def.armor, speed: def.speed,
|
||||
reward: Math.max(1, Math.round(def.reward * rewardScale(q.wave))),
|
||||
reward: Math.max(1, Math.round(def.reward * rewardScale(q.wave) * dm.reward)),
|
||||
leak: def.leak, slow: 0, slowT: 0, slowAmt: 0, stunT: 0,
|
||||
shield, maxShield: shield, shieldT: 0,
|
||||
rem: 0, dead: false, wave: q.wave,
|
||||
|
|
@ -793,7 +823,7 @@
|
|||
return;
|
||||
}
|
||||
if (this.wave > this.bonusWave && !this.monsters.length && !this.spawnQ.length) {
|
||||
const bonus = 10 + 2 * this.wave;
|
||||
const bonus = clearBonus(this.wave);
|
||||
this.gold += bonus;
|
||||
this.bonusWave = this.wave;
|
||||
this.emit({ e: 'clear', n: this.wave, bonus });
|
||||
|
|
@ -1094,6 +1124,7 @@
|
|||
map: this.mapId, rev: this.rev, towers: this.towerList(),
|
||||
winWave: this.winWave === Infinity ? 0 : this.winWave,
|
||||
maxLives: this.maxLives,
|
||||
difficulty: this.difficulty,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1117,8 +1148,9 @@
|
|||
|
||||
return {
|
||||
STEP, WAVE_INTERVAL, START_GOLD, START_LIVES, SELL_RATIO, WIN_WAVE, HEAL_EVERY, HEAL_CAP,
|
||||
DIFFICULTIES, DIFFICULTY_ORDER, DEFAULT_DIFFICULTY, isDifficulty, difficultyId,
|
||||
MAPS, MAP_ORDER, TOWERS, TOWER_ORDER, TARGET_MODES, ENEMIES, ENEMY_ORDER,
|
||||
priceFor, priceMult, upgradePrice, waveGroups, waveSummary, hpScale, rewardScale,
|
||||
priceFor, priceMult, upgradePrice, waveGroups, waveSummary, hpScale, rewardScale, clearBonus,
|
||||
buildField, nextCell, traceRoute, parseMap, Board, Sim, round2,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue