import test from "node:test"; import assert from "node:assert/strict"; import { NAV_STUCK_MS } from "../../shared/protocol/constants.js"; import { MobId } from "../../shared/definitions/mobs.js"; import { Component } from "../src/ecs/components.js"; import { mobComponents } from "../src/simulation/spawners.js"; import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js"; function workerOf (simulation, entityId) { const record = simulation.entityRecord(entityId); assert.ok(record); return simulation.workers[record.workerId]; } test("navigation stuck for 5s repaths around a blocker", () => { const harness = makeSimulation({ workerCount: 1 }); try { const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 }); harness.simulation.spawnCharacter(1, character); const moverId = harness.simulation.spawnEntity(mobComponents({ tileX: 8, tileY: 9, mobTypeId: MobId.deer })); harness.simulation.spawnEntity(mobComponents({ tileX: 9, tileY: 9, mobTypeId: MobId.deer })); harness.simulation.step(); const worker = workerOf(harness.simulation, moverId); const handle = worker.world.ecs.handleOf(moverId); const path = worker.world.ecs.get(handle, Component.path); const position = worker.world.ecs.get(handle, Component.position); path.tiles = [ { x: 9, y: 9 }, { x: 10, y: 9 }, { x: 11, y: 9 } ]; path.stuckSince = harness.now(); path.stuckTileX = position.tileX; path.stuckTileY = position.tileY; harness.advance(1_000); harness.simulation.step(); assert.equal(position.tileX, 8); assert.equal(position.tileY, 9); assert.equal(path.tiles[0]?.x, 9); assert.equal(path.tiles[0]?.y, 9); harness.advance(NAV_STUCK_MS); harness.simulation.step(); assert.equal(position.tileX, 8); assert.equal(position.tileY, 9); const next = path.tiles[0]; assert.ok(next, "expected a repath with remaining steps"); assert.ok(!(next.x === 9 && next.y === 9), "repath should not keep stepping into the blocker"); } finally { harness.close(); } });