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
268
public/js/sim.js
268
public/js/sim.js
|
|
@ -201,16 +201,21 @@
|
|||
}
|
||||
|
||||
// ---------------------------------------------------------------- definitions
|
||||
const TOWER_ORDER = ['wall', 'filter', 'ids', 'mortar', 'throttle', 'arc', 'uplink'];
|
||||
// Every tower has a 'role' so the generic code does not have to know the types:
|
||||
// wall solid block, does nothing attack shoots (dmg/rate, picks a target, can be rate-boosted)
|
||||
// aura continuous effect in range control periodic pulse that stuns everything in range
|
||||
// support no attack of its own: boosts the 'attack' towers around it
|
||||
// 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 TOWERS = {
|
||||
wall: {
|
||||
name: 'Firewall', key: '1', color: '#5aa9ff', refund: 1,
|
||||
name: 'Firewall', key: '1', color: '#5aa9ff', refund: 1, role: 'wall',
|
||||
desc: 'Blocks the route. Cheap: use it to build a long maze.',
|
||||
levels: [{ cost: 5 }],
|
||||
},
|
||||
filter: {
|
||||
name: 'Packet Filter', key: '2', color: '#35e0a1', air: true, ground: true,
|
||||
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 },
|
||||
|
|
@ -220,7 +225,7 @@
|
|||
bulletSpeed: 14,
|
||||
},
|
||||
ids: {
|
||||
name: 'IDS Sniper', key: '3', color: '#b78cff', air: true, ground: true,
|
||||
name: 'IDS Sniper', key: '3', color: '#b78cff', role: 'attack', air: true, ground: true,
|
||||
desc: 'Long range, hard hitting, slow. Great against armour and bosses.',
|
||||
levels: [
|
||||
{ cost: 60, dmg: 50, range: 6.5, rate: 0.7 },
|
||||
|
|
@ -229,7 +234,7 @@
|
|||
],
|
||||
},
|
||||
mortar: {
|
||||
name: 'Flood Mortar', key: '4', color: '#d4f04a', air: false, ground: true,
|
||||
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 },
|
||||
|
|
@ -239,7 +244,7 @@
|
|||
shellSpeed: 5.5,
|
||||
},
|
||||
throttle: {
|
||||
name: 'Rate Limiter', key: '5', color: '#4de3ff', air: true, ground: true,
|
||||
name: 'Rate Limiter', key: '5', color: '#4de3ff', role: 'aura', air: true, ground: true,
|
||||
desc: 'Slows everything in range. Pair it with damage dealers.',
|
||||
levels: [
|
||||
{ cost: 40, range: 3.2, slow: 0.35 },
|
||||
|
|
@ -248,7 +253,7 @@
|
|||
],
|
||||
},
|
||||
arc: {
|
||||
name: 'Router Arc', key: '6', color: '#ff7ad9', air: true, ground: true,
|
||||
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 },
|
||||
|
|
@ -256,27 +261,82 @@
|
|||
{ cost: 120, dmg: 36, range: 4.2, rate: 1.4, chains: 4, chainRange: 2.2, falloff: 0.75 },
|
||||
],
|
||||
},
|
||||
uplink: {
|
||||
name: 'Orbital Uplink', key: '7', color: '#ffe27a', 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. Very expensive to build and to upgrade.',
|
||||
sandbox: {
|
||||
name: 'Sandbox', key: '7', color: '#ffa447', role: 'control', air: true, ground: true,
|
||||
desc: 'Control tower, no damage. Every few seconds it traps every packet in range, ground and air, and freezes it for a moment. Bosses resist and are frozen for half as long.',
|
||||
levels: [
|
||||
{ cost: 450, dmg: 260, range: 11, rate: 0.45, width: 0.5, splash: 1.3, slowOnHit: 0.4, slowFor: 1.5 },
|
||||
{ cost: 500, dmg: 400, range: 12, rate: 0.5, width: 0.55, splash: 1.5, slowOnHit: 0.45, slowFor: 1.75 },
|
||||
{ cost: 800, dmg: 640, range: 13, rate: 0.55, width: 0.6, splash: 1.7, slowOnHit: 0.5, slowFor: 2.0 },
|
||||
{ cost: 1200, dmg: 1000, range: 14, rate: 0.6, width: 0.7, splash: 2.0, slowOnHit: 0.6, slowFor: 2.5 },
|
||||
{ cost: 90, range: 2.6, pulse: 5.0, stun: 1.0 },
|
||||
{ cost: 80, range: 3.0, pulse: 4.5, stun: 1.3 },
|
||||
{ cost: 130, range: 3.4, pulse: 4.0, stun: 1.6 },
|
||||
],
|
||||
},
|
||||
balancer: {
|
||||
name: 'Load Balancer', key: '8', color: '#d3e0ee', role: 'support',
|
||||
desc: 'Support tower, no attack. Makes every turret in range fire faster. Several balancers do not stack (the best one counts) and a balancer does not boost another balancer.',
|
||||
levels: [
|
||||
{ cost: 70, range: 2.2, boost: 0.15 },
|
||||
{ cost: 70, range: 2.6, boost: 0.25 },
|
||||
{ cost: 110, range: 3.0, boost: 0.35 },
|
||||
],
|
||||
},
|
||||
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
|
||||
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 },
|
||||
{ cost: 2000, dmg: 640, range: 13, rate: 0.55, width: 0.6, splash: 1.7, slowOnHit: 0.5, slowFor: 2.0 },
|
||||
{ cost: 3200, dmg: 1000, range: 14, rate: 0.6, width: 0.7, splash: 2.0, slowOnHit: 0.6, slowFor: 2.5 },
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const ENEMY_ORDER = ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit'];
|
||||
// ENEMY_ORDER is part of the wire format (snapshots carry the index): only ever APPEND kinds.
|
||||
// buyCost is the price of one unit in the future versus mode (about 3x the kill reward).
|
||||
// What building one more `type` costs right now, given the towers already on the board (an array, or a plain count).
|
||||
// Most towers have a fixed price; a tower with `priceGrowth` gets dearer for every one already owned. Shared by the Sim and
|
||||
// the UI so the price shown is always the price charged.
|
||||
// The price multiplier a NEW tower of this type is bought at, given how many are already owned. Each tower remembers the multiplier it was
|
||||
// bought at (tower.pm) and its upgrades cost the same multiple, so the Nth Uplink is dearer to buy and to upgrade by the same factor.
|
||||
function priceMult(type, owned) {
|
||||
const def = TOWERS[type];
|
||||
if (!def || !def.priceGrowth) return 1;
|
||||
let n = 0;
|
||||
if (Array.isArray(owned)) { for (const t of owned) if (t.type === type) n++; } else n = owned | 0;
|
||||
return Math.pow(def.priceGrowth, n);
|
||||
}
|
||||
const roundPrice = (v) => Math.round(v / 10) * 10;
|
||||
function priceFor(type, owned) {
|
||||
const def = TOWERS[type];
|
||||
if (!def) return 0;
|
||||
const base = def.levels[0].cost, m = priceMult(type, owned);
|
||||
return m === 1 ? base : roundPrice(base * m);
|
||||
}
|
||||
// What upgrading a tower of `type` that is at `level` (1-based) to the next level costs, given the multiplier it was bought at (pm, default 1).
|
||||
function upgradePrice(type, level, pm) {
|
||||
const def = TOWERS[type], lv = def && def.levels[level];
|
||||
if (!lv) return null;
|
||||
return !pm || pm === 1 ? lv.cost : roundPrice(lv.cost * pm);
|
||||
}
|
||||
|
||||
const ENEMY_ORDER = ['ping', 'worm', 'trojan', 'spam', 'ghost', 'rootkit', 'daemon', 'proxy', 'botnet'];
|
||||
const ENEMIES = {
|
||||
ping: { name: 'Ping', hp: 30, speed: 1.5, armor: 0, reward: 3, leak: 1, air: false, r: 0.26, color: '#ff5c7a' },
|
||||
worm: { name: 'Worm', hp: 18, speed: 2.8, armor: 0, reward: 2, leak: 1, air: false, r: 0.22, color: '#ff9f43' },
|
||||
trojan: { name: 'Trojan', hp: 140, speed: 0.85, armor: 3, reward: 9, leak: 2, air: false, r: 0.38, color: '#c8506b' },
|
||||
spam: { name: 'Spam', hp: 7, speed: 2.0, armor: 0, reward: 1, leak: 1, air: false, r: 0.16, color: '#ffd166' },
|
||||
ghost: { name: 'Spoof', hp: 40, speed: 1.6, armor: 0, reward: 5, leak: 1, air: true, r: 0.28, color: '#e29bff' },
|
||||
rootkit: { name: 'Rootkit', hp: 1400, speed: 0.65, armor: 5, reward: 100, leak: 5, air: false, r: 0.55, color: '#ff3b3b', slowRes: 0.5 },
|
||||
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 },
|
||||
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 },
|
||||
// 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 },
|
||||
};
|
||||
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
|
||||
|
||||
// Wave n (1-based). The first eight waves introduce each unit type; later ones loop with bigger numbers.
|
||||
function waveGroups(n) {
|
||||
|
|
@ -293,12 +353,42 @@
|
|||
case 6: g = [{ k: 'ghost', c: c(8), gap: 0.6 }, { k: 'spam', c: c(16), gap: 0.2 }]; break;
|
||||
default: g = [{ k: 'ping', c: c(10), gap: 0.4 }, { k: 'trojan', c: c(3), gap: 1.0 }, { k: 'ghost', c: c(4), gap: 0.8 }];
|
||||
}
|
||||
if (n > 8) weave(g, n, c, (n - 1) % 8);
|
||||
if (n % 10 === 0) g.push({ k: 'rootkit', c: n / 10, gap: 3 });
|
||||
return g;
|
||||
}
|
||||
// From wave 9 the eight-wave cycle gets the newer kinds woven in (groups spawn one after the other, so a group
|
||||
// appended behind another trails it):
|
||||
// daemon the first healer rides with the pings of wave 9; from then on every trojan group has an escort that
|
||||
// spawns behind it and (it is faster) catches up and heals while passing through
|
||||
// proxy from wave 12 in the spam / mixed-flyer-and-trojan slots, more slots later
|
||||
// botnet swarms from wave 14, more slots (and bigger) later
|
||||
function weave(g, n, c, p) {
|
||||
const trojans = g.find((e) => e.k === 'trojan');
|
||||
if (trojans) g.push({ k: 'daemon', c: Math.max(1, Math.round(trojans.c / 2)), gap: 1.2 });
|
||||
else if (n === 9) g.push({ k: 'daemon', c: 2, gap: 1.2 });
|
||||
if (n >= 12) {
|
||||
if (p === 3) g.push({ k: 'proxy', c: c(2), gap: 1.6 });
|
||||
else if (p === 7) g.push({ k: 'proxy', c: c(2), gap: 1.4 });
|
||||
else if (p === 5 && n >= 22) g.push({ k: 'proxy', c: c(2), gap: 1.4 });
|
||||
else if (p === 2 && n >= 19) g.push({ k: 'proxy', c: c(1), gap: 1.6 });
|
||||
else if (p === 0 && n >= 25) g.push({ k: 'proxy', c: c(1), gap: 1.6 });
|
||||
}
|
||||
if (n >= 14) {
|
||||
if (p === 5) g.push({ k: 'botnet', c: c(8), gap: 0.12 });
|
||||
else if (p === 6) g.push({ k: 'botnet', c: c(8), gap: 0.1 });
|
||||
else if (p === 1 && n >= 18) g.push({ k: 'botnet', c: c(6), gap: 0.1 });
|
||||
else if (p === 4 && n >= 21) g.push({ k: 'botnet', c: c(8), gap: 0.1 });
|
||||
else if (p === 7 && n >= 24) g.push({ k: 'botnet', c: c(6), gap: 0.12 });
|
||||
}
|
||||
}
|
||||
// What the wave list in the UI shows: one entry per kind (counts summed), in order of appearance, flyers flagged.
|
||||
function waveSummary(n) {
|
||||
const out = [];
|
||||
for (const g of waveGroups(n)) out.push({ k: g.k, c: g.c });
|
||||
const out = [], at = {};
|
||||
for (const g of waveGroups(n)) {
|
||||
if (at[g.k] === undefined) { at[g.k] = out.length; out.push({ k: g.k, c: 0, air: !!ENEMIES[g.k].air }); }
|
||||
out[at[g.k]].c += g.c;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function hpScale(n) { return 1 + 0.16 * (n - 1) + 0.022 * (n - 1) * (n - 1); }
|
||||
|
|
@ -487,6 +577,7 @@
|
|||
this.autoWaves = false;
|
||||
this.nextWaveIn = -1;
|
||||
this.spawnRR = 0;
|
||||
this.healT = 0; // seconds since the last daemon pulse (one clock for all daemons)
|
||||
|
||||
this.towers = [];
|
||||
this.towerAt = new Array(this.board.cols * this.board.rows).fill(null);
|
||||
|
|
@ -509,9 +600,9 @@
|
|||
switch (c.c) {
|
||||
case 'place': return this.place(c.type, c.x, c.y, c.by | 0);
|
||||
case 'sell': return this.sell(c.id);
|
||||
case 'upgrade': return this.upgrade(c.id);
|
||||
case 'upgrade': return this.upgrade(c.id, c.lv);
|
||||
case 'target': return this.setTargetMode(c.id, c.mode);
|
||||
case 'wave': return this.startWave();
|
||||
case 'wave': return this.startWave(c.n);
|
||||
case 'auto': return this.setAuto(!!c.v);
|
||||
case 'continue': return this.continueEndless();
|
||||
default: return { ok: false, reason: 'bad_cmd' };
|
||||
|
|
@ -548,13 +639,13 @@
|
|||
if (this.state !== 'playing') return { ok: false, reason: 'over' };
|
||||
if (typeof type !== 'string' || !Object.prototype.hasOwnProperty.call(TOWERS, type)) return { ok: false, reason: 'bad_type' };
|
||||
const def = TOWERS[type];
|
||||
const cost = def.levels[0].cost;
|
||||
const cost = priceFor(type, this.towers), pm = priceMult(type, this.towers);
|
||||
if (this.gold < cost) return { ok: false, reason: 'gold' };
|
||||
const t = this.preview(x, y, false);
|
||||
if (!t.ok) return { ok: false, reason: t.reason };
|
||||
const tower = {
|
||||
id: this.nid++, type, x, y, level: 1, mode: 'first', spent: cost, owner: by | 0,
|
||||
cd: 0, tgt: 0, kills: 0, dealt: 0,
|
||||
id: this.nid++, type, x, y, level: 1, mode: 'first', spent: cost, owner: by | 0, pm,
|
||||
cd: 0, tgt: 0, kills: 0, dealt: 0, buff: 0,
|
||||
};
|
||||
this.gold -= cost;
|
||||
this.towers.push(tower);
|
||||
|
|
@ -587,14 +678,14 @@
|
|||
return { ok: true, refund };
|
||||
}
|
||||
|
||||
upgradeCost(t) {
|
||||
const lv = TOWERS[t.type].levels[t.level];
|
||||
return lv ? lv.cost : null;
|
||||
}
|
||||
upgrade(id) {
|
||||
upgradeCost(t) { return upgradePrice(t.type, t.level, t.pm); }
|
||||
// `lv` is the level the sender SAW when it pressed Upgrade (absent: no check). Two players pressing it at the same moment send the
|
||||
// same command twice; the second one finds the tower already a level higher and is refused as 'stale' instead of being charged again.
|
||||
upgrade(id, lv) {
|
||||
if (this.state !== 'playing') return { ok: false, reason: 'over' };
|
||||
const t = this.towerById(id);
|
||||
if (!t) return { ok: false, reason: 'no_tower' };
|
||||
if (lv !== undefined && lv !== null && lv !== t.level) return { ok: false, reason: 'stale' };
|
||||
const cost = this.upgradeCost(t);
|
||||
if (cost === null) return { ok: false, reason: 'max' };
|
||||
if (this.gold < cost) return { ok: false, reason: 'gold' };
|
||||
|
|
@ -628,8 +719,11 @@
|
|||
return { ok: true };
|
||||
}
|
||||
|
||||
startWave() {
|
||||
// `expect` is the wave number the sender expects this command to start (the wave it saw + 1; absent: no check; the auto-wave timer
|
||||
// never passes one). A second "Next wave" pressed at the same moment by the other player is refused as 'stale', not started twice.
|
||||
startWave(expect) {
|
||||
if (this.state !== 'playing') return { ok: false, reason: 'over' };
|
||||
if (expect !== undefined && expect !== null && expect !== this.wave + 1) return { ok: false, reason: 'stale' };
|
||||
const n = ++this.wave;
|
||||
let t = this.time + 0.3;
|
||||
for (const g of waveGroups(n)) {
|
||||
|
|
@ -647,12 +741,15 @@
|
|||
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 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))),
|
||||
leak: def.leak, slow: 0, slowT: 0, slowAmt: 0, rem: 0, dead: false, wave: q.wave,
|
||||
leak: def.leak, slow: 0, slowT: 0, slowAmt: 0, stunT: 0,
|
||||
shield, maxShield: shield, shieldT: 0,
|
||||
rem: 0, dead: false, wave: q.wave,
|
||||
};
|
||||
m.rem = m.air
|
||||
? Math.hypot(b.core.x - s.x, b.core.y - s.y)
|
||||
|
|
@ -672,7 +769,12 @@
|
|||
|
||||
for (const m of this.monsters) { // slow = lingering slow (Orbital Uplink) unless a Rate Limiter says more
|
||||
if (m.slowT > 0) { m.slow = m.slowAmt; m.slowT -= dt; } else m.slow = 0;
|
||||
if (m.stunT > 0) m.stunT -= dt;
|
||||
if (m.maxShield > 0) this.regenShield(m, dt);
|
||||
}
|
||||
this.healT += dt;
|
||||
if (this.healT >= HEAL_EVERY) { this.healT -= HEAL_EVERY; this.healPulse(); }
|
||||
this.updateAuras();
|
||||
for (const t of this.towers) this.updateTower(t, dt);
|
||||
this.updateBullets(dt);
|
||||
for (const m of this.monsters) if (!m.dead) this.moveMonster(m, dt);
|
||||
|
|
@ -704,6 +806,7 @@
|
|||
|
||||
// ---- monsters -------------------------------------------------------------------------
|
||||
moveMonster(m, dt) {
|
||||
if (m.stunT > 0) return; // stunned (Sandbox): frozen in place
|
||||
const b = this.board;
|
||||
const slowMul = 1 - Math.min(0.6, m.slow);
|
||||
let remaining = m.speed * slowMul * dt;
|
||||
|
|
@ -747,8 +850,13 @@
|
|||
|
||||
damage(m, raw, src, ignoreArmor) {
|
||||
if (m.dead) return;
|
||||
const d = ignoreArmor ? raw : Math.max(raw - m.armor, raw * 0.25);
|
||||
m.hp -= d;
|
||||
const d = ignoreArmor ? raw : Math.max(raw - m.armor, raw * 0.25); // armour applies once, to the damage dealt
|
||||
let hit = d;
|
||||
if (m.maxShield > 0) { // a shield soaks first, any damage restarts its regrow timer
|
||||
const soak = Math.min(m.shield, d);
|
||||
m.shield -= soak; hit = d - soak; m.shieldT = 0;
|
||||
}
|
||||
m.hp -= hit;
|
||||
if (src) src.dealt += d;
|
||||
if (m.hp <= 0) {
|
||||
m.dead = true;
|
||||
|
|
@ -759,6 +867,51 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Shield: after shieldDelay s without damage it regrows shieldRegen of its maximum per second.
|
||||
regenShield(m, dt) {
|
||||
const def = ENEMIES[m.kind];
|
||||
m.shieldT += dt;
|
||||
const over = Math.min(dt, m.shieldT - def.shieldDelay);
|
||||
if (over > 0 && m.shield < m.maxShield) m.shield = Math.min(m.maxShield, m.shield + m.maxShield * def.shieldRegen * over);
|
||||
}
|
||||
|
||||
// Daemon pulse, once a second on the sim's own clock: every enemy gets healed by the daemons around it (never by itself),
|
||||
// together at most HEAL_CAP of its max hp, never above max. Shields are not healed.
|
||||
healPulse() {
|
||||
let ds = null;
|
||||
for (const m of this.monsters) if (!m.dead && ENEMIES[m.kind].heal) (ds || (ds = [])).push(m);
|
||||
if (!ds) return;
|
||||
const did = new Set();
|
||||
for (const m of this.monsters) {
|
||||
if (m.dead || m.hp >= m.maxhp) continue;
|
||||
let f = 0;
|
||||
for (const d of ds) {
|
||||
if (d === m) continue;
|
||||
const def = ENEMIES[d.kind], dx = m.x - d.x, dy = m.y - d.y;
|
||||
if (dx * dx + dy * dy > def.healRange * def.healRange) continue;
|
||||
f += def.heal; did.add(d);
|
||||
}
|
||||
if (f > 0) m.hp = Math.min(m.maxhp, m.hp + Math.min(f, HEAL_CAP) * m.maxhp);
|
||||
}
|
||||
for (const d of did) this.emit({ e: 'heal', x: round2(d.x), y: round2(d.y), r: ENEMIES[d.kind].healRange });
|
||||
}
|
||||
|
||||
// Load Balancer: each attack tower gets the best boost of the support towers in range (no stacking).
|
||||
updateAuras() {
|
||||
const ts = this.towers;
|
||||
let sup = null;
|
||||
for (const t of ts) { t.buff = 0; if (TOWERS[t.type].role === 'support') (sup || (sup = [])).push(t); }
|
||||
if (!sup) return;
|
||||
for (const s of sup) {
|
||||
const st = TOWERS[s.type].levels[s.level - 1], r2 = st.range * st.range;
|
||||
for (const t of ts) {
|
||||
if (t.buff >= st.boost || TOWERS[t.type].role !== 'attack') continue;
|
||||
const dx = t.x - s.x, dy = t.y - s.y;
|
||||
if (dx * dx + dy * dy <= r2) t.buff = st.boost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- towers ---------------------------------------------------------------------------
|
||||
findTarget(t, range, def) {
|
||||
const tx = t.x + 0.5, ty = t.y + 0.5, r2 = range * range;
|
||||
|
|
@ -771,7 +924,7 @@
|
|||
let v;
|
||||
switch (t.mode) {
|
||||
case 'last': v = m.rem; break;
|
||||
case 'strong': v = m.hp; break;
|
||||
case 'strong': v = m.hp + (m.shield || 0); break;
|
||||
case 'close': v = -d2; break;
|
||||
default: v = -m.rem; // 'first': smallest remaining distance wins
|
||||
}
|
||||
|
|
@ -781,11 +934,12 @@
|
|||
}
|
||||
|
||||
updateTower(t, dt) {
|
||||
if (t.type === 'wall') return;
|
||||
const def = TOWERS[t.type];
|
||||
if (def.role === 'wall' || def.role === 'support') return;
|
||||
const st = def.levels[t.level - 1];
|
||||
const cx = t.x + 0.5, cy = t.y + 0.5;
|
||||
if (t.type === 'throttle') {
|
||||
if (def.role === 'control') { this.pulseStun(t, st, def, cx, cy, dt); return; }
|
||||
if (def.role === 'aura') {
|
||||
const r2 = st.range * st.range;
|
||||
for (const m of this.monsters) {
|
||||
if (m.dead) continue;
|
||||
|
|
@ -796,7 +950,7 @@
|
|||
}
|
||||
return;
|
||||
}
|
||||
t.cd -= dt;
|
||||
t.cd -= dt * (1 + (t.buff || 0)); // a Load Balancer makes cooldowns elapse faster
|
||||
const m = this.findTarget(t, st.range, def);
|
||||
t.tgt = m ? m.id : 0;
|
||||
if (!m) { if (t.cd < 0) t.cd = 0; return; }
|
||||
|
|
@ -805,6 +959,27 @@
|
|||
this.fire(t, st, def, m, cx, cy);
|
||||
}
|
||||
|
||||
// Sandbox: when anything is in range it stuns everything in range (ground and air) for st.stun s, then recharges st.pulse s.
|
||||
// Enemies with slowRes (bosses) are stunned for (1 - slowRes) of that. Stunned enemies do not move.
|
||||
pulseStun(t, st, def, cx, cy, dt) {
|
||||
t.cd -= dt;
|
||||
t.tgt = 0;
|
||||
const r2 = st.range * st.range, hit = [];
|
||||
for (const m of this.monsters) {
|
||||
if (m.dead || (m.air ? !def.air : !def.ground)) continue;
|
||||
const dx = m.x - cx, dy = m.y - cy;
|
||||
if (dx * dx + dy * dy <= r2) hit.push(m);
|
||||
}
|
||||
if (!hit.length) { if (t.cd < 0) t.cd = 0; return; }
|
||||
if (t.cd > 0) return;
|
||||
t.cd += st.pulse;
|
||||
for (const m of hit) {
|
||||
const dur = st.stun * (1 - (ENEMIES[m.kind].slowRes || 0));
|
||||
if (dur > m.stunT) m.stunT = dur;
|
||||
}
|
||||
this.emit({ e: 'stun', x: round2(cx), y: round2(cy), r: st.range, n: hit.length });
|
||||
}
|
||||
|
||||
fire(t, st, def, m, cx, cy) {
|
||||
switch (t.type) {
|
||||
case 'filter':
|
||||
|
|
@ -819,7 +994,7 @@
|
|||
let gx = m.x, gy = m.y;
|
||||
if (m.tx >= 0) { // lead the target along its current step
|
||||
const ex = m.tx + 0.5 - m.x, ey = m.ty + 0.5 - m.y, el = Math.hypot(ex, ey) || 1;
|
||||
const T = Math.hypot(m.x - cx, m.y - cy) / def.shellSpeed;
|
||||
const T = Math.max(0, Math.hypot(m.x - cx, m.y - cy) / def.shellSpeed - (m.stunT > 0 ? m.stunT : 0));
|
||||
const lead = Math.min(el, m.speed * (1 - Math.min(0.6, m.slow)) * T);
|
||||
gx += (ex / el) * lead; gy += (ey / el) * lead;
|
||||
}
|
||||
|
|
@ -910,7 +1085,7 @@
|
|||
|
||||
// ---- views of the state ---------------------------------------------------------------
|
||||
towerList() {
|
||||
return this.towers.map((t) => [t.id, t.type, t.x, t.y, t.level, t.mode, t.spent, t.owner]);
|
||||
return this.towers.map((t) => [t.id, t.type, t.x, t.y, t.level, t.mode, t.spent, t.owner, t.pm === 1 ? 1 : round2(t.pm * 1000) / 1000]);
|
||||
}
|
||||
|
||||
// Everything a client needs to (re)build the board from scratch.
|
||||
|
|
@ -924,7 +1099,8 @@
|
|||
|
||||
// Compact per-tick state for the wire. Arrays, not objects, to keep it small.
|
||||
snapshot() {
|
||||
const mo = this.monsters.map((m) => [m.id, ENEMY_ORDER.indexOf(m.kind), round2(m.x), round2(m.y), Math.ceil(m.hp), m.maxhp, m.slow > 0 ? 1 : 0]);
|
||||
// a shield is sent as extra hp: hp + shield out of maxhp + maxShield (the client derives the shield part from the kind's table)
|
||||
const mo = this.monsters.map((m) => [m.id, ENEMY_ORDER.indexOf(m.kind), round2(m.x), round2(m.y), Math.ceil(m.hp + (m.shield || 0)), m.maxhp + (m.maxShield || 0), m.slow > 0 || m.stunT > 0 ? 1 : 0]);
|
||||
const bu = this.bullets.map((b) => [b.id, b.k === 'mortar' ? 1 : 0, round2(b.x), round2(b.y)]);
|
||||
const tt = [];
|
||||
for (const t of this.towers) if (t.type !== 'wall') tt.push([t.id, t.tgt, t.kills]);
|
||||
|
|
@ -940,9 +1116,9 @@
|
|||
function round2(v) { return Math.round(v * 100) / 100; }
|
||||
|
||||
return {
|
||||
STEP, WAVE_INTERVAL, START_GOLD, START_LIVES, SELL_RATIO, WIN_WAVE,
|
||||
STEP, WAVE_INTERVAL, START_GOLD, START_LIVES, SELL_RATIO, WIN_WAVE, HEAL_EVERY, HEAL_CAP,
|
||||
MAPS, MAP_ORDER, TOWERS, TOWER_ORDER, TARGET_MODES, ENEMIES, ENEMY_ORDER,
|
||||
waveGroups, waveSummary, hpScale, rewardScale,
|
||||
priceFor, priceMult, upgradePrice, waveGroups, waveSummary, hpScale, rewardScale,
|
||||
buildField, nextCell, traceRoute, parseMap, Board, Sim, round2,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue