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
This commit is contained in:
parent
962189419a
commit
28502984ec
29 changed files with 3370 additions and 230 deletions
487
test/sim.test.js
487
test/sim.test.js
|
|
@ -313,19 +313,27 @@ test('fuzz: garbage commands never throw', () => {
|
|||
});
|
||||
|
||||
test('balance tables keep the shape the client and server rely on', () => {
|
||||
assert.deepEqual(TD.TOWER_ORDER, ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc', 'uplink']);
|
||||
assert.deepEqual(TD.ENEMY_ORDER, ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit']);
|
||||
assert.deepEqual(TD.TOWER_ORDER, ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc', 'sandbox', 'balancer', 'uplink']);
|
||||
assert.deepEqual(TD.ENEMY_ORDER, ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit', 'daemon', 'proxy', 'botnet']);
|
||||
assert.equal(Object.keys(TOWERS).length, TD.TOWER_ORDER.length, 'every tower is in the palette order');
|
||||
assert.equal(Object.keys(ENEMIES).length, TD.ENEMY_ORDER.length, 'every enemy is in the wire order');
|
||||
assert.equal(TOWERS.wall.levels.length, 1);
|
||||
assert.ok(TOWERS.wall.refund, 'walls refund in full');
|
||||
const ROLES = ['wall', 'attack', 'aura', 'control', 'support'];
|
||||
for (const k of TD.TOWER_ORDER) {
|
||||
const t = TOWERS[k];
|
||||
assert.ok(t.name && t.color && t.key && t.desc, k + ' has display fields');
|
||||
assert.ok(ROLES.includes(t.role), k + ' has a known role');
|
||||
if (k === 'wall') continue;
|
||||
assert.equal(t.levels.length, k === 'uplink' ? 4 : 3, k + ' has the expected number of levels');
|
||||
t.levels.forEach((lv, i) => {
|
||||
assert.ok(lv.cost > 0 && lv.range > 0, k + ' L' + (i + 1) + ' cost/range');
|
||||
if (k === 'throttle') assert.ok(lv.slow > 0 && lv.slow <= 0.6, 'slow is capped at 0.6 by the sim');
|
||||
else if (k === 'sandbox') assert.ok(lv.pulse > 0 && lv.stun > 0 && lv.stun < lv.pulse, 'sandbox pulses and stuns for less than the recharge');
|
||||
else if (k === 'balancer') assert.ok(lv.boost > 0 && lv.boost <= 1, 'balancer boosts the fire rate');
|
||||
else assert.ok(lv.dmg > 0 && lv.rate > 0, k + ' L' + (i + 1) + ' dmg/rate');
|
||||
if (t.role === 'attack') assert.ok(lv.dmg > 0 && lv.rate > 0, k + ' attack towers have dmg and rate');
|
||||
else assert.ok(!lv.dmg && !lv.rate, k + ' deals no damage of its own');
|
||||
if (k === 'mortar') assert.ok(lv.splash > 0);
|
||||
if (k === 'arc') assert.ok(lv.chains >= 1 && lv.chainRange > 0 && lv.falloff > 0 && lv.falloff < 1);
|
||||
if (k === 'uplink') assert.ok(lv.width > 0 && lv.splash > 0 && lv.slowOnHit > 0 && lv.slowOnHit <= 0.6 && lv.slowFor > 0);
|
||||
|
|
@ -335,6 +343,8 @@ test('balance tables keep the shape the client and server rely on', () => {
|
|||
for (const k of TD.ENEMY_ORDER) {
|
||||
const e = ENEMIES[k];
|
||||
assert.ok(e.name && e.color && e.hp > 0 && e.speed > 0 && e.reward > 0 && e.leak > 0 && e.armor >= 0 && e.r > 0, k);
|
||||
assert.equal(typeof e.air, 'boolean', k + ' says whether it flies');
|
||||
assert.ok(Number.isInteger(e.buyCost) && e.buyCost > 0, k + ' has a versus buyCost');
|
||||
}
|
||||
assert.ok(TD.START_GOLD >= TOWERS.filter.levels[0].cost * 2, 'the opening credits buy at least two turrets');
|
||||
assert.ok(TD.SELL_RATIO > 0 && TD.SELL_RATIO < 1, 'selling a turret always loses credits');
|
||||
|
|
@ -384,3 +394,476 @@ test('Orbital Uplink: expensive endgame beam that pierces, ignores armour, blast
|
|||
const g = s.gold; s.sell(t.id);
|
||||
assert.equal(s.gold, g + Math.floor(upTotal * TD.SELL_RATIO));
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- new content
|
||||
// A real monster (spawned through the sim so it has every field) moved to (x, y) and, by default, held still.
|
||||
function put(s, kind, x, y, wave) {
|
||||
s.spawnMonster({ k: kind, wave: wave || 1 });
|
||||
const m = s.monsters[s.monsters.length - 1];
|
||||
m.x = x; m.y = y; m.cx = Math.floor(x); m.cy = Math.floor(y); m.tx = -1; m.ty = -1;
|
||||
m.speed = 0;
|
||||
return m;
|
||||
}
|
||||
const tick = (s, seconds) => { const n = Math.round(seconds / STEP); for (let i = 0; i < n; i++) s.tick(STEP); };
|
||||
|
||||
test('hotkeys: one unique key 1-9 per tower, in palette order; enemy kinds are only ever appended', () => {
|
||||
const keys = TD.TOWER_ORDER.map((k) => TOWERS[k].key);
|
||||
assert.deepEqual(keys, ['1', '2', '3', '4', '5', '6', '7', '8', '9']);
|
||||
assert.equal(new Set(keys).size, keys.length);
|
||||
assert.equal(TOWERS.wall.key, '1');
|
||||
assert.equal(TOWERS.sandbox.key, '7');
|
||||
assert.equal(TOWERS.balancer.key, '8');
|
||||
assert.equal(TOWERS.uplink.key, '9');
|
||||
// the first six indexes are on the wire already (snapshot kindIndex)
|
||||
assert.deepEqual(TD.ENEMY_ORDER.slice(0, 6), ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit']);
|
||||
assert.deepEqual(TD.ENEMY_ORDER.slice(6), ['daemon', 'proxy', 'botnet']);
|
||||
});
|
||||
|
||||
test('buyCost: every enemy has one, about three times its kill reward', () => {
|
||||
for (const k of TD.ENEMY_ORDER) {
|
||||
const e = ENEMIES[k];
|
||||
assert.ok(Number.isInteger(e.buyCost) && e.buyCost > 0, k);
|
||||
const ratio = e.buyCost / e.reward;
|
||||
assert.ok(ratio >= 2.5 && ratio <= 3.5, k + ' buyCost/reward = ' + ratio.toFixed(2));
|
||||
}
|
||||
assert.ok(ENEMIES.daemon.air === false && ENEMIES.proxy.air === false && ENEMIES.botnet.air === true);
|
||||
});
|
||||
|
||||
test('every tower can be built, upgraded through all its levels, and sold (solid blocks like the others)', () => {
|
||||
const s = new Sim({ map: 'open', gold: 100000 });
|
||||
let x = 3;
|
||||
for (const type of TD.TOWER_ORDER) {
|
||||
const def = TOWERS[type];
|
||||
const r = s.place(type, x, 10);
|
||||
assert.ok(r.ok, type + ' can be placed');
|
||||
assert.equal(s.board.solid[10 * s.board.cols + x], 1, type + ' is a solid block');
|
||||
assert.equal(s.place(type, x, 10).reason, 'occupied');
|
||||
const t = s.towerById(r.id);
|
||||
for (let lv = 1; lv < def.levels.length; lv++) assert.ok(s.upgrade(t.id).ok, type + ' upgrade to level ' + (lv + 1));
|
||||
assert.equal(s.upgrade(t.id).reason, 'max', type);
|
||||
assert.equal(t.level, def.levels.length);
|
||||
assert.equal(t.spent, def.levels.reduce((a, l) => a + l.cost, 0));
|
||||
assert.ok(s.setTargetMode(t.id, 'close').ok);
|
||||
const g = s.gold, sold = s.sell(t.id);
|
||||
assert.equal(sold.refund, def.refund ? t.spent : Math.floor(t.spent * TD.SELL_RATIO));
|
||||
assert.equal(s.gold, g + sold.refund);
|
||||
assert.equal(s.board.solid[10 * s.board.cols + x], 0, type + ' sold: the cell is free again');
|
||||
x++;
|
||||
}
|
||||
assert.equal(s.towers.length, 0);
|
||||
// a Sandbox or Load Balancer cannot seal the route either
|
||||
const tiny = new Sim({ map: mini(['S....', '.....', '.....', '.....', '....C']), gold: 1000 });
|
||||
assert.ok(tiny.place('sandbox', 3, 4).ok);
|
||||
assert.equal(tiny.place('balancer', 4, 3).reason, 'blocks');
|
||||
assert.equal(tiny.place('sandbox', 5, 5).reason, 'bounds');
|
||||
});
|
||||
|
||||
test('Daemon heals every other enemy within 2.2 cells for 6% of max hp, never itself, never above max', () => {
|
||||
const s = new Sim({ map: 'open', gold: 0 });
|
||||
const d = put(s, 'daemon', 10.5, 5.5);
|
||||
const near = put(s, 'trojan', 12.5, 5.5), far = put(s, 'trojan', 13.0, 5.5); // 2.0 and 2.5 cells away
|
||||
const air = put(s, 'botnet', 10.5, 7.5); // 2.0 cells away, a flyer
|
||||
const full = put(s, 'ping', 10.5, 4.0);
|
||||
const dead = put(s, 'trojan', 10.5, 6.0);
|
||||
for (const m of [near, far, d, air]) m.hp = m.maxhp / 2;
|
||||
air.maxhp = air.hp = 100; air.hp = 50;
|
||||
dead.hp = 1; dead.dead = true;
|
||||
const per = (m) => 0.06 * m.maxhp;
|
||||
const n0 = near.hp, f0 = far.hp, d0 = d.hp, a0 = air.hp;
|
||||
s.healPulse();
|
||||
assert.ok(Math.abs(near.hp - (n0 + per(near))) < 1e-9, 'a trojan 2.0 cells away is healed by 6% of its max');
|
||||
assert.equal(far.hp, f0, 'one 2.5 cells away is not');
|
||||
assert.equal(d.hp, d0, 'a daemon never heals itself');
|
||||
assert.ok(Math.abs(air.hp - (a0 + per(air))) < 1e-9, 'flyers are healed too');
|
||||
assert.equal(full.hp, full.maxhp);
|
||||
assert.equal(dead.hp, 1, 'dead enemies are not healed');
|
||||
near.hp = near.maxhp - 1;
|
||||
s.healPulse();
|
||||
assert.equal(near.hp, near.maxhp, 'never above max');
|
||||
// two daemons heal each other, a lone one does not
|
||||
const d2 = put(s, 'daemon', 10.5, 6.5);
|
||||
d.hp = d.maxhp / 2; d2.hp = d2.maxhp / 2;
|
||||
s.healPulse();
|
||||
assert.ok(d.hp > d.maxhp / 2 && d2.hp > d2.maxhp / 2);
|
||||
assert.equal(d.hp, d.maxhp / 2 + per(d), 'the healing came from the other daemon only (6%, not 12%)');
|
||||
});
|
||||
|
||||
test('several daemons never heal one enemy for more than 12% of its max hp per second', () => {
|
||||
const s = new Sim({ map: 'open', gold: 0 });
|
||||
const t = put(s, 'trojan', 10.5, 5.5);
|
||||
for (let i = 0; i < 5; i++) put(s, 'daemon', 10.5 + 0.3 * i, 6.0);
|
||||
t.hp = t.maxhp * 0.1;
|
||||
s.healPulse();
|
||||
assert.ok(Math.abs(t.hp - t.maxhp * 0.22) < 1e-9, 'five daemons heal 12%, not 30%: ' + (t.hp / t.maxhp));
|
||||
// two daemons already give the full 12%; one gives 6%
|
||||
const s1 = new Sim({ map: 'open', gold: 0 });
|
||||
const t1 = put(s1, 'trojan', 10.5, 5.5); put(s1, 'daemon', 11.0, 5.5); t1.hp = 0;
|
||||
s1.healPulse();
|
||||
assert.ok(Math.abs(t1.hp - 0.06 * t1.maxhp) < 1e-9);
|
||||
});
|
||||
|
||||
test('daemons pulse once a second on one clock; heals scale with wave hp (max hp, not base hp)', () => {
|
||||
const s = new Sim({ map: 'open', gold: 0 });
|
||||
const d = put(s, 'daemon', 10.5, 5.5, 10), t = put(s, 'trojan', 11.5, 5.5, 10);
|
||||
t.hp = 100;
|
||||
assert.equal(t.maxhp, Math.round(ENEMIES.trojan.hp * TD.hpScale(10)));
|
||||
tick(s, 0.9);
|
||||
assert.equal(t.hp, 100, 'no heal before the first second is up');
|
||||
tick(s, 0.2);
|
||||
assert.ok(Math.abs(t.hp - (100 + 0.06 * t.maxhp)) < 1e-6, 'one pulse after a second');
|
||||
tick(s, 1.0);
|
||||
assert.ok(Math.abs(t.hp - (100 + 2 * 0.06 * t.maxhp)) < 1e-6, 'one more pulse a second later');
|
||||
const ev = s.drainEvents().filter((e) => e.e === 'heal');
|
||||
assert.equal(ev.length, 2, 'each pulse tells the client where the daemon healed');
|
||||
assert.ok(ev[0].r === ENEMIES.daemon.healRange && Number.isFinite(ev[0].x));
|
||||
s.monsters.splice(s.monsters.indexOf(d), 1);
|
||||
const before = t.hp;
|
||||
tick(s, 2.5);
|
||||
assert.equal(t.hp, before, 'no daemon, no healing');
|
||||
});
|
||||
|
||||
test('Proxy: the shield soaks damage first, armour applies once, overflow hurts hp, the snapshot carries hp + shield', () => {
|
||||
const s = new Sim({ map: 'open', gold: 0 });
|
||||
const m = put(s, 'proxy', 10.5, 5.5);
|
||||
const E = ENEMIES.proxy;
|
||||
assert.equal(m.hp, E.hp); assert.equal(m.shield, E.shield); assert.equal(m.maxShield, E.shield);
|
||||
s.damage(m, 10); // armour 1: 9 get through to the shield
|
||||
assert.equal(m.shield, E.shield - 9);
|
||||
assert.equal(m.hp, E.hp, 'hp untouched while the shield holds');
|
||||
const snap1 = s.snapshot().mo[0];
|
||||
assert.equal(snap1[4], E.hp + E.shield - 9, 'hp field = hp + shield');
|
||||
assert.equal(snap1[5], E.hp + E.shield, 'maxhp field = maxhp + maxShield');
|
||||
assert.equal(snap1.length, 7);
|
||||
s.damage(m, 150); // 149 after armour: 111 left in the shield, 38 into hp (armour NOT applied a second time)
|
||||
assert.equal(m.shield, 0);
|
||||
assert.equal(m.hp, E.hp - (149 - (E.shield - 9)));
|
||||
assert.equal(s.snapshot().mo[0][4], m.hp);
|
||||
assert.equal(m.dead, false);
|
||||
s.damage(m, 1e6);
|
||||
assert.equal(m.dead, true);
|
||||
assert.equal(s.kills, 1);
|
||||
// the whole pool (shield + hp) must be dealt before it dies; armour-ignoring damage also hits the shield first
|
||||
const m2 = put(s, 'proxy', 10.5, 5.5);
|
||||
s.damage(m2, E.shield + E.hp - 1, null, true);
|
||||
assert.equal(m2.dead, false);
|
||||
s.damage(m2, 1, null, true);
|
||||
assert.equal(m2.dead, true);
|
||||
});
|
||||
|
||||
test('Proxy shield is scaled with the wave like hp, regrows 10%/s after 3 s without damage, and the timer restarts on every hit', () => {
|
||||
const s = new Sim({ map: 'open', gold: 0 });
|
||||
const m = put(s, 'proxy', 10.5, 5.5, 12);
|
||||
const sh = Math.round(ENEMIES.proxy.shield * TD.hpScale(12));
|
||||
assert.equal(m.maxShield, sh);
|
||||
assert.equal(m.maxhp, Math.round(ENEMIES.proxy.hp * TD.hpScale(12)));
|
||||
s.damage(m, 400, null, true);
|
||||
const left = sh - 400;
|
||||
assert.equal(m.shield, left);
|
||||
tick(s, 2.8);
|
||||
assert.equal(m.shield, left, 'nothing regrows during the 3 s delay');
|
||||
tick(s, 1.2); // 4.0 s since the hit: one second of regrow
|
||||
assert.ok(Math.abs(m.shield - (left + 0.1 * sh)) < 0.5, 'regrew 10% of max in the first second after the delay: ' + (m.shield - left) + ' vs ' + 0.1 * sh);
|
||||
s.damage(m, 5, null, true);
|
||||
const after = m.shield;
|
||||
tick(s, 2.9);
|
||||
assert.equal(m.shield, after, 'a hit restarts the delay');
|
||||
tick(s, 60);
|
||||
assert.equal(m.shield, sh, 'regrows to the maximum and not beyond');
|
||||
assert.equal(m.hp, m.maxhp, 'the shield regrows, hp is not touched');
|
||||
// a daemon never tops up a shield, only hp
|
||||
s.damage(m, sh + 40, null, true);
|
||||
const d = put(s, 'daemon', 11.0, 5.5, 12);
|
||||
s.healPulse();
|
||||
assert.equal(m.shield, 0);
|
||||
assert.ok(Math.abs(m.hp - (m.maxhp - 40 + 0.06 * m.maxhp)) < 1e-6 || m.hp === m.maxhp);
|
||||
assert.ok(d.hp > 0);
|
||||
});
|
||||
|
||||
test('Botnet: a fast, tiny flyer that goes straight for the core and is hit by anti-air only', () => {
|
||||
const s = new Sim({ map: 'open', gold: 1000 });
|
||||
const E = ENEMIES.botnet;
|
||||
assert.ok(E.air && E.hp <= 15 && E.speed > ENEMIES.ghost.speed && E.reward === 1);
|
||||
const m = put(s, 'botnet', 12.5, 7.5);
|
||||
s.place('mortar', 12, 6);
|
||||
tick(s, 1);
|
||||
assert.equal(m.dead, false, 'a mortar cannot hit flyers');
|
||||
s.place('filter', 11, 6);
|
||||
tick(s, 1);
|
||||
assert.ok(m.dead || m.hp < m.maxhp, 'a filter can');
|
||||
// and it flies straight at the core at its own speed
|
||||
const s2 = new Sim({ map: 'open', gold: 0 });
|
||||
const f = put(s2, 'botnet', 0.5, 7.5);
|
||||
f.speed = E.speed;
|
||||
tick(s2, 2);
|
||||
assert.ok(Math.abs(f.x - (0.5 + 2 * E.speed * Math.cos(Math.atan2(8 - 7.5, 25.5 - 0.5)))) < 0.1, 'x=' + f.x);
|
||||
});
|
||||
|
||||
test('Sandbox stuns everything in range (ground and air), not what is outside, and stunned enemies do not move', () => {
|
||||
const s = new Sim({ map: 'open', gold: 1000 });
|
||||
s.place('sandbox', 2, 6); // centre (2.5, 6.5), range 2.6
|
||||
const L = TOWERS.sandbox.levels[0];
|
||||
const ground = put(s, 'ping', 0.5, 7.5), air = put(s, 'ghost', 3.5, 7.5), out = put(s, 'ping', 8.5, 7.5);
|
||||
for (const m of [ground, air, out]) m.speed = ENEMIES[m.kind].speed;
|
||||
const gx = ground.x, ax = air.x, ox = out.x;
|
||||
tick(s, L.stun * 0.9);
|
||||
assert.ok(ground.stunT > 0 && air.stunT > 0, 'ground and air are stunned');
|
||||
assert.equal(out.stunT, 0, 'out of range: untouched');
|
||||
assert.equal(ground.x, gx, 'stunned ground unit stands still');
|
||||
assert.equal(air.x, ax, 'stunned flyer stands still');
|
||||
assert.ok(out.x > ox, 'the unit outside keeps moving');
|
||||
assert.equal(s.snapshot().mo.find((e) => e[0] === ground.id)[6], 1, 'stunned units are flagged in the snapshot (the 0/1 slow flag)');
|
||||
tick(s, L.stun * 0.3);
|
||||
assert.ok(ground.x > gx, 'moves again once the stun is over');
|
||||
const ev = s.drainEvents().filter((e) => e.e === 'stun');
|
||||
assert.equal(ev.length, 1);
|
||||
assert.equal(ev[0].n, 2);
|
||||
});
|
||||
|
||||
test('Sandbox: pulse cadence by level, only pulses when something is in range, stun does not stack, bosses get half', () => {
|
||||
const s = new Sim({ map: 'open', gold: 10000 });
|
||||
const r = s.place('sandbox', 5, 5), t = s.towerById(r.id);
|
||||
tick(s, 12);
|
||||
assert.equal(s.drainEvents().filter((e) => e.e === 'stun').length, 0, 'nothing in range: no pulse and the charge is kept');
|
||||
assert.equal(t.cd, 0);
|
||||
const boss = put(s, 'rootkit', 6.5, 6.5, 10), ping = put(s, 'ping', 5.5, 7.0);
|
||||
const L1 = TOWERS.sandbox.levels[0];
|
||||
tick(s, 0.1);
|
||||
assert.ok(Math.abs(ping.stunT - (L1.stun - 0.1 + STEP)) < 0.05, 'a ping is stunned for the full time');
|
||||
assert.ok(Math.abs(boss.stunT - (L1.stun * (1 - ENEMIES.rootkit.slowRes) - 0.1 + STEP)) < 0.05, 'a boss for half');
|
||||
assert.ok(boss.stunT < ping.stunT);
|
||||
tick(s, 8.8); // 8.9 s: pulses at 0 and 5
|
||||
assert.equal(s.drainEvents().filter((e) => e.e === 'stun').length, 2);
|
||||
// level 3 pulses faster and stuns longer; a second pulse never adds to a running stun, it only refreshes it
|
||||
s.upgrade(t.id); s.upgrade(t.id);
|
||||
const L3 = TOWERS.sandbox.levels[2];
|
||||
assert.ok(L3.pulse < L1.pulse && L3.stun > L1.stun && L3.range > L1.range);
|
||||
s.drainEvents();
|
||||
t.cd = 0; ping.stunT = 0.5;
|
||||
tick(s, 0.05);
|
||||
assert.ok(Math.abs(ping.stunT - (L3.stun - 0.05 + STEP)) < 0.05 && ping.stunT <= L3.stun, 'stun is set to the pulse stun, not added');
|
||||
t.cd = 0; ping.stunT = L3.stun * 2; // an already longer stun stays
|
||||
s.tick(STEP);
|
||||
assert.ok(ping.stunT > L3.stun, 'a shorter stun never cuts a longer one');
|
||||
s.drainEvents();
|
||||
tick(s, 12.1);
|
||||
assert.equal(s.drainEvents().filter((e) => e.e === 'stun').length, 3, 'level 3 recharges every ' + L3.pulse + ' s');
|
||||
});
|
||||
|
||||
test('Load Balancer: boosts attack towers in range, best boost only, not itself, not control/aura towers, ends when sold', () => {
|
||||
const s = new Sim({ map: 'open', gold: 100000 });
|
||||
const f1 = s.towerById(s.place('filter', 10, 5).id); // 1 cell from the balancer at (11,5)
|
||||
const fFar = s.towerById(s.place('filter', 14, 5).id); // 3 cells: outside the level 1 and 2 range, exactly inside level 3
|
||||
const sb = s.towerById(s.place('sandbox', 10, 6).id);
|
||||
const th = s.towerById(s.place('throttle', 9, 5).id);
|
||||
const wl = s.towerById(s.place('wall', 11, 6).id);
|
||||
const b1 = s.towerById(s.place('balancer', 11, 5).id);
|
||||
const B = TOWERS.balancer.levels;
|
||||
s.updateAuras();
|
||||
assert.equal(f1.buff, B[0].boost);
|
||||
assert.equal(fFar.buff, 0, 'out of range');
|
||||
for (const t of [sb, th, wl, b1]) assert.equal(t.buff, 0, t.type + ' is not an attack tower');
|
||||
// upgrading makes it stronger; a second, weaker balancer never adds to it
|
||||
s.upgrade(b1.id);
|
||||
s.updateAuras();
|
||||
assert.equal(f1.buff, B[1].boost);
|
||||
assert.equal(fFar.buff, 0);
|
||||
const b2 = s.towerById(s.place('balancer', 10, 4).id);
|
||||
s.updateAuras();
|
||||
assert.equal(f1.buff, B[1].boost, 'the best boost applies, they do not stack (not 0.15 + 0.25)');
|
||||
assert.equal(b1.buff, 0, 'a balancer does not boost another balancer'); assert.equal(b2.buff, 0);
|
||||
s.upgrade(b1.id);
|
||||
s.updateAuras();
|
||||
assert.equal(f1.buff, B[2].boost);
|
||||
assert.equal(fFar.buff, B[2].boost, 'level 3 reaches 3 cells');
|
||||
// selling the strong one drops back to the weak one, selling the last ends the boost
|
||||
s.sell(b1.id);
|
||||
s.updateAuras();
|
||||
assert.equal(f1.buff, B[0].boost);
|
||||
assert.equal(fFar.buff, 0);
|
||||
s.sell(b2.id);
|
||||
s.tick(STEP);
|
||||
assert.equal(f1.buff, 0, 'selling the last balancer ends the boost');
|
||||
});
|
||||
|
||||
test('Load Balancer: cooldowns really elapse faster, so a boosted tower fires more often', () => {
|
||||
const mk = (withBalancer) => {
|
||||
const s = new Sim({ map: 'open', gold: 10000 });
|
||||
const t = s.towerById(s.place('ids', 10, 5).id);
|
||||
if (withBalancer) s.place('balancer', 11, 5);
|
||||
const target = put(s, 'trojan', 10.5, 7.5, 1);
|
||||
target.hp = target.maxhp = 1e12; target.armor = 0;
|
||||
return { s, t, target };
|
||||
};
|
||||
const a = mk(false), b = mk(true);
|
||||
a.t.cd = b.t.cd = 1;
|
||||
a.s.tick(0.1); b.s.tick(0.1);
|
||||
assert.ok(Math.abs(a.t.cd - 0.9) < 1e-9);
|
||||
assert.ok(Math.abs(b.t.cd - (1 - 0.1 * (1 + TOWERS.balancer.levels[0].boost))) < 1e-9, 'cooldown ran 15% faster');
|
||||
const shots = (x) => { tick(x.s, 40); return x.s.drainEvents().filter((e) => e.e === 'shot' && e.k === 'ids').length; };
|
||||
const na = shots(a), nb = shots(b);
|
||||
assert.ok(na >= 25, 'baseline fires ~28 shots in 40 s: ' + na);
|
||||
assert.ok(nb > na * 1.1 && nb < na * 1.2, 'boosted ' + nb + ' vs ' + na);
|
||||
});
|
||||
|
||||
test('waves 1-8 are exactly the original introduction', () => {
|
||||
const W = [
|
||||
[{ k: 'ping', c: 8, gap: 0.7 }],
|
||||
[{ k: 'worm', c: 11, gap: 0.4 }],
|
||||
[{ k: 'ping', c: 9, gap: 0.6 }, { k: 'trojan', c: 1, gap: 1.4 }],
|
||||
[{ k: 'spam', c: 30, gap: 0.18 }],
|
||||
[{ k: 'ghost', c: 7, gap: 0.9 }, { k: 'ping', c: 8, gap: 0.5 }],
|
||||
[{ k: 'trojan', c: 4, gap: 1.2 }, { k: 'worm', c: 11, gap: 0.35 }],
|
||||
[{ k: 'ghost', c: 12, gap: 0.6 }, { k: 'spam', c: 24, gap: 0.2 }],
|
||||
[{ k: 'ping', c: 16, gap: 0.4 }, { k: 'trojan', c: 5, gap: 1 }, { k: 'ghost', c: 6, gap: 0.8 }],
|
||||
];
|
||||
for (let n = 1; n <= 8; n++) assert.deepEqual(TD.waveGroups(n), W[n - 1], 'wave ' + n);
|
||||
for (let n = 1; n <= 8; n++) assert.ok(!TD.waveGroups(n).some((g) => ['daemon', 'proxy', 'botnet'].includes(g.k)));
|
||||
});
|
||||
|
||||
test('new kinds are woven into the waves from 9 on: daemons with trojans, proxies from 12, botnets from 14', () => {
|
||||
const first = {};
|
||||
for (let n = 1; n <= 60; n++) {
|
||||
const g = TD.waveGroups(n);
|
||||
for (const e of g) {
|
||||
assert.ok(ENEMIES[e.k], 'wave ' + n + ' kind ' + e.k);
|
||||
assert.ok(Number.isInteger(e.c) && e.c >= 1 && e.gap > 0, 'wave ' + n);
|
||||
if (first[e.k] === undefined) first[e.k] = n;
|
||||
}
|
||||
assert.ok(g.length <= 8, 'wave ' + n + ' has a sane number of groups');
|
||||
const t = g.reduce((a, e) => a + e.c * e.gap + 1.5, 0);
|
||||
assert.ok(t < 120, 'wave ' + n + ' finishes spawning within two minutes (' + t.toFixed(0) + ' s)');
|
||||
if (n >= 9 && g.some((e) => e.k === 'trojan')) {
|
||||
const tr = g.find((e) => e.k === 'trojan'), dm = g.find((e) => e.k === 'daemon');
|
||||
assert.ok(dm && dm.c >= 1, 'wave ' + n + ' has a daemon escort');
|
||||
assert.ok(g.indexOf(dm) > g.indexOf(tr), 'the escort spawns behind the trojans');
|
||||
assert.ok(dm.c <= tr.c, 'the escort is not bigger than the trojan group');
|
||||
}
|
||||
}
|
||||
assert.equal(first.daemon, 9);
|
||||
assert.equal(first.proxy, 12);
|
||||
assert.equal(first.botnet, 14);
|
||||
for (const k of TD.ENEMY_ORDER) assert.ok(first[k] !== undefined, k + ' appears somewhere in waves 1-60');
|
||||
for (let n = 9; n <= 60; n++) {
|
||||
const kinds = TD.waveGroups(n).map((e) => e.k);
|
||||
if (n < 12) assert.ok(!kinds.includes('proxy'), 'no proxy before 12');
|
||||
if (n < 14) assert.ok(!kinds.includes('botnet'), 'no botnet before 14');
|
||||
}
|
||||
// the late waves combine them
|
||||
assert.ok(['daemon', 'proxy', 'botnet'].every((k) => TD.waveGroups(30).some((e) => e.k === k)), 'wave 30 has all three');
|
||||
assert.ok(TD.waveGroups(20).some((e) => e.k === 'rootkit') && TD.waveGroups(20).some((e) => e.k === 'proxy'));
|
||||
// the loop keeps growing: the same slot gets more units later
|
||||
const cnt = (n, k) => TD.waveGroups(n).filter((e) => e.k === k).reduce((a, e) => a + e.c, 0);
|
||||
assert.ok(cnt(22, 'botnet') > cnt(14, 'botnet') && cnt(36, 'proxy') > cnt(12, 'proxy'));
|
||||
});
|
||||
|
||||
test('waveSummary lists one entry per kind with counts and flags flyers', () => {
|
||||
for (let n = 1; n <= 60; n++) {
|
||||
const sum = TD.waveSummary(n), groups = TD.waveGroups(n);
|
||||
assert.equal(new Set(sum.map((e) => e.k)).size, sum.length, 'one entry per kind in wave ' + n);
|
||||
for (const e of sum) {
|
||||
assert.equal(e.air, !!ENEMIES[e.k].air, 'wave ' + n + ' ' + e.k + ' air flag');
|
||||
assert.equal(e.c, groups.filter((g) => g.k === e.k).reduce((a, g) => a + g.c, 0));
|
||||
}
|
||||
assert.equal(sum.reduce((a, e) => a + e.c, 0), groups.reduce((a, g) => a + g.c, 0));
|
||||
}
|
||||
assert.deepEqual(TD.waveSummary(5), [{ k: 'ghost', c: 7, air: true }, { k: 'ping', c: 8, air: false }]);
|
||||
assert.ok(TD.waveSummary(14).some((e) => e.k === 'botnet' && e.air === true));
|
||||
assert.ok(TD.waveSummary(7).some((e) => e.k === 'ghost' && e.air));
|
||||
});
|
||||
|
||||
test('the new waves run end to end and the snapshot (incl. daemon, proxy, botnet) survives JSON', () => {
|
||||
const s = new Sim({ map: 'twin', gold: 0, lives: 1000 });
|
||||
s.wave = 14; // every new kind in the queue at once
|
||||
s.spawnQ.push({ t: 0, k: 'daemon', wave: 14 }, { t: 0, k: 'proxy', wave: 14 }, { t: 0, k: 'botnet', wave: 14 }, { t: 0, k: 'trojan', wave: 14 });
|
||||
s.spawnQ.push(...TD.waveGroups(14).flatMap((g, gi) => Array.from({ length: g.c }, (_, i) => ({ t: gi * 5 + i * g.gap, k: g.k, wave: 14 }))));
|
||||
s.spawnQ.sort((a, b) => a.t - b.t);
|
||||
let sawNew = false, sawShield = false;
|
||||
for (let i = 0; i < 60 * 25 && s.state === 'playing'; i++) {
|
||||
s.tick(STEP);
|
||||
if (i % 30 === 0) {
|
||||
const snap = JSON.parse(JSON.stringify(s.snapshot()));
|
||||
assert.deepEqual(snap, JSON.parse(JSON.stringify(snap)));
|
||||
for (const e of snap.mo) {
|
||||
assert.equal(e.length, 7);
|
||||
assert.ok(Number.isInteger(e[1]) && e[1] >= 0 && e[1] < TD.ENEMY_ORDER.length, 'kindIndex indexes ENEMY_ORDER');
|
||||
assert.ok(e[4] > 0 && e[4] <= e[5], 'hp (incl. shield) within maxhp (incl. maxShield)');
|
||||
if (e[1] >= 6) sawNew = true;
|
||||
if (TD.ENEMY_ORDER[e[1]] === 'proxy') { sawShield = true; assert.ok(e[5] > ENEMIES.proxy.hp * TD.hpScale(14), 'proxy maxhp includes the shield'); }
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.ok(sawNew && sawShield);
|
||||
assert.ok(s.leaks > 0, 'undefended waves leak');
|
||||
assert.equal(JSON.stringify(s.fullState()).includes('null'), false);
|
||||
});
|
||||
|
||||
test('Orbital Uplink pricing: very expensive, and every one you own makes the next dearer', () => { // (25% per owned one, for buying and for upgrading)
|
||||
const base = TOWERS.uplink.levels[0].cost;
|
||||
assert.ok(base >= 8 * TD.START_GOLD, 'the first Uplink costs many times the opening credits');
|
||||
assert.ok(base >= 20 * TOWERS.ids.levels[0].cost, 'and a lot more than an IDS Sniper');
|
||||
// the shared helper: arrays of towers and plain counts agree; other towers have a flat price
|
||||
assert.equal(TD.priceFor('uplink', 0), base);
|
||||
assert.equal(TD.priceFor('uplink', [{ type: 'uplink' }, { type: 'filter' }, { type: 'uplink' }]), TD.priceFor('uplink', 2));
|
||||
assert.equal(TD.priceFor('filter', 50), TOWERS.filter.levels[0].cost, 'a Packet Filter never gets dearer');
|
||||
assert.equal(TD.priceFor('wall', [{ type: 'wall' }, { type: 'wall' }]), TOWERS.wall.levels[0].cost);
|
||||
for (let n = 1; n < 6; n++) assert.ok(TD.priceFor('uplink', n) >= 1.2 * TD.priceFor('uplink', n - 1), 'each Uplink is about 25% dearer than the one before');
|
||||
|
||||
const s = new Sim({ map: 'open', gold: 1e6 });
|
||||
const ids = [];
|
||||
let prev = 0;
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const want = TD.priceFor('uplink', s.towers);
|
||||
assert.ok(want > prev, 'price keeps rising');
|
||||
prev = want;
|
||||
const g = s.gold;
|
||||
const r = s.place('uplink', 4 + 2 * i, 6);
|
||||
assert.ok(r.ok);
|
||||
assert.equal(g - s.gold, want, 'the sim charges exactly the price the UI shows');
|
||||
assert.equal(s.towerById(r.id).spent, want, 'spent records what was actually paid');
|
||||
ids.push(r.id);
|
||||
}
|
||||
// refunds follow what each one cost, and selling brings the price back down
|
||||
const before = TD.priceFor('uplink', s.towers);
|
||||
const g0 = s.gold, t0 = s.towerById(ids[0]);
|
||||
const refund = s.sell(ids[0]).refund;
|
||||
assert.equal(refund, Math.floor(t0.spent * TD.SELL_RATIO));
|
||||
assert.equal(s.gold, g0 + refund);
|
||||
assert.ok(TD.priceFor('uplink', s.towers) < before, 'owning fewer makes the next one cheaper again');
|
||||
// not enough credits for the dearer one: refused without charging
|
||||
const poor = new Sim({ map: 'open', gold: base });
|
||||
assert.ok(poor.place('uplink', 5, 5).ok);
|
||||
poor.gold = TD.priceFor('uplink', poor.towers) - 10;
|
||||
const gp = poor.gold;
|
||||
assert.equal(poor.place('uplink', 8, 5).reason, 'gold');
|
||||
assert.equal(poor.gold, gp);
|
||||
});
|
||||
|
||||
test('Orbital Uplink upgrades get dearer by the same factor as the tower they belong to', () => {
|
||||
const s = new Sim({ map: 'open', gold: 1e7 });
|
||||
const a = s.towerById(s.place('uplink', 4, 6).id), b = s.towerById(s.place('uplink', 8, 6).id), c = s.towerById(s.place('uplink', 12, 6).id);
|
||||
assert.equal(a.pm, 1);
|
||||
assert.ok(Math.abs(b.pm - TOWERS.uplink.priceGrowth) < 1e-9 && Math.abs(c.pm - TOWERS.uplink.priceGrowth ** 2) < 1e-9, 'each remembers the multiplier it was bought at');
|
||||
for (const t of [a, b, c]) {
|
||||
const m = t.pm;
|
||||
const g0 = s.gold, up1 = TD.upgradePrice('uplink', 1, m);
|
||||
assert.equal(s.upgradeCost(t), up1, 'the sim and the shared helper agree');
|
||||
assert.ok(Math.abs(up1 / TOWERS.uplink.levels[1].cost - m) < 0.01 * m + 0.01, 'level 2 costs the base upgrade times the multiplier');
|
||||
assert.ok(s.upgrade(t.id).ok);
|
||||
assert.equal(g0 - s.gold, up1);
|
||||
assert.equal(t.spent, TD.priceFor('uplink', t.pm === 1 ? 0 : Math.round(Math.log(t.pm) / Math.log(TOWERS.uplink.priceGrowth))) + up1);
|
||||
}
|
||||
assert.ok(TD.upgradePrice('uplink', 3, c.pm) > TD.upgradePrice('uplink', 3, a.pm) * 1.5, 'the third Uplink is much dearer to upgrade than the first');
|
||||
// flat-price towers are untouched
|
||||
const f = s.towerById(s.place('filter', 6, 10).id);
|
||||
assert.equal(f.pm, 1);
|
||||
assert.equal(TD.upgradePrice('filter', 1, f.pm), TOWERS.filter.levels[1].cost);
|
||||
// a tower bought after another was sold gets the lower multiplier back
|
||||
s.sell(a.id);
|
||||
const d = s.towerById(s.place('uplink', 16, 6).id);
|
||||
assert.ok(d.pm < c.pm * 1.0001 && d.pm >= b.pm - 1e-9, 'owning fewer when you buy lowers the multiplier again');
|
||||
// the multiplier travels in the tower list so a co-op client can show the same upgrade price
|
||||
const row = s.towerList().find((r) => r[0] === c.id);
|
||||
assert.equal(row.length, 9);
|
||||
assert.ok(Math.abs(row[8] - c.pm) < 0.002);
|
||||
assert.equal(s.towerList().find((r) => r[0] === f.id)[8], 1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue