feedback1 integrate: WD 转译基底 transforms, 逐火 embers beatable, knock-out forms kept by the client
# Conflicts: # docs/PLAYING.md
This commit is contained in:
commit
3328dedea2
19 files changed
+1850
-188
No files matched your search
@@ -15,6 +15,7 @@ const E = JSON.parse(fs.readFileSync(new URL('../../data/enemies.json', import.m
|
||||
const W = JSON.parse(fs.readFileSync(new URL('../../data/waves.json', import.meta.url), 'utf8'));
|
||||
const { KITS, STATS_ONLY, EROSION, EROSION_BURST } = enemiesMod;
|
||||
const { BOSS_KITS, PART_TRANSFER, BLADE_TRANSFER, DRONE_LINK_BASE, droneLinkBase } = bossesMod;
|
||||
const { HUSK_REBIRTH, TRANSLATOR_CHANGE } = enemiesMod;
|
||||
|
||||
const BIG = [];
|
||||
for (let dr = -4; dr <= 4; dr++) for (let dc = -12; dc <= 12; dc++) BIG.push([dr, dc]);
|
||||
@@ -213,7 +214,7 @@ for (const key of ['enemy_1200_msfjin', 'enemy_1204_msfhu', 'enemy_1288_duskls']
|
||||
h.step();
|
||||
const e = put(h, key, [10, 7]);
|
||||
const g = h.unit('t_mage');
|
||||
if (/duskls/.test(key)) { killed(h, e, g); assert.ok(e.alive, 'ember'); }
|
||||
if (/duskls/.test(key)) { killed(h, e, g); assert.ok(e.alive, 'ember'); h.run(HUSK_REBIRTH + 0.05); }
|
||||
const hits = e.s.maxHp;
|
||||
assert.ok(hits > 1 && hits <= 30);
|
||||
let n = 0;
|
||||
@@ -307,7 +308,7 @@ for (const key of ['enemy_1203_sfhu', 'enemy_1203_sfhu_2']) {
|
||||
}
|
||||
|
||||
for (const key of ['enemy_1288_duskls', 'enemy_1288_duskls_2', 'enemy_1292_duskld']) {
|
||||
test(`${nm(key)}: knocked out ⇒ stealthed ember needing ${tb(key, 'Revive[Trigger].prop_max_hp')} hits; revives at full HP after ${tb(key, 'Revive[Trigger].interval')} s`, () => {
|
||||
test(`${nm(key)}: knocked out ⇒ ${HUSK_REBIRTH} s 重生, then a walking, disarmed, 隐匿 ember needing ${tb(key, 'Revive[Trigger].prop_max_hp')} hits; full HP again ${tb(key, 'Revive[Trigger].interval')} s later`, () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 12, col: 3 }] });
|
||||
h.step();
|
||||
const e = put(h, key, [10, 7]);
|
||||
@@ -315,19 +316,23 @@ for (const key of ['enemy_1288_duskls', 'enemy_1288_duskls_2', 'enemy_1292_duskl
|
||||
killed(h, e, h.unit('t_gun'));
|
||||
assert.ok(e.alive);
|
||||
assert.equal(e.s.maxHp, tb(key, 'Revive[Trigger].prop_max_hp'));
|
||||
assert.ok(e.s.flags.stealth && e.profile.noAttack);
|
||||
h.run(tb(key, 'Revive[Trigger].interval') + 0.1);
|
||||
assert.ok(e.s.flags.invulnerable && e.s.flags.unblockable && e.s.flags.noMove, '重生');
|
||||
h.run(HUSK_REBIRTH + 0.05);
|
||||
assert.ok(e.s.flags.stealth && e.s.flags.disarm && e.profile.noAttack, '余烬: 隐匿, 缴械');
|
||||
assert.ok(!e.s.flags.unblockable && !e.s.flags.noMove, 'blockable, walks');
|
||||
h.run(tb(key, 'Revive[Trigger].interval'));
|
||||
assert.equal(e.s.maxHp, max);
|
||||
assert.equal(e.hp, max);
|
||||
assert.ok(!e.s.flags.stealth);
|
||||
// an ember hit N times dies for good
|
||||
killed(h, e, null);
|
||||
h.run(HUSK_REBIRTH + 0.05);
|
||||
for (let i = 0; i < tb(key, 'Revive[Trigger].prop_max_hp'); i++) h.b.dealDamage(null, e, { amount: 1, type: 'arts' });
|
||||
assert.ok(!e.alive);
|
||||
});
|
||||
}
|
||||
|
||||
test(`${nm('enemy_9010_acpupp')}: knocked out ⇒ 15-hit regeneration husk that revives, and nearby enemies get a 5-hit shield`, () => {
|
||||
test(`${nm('enemy_9010_acpupp')}: knocked out ⇒ an unblockable 15-hit 傀儡 that walks on and revives, and nearby enemies get a 5-hit shield`, () => {
|
||||
const h = arena();
|
||||
h.step();
|
||||
const e = put(h, 'enemy_9010_acpupp', [10, 7]);
|
||||
@@ -335,6 +340,8 @@ test(`${nm('enemy_9010_acpupp')}: knocked out ⇒ 15-hit regeneration husk that
|
||||
killed(h, e, null);
|
||||
assert.ok(e.alive);
|
||||
assert.equal(e.s.maxHp, tb('enemy_9010_acpupp', 'Revive[Trigger].prop_max_hp'));
|
||||
h.run(HUSK_REBIRTH + 0.05);
|
||||
assert.ok(e.s.flags.unblockable && e.s.flags.disarm && !e.s.flags.stealth && !e.s.flags.noMove, '傀儡: 不可被阻挡, not stealthed');
|
||||
const hp = o.hp;
|
||||
for (let i = 0; i < tb('enemy_9010_acpupp', 'Aura.max_damage_block_cnt'); i++) h.b.dealDamage(null, o, { amount: 100, type: 'phys' });
|
||||
assert.equal(o.hp, hp, 'shield negates the hits');
|
||||
@@ -342,6 +349,7 @@ test(`${nm('enemy_9010_acpupp')}: knocked out ⇒ 15-hit regeneration husk that
|
||||
assert.ok(o.hp < hp);
|
||||
h.run(tb('enemy_9010_acpupp', 'Revive[Trigger].interval') + 0.1);
|
||||
assert.equal(e.hp, E.enemy_9010_acpupp.stats.maxHp);
|
||||
assert.ok(!e.s.flags.unblockable);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
@@ -640,17 +648,33 @@ for (const key of ['enemy_1169_duphlx', 'enemy_1169_duphlx_2']) {
|
||||
}
|
||||
|
||||
for (const key of ['enemy_1172_dugago', 'enemy_1172_dugago_2']) {
|
||||
test(`${nm(key)}: first knock-out ⇒ statue (DEF +${tb(key, 'stone.def')}) for ${tb(key, 'stone.duration')} s, then reborn as a flyer`, () => {
|
||||
const h = arena({ units: [{ chessId: 't_wall', row: 10, col: 7 }] });
|
||||
test(`${nm(key)}: melee only while blocked; first knock-out ⇒ unblockable statue (DEF +${tb(key, 'stone.def')}, 失衡 / 浮空 immune) for ${tb(key, 'stone.duration')} s, then a flyer with ranged arts attacks that skip flyers (PRTS 天赋)`, () => {
|
||||
// 地面模式: an operator in its 1.6 radius but not blocking it is never attacked
|
||||
const h0 = arena({ units: [{ chessId: 't_gun', row: 11, col: 7 }] });
|
||||
h0.step();
|
||||
put(h0, key, [10, 7]);
|
||||
h0.run(6);
|
||||
assert.equal(h0.unit('t_gun').stats.taken, 0, 'no ranged attack in its ground mode');
|
||||
const h = arena({ units: [{ chessId: 't_wall', row: 10, col: 7 }, { chessId: 't_gun', row: 11, col: 7 }], kits: { t_gun: NOATK }, hooks: ['damaged'], captureNoisy: true });
|
||||
h.step();
|
||||
const e = put(h, key, [10, 7]);
|
||||
h.step();
|
||||
killed(h, e, null);
|
||||
assert.ok(e.alive);
|
||||
assert.equal(e.hp, e.s.maxHp, 'an instant 重生 to full HP');
|
||||
assert.equal(e.s.def, E[key].stats.def + tb(key, 'stone.def'));
|
||||
h.step();
|
||||
assert.ok(e.s.flags.unblockable && e.s.flags.noDisplace && !e.blockedBy, '转换模式: 无法被阻挡, 失衡免疫');
|
||||
assert.equal(h.b.applyStatus(e, 'levitate', { duration: 2 }), false, '免疫浮空');
|
||||
h.b.dealDamage(h.unit('t_gun'), e, { amount: e.s.maxHp * 0.3, type: 'true' });
|
||||
const hp = e.hp;
|
||||
h.run(tb(key, 'stone.duration') + 0.5);
|
||||
assert.equal(e.motion, 'FLY');
|
||||
assert.ok(!e.blockedBy);
|
||||
assert.equal(e.hp, hp, 'no second refill when it takes off');
|
||||
assert.ok(h.runUntil(() => e.stats.attacks > 0, 10), '飞行模式 attacks at range');
|
||||
assert.ok(h.unit('t_gun').stats.taken + h.unit('t_wall').stats.taken > 0, 'an operator in its radius');
|
||||
assert.ok(h.hooksOf('damaged').filter((c) => c.source === e && c.dmg.isAttack).every((c) => c.dmg.type === 'arts'), 'arts damage');
|
||||
killed(h, e, null);
|
||||
assert.ok(!e.alive, 'second knock-out is final');
|
||||
});
|
||||
@@ -1849,30 +1873,34 @@ test(`${nm('enemy_1535_wlfmster')}: −${tb('enemy_1535_wlfmster', 'Passive.dama
|
||||
assert.equal(h.b.applyStatus(e, 'stun', { duration: 1 }), true, 'stunnable in the second form');
|
||||
});
|
||||
|
||||
test(`${nm('enemy_10081_mpplai')}: no attack until 4 physical hits (复仇: melee), 4 arts hits (术士: ranged arts) or being blocked (幽灵: unblockable)`, () => {
|
||||
test(`${nm('enemy_10081_mpplai')}: original form cancels every damage instance; 4th physical hit ⇒ 寻仇者 (melee), 4th arts hit ⇒ 特战术师 (ranged arts), blocked ⇒ 幽灵 (unblockable) — each after a ${TRANSLATOR_CHANGE} s change`, () => {
|
||||
const mk = () => { const h = arena({ units: [{ chessId: 't_gun', row: 12, col: 3 }, { chessId: 't_mage', row: 12, col: 4 }], kits: { t_gun: NOATK, t_mage: NOATK } }); h.step(); return h; };
|
||||
let h = mk();
|
||||
let e = put(h, 'enemy_10081_mpplai', [10, 7]);
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(h.unit('t_gun'), e, { amount: 10, type: 'phys' });
|
||||
const hp = e.hp;
|
||||
for (let i = 0; i < 4; i++) assert.equal(h.b.dealDamage(h.unit('t_gun'), e, { amount: 1e6, type: 'phys' }), 0);
|
||||
assert.equal(e.hp, hp, 'no damage lands in the original form');
|
||||
h.run(TRANSLATOR_CHANGE + 0.05);
|
||||
approx(e.s.atk, E.enemy_10081_mpplai.stats.atk + tb('enemy_10081_mpplai', 'Mode_Fuchou_Passive.atk'));
|
||||
approx(e.s.maxHp, E.enemy_10081_mpplai.stats.maxHp + tb('enemy_10081_mpplai', 'Mode_Fuchou_Passive.max_hp'));
|
||||
const h2 = arena({ units: [{ chessId: 't_wall', row: 10, col: 6 }] });
|
||||
h2.step();
|
||||
const f = put(h2, 'enemy_10081_mpplai', [10, 7]);
|
||||
for (let i = 0; i < 4; i++) h2.b.dealDamage(null, f, { amount: 1, type: 'arts' });
|
||||
assert.equal(f.mem.ab.list.length, 3);
|
||||
// arts hits from nobody (terrain) do not count
|
||||
h2.run(TRANSLATOR_CHANGE + 0.05);
|
||||
assert.equal(f.findBuff('ab:form'), null);
|
||||
h = mk();
|
||||
e = put(h, 'enemy_10081_mpplai', [11, 5]);
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(h.unit('t_mage'), e, { amount: 10, type: 'arts' });
|
||||
h.run(TRANSLATOR_CHANGE + 0.05);
|
||||
approx(e.s.res, E.enemy_10081_mpplai.stats.res + tb('enemy_10081_mpplai', 'Mode_Shushi_Passive.magic_resistance'));
|
||||
h.run(3);
|
||||
assert.ok(e.stats.attacks > 0 && h.unit('t_gun').stats.taken + h.unit('t_mage').stats.taken > 0, '术士 attacks in range');
|
||||
assert.ok(e.stats.attacks > 0 && h.unit('t_gun').stats.taken + h.unit('t_mage').stats.taken > 0, '特战术师 attacks in range');
|
||||
const h3 = arena({ units: [{ chessId: 't_wall', row: 9, col: 5 }] });
|
||||
h3.step();
|
||||
const g = put(h3, 'enemy_10081_mpplai', [9, 5]);
|
||||
h3.run(0.5);
|
||||
h3.run(TRANSLATOR_CHANGE + 0.3);
|
||||
assert.ok(g.findBuff('ab:form') && g.s.flags.unblockable, '幽灵');
|
||||
assert.equal(g.stats.attacks, 0);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
// test/match/feedback1-runner-forms.test.js — player report #5 after 0.1.0 ("转译基底不会变身…加载变身动画然后就没了"), the
|
||||
// client runner's part (public/js/battle/runner.js under Node: fake socket, manual clock and animation frames, the real
|
||||
// sim on the real stage 战场#01). A form change reaches the view only as an fx with a `form` (sim content/enemies.js
|
||||
// setForm; shared/protocol.js fxForm) — b.snap tuples carry no form. The runner used to drop those fx in a catch-up
|
||||
// frame (a stall of more than ≈0.53 s real at 2×: only spawn / die / deploy / status / skill / leak passed) and every
|
||||
// event while the tab was hidden, so the view kept the first form and the 转译基底·α died on the 寻仇者's B_Die (the
|
||||
// review's headless-Chrome repro). Now a catch-up keeps them (keepsState), a hidden tab holds the battle on screen's
|
||||
// state-bearing events for the first frame back (≤ HELD_MAX, else the view re-enters from the field meta), and the game
|
||||
// screen's pre-entry buffer keeps them too (screens/game.js keepEarly, same predicate).
|
||||
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createBattleRunner, keepsState, HELD_MAX } from '../../public/js/battle/runner.js';
|
||||
import { createStore, initialState } from '../../public/js/store.js';
|
||||
import * as specMod from '../../server/sim/spec.js';
|
||||
import { DataSource } from '../../server/sim/simdata.js';
|
||||
import { validateC2S, fxForm } from '../../shared/protocol.js';
|
||||
import { DATA } from './harness.js';
|
||||
|
||||
const DS = new DataSource(DATA, null);
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const TR = 'enemy_10081_mpplai';
|
||||
|
||||
function fakeNet() {
|
||||
const handlers = new Map();
|
||||
const n = {
|
||||
sent: [],
|
||||
on(t, fn) { if (!handlers.has(t)) handlers.set(t, new Set()); handlers.get(t).add(fn); return () => handlers.get(t).delete(fn); },
|
||||
emit(t, msg) { for (const fn of handlers.get(t) || []) fn({ t, ...msg }); },
|
||||
send(t, fields) { const msg = { ...fields, t }; assert.equal(validateC2S(msg), null, `invalid ${t}`); n.sent.push(msg); return true; },
|
||||
request(t, fields) { const msg = { ...fields, t, rid: 1 }; assert.equal(validateC2S(msg), null, `invalid ${t}`); n.sent.push(msg); return Promise.resolve({ t: 'ok' }); },
|
||||
};
|
||||
return n;
|
||||
}
|
||||
|
||||
function rig({ hidden = false } = {}) {
|
||||
let t = 1000;
|
||||
const frames = [];
|
||||
const intervals = [];
|
||||
const docListeners = [];
|
||||
const doc = { hidden, addEventListener(type, fn) { if (type === 'visibilitychange') docListeners.push(fn); } };
|
||||
const net = fakeNet();
|
||||
const store = createStore(initialState);
|
||||
const runner = createBattleRunner({
|
||||
net, store, doc,
|
||||
now: () => t,
|
||||
raf: (fn) => { frames.push(fn); return frames.length; },
|
||||
caf: () => {},
|
||||
setInterval: (fn) => { intervals.push(fn); return intervals.length; },
|
||||
clearInterval: () => {},
|
||||
loadSim: async () => ({ spec: specMod, ds: DS }),
|
||||
logger: { error() {}, warn() {}, info() {}, debug() {} },
|
||||
});
|
||||
const feed = { evs: [], fields: [], snaps: 0 };
|
||||
runner.on('ev', (e) => feed.evs.push(e));
|
||||
runner.on('field', (f) => feed.fields.push(f));
|
||||
runner.on('snap', () => { feed.snaps++; });
|
||||
return {
|
||||
runner, net, doc, feed,
|
||||
/** advance the clock by `ms` in animation frames of `step` ms (pump intervals while hidden) */
|
||||
advance(ms, step = 1000 / 60) {
|
||||
const end = t + ms;
|
||||
while (t < end) {
|
||||
t = Math.min(end, t + step);
|
||||
if (doc.hidden) { for (const fn of intervals) fn(); continue; }
|
||||
const q = frames.splice(0);
|
||||
for (const fn of q) fn(t);
|
||||
}
|
||||
},
|
||||
show() { doc.hidden = false; for (const fn of docListeners) fn(); },
|
||||
async settle() { for (let i = 0; i < 50; i++) { await new Promise((res) => setImmediate(res)); const q = frames.splice(0); for (const fn of q) fn(t); } },
|
||||
};
|
||||
}
|
||||
|
||||
/** 战场#01: 百炼嘉维尔 blocks the lower lane on (9,8); one 转译基底·α walks it (9,10) → (9,2) — blocked, it turns 幽灵. */
|
||||
const start = (authoritative = false) => ({
|
||||
battleId: 'fb1.runner', fieldId: 'n:P1', kind: 'normal', speed: 2, elapsed: 0, authoritative, watch: !authoritative,
|
||||
spec: specMod.buildBattleSpec({
|
||||
battleId: 'fb1.runner', fieldId: 'n:P1', kind: 'normal', seed: 5, modeId: 'mode_multi_hard', round: 3, stageId: 'act2autochess_m01', timeLimit: 400,
|
||||
players: [{ playerId: 'P1', seat: 0, side: 'L', colOffset: 0, units: [{ uid: 1, kind: 'chess', chessId: 'chess_char_4_23_b', row: 9, col: 8, dir: 'RIGHT' }], bonds: {}, playerEffects: [] }],
|
||||
spawns: [{ time: 0, enemyKey: TR, routeIndex: 0, count: 1, mods: { hpMul: 1, atkMul: 0.01 } }],
|
||||
routes: [{ motion: 'WALK', start: [9, 10], end: [9, 2], checkpoints: [] }], flags: {},
|
||||
}),
|
||||
});
|
||||
|
||||
const all = (feed) => feed.evs.flatMap((x) => x.ev);
|
||||
const formsOf = (list, id) => list.filter((x) => fxForm(x) !== undefined && x[4].id === id).map(fxForm);
|
||||
const trOf = (e) => e.battle.units.find((u) => u.defId === TR);
|
||||
|
||||
test('fxForm / keepsState: a setForm fx (any fx kind with a `form`) is state; a barrier \'phase\', hit sparks and damage numbers are not', () => {
|
||||
assert.equal(fxForm(['fx', 'phase', 1, 2, { id: 3, kind: 'translator_youling', form: 'translator_youling', dur: 2 }]), 'translator_youling');
|
||||
assert.equal(fxForm(['fx', 'ember', 1, 2, { id: 3, hits: 5, dur: 11, form: 'husk' }]), 'husk');
|
||||
assert.equal(fxForm(['fx', 'revive', 1, 2, { id: 3, form: null }]), null, 'null = back to the base clip set');
|
||||
assert.equal(fxForm(['fx', 'phase', 1, 2, { id: 3, kind: 'artsBarrier', value: 300 }]), undefined, 'a barrier phase is no form');
|
||||
assert.equal(fxForm(['fx', 'ember', 1, 2, { form: 'husk' }]), undefined, 'no unit');
|
||||
assert.equal(fxForm(['dmg', 3, 100]), undefined);
|
||||
assert.ok(keepsState(['fx', 'revive', 1, 2, { id: 3, form: 'revived' }]));
|
||||
assert.ok(keepsState(['spawn', { id: 3 }]) && keepsState(['die', 3, 'killed']));
|
||||
assert.ok(!keepsState(['fx', 'explode', 1, 2, { r: 1 }]) && !keepsState(['atk', 1, 3]) && !keepsState(['dmg', 3, 100]));
|
||||
});
|
||||
|
||||
test('the smooth feed carries 转译基底·α\'s form fx (blocked ⇒ 幽灵)', async () => {
|
||||
const r = rig();
|
||||
r.net.emit('b.start', start());
|
||||
await r.settle();
|
||||
const e = r.runner._entries.get('fb1.runner');
|
||||
for (let i = 0; i < 12 && trOf(e)?.form == null; i++) r.advance(1000);
|
||||
r.advance(1500);
|
||||
const tr = trOf(e);
|
||||
assert.equal(tr?.form, 'translator_youling', 'fixture: blocked by 百炼嘉维尔 it turns 幽灵');
|
||||
assert.equal(r.runner.stats().catchups, 0, 'no catch-up');
|
||||
assert.deepEqual(formsOf(all(r.feed), tr.id), ['translator_youling']);
|
||||
r.runner.dispose();
|
||||
});
|
||||
|
||||
test('janky frames (0.7 s each: every frame a catch-up) keep the form fx — hit sparks and damage numbers still go', async () => {
|
||||
const r = rig();
|
||||
r.net.emit('b.start', start());
|
||||
await r.settle();
|
||||
const e = r.runner._entries.get('fb1.runner');
|
||||
for (let i = 0; i < 40 && !e.done && !(trOf(e)?.form && e.battle.time > 12); i++) r.advance(700, 700);
|
||||
const tr = trOf(e);
|
||||
assert.equal(tr?.form, 'translator_youling');
|
||||
assert.ok(r.runner.stats().catchups > 5, `catch-up frames (${r.runner.stats().catchups})`);
|
||||
const list = all(r.feed);
|
||||
assert.deepEqual(formsOf(list, tr.id), ['translator_youling'], 'the view learns the 幽灵 form (it used to keep the A model)');
|
||||
assert.ok(!list.some((x) => x[0] === 'atk' || x[0] === 'dmg'), 'catch-up frames still drop the decoration');
|
||||
const spawnAt = list.findIndex((x) => x[0] === 'spawn' && x[1].id === tr.id);
|
||||
const formAt = list.findIndex((x) => fxForm(x) !== undefined && x[4].id === tr.id);
|
||||
const dieAt = list.findIndex((x) => x[0] === 'die' && x[1] === tr.id);
|
||||
assert.ok(spawnAt >= 0 && formAt > spawnAt && (dieAt < 0 || dieAt > formAt), `in order: spawn ${spawnAt}, form ${formAt}, die ${dieAt}`);
|
||||
r.runner.dispose();
|
||||
});
|
||||
|
||||
test('a hidden tab across the change: nothing rendered meanwhile, the first frame back delivers the held spawn and form fx', async () => {
|
||||
const r = rig({ hidden: true });
|
||||
r.net.emit('b.start', start(true));
|
||||
await r.settle();
|
||||
const e = r.runner._entries.get('fb1.runner');
|
||||
assert.equal(r.feed.fields.length, 1, 'shown (the field meta) before the first tick');
|
||||
for (let i = 0; i < 12 && trOf(e)?.form == null; i++) r.advance(1000, 250);
|
||||
r.advance(1500, 250);
|
||||
const tr = trOf(e);
|
||||
assert.equal(tr?.form, 'translator_youling', 'pumped through the change while hidden');
|
||||
assert.equal(r.feed.evs.length, 0, 'nothing rendered while hidden');
|
||||
assert.ok(e.held.length > 0 && e.held.every(keepsState), 'the battle on screen holds its state-bearing events');
|
||||
r.show();
|
||||
r.advance(1000 / 60);
|
||||
const first = r.feed.evs[0]?.ev || [];
|
||||
assert.ok(first.some((x) => x[0] === 'spawn' && x[1].id === tr.id), 'the translator\'s spawn (it used to come back as an unknown view)');
|
||||
assert.deepEqual(formsOf(first, tr.id), ['translator_youling'], 'and its form');
|
||||
assert.equal(e.held.length, 0);
|
||||
assert.equal(r.feed.fields.length, 1, 'no re-entry needed');
|
||||
r.runner.dispose();
|
||||
});
|
||||
|
||||
test('a hidden-tab backlog beyond HELD_MAX: the first frame back re-enters the view from the field meta (UnitInfo `form`)', async () => {
|
||||
const r = rig({ hidden: true });
|
||||
r.net.emit('b.start', start(true));
|
||||
await r.settle();
|
||||
const e = r.runner._entries.get('fb1.runner');
|
||||
for (let i = 0; i < 12 && trOf(e)?.form == null; i++) r.advance(1000, 250);
|
||||
const tr = trOf(e);
|
||||
assert.ok(tr?.form, 'changing');
|
||||
e.held.push(...Array.from({ length: HELD_MAX }, () => ['status', tr.id, 'stun', false]));
|
||||
r.advance(500, 250);
|
||||
assert.ok(e.stale && e.held.length === 0, 'overflow: dropped, marked stale');
|
||||
r.show();
|
||||
r.advance(1000 / 60);
|
||||
assert.equal(r.feed.fields.length, 2, 're-entered');
|
||||
const meta = r.feed.fields[1];
|
||||
assert.equal(meta.units.find((u) => u.id === tr.id)?.form, 'translator_youling', 'the field meta carries the form');
|
||||
assert.equal(e.stale, false);
|
||||
r.advance(1000 / 60);
|
||||
assert.ok(!r.feed.evs.some((x) => x.ev.some((y) => y[0] === 'status' && y[2] === 'stun')), 'the dropped backlog never arrives');
|
||||
r.runner.dispose();
|
||||
});
|
||||
|
||||
test('screens/game.js buffers the form fx with the state-bearing events it replays when a field is entered late', () => {
|
||||
const src = readFileSync(path.join(ROOT, 'public/js/screens/game.js'), 'utf8');
|
||||
assert.match(src, /const keepEarly = \(e\) => Array\.isArray\(e\) && \(STATE_EV\.has\(e\[0\]\) \|\| fxForm\(e\) !== undefined\);/);
|
||||
assert.match(src, /for \(const e of msg\.ev\) if \(keepEarly\(e\)\) buf\.push\(e\);/);
|
||||
});
|
||||
@@ -0,0 +1,291 @@
|
||||
// test/render/feedback1-forms.browser.test.js — player reports after 0.1.0 (#5, #8) in headless Chrome: the real sim runs
|
||||
// in the page (the client runner's loadBrowserSim) and feeds the render demo's field view on 战场#01 (render/app.js fx
|
||||
// 'phase' / `form` → render/units.js setForm / FORMS):
|
||||
// #5 转译基底·α walks on its A_* clips, takes 4 physical hits without losing HP, plays its 2 s A_Die_B change and goes on
|
||||
// as 寻仇者 (B_*), dying on B_Die — it used to die in its first form, on B_Die ("加载变身动画然后就没了");
|
||||
// #8 a 深池逐火战士 knocked out in front of 百炼嘉维尔 plays 'Die' (its 1 s 重生), stands there as the 隐匿 ember on
|
||||
// Idle_2 (blocked, so its blocker beats it) and dies on Die_2 — it used to stay an untargetable ember forever;
|
||||
// a view built mid-battle — the real `view.enterBattle(b.fieldMeta())` after a silent catch-up, as for a teammate's
|
||||
// field watched later, 联防 observers or a reconnect — starts in the current forms (UnitInfo `form` → render/app.js
|
||||
// renderInfo): it used to draw the warrior / the A model again (the look of report #5) and 掠海漂移体 hovering;
|
||||
// the real client runner (battle/runner.js createBattleRunner) feeding the view the way screens/game.js does, with
|
||||
// janky 0.7 s frames (every frame a catch-up) across the change of a 转译基底·α that walks into 百炼嘉维尔's block:
|
||||
// the view turns 幽灵 (C_*) — the catch-up filter used to drop the form fx, so it stayed on A_Move and died on B_Die.
|
||||
//
|
||||
// Opt-in (starts Chrome): RENDER_E2E=1 node --test test/render/feedback1-forms.browser.test.js
|
||||
// Chrome path: $CHROME_PATH or the macOS default. Screenshots → test/e2e/out/feedback1-*.png.
|
||||
|
||||
import { test, describe, before, after } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync, mkdirSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { buildBattleSpec } from '../../server/sim/spec.js';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const OUT = path.join(ROOT, 'test/e2e/out');
|
||||
const CHROME = process.env.CHROME_PATH || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
||||
const enabled = process.env.RENDER_E2E === '1' && existsSync(CHROME) && existsSync(path.join(ROOT, 'public/assets'));
|
||||
const skip = enabled ? false : 'set RENDER_E2E=1 (needs Chrome and downloaded assets)';
|
||||
/** The view plays the feed a little behind the sim (its interpolation buffer): game seconds allowed after an event. */
|
||||
const LAG = 0.4;
|
||||
|
||||
/** 百炼嘉维尔 facing the lower gate on (9,8) (`row`, `col`: elsewhere); one enemy walking the lower lane (9,10) → (9,2). */
|
||||
const spec = (enemyKey, id, row = 9, col = 8) => buildBattleSpec({
|
||||
battleId: `e2e.${id}`, fieldId: 'n:P1', kind: 'normal', seed: 5, modeId: 'mode_multi_hard', round: 3, stageId: 'act2autochess_m01', timeLimit: 400,
|
||||
players: [{ playerId: 'P1', seat: 0, side: 'L', colOffset: 0, units: [{ uid: 1, kind: 'chess', chessId: 'chess_char_4_23_b', row, col, dir: 'RIGHT' }], bonds: {}, playerEffects: [] }],
|
||||
spawns: [{ time: 0, enemyKey, routeIndex: 0, count: 1, mods: { hpMul: 1, atkMul: 0.01 } }],
|
||||
routes: [{ motion: 'WALK', start: [9, 10], end: [9, 2], checkpoints: [] }], flags: {},
|
||||
});
|
||||
|
||||
/**
|
||||
* Run `spec` in the page for `secs` game seconds; `act(b, e, ally)` runs every tick (the test's own interventions).
|
||||
* Returns samples { t, clip, form, alive, hp, stealth, blocked } of the enemy's view every 6 ticks.
|
||||
*/
|
||||
async function runInPage(page, port, s, enemyKey, secs, actSrc) {
|
||||
await page.goto(`http://127.0.0.1:${port}/dev/render-demo.html?scene=normal-m01&paused=1&panel=0`);
|
||||
await page.waitForFunction('window.__demo && (window.__demo.ready || window.__demo.error)', { timeout: 30000 });
|
||||
return page.evaluate(async (spec, key, secs, actSrc) => {
|
||||
const act = new Function('b', 'e', 'ally', 'state', actSrc);
|
||||
const { loadBrowserSim } = await import('/js/battle/runner.js');
|
||||
const { data } = await import('/js/data.js');
|
||||
const { spec: S, ds } = await loadBrowserSim();
|
||||
const b = S.createBattleFromSpec(spec, ds, { quiet: true });
|
||||
const v = window.__demo.view;
|
||||
v.setStage(data.lookup('stages', spec.stageId));
|
||||
b.step();
|
||||
const meta = b.fieldMeta();
|
||||
v.enterBattle(meta);
|
||||
v.setCamera('normal', { rect: meta.rect, side: 'L', instant: true });
|
||||
v.setLocalFeed({ on: true, speed: 2 });
|
||||
const raf = () => new Promise((r) => requestAnimationFrame(() => r()));
|
||||
const out = [];
|
||||
const state = {};
|
||||
let e = null;
|
||||
for (let i = 0; i < 30 * secs; i++) {
|
||||
if (!b.finished) b.step(); // (the view goes on after the end: the death clip)
|
||||
const t = Math.max(b.time, (i + 1) / 30);
|
||||
e = e ?? b.units.find((x) => x.side === 'enemy' && x.defId === key) ?? null;
|
||||
const ally = b.allyUnits[0];
|
||||
if (e) act(b, e, ally, state);
|
||||
if (i % 3 === 2) {
|
||||
const ev = b.drainEvents();
|
||||
if (ev.length) v.pushEvents({ t: 'b.ev', fieldId: meta.fieldId, gt: b.time, ev });
|
||||
v.pushSnapshot(b.snapshot());
|
||||
await raf();
|
||||
if (i === 30 * 2) await new Promise((r) => setTimeout(r, 2500)); // the Spine models load
|
||||
const view = e && v.debug.views.get(e.id);
|
||||
if (e && i % 6 === 5) out.push({ t: +t.toFixed(2), clip: view?.actor?.current ?? null, form: view?.form ?? null, spine: !!view?.spineReady, alive: e.alive, hp: e.hp, max: e.s.maxHp, stealth: !!e.s.flags.stealth, blocked: !!e.blockedBy });
|
||||
}
|
||||
}
|
||||
return { out, state };
|
||||
}, s, enemyKey, secs, actSrc);
|
||||
}
|
||||
|
||||
/**
|
||||
* The late view: `spec` runs silently in the page (events drained and dropped, like the client runner's catch-up) while
|
||||
* `setupSrc(b, ally)` changes the enemies' forms; at `atSecs` the field view enters the battle from `b.fieldMeta()` and
|
||||
* follows the feed. Returns { [name]: { clip, form, alive } } of the views of the enemies `setupSrc` returns by name.
|
||||
*/
|
||||
async function lateViewInPage(page, port, s, atSecs, setupSrc) {
|
||||
await page.goto(`http://127.0.0.1:${port}/dev/render-demo.html?scene=normal-m01&paused=1&panel=0`);
|
||||
await page.waitForFunction('window.__demo && (window.__demo.ready || window.__demo.error)', { timeout: 30000 });
|
||||
return page.evaluate(async (spec, atSecs, setupSrc) => {
|
||||
const setup = new Function('b', 'ally', setupSrc);
|
||||
const { loadBrowserSim } = await import('/js/battle/runner.js');
|
||||
const { data } = await import('/js/data.js');
|
||||
const { spec: S, ds } = await loadBrowserSim();
|
||||
const b = S.createBattleFromSpec(spec, ds, { quiet: true });
|
||||
const v = window.__demo.view;
|
||||
v.setStage(data.lookup('stages', spec.stageId));
|
||||
b.step();
|
||||
const named = setup(b, b.allyUnits[0]);
|
||||
while (b.time < atSecs) { b.step(); b.drainEvents(); }
|
||||
const meta = b.fieldMeta();
|
||||
v.enterBattle(meta);
|
||||
v.setCamera('normal', { rect: meta.rect, side: 'L', instant: true });
|
||||
v.setLocalFeed({ on: true, speed: 2 });
|
||||
const raf = () => new Promise((r) => requestAnimationFrame(() => r()));
|
||||
const read = () => Object.fromEntries(Object.entries(named).map(([k, u]) => {
|
||||
const view = v.debug.views.get(u.id);
|
||||
return [k, { clip: view?.actor?.current ?? null, form: view?.form ?? null, spine: !!view?.spineReady, alive: u.alive, simForm: u.form }];
|
||||
}));
|
||||
for (let i = 0; i < 30; i++) {
|
||||
b.step();
|
||||
if (i % 3 === 2) {
|
||||
const ev = b.drainEvents();
|
||||
if (ev.length) v.pushEvents({ t: 'b.ev', fieldId: meta.fieldId, gt: b.time, ev });
|
||||
v.pushSnapshot(b.snapshot());
|
||||
await raf();
|
||||
}
|
||||
if (i === 15) await new Promise((r) => setTimeout(r, 2500)); // the Spine models load
|
||||
}
|
||||
return read();
|
||||
}, s, atSecs, setupSrc);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real client runner in the page (fake socket / store, its default sim loader and clock) feeds the demo's view like
|
||||
* screens/game.js (field → enterBattle, snap → pushSnapshot, ev → pushEvents); its animation frames come every `jankMs`
|
||||
* real ms for `secs` real s. Returns samples { t, simForm, form, clip, spine, alive } of the 转译基底·α's view and the
|
||||
* runner's catch-up count.
|
||||
*/
|
||||
async function runnerInPage(page, port, s, jankMs, secs) {
|
||||
await page.goto(`http://127.0.0.1:${port}/dev/render-demo.html?scene=normal-m01&paused=1&panel=0`);
|
||||
await page.waitForFunction('window.__demo && (window.__demo.ready || window.__demo.error)', { timeout: 30000 });
|
||||
return page.evaluate(async (spec, jankMs, secs) => {
|
||||
const { createBattleRunner } = await import('/js/battle/runner.js');
|
||||
const { data } = await import('/js/data.js');
|
||||
const v = window.__demo.view;
|
||||
v.setStage(data.lookup('stages', spec.stageId));
|
||||
const handlers = new Map();
|
||||
const net = {
|
||||
on(t, fn) { if (!handlers.has(t)) handlers.set(t, new Set()); handlers.get(t).add(fn); return () => handlers.get(t).delete(fn); },
|
||||
send() { return true; }, request() { return Promise.resolve({ t: 'ok' }); },
|
||||
};
|
||||
const queue = [];
|
||||
const runner = createBattleRunner({ net, store: { patch() {} }, doc: { hidden: false, addEventListener() {} }, raf: (fn) => { queue.push(fn); return queue.length; }, caf() {} });
|
||||
runner.on('field', (f) => { v.enterBattle(f); v.setCamera('normal', { rect: f.rect, side: 'L', instant: true }); v.setLocalFeed({ on: true, speed: f.speed }); });
|
||||
runner.on('snap', (x) => v.pushSnapshot(x));
|
||||
runner.on('ev', (m) => v.pushEvents(m));
|
||||
for (const fn of handlers.get('b.start') || []) fn({ t: 'b.start', battleId: spec.battleId, fieldId: spec.fieldId, kind: 'normal', spec, authoritative: false, watch: true, speed: 2, elapsed: 0 });
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
for (let i = 0; i < 100 && !runner._entries.size; i++) await sleep(50);
|
||||
const e = [...runner._entries.values()][0];
|
||||
const out = [];
|
||||
const end = performance.now() + secs * 1000;
|
||||
while (performance.now() < end) {
|
||||
await sleep(jankMs);
|
||||
for (const fn of queue.splice(0)) fn(performance.now());
|
||||
const tr = e.battle.units.find((u) => u.defId === 'enemy_10081_mpplai');
|
||||
const view = tr && v.debug.views.get(tr.id);
|
||||
if (tr) out.push({ t: +e.battle.time.toFixed(2), simForm: tr.form, form: view?.form ?? null, clip: view?.actor?.current ?? null, spine: !!view?.spineReady, alive: tr.alive });
|
||||
}
|
||||
const catchups = runner.stats().catchups;
|
||||
runner.dispose();
|
||||
return { out, catchups };
|
||||
}, s, jankMs, secs);
|
||||
}
|
||||
|
||||
describe('player reports after 0.1.0: the models follow the knock-out forms (headless Chrome, real sim)', { skip }, () => {
|
||||
let srv, browser;
|
||||
before(async () => {
|
||||
const puppeteer = (await import('puppeteer-core')).default;
|
||||
const { startServer } = await import('../../server/index.js');
|
||||
srv = await startServer({ port: 0, host: '127.0.0.1', quiet: true });
|
||||
browser = await puppeteer.launch({ executablePath: CHROME, headless: true, args: ['--no-first-run'] });
|
||||
mkdirSync(OUT, { recursive: true });
|
||||
});
|
||||
after(async () => {
|
||||
await browser?.close();
|
||||
await srv?.close();
|
||||
});
|
||||
|
||||
async function page() {
|
||||
const p = await browser.newPage();
|
||||
const problems = [];
|
||||
p.on('console', (m) => { if (m.type() === 'error') problems.push(`console: ${m.text()}`); });
|
||||
p.on('pageerror', (e) => problems.push(`pageerror: ${e.message}`));
|
||||
p.on('response', (r) => { if (r.status() >= 400) problems.push(`HTTP ${r.status()} ${r.url()}`); });
|
||||
await p.setViewport({ width: 1280, height: 720 });
|
||||
return { p, problems };
|
||||
}
|
||||
|
||||
test('#5 转译基底·α: A_* while 4 physical hits do nothing, A_Die_B, then 寻仇者 B_*; it dies on B_Die', async () => {
|
||||
const { p, problems } = await page();
|
||||
try {
|
||||
// the operator stands off its lane (no block); at 3 s: 4 physical hits from it (the 4th starts the change); at 9 s:
|
||||
// knocked out for good
|
||||
const log = await runInPage(p, srv.port, spec('enemy_10081_mpplai', 'translator', 11, 4), 'enemy_10081_mpplai', 12, `
|
||||
if (!state.hit && b.time >= 3) { state.hit = b.time; state.hp = e.hp; for (let i = 0; i < 4; i++) b.dealDamage(ally, e, { amount: 1e6, type: 'phys' }); state.after = e.hp; }
|
||||
if (!state.kill && b.time >= 9 && e.alive) { state.kill = b.time; b.kill(e, ally); }
|
||||
`);
|
||||
await p.screenshot({ path: path.join(OUT, 'feedback1-translator.png') });
|
||||
const { out, state } = log;
|
||||
assert.equal(state.after, state.hp, 'the 4 hits took no HP');
|
||||
const pre = out.filter((x) => x.spine && x.t < state.hit);
|
||||
assert.ok(pre.length > 0 && pre.every((x) => /^A_/.test(x.clip)), `first form: A_* (${[...new Set(pre.map((x) => x.clip))]})`);
|
||||
const change = out.filter((x) => x.t > state.hit + 2 * LAG && x.t < state.hit + 1.8); // (a loaded machine: the view lags more)
|
||||
assert.ok(change.length > 0 && change.every((x) => x.clip === 'A_Die_B' && x.alive), `the change clip (${[...new Set(change.map((x) => x.clip))]})`);
|
||||
const form = out.filter((x) => x.t > state.hit + 2 + LAG && x.t < state.kill);
|
||||
assert.ok(form.length > 0 && form.every((x) => /^B_/.test(x.clip) && x.form === 'translator_fuchou'), `寻仇者 clips (${[...new Set(form.map((x) => x.clip))]})`);
|
||||
const dead = out.filter((x) => x.t > state.kill + LAG);
|
||||
assert.ok(dead.length > 0 && dead.every((x) => !x.alive && x.clip === 'B_Die'), `dies on B_Die (${[...new Set(dead.map((x) => x.clip))]})`);
|
||||
assert.deepEqual(problems, []);
|
||||
} finally {
|
||||
await p.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('#8 深池逐火战士 knocked out in front of 百炼嘉维尔: Die (重生), the 隐匿 ember on Idle_2, beaten, Die_2', async () => {
|
||||
const { p, problems } = await page();
|
||||
try {
|
||||
const log = await runInPage(p, srv.port, spec('enemy_1288_duskls', 'ember'), 'enemy_1288_duskls', 16, `
|
||||
if (!state.ko && e.blockedBy && b.time >= 6) { state.ko = b.time; b.kill(e, ally); }
|
||||
if (state.ko && !state.dead && !e.alive) state.dead = b.time;
|
||||
`);
|
||||
await p.screenshot({ path: path.join(OUT, 'feedback1-ember.png') });
|
||||
const { out, state } = log;
|
||||
assert.ok(state.ko, 'blocked and knocked out');
|
||||
const pre = out.filter((x) => x.spine && x.t < state.ko);
|
||||
assert.ok(pre.length > 0 && pre.every((x) => !/_2$/.test(x.clip)), `the warrior's clips (${[...new Set(pre.map((x) => x.clip))]})`);
|
||||
const reb = out.filter((x) => x.t > state.ko + LAG && x.t < state.ko + 0.9);
|
||||
assert.ok(reb.length > 0 && reb.every((x) => x.clip === 'Die' && x.alive), `重生: 'Die' (${[...new Set(reb.map((x) => x.clip))]})`);
|
||||
assert.ok(state.dead > state.ko + 1, `the blocker beats the ember (dead at ${state.dead})`);
|
||||
const ember = out.filter((x) => x.t > state.ko + 1 + LAG && x.t < state.dead);
|
||||
assert.ok(ember.length > 0 && ember.every((x) => x.clip === 'Idle_2' && x.stealth && x.max === 5), `the 隐匿 ember on Idle_2 (${[...new Set(ember.map((x) => x.clip))]})`);
|
||||
assert.ok(ember.some((x) => x.hp < 5), 'its hit counter runs down');
|
||||
const dead = out.filter((x) => x.t > state.dead + LAG);
|
||||
assert.ok(dead.length > 0 && dead.every((x) => x.clip === 'Die_2'), `dies on Die_2 (${[...new Set(dead.map((x) => x.clip))]})`);
|
||||
assert.deepEqual(problems, []);
|
||||
} finally {
|
||||
await p.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('a view built mid-battle (enterBattle(fieldMeta) after a silent catch-up) starts in the current forms: 特战术师 D_*, 幽灵 C_*, the ember Idle_2 / Move_2, 掠海漂移体 *_02', async () => {
|
||||
const { p, problems } = await page();
|
||||
try {
|
||||
const got = await lateViewInPage(p, srv.port, spec('enemy_1007_slime', 'late', 9, 8), 7.5, `
|
||||
ally.base.atk = 0; ally.markDirty(); // 百炼嘉维尔 only blocks
|
||||
const still = { mods: { speedMul: 0 } };
|
||||
const shushi = b.spawnEnemy('enemy_10081_mpplai', { pos: [11, 9], ...still });
|
||||
const youling = b.spawnEnemy('enemy_10081_mpplai', { pos: [9, 8.4], ...still }); // blocked ⇒ 幽灵
|
||||
const ember = b.spawnEnemy('enemy_1288_duskls', { pos: [12, 9], ...still });
|
||||
const drift = b.spawnEnemy('enemy_2025_syufo', { pos: [11, 6], ...still });
|
||||
for (let i = 0; i < 4; i++) b.dealDamage(ally, shushi, { amount: 1, type: 'arts' });
|
||||
b.kill(ember, ally);
|
||||
b.applyStatus(drift, 'stun', { duration: 1, source: ally });
|
||||
return { shushi, youling, ember, drift };
|
||||
`);
|
||||
await p.screenshot({ path: path.join(OUT, 'feedback1-lateview.png') });
|
||||
assert.deepEqual(Object.fromEntries(Object.entries(got).map(([k, x]) => [k, x.simForm])),
|
||||
{ shushi: 'translator_shushi', youling: 'translator_youling', ember: 'husk', drift: 'crawl' }, 'the sim\'s forms');
|
||||
for (const [k, x] of Object.entries(got)) assert.ok(x.spine && x.alive && x.form === x.simForm, `${k}: a live Spine view in the sim's form (${JSON.stringify(x)})`);
|
||||
assert.match(got.shushi.clip, /^D_/, `特战术师 (${got.shushi.clip})`);
|
||||
assert.match(got.youling.clip, /^C_/, `幽灵 (${got.youling.clip})`);
|
||||
assert.match(got.ember.clip, /^(Idle|Move)_2$/, `the ember (${got.ember.clip})`);
|
||||
assert.match(got.drift.clip, /_02$/, `crawling (${got.drift.clip})`);
|
||||
assert.deepEqual(problems, []);
|
||||
} finally {
|
||||
await p.close();
|
||||
}
|
||||
});
|
||||
test('the real client runner with janky frames (every frame a catch-up): 转译基底·α blocked by 百炼嘉维尔 turns 幽灵 in the view (C_*), never back to A_Move / B_Die', async () => {
|
||||
const { p, problems } = await page();
|
||||
try {
|
||||
const { out, catchups } = await runnerInPage(p, srv.port, spec('enemy_10081_mpplai', 'runner', 9, 7), 700, 9);
|
||||
await p.screenshot({ path: path.join(OUT, 'feedback1-runner.png') });
|
||||
assert.ok(catchups >= 5, `catch-up frames (${catchups})`);
|
||||
const changed = out.find((x) => x.simForm === 'translator_youling');
|
||||
assert.ok(changed, `the sim's 转译基底·α turned 幽灵 (${JSON.stringify(out.slice(-3))})`);
|
||||
const after = out.filter((x) => x.spine && x.t > changed.t + 2 + LAG);
|
||||
assert.ok(after.length > 0, 'samples after the change');
|
||||
assert.ok(after.every((x) => x.form === 'translator_youling' && /^C_/.test(x.clip)), `幽灵's clips (${[...new Set(after.map((x) => `${x.form}:${x.clip}`))]})`);
|
||||
assert.ok(!out.some((x) => x.spine && /^B_/.test(x.clip)), 'never the 寻仇者\'s clips (B_Die was the look of report #5)');
|
||||
assert.deepEqual(problems, []);
|
||||
} finally {
|
||||
await p.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
+254
-3
@@ -3,6 +3,12 @@
|
||||
// melee operators block and hit it, so its model must stop hovering: render/units.js FORMS switches the view to the
|
||||
// skeleton's crawl clips (*_02) after its 'Change' clip (render/spine.js SpineActor.setForm), also for a view built
|
||||
// after the change (render/app.js keeps the mode on the unit info). Headless fake PIXI (test/render/fakepixi.js).
|
||||
// Player reports after 0.1.0 (#5, #8): 转译基底·α changes on its 2 s A_Die_B / _C / _D clip into the 寻仇者 B_*, 幽灵 C_* or
|
||||
// 特战术师 D_* set (it used to stay on A_Idle / A_Move and die on B_Die — "加载变身动画然后就没了"); a knocked-out 逐火 plays
|
||||
// 'Die' (its 1 s 重生) and walks as the ember on Idle_2 / Move_2, dying on Die_2, and 'Revive' — timed from the 'ember'
|
||||
// fx's `dur` to end as it stands up — brings the warrior back (sim fx 'ember' / 'revive' { form: 'husk' | 'revived' });
|
||||
// 假想敌:再生's 傀儡 the same with A_Die / B_* / B_Revive; the leaders' 重生 close on their last clip as the 重生 ends.
|
||||
// A view built mid-battle gets the current form from UnitInfo `form` through render/app.js renderInfo (enterBattle).
|
||||
|
||||
import { test, describe, before, after } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -12,15 +18,17 @@ import { fileURLToPath } from 'node:url';
|
||||
import { installFakePixi, fakeViewCtx } from './fakepixi.js';
|
||||
import { presetCamera } from '../../public/js/render/projection.js';
|
||||
import { UF, ANIM } from '../../shared/constants.js';
|
||||
import { makeBattle, chessRec } from '../helpers/battleHarness.js';
|
||||
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
||||
const assets = JSON.parse(readFileSync(path.join(ROOT, 'data/assets.json'), 'utf8'));
|
||||
const SYUFO = 'enemy_2025_syufo';
|
||||
|
||||
let fake, UnitView, FORMS;
|
||||
let fake, UnitView, FORMS, renderInfo;
|
||||
before(async () => {
|
||||
fake = installFakePixi();
|
||||
({ UnitView, FORMS } = await import('../../public/js/render/units.js'));
|
||||
({ renderInfo } = await import('../../public/js/render/app.js'));
|
||||
});
|
||||
after(() => fake.restore());
|
||||
|
||||
@@ -116,7 +124,250 @@ describe('掠海漂移体 爬行模式 (FORMS)', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('render/app.js hands the sim\'s fx \'phase\' to the view and keeps the mode on the unit info', () => {
|
||||
/** A real-manifest enemy view (any skeleton). */
|
||||
async function enemy(id, info = {}) {
|
||||
const ctx = fakeViewCtx(fake.P, { assets: store(id), cam });
|
||||
const v = new UnitView(ctx, { id: 9, side: 'enemy', kind: 'enemy', defId: id, spine: id, tier: 2, x: 8, y: 9, maxHp: 1000, facing: -1, ...info });
|
||||
await tick(); await tick();
|
||||
assert.ok(v.actor, 'Spine model built');
|
||||
return v;
|
||||
}
|
||||
|
||||
describe('转译基底·α forms (user report after 0.1.0, #5)', () => {
|
||||
const TR = 'enemy_10081_mpplai';
|
||||
test('every clip of the three forms exists in the skeleton; the change clips last the official 2 s; the manifest keeps the original form', () => {
|
||||
const anims = assets.enemies[TR].spine.animations;
|
||||
for (const [kind, f] of Object.entries(FORMS[TR])) {
|
||||
for (const name of [f.change, f.roles.idle, f.roles.die, f.roles.move.loop]) assert.ok(name in anims, `${kind}: ${name}`);
|
||||
assert.equal(anims[f.change], 2, `${kind}: ${f.change}`);
|
||||
}
|
||||
assert.equal(FORMS[TR].translator_youling.roles.attack, null, '幽灵 never attacks');
|
||||
assert.equal(assets.enemies[TR].spine.anims.idle, 'A_Idle');
|
||||
assert.equal(assets.enemies[TR].spine.anims.move.loop, 'A_Move');
|
||||
});
|
||||
|
||||
for (const [kind, set, attack] of [['translator_fuchou', 'B', 'B_Attack'], ['translator_shushi', 'D', 'D_Attack'], ['translator_youling', 'C', null]]) {
|
||||
test(`${kind}: the original form walks on A_*, the change clip plays out (2 s, moving or not), then the ${set}_* set`, async () => {
|
||||
const v = await enemy(TR);
|
||||
v.sync(sample(0, ANIM.MOVE), 1);
|
||||
assert.equal(clip(v), 'A_Move');
|
||||
v.setForm(kind);
|
||||
assert.equal(clip(v), FORMS[TR][kind].change);
|
||||
frames(v, 60);
|
||||
v.sync(sample(0, ANIM.MOVE), 2);
|
||||
assert.equal(clip(v), FORMS[TR][kind].change, 'not cut short');
|
||||
frames(v, 70);
|
||||
assert.equal(clip(v), `${set}_Move`);
|
||||
v.sync(sample(0, ANIM.IDLE), 3);
|
||||
assert.equal(clip(v), `${set}_Idle`);
|
||||
v.onAttack(null, 3.2);
|
||||
assert.equal(clip(v), attack ?? `${set}_Idle`, attack ? 'its attack clip' : 'no attack clip');
|
||||
v.die();
|
||||
assert.equal(clip(v), `${set}_Die`);
|
||||
});
|
||||
}
|
||||
|
||||
test('a view built after the change starts on the form\'s clips', async () => {
|
||||
const v = await enemy(TR, { form: 'translator_shushi' });
|
||||
v.sync(sample(), 1);
|
||||
assert.equal(clip(v), 'D_Idle');
|
||||
});
|
||||
});
|
||||
|
||||
describe('逐火 embers and the 再生 puppet (user report after 0.1.0, #8)', () => {
|
||||
for (const id of ['enemy_1288_duskls', 'enemy_1288_duskls_2', 'enemy_1292_duskld']) {
|
||||
test(`${id}: knocked out ⇒ 'Die' once, the ember on Idle_2 / Move_2 / Die_2; 'Revive' ends as it stands up, then the warrior's clips`, async () => {
|
||||
const anims = assets.enemies[id].spine.animations;
|
||||
for (const name of ['Die', 'Idle_2', 'Move_2', 'Die_2', 'Revive']) assert.ok(name in anims, name);
|
||||
const v = await enemy(id);
|
||||
v.sync(sample(0, ANIM.MOVE), 1);
|
||||
assert.equal(clip(v), 'Move');
|
||||
const dur = 4; // the 'ember' fx: 1 s 重生 + the husk (10 s officially)
|
||||
v.setForm('husk', { dur });
|
||||
assert.equal(clip(v), 'Die', 'the knock-out (its 1 s 重生)');
|
||||
frames(v, 65);
|
||||
assert.equal(clip(v), 'Move_2', 'the ember walks');
|
||||
v.sync(sample(UF.STEALTH, ANIM.IDLE), 2);
|
||||
assert.equal(clip(v), 'Idle_2');
|
||||
frames(v, Math.round((dur - anims.Revive - 65 / 60) * 60) + 3);
|
||||
assert.equal(clip(v), 'Revive', 'the stand-up clip starts so that it ends with the husk');
|
||||
frames(v, Math.round(anims.Revive * 60) - 6);
|
||||
v.setForm('revived'); // the sim's 'revive' fx
|
||||
assert.equal(clip(v), 'Revive', 'plays out, not restarted');
|
||||
frames(v, 10);
|
||||
assert.equal(clip(v), 'Idle', 'the warrior again');
|
||||
v.onAttack(null, 6);
|
||||
assert.equal(clip(v), 'Attack', 'it attacks at once');
|
||||
v.setForm('husk', { dur });
|
||||
frames(v, 65);
|
||||
v.die();
|
||||
assert.equal(clip(v), 'Die_2', 'the ember dies on its own clip');
|
||||
frames(v, 300);
|
||||
assert.equal(clip(v), 'Die_2', 'no stand-up clip after its death');
|
||||
});
|
||||
}
|
||||
|
||||
test('假想敌:再生: A_Die, the 傀儡 on B_Idle / B_Move / B_Die; B_Revive back to the A_* clips', async () => {
|
||||
const v = await enemy('enemy_9010_acpupp');
|
||||
v.setForm('husk', { dur: 3 });
|
||||
assert.equal(clip(v), 'A_Die');
|
||||
frames(v, 65);
|
||||
assert.equal(clip(v), 'B_Idle');
|
||||
v.sync(sample(0, ANIM.MOVE), 2);
|
||||
assert.equal(clip(v), 'B_Move');
|
||||
frames(v, 60);
|
||||
assert.equal(clip(v), 'B_Revive', 'its last second');
|
||||
frames(v, 57);
|
||||
v.setForm('revived');
|
||||
frames(v, 6);
|
||||
assert.equal(clip(v), 'A_Move');
|
||||
});
|
||||
|
||||
test('beaten in its last second (the stand-up clip already playing, still a husk in the sim): the ember dies on Die_2, 再生\'s 傀儡 on B_Die — the warrior\'s / A_* death clip only after the revive fx', async () => {
|
||||
for (const [id, end, die, die0] of [['enemy_1288_duskls', 'Revive', 'Die_2', 'Die'], ['enemy_9010_acpupp', 'B_Revive', 'B_Die', 'A_Die']]) {
|
||||
const anims = assets.enemies[id].spine.animations;
|
||||
const v = await enemy(id);
|
||||
v.setForm('husk', { dur: 4 });
|
||||
frames(v, Math.round((4 - anims[end]) * 60) + 6);
|
||||
assert.equal(clip(v), end, `${id}: the closing clip plays`);
|
||||
v.die();
|
||||
assert.equal(clip(v), die, `${id}: the husk's death clip (review of WD)`);
|
||||
const w = await enemy(id);
|
||||
w.setForm('husk', { dur: 4 });
|
||||
frames(w, 4 * 60 + 6);
|
||||
w.setForm('revived');
|
||||
frames(w, 6);
|
||||
w.die();
|
||||
assert.equal(clip(w), die0, `${id}: stood up, it dies on its first form's clip`);
|
||||
}
|
||||
});
|
||||
|
||||
test('a view built mid-husk (UnitInfo form, no timing) shows the husk; the revival lands in the manifest clips', async () => {
|
||||
const v = await enemy('enemy_1288_duskls', { form: 'husk' });
|
||||
v.sync(sample(UF.STEALTH, ANIM.MOVE), 1);
|
||||
assert.equal(clip(v), 'Move_2');
|
||||
v.setForm('revived');
|
||||
assert.equal(clip(v), 'Move', 'no stand-up clip without the timing');
|
||||
});
|
||||
});
|
||||
|
||||
describe('the leaders\' 重生 and 守墓石像 (audit of the knock-out forms after report #5)', () => {
|
||||
const REBIRTH = {
|
||||
enemy_1525_blkswb: ['Revive1', 'Revive2', 'Revive3', 'B_Idle', 'B_Die'],
|
||||
enemy_1535_wlfmster: ['A_revive_1', 'A_revive_2', 'A_revive_3', 'B_Idle', 'B_Die'],
|
||||
enemy_1539_reid: ['Revive_Begin', 'Revive_Loop', 'Revive_End', 'Idle', 'Die'],
|
||||
};
|
||||
for (const [id, [begin, hold, end, idle2, die2]] of Object.entries(REBIRTH)) {
|
||||
test(`${id}: knock-out ⇒ ${begin}, ${hold} held through the 重生's stun, ${end}, then ${idle2}; dies on ${die2}`, async () => {
|
||||
const anims = assets.enemies[id].spine.animations;
|
||||
for (const name of [begin, hold, end, idle2, die2]) assert.ok(name in anims, name);
|
||||
const v = await enemy(id);
|
||||
v.sync(sample(UF.STUNNED, ANIM.STUN), 1);
|
||||
const dur = 6; // the 'telegraph' fx's dur (Reborn.duration)
|
||||
v.setForm('reborn', { dur });
|
||||
assert.equal(clip(v), begin);
|
||||
frames(v, Math.ceil(anims[begin] * 60) + 5);
|
||||
assert.equal(clip(v), hold, 'held (its stun role) while the sim keeps it stunned');
|
||||
const at = Math.ceil(anims[begin] * 60) + 5;
|
||||
frames(v, Math.round((dur - anims[end]) * 60) - at + 3);
|
||||
assert.equal(clip(v), end, 'the closing clip starts so that it ends with the 重生');
|
||||
frames(v, Math.round(anims[end] * 60) - 6);
|
||||
v.sync(sample(0, ANIM.IDLE), dur + 1); // the sim's 'revive' fx: the 重生 is over
|
||||
v.setForm('form2');
|
||||
frames(v, 6);
|
||||
assert.equal(clip(v), idle2, 'the second form at once');
|
||||
v.onAttack(null, dur + 1.2);
|
||||
assert.notEqual(clip(v), idle2, 'its first attack is drawn, not swallowed by a change clip');
|
||||
v.die();
|
||||
assert.equal(clip(v), die2);
|
||||
});
|
||||
}
|
||||
|
||||
test('enemy_1516_jakill 杰斯顿: C1_Die is its 4 s 重生, then the killer form C2_*', async () => {
|
||||
const v = await enemy('enemy_1516_jakill');
|
||||
v.setForm('reborn');
|
||||
assert.equal(clip(v), 'C1_Die');
|
||||
frames(v, 245);
|
||||
v.setForm('form2');
|
||||
v.sync(sample(0, ANIM.MOVE), 5);
|
||||
assert.equal(clip(v), 'C2_Move');
|
||||
v.onAttack(null, 5.5);
|
||||
assert.equal(clip(v), 'C2_Attack');
|
||||
});
|
||||
|
||||
test('enemy_1172_dugago 守墓石像: the statue on Sleep, the flyer on *_2', async () => {
|
||||
const v = await enemy('enemy_1172_dugago');
|
||||
v.setForm('stone');
|
||||
v.sync(sample(), 1);
|
||||
assert.equal(clip(v), 'Sleep');
|
||||
v.setForm('fly');
|
||||
v.sync(sample(UF.FLYING, ANIM.MOVE), 2);
|
||||
assert.equal(clip(v), 'Move_2');
|
||||
v.die();
|
||||
assert.equal(clip(v), 'Die_2');
|
||||
});
|
||||
|
||||
test('a kind without a clip set of that skeleton (an arts barrier, a broken charge) keeps the current form', async () => {
|
||||
const v = await enemy('enemy_10081_mpplai');
|
||||
v.setForm('translator_fuchou');
|
||||
frames(v, 130);
|
||||
v.setForm('artsBarrier');
|
||||
assert.equal(v.form, 'translator_fuchou');
|
||||
v.sync(sample(), 3);
|
||||
assert.equal(clip(v), 'B_Idle');
|
||||
});
|
||||
});
|
||||
|
||||
test('a view built mid-battle from the real sim\'s fieldMeta (fx dropped by a silent catch-up), through render/app.js renderInfo — what enterBattle(meta) hands the views — starts in the current form: the changed 转译基底·α on D_Idle / C_Idle, the 逐火 ember on Idle_2, 锏 after its 重生 on B_Idle, 掠海漂移体 crawling', async () => {
|
||||
const mage = chessRec({ id: 't_mage', profession: 'CASTER', stats: { atk: 50, blockCnt: 0 }, rangeGrid: [[0, 0]], skill: null });
|
||||
const wall = chessRec({ id: 't_wall', profession: 'TANK', stats: { atk: 0, maxHp: 1e7, blockCnt: 3 }, rangeGrid: [[0, 0]], skill: null });
|
||||
const quiet = () => ({ trait: { noAttack: true } });
|
||||
const h = makeBattle({
|
||||
stageId: 'act2autochess_m01', content: 'full', seed: 7, autoFinish: false, timeLimit: 600, modeId: 'mode_multi_hard', round: 3,
|
||||
defs: { chess: { t_mage: mage, t_wall: wall } }, units: [{ chessId: 't_mage', row: 12, col: 2 }, { chessId: 't_wall', row: 9, col: 4 }],
|
||||
kits: { t_mage: quiet, t_wall: quiet },
|
||||
});
|
||||
h.step();
|
||||
const still = { mods: { speedMul: 0 } };
|
||||
const tr = h.b.spawnEnemy('enemy_10081_mpplai', { pos: [10, 8], ...still });
|
||||
const ghost = h.b.spawnEnemy('enemy_10081_mpplai', { pos: [9, 4.4], ...still }); // walks into the wall: blocked ⇒ 幽灵
|
||||
const ember = h.b.spawnEnemy('enemy_1288_duskls', { pos: [11, 8], ...still });
|
||||
const mace = h.b.spawnEnemy('enemy_1525_blkswb', { pos: [12, 8], ...still });
|
||||
const drift = h.b.spawnEnemy(SYUFO, { pos: [11, 10], ...still });
|
||||
const m = h.unit('t_mage');
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(m, tr, { amount: 1, type: 'arts' }); // the 4th arts hit ⇒ 特战术师
|
||||
h.b.kill(ember, m);
|
||||
h.b.kill(mace, m);
|
||||
h.b.applyStatus(drift, 'stun', { duration: 1, source: m }); // 掠海漂移体 drops to 爬行模式
|
||||
const until = h.b.time + 6;
|
||||
while (h.b.time < until) { h.b.step(); h.b.drainEvents(); }
|
||||
const meta = h.b.fieldMeta();
|
||||
const view = async (u) => {
|
||||
const info = renderInfo(meta.units.find((x) => x.id === u.id));
|
||||
const ctx = fakeViewCtx(fake.P, { assets: store(info.spine), cam });
|
||||
const v = new UnitView(ctx, info);
|
||||
await tick(); await tick();
|
||||
v.sync(sample(), 1);
|
||||
return v;
|
||||
};
|
||||
assert.equal(clip(await view(tr)), 'D_Idle', '特战术师, not the A model');
|
||||
assert.equal(clip(await view(ghost)), 'C_Idle', '幽灵 (blocked first), not the A model');
|
||||
const e = await view(ember);
|
||||
assert.equal(clip(e), 'Idle_2', 'the ember, not the warrior');
|
||||
e.die();
|
||||
assert.equal(clip(e), 'Die_2', 'and it dies on the ember\'s clip');
|
||||
assert.equal(clip(await view(mace)), 'B_Idle', '锏\'s second form');
|
||||
assert.equal(clip(await view(drift)), 'Idle_02', '掠海漂移体 crawls (DESIGN §19.1: a reload used to hover)');
|
||||
});
|
||||
|
||||
test('render/app.js renderInfo keeps UnitInfo `form` (it used to drop it: views built from fieldMeta drew the first form)', () => {
|
||||
assert.equal(renderInfo({ id: 3, kind: 'enemy', side: 'enemy', defId: 'enemy_1288_duskls', form: 'husk' }).form, 'husk');
|
||||
assert.equal(renderInfo({ id: 3, kind: 'enemy', side: 'enemy', defId: 'enemy_1288_duskls' }).form, undefined);
|
||||
assert.equal(renderInfo({ id: 3, form: 7 }).form, undefined, 'only a string');
|
||||
assert.equal(renderInfo({ kind: 'enemy' }), null, 'no id: no info');
|
||||
});
|
||||
|
||||
test('render/app.js hands the `form` of a sim fx (shared/protocol.js fxForm) with the fx to the view and keeps the mode on the unit info', () => {
|
||||
const src = readFileSync(path.join(ROOT, 'public/js/render/app.js'), 'utf8');
|
||||
assert.match(src, /e\[1\] === 'phase'[\s\S]{0,300}inf\.form = [\s\S]{0,200}setForm\?\.\(e\[4\]\.kind\)/);
|
||||
assert.match(src, /const form = fxForm\(e\);[\s\S]{0,200}inf\.form = form[\s\S]{0,120}setForm\?\.\(form, e\[4\]\)/);
|
||||
});
|
||||
@@ -0,0 +1,572 @@
|
||||
// test/sim/feedback1-transform.test.js — player reports after the public 0.1.0 (workstream WD: enemies that change form
|
||||
// when "killed"), real enemy data in the real sim:
|
||||
// #5 转译基底·α "不会变身,原血量打死就加载变身动画然后就没了": its original form cancels every damage instance (PRTS 转译基底·α
|
||||
// 天赋 "受到伤害时取消此伤害"); the 4th physical / 4th arts instance or being blocked starts a 2 s change into 寻仇者 /
|
||||
// 特战术师 / 幽灵 (Mode_*_Passive) — only the changed form can die. v0.1.0 let damage through: a sniper + caster lineup
|
||||
// killed it in its first form without any change, and its model (still in that form) played the 寻仇者's B_Die.
|
||||
// #8 深池逐火战士 / 精锐战士 / 护卫 "被击倒后变的怨恨的余烬无法被击杀": every knock-out ⇒ 1 s 重生 (无敌 + 无法阻挡, immobile) ⇒
|
||||
// a 隐匿, disarmed ember of 5 (护卫 10) hits that walks its route on and can be blocked — blocked it is targetable and
|
||||
// dies for good after that many damage instances; still standing after 10 s it is the warrior again with full HP
|
||||
// (PRTS 深池逐火战士 天赋). v0.1.0's ember stood still, stealthed AND unblockable: nobody could ever target it, so
|
||||
// every 逐火 enemy of a round leaked.
|
||||
// The real-round tests build the battle like Match._normalOpts: an official wave (waves.js buildNormalWave, a 悬赏 card
|
||||
// through withBounties), the real stage 战场#01, real chess, full content, buildBattleSpec → createBattleFromSpec.
|
||||
// Review follow-ups: a view built mid-battle (fieldMeta — a watched teammate's field, 联防 observers, a reconnect; the
|
||||
// client runner's silent catch-up drops the fx) learns the current form from UnitInfo `form`; an HP loss (流失) cannot
|
||||
// knock 转译基底·α out before its change; 假想敌:再生's shields come with its 再生状态, within 1.8 (PRTS 天赋); enemy
|
||||
// profiles keep one object shape from spawn (the sim's hot loop).
|
||||
|
||||
import { test, describe } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { getData } from '../../server/data.js';
|
||||
import { GameData } from '../../server/match/gamedata.js';
|
||||
import { buildNormalWave, withBounties } from '../../server/match/waves.js';
|
||||
import { createRng } from '../../server/sim/rng.js';
|
||||
import { buildBattleSpec, createBattleFromSpec } from '../../server/sim/spec.js';
|
||||
import { getDefaultSource } from '../../server/sim/simdata.js';
|
||||
import { GEO } from '../../shared/constants.js';
|
||||
import { makeBattle, chessRec, checkInvariants } from '../helpers/battleHarness.js';
|
||||
import { canTargetEnemy } from '../../server/sim/targeting.js';
|
||||
import { HUSK_REBIRTH, TRANSLATOR_CHANGE, abOf } from '../../server/sim/content/enemies.js';
|
||||
|
||||
const QUIET = { warn() {}, error() {}, info() {} };
|
||||
const DATA = getData({ log: QUIET });
|
||||
const E = DATA.enemies;
|
||||
const MODE = 'mode_multi_hard';
|
||||
const STAGE = 'act2autochess_m01';
|
||||
const gd = new GameData(DATA, MODE);
|
||||
const tb = (key, k) => E[key].talents.bb[k];
|
||||
const TR = 'enemy_10081_mpplai';
|
||||
const EMBERS = ['enemy_1288_duskls', 'enemy_1288_duskls_2', 'enemy_1292_duskld'];
|
||||
const approx = (a, b, eps = 1e-6, msg = '') => assert.ok(Math.abs(a - b) <= eps * Math.max(1, Math.abs(b)), `${msg} ${a} ≈ ${b}`);
|
||||
|
||||
/** A player's normal field as Match._normalOpts builds it (real wave, real stage, full content). */
|
||||
function realBattle({ round, wave, spawns, units, seed = 77 }) {
|
||||
const spec = buildBattleSpec({
|
||||
battleId: 'fb1.wd', fieldId: 'n:p1', kind: 'normal', seed, modeId: MODE, round, stageId: STAGE, rect: { ...GEO.NORMAL_RECT },
|
||||
timeLimit: wave.timeLimit, players: [{ playerId: 'p1', seat: 0, side: 'L', colOffset: 0, units, bonds: {}, playerEffects: [] }],
|
||||
spawns: (spawns ?? wave.spawns).map((s) => ({ ...s, ownerPlayerId: 'p1' })), routes: wave.routes,
|
||||
flags: { layerGainsEnabled: true, ...gd.dp }, enemyOverrides: wave.overrides, waveId: wave.templateId,
|
||||
});
|
||||
return createBattleFromSpec(spec, getDefaultSource(), { quiet: true });
|
||||
}
|
||||
const chess = (uid, chessId, row, col, dir = 'RIGHT') => ({ uid, kind: 'chess', chessId, row, col, dir });
|
||||
|
||||
// synthetic operators for the rule tests (real enemies, real stage and routes): a blocker that never attacks, an
|
||||
// instant long-range phys gun and arts mage that reach the whole field
|
||||
const BIG = [];
|
||||
for (let dr = -4; dr <= 4; dr++) for (let dc = -12; dc <= 12; dc++) BIG.push([dr, dc]);
|
||||
const CHESS = {
|
||||
t_wall: chessRec({ id: 't_wall', profession: 'TANK', stats: { atk: 0, maxHp: 1e7, def: 0, res: 0, blockCnt: 3 }, rangeGrid: [[0, 0]], skill: null }),
|
||||
t_gun: chessRec({ id: 't_gun', profession: 'SNIPER', projectile: 'none', stats: { atk: 50, maxHp: 1e7, bat: 1, blockCnt: 0 }, rangeGrid: BIG, skill: null }),
|
||||
t_mage: chessRec({ id: 't_mage', profession: 'CASTER', projectile: 'none', stats: { atk: 50, maxHp: 1e7, bat: 1, blockCnt: 0 }, rangeGrid: BIG, skill: null }),
|
||||
};
|
||||
const NOATK = () => ({ trait: { noAttack: true } });
|
||||
/** Real stage + the real routes of an official wave template (route 0 = 战场#01's lower lane (9,10) → (9,2)). */
|
||||
const ROUTES = DATA.waves.act1autochess_03.routes;
|
||||
function arena(o = {}) {
|
||||
const { kits = {}, ...rest } = o;
|
||||
return makeBattle({
|
||||
stageId: STAGE, routes: ROUTES, content: 'full', seed: 7, autoFinish: false, timeLimit: 600, modeId: MODE, round: 3,
|
||||
defs: { chess: CHESS }, kits: { t_wall: NOATK, ...kits }, ...rest,
|
||||
});
|
||||
}
|
||||
const put = (h, key, o = {}) => h.spawn(key, { routeIndex: 0, ...o });
|
||||
/** Synthetic attackers that never attack (the test deals every hit itself). */
|
||||
const QUIET_GUNS = { t_gun: NOATK, t_mage: NOATK };
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// #8 逐火 embers
|
||||
|
||||
describe('#8 深池逐火: a knock-out is a walking 隐匿 ember that a blocker can beat', () => {
|
||||
test('a real TIMES round (R3, 深池逐火精锐战士 pick) on 战场#01: every knocked-out 逐火 becomes an ember, the blocked embers die for good — cleared, nobody leaks, each enemy dies once', () => {
|
||||
let wave = null;
|
||||
for (let seed = 1; seed < 500 && !wave; seed++) {
|
||||
const w = buildNormalWave(gd, createRng(seed), ['TIMES', 'INVISIBLE', 'FLY'], 3);
|
||||
if (w.pick && w.pick.key === 'enemy_1288_duskls_2') wave = w;
|
||||
}
|
||||
assert.ok(wave, 'fixture: an official R3 wave with the 深池逐火 TIMES entry');
|
||||
assert.ok(wave.spawns.some((s) => EMBERS.includes(s.enemyKey)), 'the round sends 逐火 enemies');
|
||||
const b = realBattle({
|
||||
round: 3, wave, units: [
|
||||
chess(1, 'chess_char_4_23_b', 9, 8), // 百炼嘉维尔 blocks the lower lane
|
||||
chess(2, 'chess_char_4_20_b', 10, 4), // 远牙
|
||||
chess(3, 'chess_char_4_02_b', 11, 4), // 莫斯提马
|
||||
chess(4, 'chess_char_4_17_b', 12, 6), // 星熊 blocks the upper lane's way down
|
||||
],
|
||||
});
|
||||
const ember = new Map(); // id → { u, at, x, y, attacks } of its current ember
|
||||
let walked = 0; // the longest walk of an ember past its 重生
|
||||
const deaths = new Map();
|
||||
const bad = new Set(); // rule details that did not hold (asserted after the outcome)
|
||||
const check = (ok, what) => { if (!ok) bad.add(what); };
|
||||
let n = 0;
|
||||
while (!b.finished && n++ < 30 * 300) {
|
||||
b.step();
|
||||
for (const ev of b.drainEvents()) {
|
||||
if (ev[0] === 'fx' && ev[1] === 'ember') {
|
||||
const u = b.units.find((x) => x.id === ev[4].id);
|
||||
check(u && u.alive, 'a knock-out never removes the unit');
|
||||
check(ev[4].form === 'husk', 'the ember fx carries the clip set of the model (form: husk)');
|
||||
ember.set(u.id, { u, at: b.time, x: u.x, y: u.y, attacks: u.stats.attacks });
|
||||
}
|
||||
if (ev[0] === 'die') {
|
||||
const u = b.units.find((x) => x.id === ev[1]);
|
||||
if (u && u.side === 'enemy') {
|
||||
deaths.set(u.id, (deaths.get(u.id) ?? 0) + 1);
|
||||
check(ev[2] === 'killed', 'enemies only die by being killed');
|
||||
check(ember.has(u.id) && u.mem.ab.list[0].state === 'husk', 'a 逐火 dies only as an ember');
|
||||
check(u.s.maxHp === tb(u.defId, 'Revive[Trigger].prop_max_hp'), 'killed through its hit counter');
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const [, m] of ember) {
|
||||
const u = m.u;
|
||||
if (!u.alive || u.mem.ab.list[0].state !== 'husk') continue;
|
||||
if (b.time < m.at + HUSK_REBIRTH - 1e-6) {
|
||||
// (its blocker lets go at the next enemy update)
|
||||
check(u.s.flags.invulnerable && u.s.flags.unblockable && (b.time - m.at < 0.05 || !u.blockedBy), '重生: 无敌 + 无法阻挡');
|
||||
check(u.x === m.x && u.y === m.y, '重生: immobile');
|
||||
} else {
|
||||
check(u.s.flags.stealth && u.s.flags.disarm && !u.s.flags.unblockable, '余烬: 隐匿 + 缴械, blockable');
|
||||
walked = Math.max(walked, Math.hypot(u.x - m.x, u.y - m.y));
|
||||
}
|
||||
check(u.stats.attacks === m.attacks, 'an ember never attacks');
|
||||
if (n % 30 === 0) check(b.fieldMeta().units.find((x) => x.id === u.id)?.form === 'husk', 'a view built now (fieldMeta) shows the ember');
|
||||
}
|
||||
}
|
||||
const r = b.result();
|
||||
const dusk = b.units.filter((u) => u.side === 'enemy' && EMBERS.includes(u.defId));
|
||||
assert.ok(dusk.length >= 5);
|
||||
assert.deepEqual({ reason: r.reason, leaked: r.perPlayer.p1.leaked.length, killed: r.perPlayer.p1.killed },
|
||||
{ reason: 'cleared', leaked: 0, killed: r.perPlayer.p1.total }, 'the round is cleared: every enemy killed, no 逐火 walks out');
|
||||
for (const u of dusk) assert.equal(deaths.get(u.id), 1, `${u.defId} #${u.id} dies exactly once`);
|
||||
assert.equal(ember.size, dusk.length, 'every 逐火 went through its ember');
|
||||
assert.deepEqual([...bad], [], 'ember rules');
|
||||
assert.ok(walked > 1, `an ember whose blocker fell walks on (${walked.toFixed(2)} tiles)`);
|
||||
});
|
||||
|
||||
for (const key of EMBERS) {
|
||||
const hits = tb(key, 'Revive[Trigger].prop_max_hp'), delay = tb(key, 'Revive[Trigger].interval');
|
||||
test(`${key} ${E[key].name}: 1 s 重生, then a walking 隐匿 ember of ${hits} hits — unblocked no ranged unit can target it, blocked it dies after ${hits} instances; ${delay} s later it would stand up again`, () => {
|
||||
// unblocked: the gun cannot target it while it walks on; it revives at full HP, and the next knock-out repeats
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const e = put(h, key, { mods: { speedMul: 1 } });
|
||||
const gun = h.unit('t_gun');
|
||||
h.run(2);
|
||||
const full = e.s.maxHp;
|
||||
const kills = () => h.hooksOf('kill').filter((c) => c.victim === e).length;
|
||||
h.b.kill(e, h.unit('t_gun'));
|
||||
assert.ok(e.alive, 'not removed');
|
||||
assert.equal(kills(), 0, 'a knock-out is no kill for anyone (credit, bounty, bond kill triggers)');
|
||||
assert.equal(h.b.killed, 0, 'and no kill count');
|
||||
assert.equal(e.s.maxHp, hits);
|
||||
assert.equal(e.hp, hits);
|
||||
const x0 = e.x;
|
||||
assert.equal(h.b.dealDamage(h.unit('t_gun'), e, { amount: 1e6, type: 'true' }), 0, '重生 is invulnerable');
|
||||
h.run(HUSK_REBIRTH - 0.05);
|
||||
approx(e.x, x0, 1e-9, 'immobile during the 重生');
|
||||
h.run(0.1);
|
||||
assert.ok(e.s.flags.stealth && e.s.flags.disarm && e.profile.noAttack && !e.s.flags.unblockable);
|
||||
assert.equal(canTargetEnemy(gun, e, gun.profile), false, 'unblocked and 隐匿: no ranged operator can target it');
|
||||
h.run(3);
|
||||
assert.ok(Math.abs(e.x - x0) > 0.5, 'walks its route on');
|
||||
assert.equal(e.hp, hits);
|
||||
h.run(delay - 3.15);
|
||||
assert.ok(e.s.flags.stealth, `still an ember just before ${delay} s`);
|
||||
h.run(0.2);
|
||||
assert.equal(e.s.maxHp, full, 'the warrior again');
|
||||
assert.equal(e.hp, full, 'with full HP');
|
||||
assert.ok(!e.s.flags.stealth && !e.s.flags.disarm && !e.profile.noAttack);
|
||||
assert.ok(h.eventsOf('fx').some((ev) => ev[1] === 'revive' && ev[4].id === e.id && ev[4].form === 'revived'));
|
||||
h.b.kill(e, null);
|
||||
assert.ok(e.alive && e.s.maxHp === hits, 'every knock-out of the warrior starts it again');
|
||||
|
||||
// blocked: the blocker lifts its 隐匿, so the gun hits it: `hits` instances end it for good
|
||||
const h2 = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }, { chessId: 't_wall', row: 9, col: 7 }] });
|
||||
h2.step();
|
||||
const f = put(h2, key, { mods: { speedMul: 1 } });
|
||||
assert.ok(h2.runUntil(() => !!f.blockedBy, 20), 'blocked');
|
||||
h2.b.kill(f, null);
|
||||
h2.run(HUSK_REBIRTH + 0.1);
|
||||
assert.ok(f.blockedBy, 'blocked again once the 重生 is over');
|
||||
assert.ok(canTargetEnemy(h2.unit('t_gun'), f, h2.unit('t_gun').profile), 'blocked: targetable in spite of its 隐匿');
|
||||
assert.ok(h2.runUntil(() => !f.alive, 3 * hits), `beaten by ${hits} gun shots`);
|
||||
assert.equal(f.removeReason, 'killed');
|
||||
assert.equal(h2.hooksOf('kill').filter((c) => c.victim === f).length, 1, 'one kill: the real death');
|
||||
assert.equal(h2.b.killed, 1);
|
||||
assert.equal(h2.eventsOf('die').filter((ev) => ev[1] === f.id).length, 1, 'one die event');
|
||||
checkInvariants(h2.b);
|
||||
});
|
||||
}
|
||||
|
||||
test('an ember counts every damage instance as one hit — physical, arts, true, 元素伤害 (AoE / DoT ticks alike); element 损伤 does not', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const e = put(h, 'enemy_1292_duskld', { mods: { speedMul: 0 } });
|
||||
const g = h.unit('t_gun');
|
||||
h.b.kill(e, g);
|
||||
h.run(HUSK_REBIRTH + 0.05);
|
||||
const n = e.hp;
|
||||
for (const type of ['phys', 'arts', 'true', 'elemental']) h.b.dealDamage(g, e, { amount: 1e6, type, tags: ['aoe'] });
|
||||
h.b.dealDamage(g, e, { type: 'element', element: 'burn', amount: 300 });
|
||||
assert.equal(e.hp, n - 4);
|
||||
assert.ok(e.alive);
|
||||
});
|
||||
|
||||
test('假想敌:再生 (PRTS 天赋 "被击倒后重生,持续1s,随后变为再生状态 … 进入此形态时,使半径1.8范围内的其他敌方单位…获得5层…护盾"): no shields during the 1 s 重生, then 5-hit shields within 1.8 only', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const still = { mods: { speedMul: 0 } };
|
||||
const e = put(h, 'enemy_9010_acpupp', { pos: [10, 8], ...still });
|
||||
const near = put(h, 'enemy_1007_slime', { pos: [10, 6.3], ...still }); // 1.7 away
|
||||
const far = put(h, 'enemy_1007_slime', { pos: [11.9, 8], ...still }); // 1.9 away
|
||||
h.b.kill(e, h.unit('t_gun'));
|
||||
assert.ok(e.alive && e.form === 'husk');
|
||||
h.run(HUSK_REBIRTH - 0.1);
|
||||
assert.equal(abOf(h.b, near).hitShield ?? 0, 0, 'no shield while it is still in its 重生');
|
||||
h.run(0.2);
|
||||
assert.equal(abOf(h.b, near).hitShield, tb('enemy_9010_acpupp', 'Aura.max_damage_block_cnt'), 'the 再生状态 begins: 5 hits of shield within 1.8');
|
||||
assert.equal(abOf(h.b, far).hitShield ?? 0, 0, 'nothing 1.9 away');
|
||||
assert.ok(e.s.flags.unblockable && !e.s.flags.noMove, '不可阻挡, free to move after the 1 s');
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// audit: every other knock-out form of the mode ends in a targetable, killable unit and tells the model its clip set
|
||||
|
||||
describe('audit: the leaders\' 重生 and 守墓石像 — no vanishing, killable afterwards, the model follows', () => {
|
||||
const CASES = [
|
||||
['enemy_1525_blkswb', 'Reborn.duration', 'Reborn.invincible', 'reborn', 'form2'],
|
||||
['enemy_1535_wlfmster', 'Reborn.duration', 'Passive2.invincible_time', 'reborn', 'form2'],
|
||||
['enemy_1539_reid', 'Reborn.duration', 'Reborn.invincible', 'reborn', 'form2'],
|
||||
['enemy_1516_jakill', 'reborn.duration', null, 'reborn', 'form2'],
|
||||
['enemy_1517_xi', 'reborn.duration', 'reborn.invincible', 'reborn', 'form2'],
|
||||
['enemy_1512_mcmstr', 'reborn.duration', null, 'reborn', 'form2'],
|
||||
['enemy_10098_crhro', 'reborn.duration', 'reborn.invincible', 'reborn', 'form2'],
|
||||
['enemy_1172_dugago', 'stone.duration', null, 'stone', 'fly'],
|
||||
['enemy_1172_dugago_2', 'stone.duration', null, 'stone', 'fly'],
|
||||
];
|
||||
for (const [key, durKey, invKey, f1, f2] of CASES) {
|
||||
test(`${key} ${E[key].name}: knock-out ⇒ form '${f1}' (no die event, no kill), then '${f2}' — targetable and killed for good by the next knock-out`, () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const e = put(h, key, { pos: [10, 7], mods: { speedMul: 0 } });
|
||||
const gun = h.unit('t_gun');
|
||||
h.b.kill(e, gun);
|
||||
assert.ok(e.alive, 'not removed');
|
||||
const fxOf = (form) => h.eventsOf('fx').some((ev) => ev[4] && ev[4].id === e.id && ev[4].form === form);
|
||||
assert.ok(fxOf(f1), `fx form '${f1}' at the knock-out`);
|
||||
assert.equal(h.eventsOf('die').filter((ev) => ev[1] === e.id).length, 0, 'no die event');
|
||||
assert.equal(h.b.killed, 0, 'no kill');
|
||||
h.run((tb(key, durKey) ?? 0) + (invKey ? tb(key, invKey) ?? 0 : 0) + 0.3);
|
||||
assert.ok(e.alive && fxOf(f2), `fx form '${f2}' when it stands up`);
|
||||
assert.ok(!e.s.flags.untargetable && !e.s.flags.invulnerable, 'targetable and vulnerable again');
|
||||
if (!e.s.flags.stealth && !e.isFlying) assert.ok(canTargetEnemy(gun, e, gun.profile), 'a ranged operator can target it');
|
||||
h.b.kill(e, gun);
|
||||
assert.ok(!e.alive && e.removeReason === 'killed', 'the second knock-out is its death');
|
||||
assert.equal(h.b.killed, 1);
|
||||
assert.equal(h.eventsOf('die').filter((ev) => ev[1] === e.id).length, 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// #5 转译基底·α
|
||||
|
||||
describe('#5 转译基底·α: damage is cancelled until its form change; only the changed form can die', () => {
|
||||
test('悬赏·特异I in a real round (R4) on 战场#01, a sniper + caster + late blocker: no HP lost before the change, the 4th physical hit ⇒ 2 s change ⇒ 寻仇者, then killed for the bounty coin', () => {
|
||||
const wave = buildNormalWave(gd, createRng(5), ['TIMES', 'INVISIBLE', 'FLY'], 4);
|
||||
const card = DATA.choices.cards.bounty.find((c) => c.effectId === 'enemyeffect_16_12');
|
||||
assert.equal(card.enemyKey, TR, 'fixture: the 悬赏 card adds a 转译基底·α');
|
||||
const spawns = withBounties(gd, 4, wave, [{ id: 'b1', card }], 'p1');
|
||||
assert.equal(spawns.filter((s) => s.enemyKey === TR && s.tag === 'bounty').length, 1);
|
||||
const b = realBattle({
|
||||
round: 4, wave, spawns, units: [
|
||||
chess(1, 'chess_char_4_23_b', 9, 3), // 百炼嘉维尔 near the goal
|
||||
chess(2, 'chess_char_6_01_b', 10, 4), // 蕾缪安 (physical)
|
||||
chess(3, 'chess_char_4_02_b', 11, 4), // 莫斯提马 (arts)
|
||||
],
|
||||
});
|
||||
let tr = null, phaseAt = null, kind = null, diedAt = null, formAt = null, maxBefore = null, firstFormLoss = null, earlyAttack = false;
|
||||
let lateForm; // UnitInfo.form of the translator in fieldMeta() 1 s after its change began
|
||||
let n = 0;
|
||||
while (!b.finished && n++ < 30 * 300) {
|
||||
b.step();
|
||||
tr = tr ?? b.enemies.find((e) => e.defId === TR) ?? null;
|
||||
if (tr && tr.alive && phaseAt != null && lateForm === undefined && b.time >= phaseAt + 1) lateForm = b.fieldMeta().units.find((u) => u.id === tr.id)?.form ?? null;
|
||||
for (const ev of b.drainEvents()) {
|
||||
if (!tr) continue;
|
||||
if (ev[0] === 'fx' && ev[1] === 'phase' && ev[4].id === tr.id) { phaseAt = b.time; kind = ev[4].kind; }
|
||||
if (ev[0] === 'die' && ev[1] === tr.id) { diedAt = b.time; assert.equal(ev[2], 'killed'); }
|
||||
if (ev[0] === 'atk' && ev[1] === tr.id && formAt == null) earlyAttack = true;
|
||||
}
|
||||
if (!tr || !tr.alive) continue;
|
||||
if (formAt == null && tr.findBuff('ab:form')) formAt = b.time;
|
||||
if (formAt == null) {
|
||||
maxBefore = maxBefore ?? tr.s.maxHp;
|
||||
if (tr.hp !== maxBefore && firstFormLoss == null) firstFormLoss = { t: +b.time.toFixed(2), hp: Math.round(tr.hp), max: Math.round(maxBefore) };
|
||||
}
|
||||
}
|
||||
assert.ok(diedAt != null, 'killed');
|
||||
assert.ok(phaseAt != null && diedAt > phaseAt + TRANSLATOR_CHANGE - 0.05, 'it changed form before it died — never killed in its first form');
|
||||
assert.equal(firstFormLoss, null, 'its first form loses no HP');
|
||||
assert.equal(kind, 'translator_fuchou', '4 physical hits first ⇒ 寻仇者');
|
||||
assert.equal(lateForm, 'translator_fuchou', 'a view built mid-battle (fieldMeta) draws the changing form, not the A model');
|
||||
approx(formAt - phaseAt, TRANSLATOR_CHANGE, 0.02, 'the change lasts 2 s');
|
||||
assert.ok(!earlyAttack, 'no attack before its change');
|
||||
const r = b.result();
|
||||
assert.equal(r.perPlayer.p1.coins, card.coin, 'the bounty coin is paid to the player');
|
||||
assert.equal(r.perPlayer.p1.killed, r.perPlayer.p1.total);
|
||||
assert.equal(r.perPlayer.p1.leaked.length, 0);
|
||||
});
|
||||
|
||||
test('original form: every damage instance cancelled; 3 physical + 3 arts change nothing; the 4th physical ⇒ a 2 s change (immobile, still cancelled, immune) ⇒ 寻仇者 stats, melee physical attacks through the engine, ATK +100 % below half HP', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }, { chessId: 't_mage', row: 11, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const e = put(h, TR, { mods: { speedMul: 1 } });
|
||||
const g = h.unit('t_gun'), m = h.unit('t_mage');
|
||||
const base = { hp: e.s.maxHp, atk: e.s.atk, def: e.s.def, res: e.s.res, move: e.s.moveSpeed, bat: e.base.bat, mass: e.s.massLevel };
|
||||
for (let i = 0; i < 3; i++) {
|
||||
assert.equal(h.b.dealDamage(g, e, { amount: 1e6, type: 'phys' }), 0);
|
||||
assert.equal(h.b.dealDamage(m, e, { amount: 1e6, type: 'arts' }), 0);
|
||||
}
|
||||
assert.equal(h.b.dealDamage(g, e, { amount: 1e6, type: 'true' }), 0, 'true damage too');
|
||||
assert.equal(e.hp, base.hp);
|
||||
assert.ok(!e.findBuff('ab:change'), '3 + 3 hits: no change yet');
|
||||
for (const s of ['stun', 'sleep', 'cold', 'freeze', 'levitate', 'fear']) assert.equal(h.b.applyStatus(e, s, { duration: 3, source: g }), false, `immune to ${s}`);
|
||||
assert.ok(e.s.flags.noDisplace, '失衡免疫');
|
||||
h.b.dealDamage(g, e, { amount: 10, type: 'phys' });
|
||||
assert.ok(e.findBuff('ab:change'), 'the 4th physical hit starts the change');
|
||||
assert.ok(h.eventsOf('fx').some((ev) => ev[1] === 'phase' && ev[4].id === e.id && ev[4].kind === 'translator_fuchou'));
|
||||
const x0 = e.x;
|
||||
h.run(TRANSLATOR_CHANGE - 0.1);
|
||||
approx(e.x, x0, 1e-9, 'stands still while changing');
|
||||
assert.equal(h.b.dealDamage(g, e, { amount: 1e6, type: 'phys' }), 0, 'still cancelled while changing');
|
||||
assert.ok(!e.findBuff('ab:form'));
|
||||
h.run(0.15);
|
||||
const t = (k) => tb(TR, `Mode_Fuchou_Passive.${k}`);
|
||||
approx(e.s.maxHp, base.hp + t('max_hp'));
|
||||
approx(e.hp, e.s.maxHp, 1e-6, 'full HP');
|
||||
approx(e.s.atk, base.atk + t('atk'));
|
||||
approx(e.s.def, base.def + t('def'));
|
||||
approx(e.s.res, base.res + t('magic_resistance'));
|
||||
approx(e.s.moveSpeed, base.move * (1 + t('move_speed')));
|
||||
approx(e.s.interval, base.bat + t('base_attack_time'));
|
||||
assert.equal(e.s.massLevel, base.mass + t('mass_level'));
|
||||
assert.ok(!e.s.flags.noDisplace, 'the original form\'s immunities are gone');
|
||||
assert.ok(h.b.applyStatus(e, 'stun', { duration: 0.5, source: g }));
|
||||
assert.ok(h.b.dealDamage(g, e, { amount: 100, type: 'true' }) > 0, 'damage lands now');
|
||||
// the 4th arts hit / a block no longer change anything
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(m, e, { amount: 1, type: 'arts' });
|
||||
assert.equal(e.findBuff('ab:form').mods.resFlat, t('magic_resistance'), 'one change only');
|
||||
// melee physical attacks on its blocker, through the engine ('atk' event, the attack hooks)
|
||||
const h2 = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }, { chessId: 't_wall', row: 9, col: 7 }], kits: QUIET_GUNS, hooks: ['damaged'], captureNoisy: true });
|
||||
h2.step();
|
||||
const f = put(h2, TR, { mods: { speedMul: 1 } });
|
||||
for (let i = 0; i < 4; i++) h2.b.dealDamage(h2.unit('t_gun'), f, { amount: 1, type: 'phys' });
|
||||
assert.ok(h2.runUntil(() => f.stats.attacks >= 1, 20));
|
||||
const w = h2.unit('t_wall');
|
||||
assert.ok(h2.eventsOf('atk').some((ev) => ev[1] === f.id && ev[2] === w.id && ev[3] === 'none'), 'a melee attack on its blocker');
|
||||
const hit = h2.hooksOf('damaged').find((c) => c.source === f);
|
||||
assert.equal(hit.dmg.type, 'phys');
|
||||
const atk = f.s.atk;
|
||||
h2.b.dealDamage(h2.unit('t_gun'), f, { amount: f.s.maxHp * 0.6, type: 'true' });
|
||||
h2.step();
|
||||
approx(f.s.atk, atk * (1 + tb(TR, 'Mode_Fuchou_Anger.atk')), 1e-6, 'ATK +100 % below half HP');
|
||||
h2.b.heal(null, f, f.s.maxHp);
|
||||
h2.step();
|
||||
approx(f.s.atk, atk, 1e-6, 'and back above half');
|
||||
checkInvariants(h2.b);
|
||||
});
|
||||
|
||||
test('an HP loss (流失 — no damage instance to cancel, e.g. 隐德来希\'s 心烛 hand-over) cannot knock out its original form; once changed it can', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const e = put(h, TR, { mods: { speedMul: 0 } });
|
||||
const g = h.unit('t_gun');
|
||||
h.b.loseHp(e, 1e9, { source: g });
|
||||
assert.ok(e.alive && e.hp >= 1, 'still standing in its first form');
|
||||
assert.equal(h.b.killed, 0);
|
||||
assert.equal(h.eventsOf('die').filter((ev) => ev[1] === e.id).length, 0, 'no die event: its first form has no death clip');
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(g, e, { amount: 1, type: 'phys' });
|
||||
h.b.loseHp(e, 1e9, { source: g });
|
||||
assert.ok(e.alive, 'not during its change either');
|
||||
h.run(TRANSLATOR_CHANGE + 0.1);
|
||||
h.b.loseHp(e, 1e9, { source: g });
|
||||
assert.ok(!e.alive && e.removeReason === 'killed', 'the changed form dies');
|
||||
assert.equal(h.b.killed, 1);
|
||||
});
|
||||
|
||||
test('the 4th arts hit ⇒ 特战术师: its stats, ranged arts attacks on 2 targets at once', () => {
|
||||
const h = arena({ units: [{ chessId: 't_mage', row: 11, col: 6 }, { chessId: 't_gun', row: 10, col: 7 }], kits: QUIET_GUNS, hooks: ['damaged'], captureNoisy: true });
|
||||
h.step();
|
||||
const e = put(h, TR, { pos: [9, 7], mods: { speedMul: 0 } });
|
||||
const base = { hp: e.s.maxHp, res: e.s.res, bat: e.base.bat };
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(h.unit('t_mage'), e, { amount: 1, type: 'arts' });
|
||||
assert.ok(h.eventsOf('fx').some((ev) => ev[1] === 'phase' && ev[4].id === e.id && ev[4].kind === 'translator_shushi'));
|
||||
h.run(TRANSLATOR_CHANGE + 0.1);
|
||||
const t = (k) => tb(TR, `Mode_Shushi_Passive.${k}`);
|
||||
approx(e.s.maxHp, base.hp + t('max_hp'));
|
||||
approx(e.s.res, base.res + t('magic_resistance'));
|
||||
approx(e.s.interval, base.bat + t('base_attack_time'));
|
||||
assert.ok(h.runUntil(() => e.stats.attacks >= 1, 10));
|
||||
assert.equal(h.eventsOf('atk').filter((ev) => ev[1] === e.id).length, 2, 'one attack, two shots');
|
||||
h.run(0.6); // the shots land
|
||||
const hits = h.hooksOf('damaged').filter((c) => c.source === e);
|
||||
assert.equal(new Set(hits.map((c) => c.target.id)).size, 2, 'two targets at once');
|
||||
assert.ok(hits.every((c) => c.dmg.type === 'arts'));
|
||||
});
|
||||
|
||||
test('blocked first ⇒ 幽灵: the 2 s change held by its blocker, then unblockable, walks on, never attacks, takes damage', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }, { chessId: 't_wall', row: 9, col: 7 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const e = put(h, TR, { mods: { speedMul: 1 } });
|
||||
assert.ok(h.runUntil(() => !!e.findBuff('ab:change'), 20), 'the block starts the change');
|
||||
assert.ok(h.eventsOf('fx').some((ev) => ev[1] === 'phase' && ev[4].id === e.id && ev[4].kind === 'translator_youling'));
|
||||
assert.ok(e.blockedBy);
|
||||
const hp = e.hp;
|
||||
h.run(TRANSLATOR_CHANGE - 0.1);
|
||||
assert.equal(h.b.dealDamage(h.unit('t_gun'), e, { amount: 1e6, type: 'phys' }), 0, 'damage cancelled while changing');
|
||||
assert.equal(e.hp, hp);
|
||||
h.run(0.3);
|
||||
assert.ok(e.s.flags.unblockable && !e.blockedBy, '幽灵: unblockable, its blocker lets go');
|
||||
const x = e.x;
|
||||
h.run(3);
|
||||
assert.ok(Math.hypot(e.x - x, e.y - 9) > 0.5, 'walks on');
|
||||
assert.ok(h.b.dealDamage(h.unit('t_gun'), e, { amount: 100, type: 'phys' }) > 0, 'damage lands now');
|
||||
assert.equal(e.stats.attacks, 0, '幽灵 never attacks');
|
||||
assert.equal(e.mem.ab.list.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// review follow-ups: the form reaches a view built mid-battle; stable enemy shapes
|
||||
|
||||
describe('a view built mid-battle learns the form (UnitInfo `form` in fieldMeta)', () => {
|
||||
const formOf = (h, e) => h.b.fieldMeta().units.find((u) => u.id === e.id)?.form;
|
||||
test('spawned: no form; 转译基底·α changing / changed, a 逐火 ember and its revival, a leader\'s 重生 and second form, 守墓石像 — each fieldMeta carries the current one', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }, { chessId: 't_mage', row: 11, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const still = { mods: { speedMul: 0 } };
|
||||
const tr = put(h, TR, { pos: [9, 8], ...still });
|
||||
const ember = put(h, 'enemy_1288_duskls', { pos: [10, 8], ...still });
|
||||
const mace = put(h, 'enemy_1525_blkswb', { pos: [11, 8], ...still });
|
||||
const stone = put(h, 'enemy_1172_dugago', { pos: [12, 8], ...still });
|
||||
const spawned = h.eventsOf('spawn').find((ev) => ev[1].id === tr.id)[1];
|
||||
assert.equal(spawned.form, undefined, 'a fresh enemy has no form');
|
||||
assert.equal(formOf(h, tr), undefined);
|
||||
const m = h.unit('t_mage');
|
||||
for (let i = 0; i < 4; i++) h.b.dealDamage(m, tr, { amount: 1, type: 'arts' });
|
||||
h.b.kill(ember, m);
|
||||
h.b.kill(mace, m);
|
||||
h.b.kill(stone, m);
|
||||
// the client runner's silent catch-up: the fx are drained and dropped
|
||||
h.b.step();
|
||||
h.b.drainEvents();
|
||||
assert.equal(formOf(h, tr), 'translator_shushi', 'changing');
|
||||
assert.equal(formOf(h, ember), 'husk');
|
||||
assert.equal(formOf(h, mace), 'reborn');
|
||||
assert.equal(formOf(h, stone), 'stone');
|
||||
h.b.kill(ember, null); // still in its 1 s 重生: nothing changes
|
||||
while (h.b.time < 12.5) { h.b.step(); h.b.drainEvents(); }
|
||||
assert.equal(formOf(h, tr), 'translator_shushi', 'changed');
|
||||
assert.equal(formOf(h, ember), 'revived', 'the warrior again');
|
||||
assert.equal(formOf(h, mace), 'form2', 'after its 重生');
|
||||
assert.equal(formOf(h, stone), 'fly');
|
||||
});
|
||||
});
|
||||
|
||||
test('every enemy starts with the same profile fields and `moving` / `form` (one object shape for the hot loop)', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const keys = [TR, ...EMBERS, 'enemy_1007_slime', 'enemy_1172_dugago', 'enemy_1525_blkswb', 'enemy_9010_acpupp'];
|
||||
const shapes = new Set();
|
||||
for (const key of keys) {
|
||||
const e = put(h, key);
|
||||
assert.equal(e.moving, false, `${key} moving`);
|
||||
assert.equal(e.form, null, `${key} form`);
|
||||
assert.ok('dmgType' in e.profile && e.profile.dmgType === null, `${key} profile.dmgType`);
|
||||
shapes.add(Object.keys(e).join());
|
||||
}
|
||||
assert.equal(shapes.size, 1, 'one key order for every enemy');
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------
|
||||
// second review: a 重生 clears the statuses; a blocked 隐匿 enemy is drawn solid
|
||||
|
||||
describe('a 重生 clears what operators put on the enemy (PRTS 特殊机制 §重生 "清空自身身上除白名单外所有Buff")', () => {
|
||||
test('a 深池逐火战士 knocked out while feared and slowed (叙拉古-style 恐惧 makes it unblockable) is an ember without them: blocked again, beaten by the gun — its own talents stay', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }, { chessId: 't_wall', row: 9, col: 7 }] });
|
||||
h.step();
|
||||
const e = put(h, 'enemy_1288_duskls', { mods: { speedMul: 1 } });
|
||||
const gun = h.unit('t_gun');
|
||||
assert.ok(h.runUntil(() => !!e.blockedBy, 20), 'blocked by the wall');
|
||||
assert.ok(h.b.applyStatus(e, 'fear', { duration: 30, source: gun }), 'feared');
|
||||
assert.ok(h.b.applyStatus(e, 'slow', { duration: 30, source: gun, value: 0.5 }), 'slowed');
|
||||
h.b.addBuff(e, { key: 'test:opDebuff', duration: 30, mods: { defFlat: -50 }, source: gun }); // a skill's debuff
|
||||
assert.ok(e.s.flags.fear && e.s.flags.unblockable && !e.blockedBy, 'the fear releases it');
|
||||
h.b.kill(e, gun);
|
||||
assert.ok(e.alive && e.form === 'husk', 'knocked out: its 重生');
|
||||
for (const k of ['fear', 'slow', 'test:opDebuff']) assert.equal(e.findBuff(k), null, `${k} cleared by the 重生`);
|
||||
assert.ok(e.findBuff('ab:ember') && e.findBuff('ab:hitCount'), 'the ember\'s own buffs');
|
||||
assert.ok(h.eventsOf('status').some((ev) => ev[1] === e.id && ev[2] === 'fear' && ev[3] === 0), 'the fear icon goes');
|
||||
h.run(HUSK_REBIRTH + 0.1);
|
||||
assert.ok(!e.s.flags.fear && !e.s.flags.unblockable && e.s.flags.stealth, 'a 隐匿 ember that can be blocked');
|
||||
assert.ok(h.runUntil(() => !e.alive, 8), 'blocked, it is beaten before it could stand up');
|
||||
assert.equal(e.removeReason, 'killed');
|
||||
assert.ok(h.b.time < 2 + HUSK_REBIRTH + tb('enemy_1288_duskls', 'Revive[Trigger].interval') + 10);
|
||||
});
|
||||
|
||||
test('锏\'s 重生 clears an operator\'s slow and 脆弱 but keeps its 抵抗 (a self-applied talent status); 守墓石像\'s instant 重生 too', () => {
|
||||
const h = arena({ units: [{ chessId: 't_gun', row: 10, col: 4 }], kits: QUIET_GUNS });
|
||||
h.step();
|
||||
const still = { mods: { speedMul: 0 } };
|
||||
const mace = put(h, 'enemy_1525_blkswb', { pos: [10, 7], ...still });
|
||||
const stone = put(h, 'enemy_1172_dugago', { pos: [11, 7], ...still });
|
||||
const gun = h.unit('t_gun');
|
||||
assert.ok(mace.findBuff('resist'), '锏 has its 抵抗');
|
||||
for (const u of [mace, stone]) {
|
||||
assert.ok(h.b.applyStatus(u, 'slow', { duration: 30, source: gun, value: 0.5 }));
|
||||
assert.ok(h.b.applyStatus(u, 'fragile', { duration: 30, source: gun, value: 0.3 }));
|
||||
h.b.kill(u, gun);
|
||||
assert.ok(u.alive, 'a 重生, not a death');
|
||||
assert.equal(u.findBuff('slow'), null, `${u.defId}: slow cleared`);
|
||||
assert.equal(u.findBuff('fragile'), null, `${u.defId}: 脆弱 cleared`);
|
||||
}
|
||||
assert.ok(mace.findBuff('resist'), '锏 keeps its 抵抗');
|
||||
assert.ok(stone.findBuff('ab:stone'), 'the statue form starts');
|
||||
});
|
||||
});
|
||||
|
||||
describe('a blocked 隐匿 enemy is drawn solid (b.snap stealth bit: PRTS 作战机制 §隐匿 "在被阻挡时开关会被关掉")', () => {
|
||||
test('the 逐火 ember: see-through while it walks unblocked, solid while blocked or revealed; an ally keeps its 迷彩 / 隐匿 look while blocking', async () => {
|
||||
const { flagsOf } = await import('../../server/sim/snapshot.js');
|
||||
const { UF } = await import('../../shared/constants.js');
|
||||
const h = arena({ units: [{ chessId: 't_wall', row: 9, col: 7 }] });
|
||||
h.step();
|
||||
const e = put(h, 'enemy_1288_duskls', { mods: { speedMul: 1 } });
|
||||
h.run(0.5);
|
||||
h.b.kill(e, null);
|
||||
h.run(HUSK_REBIRTH + 0.1);
|
||||
assert.ok(e.s.flags.stealth && !e.blockedBy);
|
||||
assert.ok(flagsOf(e) & UF.STEALTH, 'unblocked: see-through');
|
||||
const tuple = () => h.b.snapshot().units.find((t) => t[0] === e.id);
|
||||
assert.ok(tuple()[7] & UF.STEALTH, 'in b.snap too');
|
||||
assert.ok(h.runUntil(() => !!e.blockedBy, 10), 'walks into the wall');
|
||||
assert.ok(e.s.flags.stealth, 'the sim keeps the 隐匿 flag (it returns once the block ends)');
|
||||
assert.equal(flagsOf(e) & UF.STEALTH, 0, 'blocked: drawn solid');
|
||||
assert.equal(tuple()[7] & UF.STEALTH, 0);
|
||||
assert.ok(flagsOf(e) & UF.BLOCKED);
|
||||
const g = put(h, 'enemy_1288_duskls', { pos: [11, 9], mods: { speedMul: 0 } });
|
||||
h.b.kill(g, null);
|
||||
h.run(HUSK_REBIRTH + 0.1);
|
||||
assert.ok(flagsOf(g) & UF.STEALTH);
|
||||
h.b.addBuff(g, { key: 'test:reveal', duration: 5, flags: { reveal: true } });
|
||||
assert.equal(flagsOf(g) & UF.STEALTH, 0, 'revealed: drawn solid');
|
||||
const wall = h.unit('t_wall');
|
||||
h.b.addBuff(wall, { key: 'test:stealth', duration: 5, flags: { stealth: true } });
|
||||
assert.ok(wall.blocking.length > 0 && flagsOf(wall) & UF.STEALTH, 'an ally keeps its 隐匿 look while blocking');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user