From 130266553d235a311bdb5112115a0a9202267aa5 Mon Sep 17 00:00:00 2001 From: sganggs Date: Sun, 4 Oct 2026 03:23:23 +0800 Subject: [PATCH] =?UTF-8?q?feedback2=20WK:=20a=20ranged=20enemy's=20attack?= =?UTF-8?q?=20stand=20holds=20only=20its=20walking=20=E2=80=94=20route=20W?= =?UTF-8?q?AIT=20legs=20keep=20running=20and=20DISAPPEAR=20/=20APPEAR=20le?= =?UTF-8?q?gs=20still=20happen,=20hiding=20ends=20the=20stand;=20the=20[AS?= =?UTF-8?q?SUMED]=20form-clip=20note=20names=20=E6=89=8E=E7=BD=97=20and=20?= =?UTF-8?q?=E7=89=B9=E6=88=98=E6=9C=AF=E5=B8=88;=20=E6=9A=B4=E9=B8=B0's=20?= =?UTF-8?q?hover=20comment=20(review=20of=20GitHub=20#58)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/SIM.md | 3 +- server/sim/ai.js | 24 +++++++--- server/sim/content/enemies.js | 5 +- test/sim/feedback2-enemy-attack-stand.test.js | 48 +++++++++++++++++++ 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/docs/SIM.md b/docs/SIM.md index b82fd128..02bf6331 100644 --- a/docs/SIM.md +++ b/docs/SIM.md @@ -279,7 +279,8 @@ halving — PRTS: a map effect —, 【国度】, a chimera's 源石污染区 au and, unblocked, stand for each attack's clip — `attackStand`: data/enemies.json `attackAnim`, through its wind-up (cooldown ≤ the strike frame, a target in range) and the rest of the clip after the strike, shortened when the attacks come quicker than the clip; `ATTACK_PAUSE` (0.35 s) after the strike when no clip is known; an `attackMoves` -(「不停止移动」) enemy never stops; a stun ends the stand; GitHub #58 — then walk on; `fear`/`disarm` stop attacks; `dmgType 'none'` enemies +(「不停止移动」) enemy never stops; a stun ends the stand; only the walking waits — a route WAIT keeps running and +DISAPPEAR / APPEAR legs still happen, hiding ends the stand; GitHub #58 — then walk on; `fear`/`disarm` stop attacks; `dmgType 'none'` enemies never attack — unless content arms them through `enemy.profile` (`noAttack: false`, `melee`, `dmgType`, `maxTargets`: 转译基底·α's 寻仇者 / 特战术师 forms, which then attack like any enemy); `dmgType 'heal'` enemies heal the lowest-HP% enemy in their radius instead. A `noMove` enemy stands (not `moving`, drawn idle). Content can take over an enemy's attack: `enemy.profile.deferHit` = the engine makes the attack (target, timing, the `'atk'` event) but deals no diff --git a/server/sim/ai.js b/server/sim/ai.js index ccc164f0..fe9a1ab1 100644 --- a/server/sim/ai.js +++ b/server/sim/ai.js @@ -465,17 +465,18 @@ export function updateEnemy(b, e, dt) { } if (!e.hidden && b._checkBlock(e)) return; if (b.time < e.pauseUntil) return; - // standing for an attack clip (attackStand, GitHub #58): drawn idle — the client plays the clip, then Move again; a - // 恐惧 runs at once (it cannot attack) - if (winding || (b.time < e.atkStandUntil && !e.s.flags.fear)) { e.moving = false; return; } + // standing for an attack clip (attackStand, GitHub #58): only the walking waits — a checkpoint's WAIT keeps running + // and DISAPPEAR / APPEAR legs still happen (advanceRoute); drawn idle (the client plays the clip, then Move again); + // a 恐惧 runs at once (it cannot attack) + const standing = winding || (b.time < e.atkStandUntil && !e.s.flags.fear); if (e.s.flags.noMove) { e.moving = false; return; } // standing (a 重生, a form change): drawn idle, not walking // 恐惧 (ba.fear "无法被阻挡并四散逃跑"; PRTS 诱发移动: 恐惧 outranks 诱导): runs to random tiles of the fan away from // its source — a self-inflicted fear flutters inside its own tile (fear.js); the route re-plans once it ends if (e.s.flags.fear && !e.hidden) { moveFeared(b, e, dt); return; } if (e.mem.fearMove) endFear(e); // 诱导 (ba.attract "无法被阻挡并向目标位置移动"): walks to the attract point instead of following its route - if (e.s.flags.attract) { moveAttracted(b, e, dt); return; } - advanceRoute(b, e, dt, R); + if (e.s.flags.attract) { if (standing) e.moving = false; else moveAttracted(b, e, dt); return; } + advanceRoute(b, e, dt, R, standing); } /** @@ -520,7 +521,11 @@ function moveAttracted(b, e, dt) { if (moved && e.route) e.route.pts = null; } -function advanceRoute(b, e, dt, R) { +/** + * One tick along the route legs. `standing` (an attack clip, attackStand): the time-based legs go on — a WAIT runs + * down, DISAPPEAR / APPEAR happen (leaving the field ends the clip) — and a MOVE leg holds (GitHub #58 review). + */ +function advanceRoute(b, e, dt, R, standing = false) { let budget = dt; let guard = 16; while (budget > 1e-9 && guard-- > 0 && e.alive) { @@ -537,6 +542,7 @@ function advanceRoute(b, e, dt, R) { } if (leg.t === 'disappear') { b._setHidden(e, true); + e.atkStandUntil = -Infinity; standing = false; // off the field: its attack clip is over R.legIdx++; R.pts = null; continue; } @@ -547,6 +553,7 @@ function advanceRoute(b, e, dt, R) { continue; } // move + if (standing) { e.moving = false; return; } // the walking waits for the attack clip if (!R.pts || R.version !== b.grid.version) planLeg(b, e, leg); const speed = e.s.moveSpeed * MOVE_SCALE; if (speed <= 0) { e.moving = false; return; } @@ -587,7 +594,10 @@ function advanceRoute(b, e, dt, R) { * plays for its attacks and its strike frame (tools/build-data.mjs, from the asset manifest) —, `hit` of it before * the strike (the wind-up, while a target is in range) and the rest after it, both shortened when the attacks come * quicker than the clip (it then plays faster: render/spine.js, the same rule) — no source gives a length. An enemy in - * another form (掠海漂移体's crawl, 转译基底's forms, 杰斯顿's second form) stands for its base clip [ASSUMED]. + * another form (掠海漂移体's crawl, 转译基底's forms, 杰斯顿's second form) stands for its base clip [ASSUMED]; known + * mismatches: 扎罗's second form stands 1.433 s (A_Attack) though its B_Attack lasts 2.0 s (2.5 s interval: ~0.4 s of + * walking during the recovery), 转译基底's 特战术师 stands 2.0 s (B_Attack) though its D_Attack lasts 1.667 s — a per-form + * clip needs the client's FORMS mapping (render/units.js) in shared data. * Returns the wind-up and rest (s) into `out`: an enemy with no attack clip known stands ATTACK_PAUSE after the strike * (the old rule), a 「不停止移动」 one (`attackMoves`: data or content) never stops. */ diff --git a/server/sim/content/enemies.js b/server/sim/content/enemies.js index 0bc054ca..b782968b 100644 --- a/server/sim/content/enemies.js +++ b/server/sim/content/enemies.js @@ -1742,8 +1742,9 @@ function kitRoar(ab) { * ×boomb.move_speed, and it flies on. A stun / freeze / sleep before the release interrupts the cast (Boomb * `_immuneStunWhenAffecting` 0, like the other enemy channels here): nothing leaves the drone, it keeps its bomb and casts * again after the skill's cooldown (1 s, counted from the interrupt) once it is free and an operator is in range. - * [ASSUMED] no drop when the drone is dead at the release; the ATK at the release; the hover through the cast (the - * engine stands a ranged enemy for its attack clip, ai.js attackStand; the drop is the drone's only attack-like cast); the + * [ASSUMED] no drop when the drone is dead at the release; the ATK at the release; the hover through the cast (its own + * hold, `pauseUntil`: the drone has no normal attack — `noAttack` —, so ai.js attackStand, the stand of a ranged enemy + * for its attack clip, never runs for it; the drop is its only attack-like cast); the * bomb-less look from the release (the bomb leaves the drone on that frame of the Attack clip; at the cast end — 1 tick * before the clip ends — the client would draw the bomb back for a frame); an interrupted cast does not use up the one * trigger (`_maxTriggerTime` 1 — the bomb is still on the drone); a stun after the release does not stop the cast end. diff --git a/test/sim/feedback2-enemy-attack-stand.test.js b/test/sim/feedback2-enemy-attack-stand.test.js index 0a3de3b4..08e401b9 100644 --- a/test/sim/feedback2-enemy-attack-stand.test.js +++ b/test/sim/feedback2-enemy-attack-stand.test.js @@ -126,3 +126,51 @@ test('no attack clip known: ATTACK_PAUSE after the strike and no wind-up stand; h.run(0.3); assert.notEqual(e.x, x0, 'walks once the stun is over'); }); + +// review: a stand holds only the walking — a route's WAIT keeps running and DISAPPEAR / APPEAR still happen +// (data/waves.json has 122 WAIT and 99 DISAPPEAR checkpoints); it used to hold every leg, so a wait ran long by each +// clip and never ended for an enemy attacking quicker than its clip +function routeField(key, bat, dur, checkpoints, ally) { + const rec = { ...enemyRec({ key, hp: 1e9, atk: 1, range: 3, bat, speed: 1 }), attackAnim: { clip: 'Attack', dur, hit: dur / 2 } }; + return makeBattle({ + defs: { chess: { t_a: chessRec({ id: 't_a', stats: { maxHp: 1e9, atk: 0, def: 1e6 } }) }, enemies: { [key]: rec } }, + units: ally ? [{ chessId: 't_a', row: 10, col: 7 }] : [], routes: [{ motion: 'WALK', start: [9, 8], end: [9, 2], checkpoints }], + enemies: [{ key, time: 0, route: 0 }], content: 'none', autoFinish: false, timeLimit: 60, hooks: ['attack'], + }); +} + +test('a ranged enemy with a target in range on a WAIT checkpoint leaves when the wait (and its current clip) is over, as without a target', () => { + const leaves = (bat, dur, ally) => { + const h = routeField('enemy_waiter', bat, dur, [{ type: 'WAIT', time: 3 }], ally); + let waited = null, moved = null, x0 = null; + for (let i = 0; i < Math.round(8 / TICK); i++) { + h.step(); + const e = h.enemies()[0]; + x0 ??= e.x; + if (waited == null && e.route.legIdx >= 1) waited = h.b.time; + if (moved == null && Math.abs(e.x - x0) > 1e-6) moved = h.b.time; + } + return { waited, moved, attacks: h.hooksOf('attack').length }; + }; + const free = leaves(2.7, 1, false), sniper = leaves(2.7, 1, true), quick = leaves(1, 2, true); + assert.equal(free.attacks, 0); + assert.ok(sniper.attacks >= 2 && quick.attacks >= 5); + assert.ok(Math.abs(sniper.waited - free.waited) < 1e-9 && Math.abs(quick.waited - free.waited) < 1e-9, `the wait ends at ${free.waited.toFixed(2)} s for all three`); + // it walks on once the attack clip running at the end of the wait is over (the attack at 2.7 s: until 3.2 s) + assert.ok(sniper.moved > free.moved && sniper.moved <= 3.2 + 2 * TICK, `leaves at ${sniper.moved?.toFixed(2)} s (no target: ${free.moved.toFixed(2)} s)`); + assert.equal(quick.moved, null, 'an enemy attacking quicker than its clip stands while the target stays in range'); +}); + +test('DISAPPEAR / APPEAR legs proceed while an enemy stands for its attacks; leaving the field ends the stand', () => { + const h = routeField('enemy_ghost', 1, 2, [{ type: 'WAIT', time: 1 }, { type: 'DISAPPEAR' }, { type: 'WAIT', time: 1 }, { type: 'APPEAR', pos: [9, 4] }], true); + let hiddenAt = null, appeared = null; + for (let i = 0; i < Math.round(4 / TICK); i++) { + h.step(); + const e = h.enemies()[0]; + if (hiddenAt == null && e.hidden) { hiddenAt = h.b.time; assert.equal(e.atkStandUntil, -Infinity, 'no stand left once hidden'); } + if (appeared == null && hiddenAt != null && !e.hidden) appeared = { t: h.b.time, x: e.x, y: e.y }; + } + assert.ok(h.hooksOf('attack').length >= 1, 'it attacked before leaving'); + assert.ok(hiddenAt != null && Math.abs(hiddenAt - 1) < 2 * TICK, `disappears after its 1 s wait (${hiddenAt})`); + assert.ok(appeared && Math.abs(appeared.t - 2) < 2 * TICK && Math.abs(appeared.x - 4) < 0.05 && appeared.y === 9, `appears on (9,4) 1 s later (${JSON.stringify(appeared)})`); +});