Files
ark-stronghold-protocol/test/match/feedback5-watch-follow.test.js
sganggs 221e6b8dd2 0.2.5-dev: community round 30 and follow-ups
- Stock: fixed trait gifts (缪尔赛思 / 变形者集群 变形同构体, 耶拉 不融冰, 蜜蜡 / 卡涅利安 迅捷作战粮, 诗怀雅 盟约之币) still occupy stock but are granted past the cap; an operator card already shown in the shop or a reward can be taken after the pool runs out and overdraws (GitHub #498, the owner's decision); item buys and item rewards keep the stock check. 洛洛 / 焰尾 sub-pools use the measured weights (PR #497 by @2321Robin; the occupancy idea of PR #496 by @2321Robin re-implemented differently).
- Boss pairs are drawn at random once per match and fixed to battle start; the Hidden Core reuses them; a leaver does not split a full pair (the owner's decision).
- 阿戈尔 in 联防 no longer re-applies the opening devour HP loss or a false revive; Touch's team medic stays for the match after its holder leaves (owner-approved, official lifetime unverified).
- Auto-skill ranges: 司霆惊蛰 S2, 斩业星熊 S3 against air, 予愿安洁莉娜 S3; 自在's post-rebirth invulnerability is also untargetable (#510); Horn / Clementia / catapult / 忍冬 first hit (PR #502 by @Xinglan233); 不融冰 / tear gas trigger on real damage.
- Bond layer-up sound in round start / draft / prep / battle (#482): one channel, a new cue replaces the old, no extra cooldown; a prep update that adds layers and activates a bond plays one cue.
- Client: multi-swing fix (#506), refresh single-flight (PR #507 by @robll-v1), LP tower keeps the settled value with a −N tick (PR #504 by @robll-v1), export with only 潜能 / 练度 changes (PR #503 by @Xinglan233), spectator rosters list DIY members (PR #505 by @Xinglan233), banned members beside bond tooltips (PR #494 by @YuriRestia), recovery action above the away overlay (PR #511 by @RainoutOvO), the /dev/sim-check.html consistency page (PR #492 by @Cloudnyco), Korean (PR #490 by @D-Roote) and English Victoria wording (PR #499 by @YuriRestia).
- golden: 45 of 287 scenarios move against 0.2.4 (roster 17, bonds 3, fields 6, matches 17, standins 2), each attributed in docs/history/0.2.5.md §30.9 / §30.16.
2026-10-12 14:07:08 +08:00

158 lines
9.5 KiB
JavaScript

// Community report of 2026-10-06, item 56: 「死亡观战时每一回合结束都会被转回自己家」. An eliminated human (and a spectator
// seat) now follows a player through every phase reset — the official keeps observing after death (research 09 §3.1:
// self_dead_dialog KEEP_WATCH, DeadAutoObDn { obIndex, state, preparation }, FindFirstAvailObTarget): the player it last
// watched with a manual g.watch (Match.watchPref), else the first player still in (seat order, AI seats included —
// they are players of the remake). Round start: that player's prep board (m.field prep); 各自行动 (both combat modes),
// 最终攻势 / 隐秘核心: that player's field; a resync / a spectator joining in prep: the board again. The idea and most
// cases come from PR #189 by @2321Robin (watch preference), not merged; the shared-field rule of its review is solved
// with g.watch's optional `playerId` (the tapped player). The client side: battle/observe.js followedScout.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { PHASE } from '../../shared/constants.js';
import { validateC2S } from '../../shared/protocol.js';
import { makeMatch } from './harness.js';
import { followedScout } from '../../public/js/battle/observe.js';
const S = 's_spec';
test('round start: an eliminated viewer scouts the board it last watched; a spectator without a pick the first player still in', () => {
const h = makeMatch({ mode: 'coop', humans: 2, seed: 1001, fake: true, spectators: [S] }).start();
h.toPrep(1);
const m = h.m;
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:p_1' }), { ok: true });
assert.equal(m.watchPref.get('p_0'), 'p_1', 'the manual scout is the preference');
h.ps('p_0').eliminate(1);
h.toPrep(2);
assert.equal(m.watchers.get('p_0'), 'n:p_1', 'the eliminated viewer scouts its preference again');
const meta = h.lastTo('p_0', 'm.field');
assert.deepEqual([meta?.fieldId, meta?.prep], ['n:p_1', true], 'the prep board itself was pushed');
assert.equal(m.watchPref.get('p_0'), 'p_1', 'the automatic assignment leaves the preference alone');
assert.equal(m.watchers.get(S), 'n:p_1', 'the spectator (no pick) follows the first player still in: p_1 (p_0 is out)');
assert.equal(h.lastTo(S, 'm.field')?.fieldId, 'n:p_1');
m.dispose();
});
test('the item: one human with AI teammates — eliminated, it follows an AI seat\'s board every round, never its own empty one', () => {
const h = makeMatch({ mode: 'coop', humans: 1, bots: 3, seed: 1010, fake: true }).start();
h.toPrep(1);
const m = h.m;
h.ps('p_0').eliminate(1);
h.toPrep(2);
assert.equal(m.watchers.get('p_0'), 'n:ai_0', 'the first player still in');
assert.equal(h.lastTo('p_0', 'm.field')?.fieldId, 'n:ai_0');
// a row tapped: that AI seat from now on, in combat and at the next round start
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:ai_2' }), { ok: true });
h.runToPhase(PHASE.COMBAT, 2);
assert.equal(m.watchers.get('p_0'), 'n:ai_2', 'its battle (server-run combat)');
h.toPrep(3);
assert.equal(m.watchers.get('p_0'), 'n:ai_2', 'its board again at the round start');
assert.equal(h.lastTo('p_0', 'm.field')?.fieldId, 'n:ai_2');
m.dispose();
});
test('a dead preference falls back to the first player still in; a followed player who quits mid-prep hands over at once', () => {
const h = makeMatch({ mode: 'coop', humans: 4, seed: 1002, fake: true }).start();
h.toPrep(1);
const m = h.m;
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:p_3' }), { ok: true });
h.ps('p_0').eliminate(1);
h.ps('p_3').eliminate(1);
h.toPrep(2);
assert.equal(m.watchers.get('p_0'), 'n:p_1', 'p_3 is gone → the first player still in (p_1)');
// p_1 quits during the prep: whoever scouted it follows the next player still in at once
m.onLeave('p_1');
assert.equal(m.watchers.get('p_0'), 'n:p_2');
assert.deepEqual([h.lastTo('p_0', 'm.field')?.fieldId, h.lastTo('p_0', 'm.field')?.prep], ['n:p_2', true]);
m.dispose();
});
test('server-run combat: the default watch starts an eliminated viewer on its preference; a mid-phase switch re-records it', () => {
const h = makeMatch({ mode: 'coop', humans: 3, seed: 1003, fake: true }).start();
h.toPrep(1);
const m = h.m;
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:p_2' }), { ok: true });
h.ps('p_0').eliminate(1);
h.runToPhase(PHASE.COMBAT, 1);
assert.equal(m.watchers.get('p_0'), 'n:p_2');
assert.equal(m.watchers.get('p_1'), 'n:p_1', 'a fighting player stays on its own field');
assert.equal(m.watchPref.get('p_0'), 'p_2', 'the combat assignment does not touch the preference');
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:p_1' }), { ok: true });
assert.equal(m.watchers.get('p_0'), 'n:p_1');
assert.equal(m.watchPref.get('p_0'), 'p_1', 'the manual switch is the new preference');
m.dispose();
});
test('client combat: an eliminated human is started on the field of the player it last watched; a reconnect puts it back there', () => {
const h = makeMatch({ mode: 'coop', humans: 3, seed: 1004, fake: true, clientCombat: true }).start();
h.toPrep(1);
const m = h.m;
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:p_2' }), { ok: true });
h.ps('p_0').eliminate(1);
h.runToPhase(PHASE.COMBAT, 1);
let start = h.lastTo('p_0', 'b.start');
assert.deepEqual([start?.watch, start?.fieldId], [true, 'n:p_2'], 'the preference\'s field, not the first seat\'s');
m.onDisconnect('p_0');
m.onReconnect('p_0');
start = h.lastTo('p_0', 'b.start');
assert.deepEqual([start?.watch, start?.fieldId], [true, 'n:p_2']);
m.dispose();
});
test('Final Assault: an eliminated viewer is started on its preference\'s boss field; a shared field records the tapped player only', () => {
const h = makeMatch({ mode: 'coop', difficulty: 'FUNNY', humans: 4, seed: 54, fake: true, instant: false, script: (b) => (b.kind === 'boss' ? { bossDps: 1 } : {}) }).start();
const m = h.m;
m.bossPairs = [['p_0', 'p_1'], ['p_2', 'p_3']]; // named watcher-role fixture; random assignment has its own tests
h.drive(() => m.phase === PHASE.PREP && m.round === 14);
h.ps('p_3').eliminate(13);
assert.deepEqual(m.handle('p_3', { t: 'g.watch', fieldId: 'n:p_2' }), { ok: true }, 'records the preference in prep');
h.drive(() => m.phase === PHASE.FINAL_ASSAULT);
assert.deepEqual(m.fields.map((f) => [f.fieldId, f.players]), [['b1', ['p_0', 'p_1']], ['b2', ['p_2']]]);
assert.equal(m.watchers.get('p_3'), 'b2', 'follows p_2 into b2 without a tap');
assert.equal(m.watchers.get('p_0'), 'b1', 'a fighting player stays on its own boss field');
// PR #189's review: a shared field's id does not say who was tapped — without `playerId` nothing is recorded
assert.deepEqual(m.handle('p_3', { t: 'g.watch', fieldId: 'b1' }), { ok: true });
assert.equal(m.watchPref.get('p_3'), 'p_2');
// with it (the client sends the row tapped), that player is the preference; a player not on the field is not
assert.deepEqual(m.handle('p_3', { t: 'g.watch', fieldId: 'b1', playerId: 'p_1' }), { ok: true });
assert.equal(m.watchPref.get('p_3'), 'p_1');
assert.deepEqual(m.handle('p_3', { t: 'g.watch', fieldId: 'b1', playerId: 'p_2' }), { ok: true });
assert.equal(m.watchPref.get('p_3'), 'p_1', 'p_2 is not on b1');
m.dispose();
});
test('a resync in prep sends the followed board: a spectator joining, an eliminated human reconnecting (client combat)', () => {
const h = makeMatch({ mode: 'coop', humans: 2, seed: 1006, fake: true, clientCombat: true }).start();
h.toPrep(1);
const m = h.m;
m.addSpectator(S);
let meta = h.lastTo(S, 'm.field');
assert.deepEqual([meta?.fieldId, meta?.prep], ['n:p_0', true], 'no pick → the first player still in');
assert.equal(m.watchers.get(S), 'n:p_0', 'registered as a scout: later board changes push again');
assert.deepEqual(m.handle('p_0', { t: 'g.watch', fieldId: 'n:p_1' }), { ok: true });
h.ps('p_0').eliminate(1);
m.onDisconnect('p_0');
const n = h.allTo('p_0', 'm.field').length;
m.onReconnect('p_0');
assert.ok(h.allTo('p_0', 'm.field').length > n, 'the reconnect pushed a board');
meta = h.lastTo('p_0', 'm.field');
assert.deepEqual([meta?.fieldId, meta?.prep], ['n:p_1', true], 'the preference survived the disconnect');
m.dispose();
});
test('g.watch\'s optional playerId passes the protocol check; junk does not', () => {
assert.equal(validateC2S({ t: 'g.watch', fieldId: 'b1' }), null);
assert.equal(validateC2S({ t: 'g.watch', fieldId: 'b1', playerId: 'p_1' }), null);
assert.notEqual(validateC2S({ t: 'g.watch', fieldId: 'b1', playerId: 7 }), null);
});
test('client: followedScout adopts the server\'s prep board for an eliminated player / spectator seat only, from home', () => {
const scout = { t: 'm.field', fieldId: 'n:p_1', prep: true };
assert.equal(followedScout({ field: scout, watching: null, alive: false, myId: 'p_0' }), 'n:p_1');
assert.equal(followedScout({ field: scout, watching: null, alive: false, spectator: true, myId: 's_x' }), 'n:p_1');
assert.equal(followedScout({ field: scout, watching: null, alive: true, myId: 'p_0' }), null, 'a living player keeps its own board');
assert.equal(followedScout({ field: scout, watching: 'n:p_2', alive: false, myId: 'p_0' }), null, 'already watching');
assert.equal(followedScout({ field: { ...scout, prep: false }, alive: false, myId: 'p_0' }), null, 'a battle field');
assert.equal(followedScout({ field: { ...scout, fieldId: 'n:p_0' }, alive: false, myId: 'p_0' }), null, 'its own board');
assert.equal(followedScout({ field: null, alive: false, myId: 'p_0' }), null);
});