import { describe, expect, it } from "vitest"; import { trainerWalkBuffer } from "../src/game/scripts/interpreter"; import { readMovement } from "../src/game/scripts/movement"; describe("TrainerWalkToPlayer", () => { const decode = (buffer: number[]) => readMovement({ byte: (index) => buffer[index] }, 0); it("only pauses when the player is adjacent", () => { expect(trainerWalkBuffer({ x: 5, y: 5 }, { x: 5, y: 6 }, 1)).toEqual([0x3e, 0x47]); expect(decode([0x3e, 0x47])).toEqual([{ kind: "sleep", ticks: 1 }]); }); it("walks all but the last tile toward the player at normal speed", () => { // step DOWN is movement_step | DOWN. expect(trainerWalkBuffer({ x: 1, y: 7 }, { x: 1, y: 10 }, 3)).toEqual([0x3e, 0x0c, 0x0c, 0x47]); expect(trainerWalkBuffer({ x: 9, y: 4 }, { x: 4, y: 4 }, 5)).toEqual([0x3e, 0x0e, 0x0e, 0x0e, 0x0e, 0x47]); expect(trainerWalkBuffer({ x: 2, y: 4 }, { x: 4, y: 4 }, 2)).toEqual([0x3e, 0x0f, 0x47]); expect(decode([0x3e, 0x0d, 0x47])).toEqual([ { kind: "sleep", ticks: 1 }, { kind: "step", direction: "up", ticks: 8, animate: true }, ]); }); it("follows ComputePathToWalkToPlayer off a straight line: the shorter axis first", () => { expect(trainerWalkBuffer({ x: 0, y: 0 }, { x: 3, y: 1 }, 4)).toEqual([0x3e, 0x0c, 0x0f, 0x0f, 0x47]); }); });