Open Route 32 to Route 34, the Ruins of Alph and Azalea Town (#32)
Enable Route 32 and its Pokémon Center, the Ruins of Alph with the four chambers, item and word rooms, inner chamber and research center, Union Cave, Route 33, Azalea Town with Kurt's house, the kiln and Bugsy's gym, the Slowpoke Well, Ilex Forest and Route 34. Port what their scripts need: saved WRAM bytes by label (readmem, writemem, loadmem: wFarfetchdPosition, wKurtApricornQuantity), VAR_UNOWNCOUNT and VAR_KURT_APRICORNS, SelectApricornForKurt and verbosegiveitemvar, Unown letters (GetUnownLetter, per-letter pictures, CheckUnownLetter's redraw, UpdateUnownDex, wFirstUnownSeen), the chamber puzzles (_UnownPuzzle), DisplayUnownWords, HoOhChamber and OmanyteChamber. Minigames and specials that draw a whole screen in tiles now share a tile screen effect with ROM graphics, palettes and sprites, answered with buttons; the standard font and textbox frame load for them. The playthrough continues through Kurt's Slowpoke Well, Bugsy, the rival and the Farfetch'd to the Route 34 gate; its helpers move to tests/playthrough-driver.ts. New tests solve the Kabuto puzzle through the world, catch Unown and make Kurt's balls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
15a31f95e4
commit
f4ef244fc7
31 files changed
+2334
-528
No files matched your search
+228
-464
@@ -1,12 +1,8 @@
|
||||
import { beforeEach, describe, expect, it, onTestFailed } from "vitest";
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { encodeSave } from "../src/storage/saves";
|
||||
import { CRYSTAL_ROM } from "../src/rom/validate";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { CrystalAssets } from "../src/game/rom/assets";
|
||||
import { GameWorld } from "../src/game/world/world";
|
||||
import type { Direction } from "../src/game/world/types";
|
||||
import { C } from "../src/game/battle/constants";
|
||||
import { findPath } from "./world-driver";
|
||||
import { Playthrough } from "./playthrough-driver";
|
||||
|
||||
const romPath =
|
||||
process.env.CRYSTAL_ROM_PATH ??
|
||||
@@ -29,6 +25,27 @@ const NEW_BARK = "24:4",
|
||||
KYLES_HOUSE = "10:11";
|
||||
const DARK_CAVE = "3:78",
|
||||
EARLS_ACADEMY = "10:8";
|
||||
const ROUTE_32 = "10:1",
|
||||
ROUTE_32_CENTER = "10:13",
|
||||
UNION_CAVE_1F = "3:37",
|
||||
ROUTE_33 = "8:6",
|
||||
AZALEA = "8:7",
|
||||
AZALEA_CENTER = "8:1",
|
||||
KURTS_HOUSE = "8:4",
|
||||
AZALEA_GYM = "8:5",
|
||||
SLOWPOKE_WELL_B1F = "3:40",
|
||||
ILEX_GATE = "11:22",
|
||||
ILEX_FOREST = "3:52",
|
||||
ROUTE_34_GATE = "11:23";
|
||||
const MIRACLE_SEED = 0x75,
|
||||
LURE_BALL = 0xa0,
|
||||
HM01 = 0xf3,
|
||||
CUT = 15;
|
||||
const EVENT_CLEARED_SLOWPOKE_WELL = 0x2b,
|
||||
EVENT_BEAT_BUGSY = 0x4be,
|
||||
EVENT_RIVAL_AZALEA_TOWN = 0x6bf,
|
||||
EVENT_HERDED_FARFETCHD = 0x29,
|
||||
ENGINE_HIVEBADGE = 0x1c;
|
||||
const PHONE_BUG_CATCHER_WADE = 16;
|
||||
const FLASH = 148,
|
||||
HM05 = 0xf7;
|
||||
@@ -50,336 +67,28 @@ const EVENT_TALKED_TO_MOM_AFTER_MYSTERY_EGG_QUEST = 0x40,
|
||||
describe.skipIf(!existsSync(romPath))(
|
||||
"a continuous opening playthrough",
|
||||
() => {
|
||||
const bytes = existsSync(romPath)
|
||||
? new Uint8Array(readFileSync(romPath))
|
||||
: new Uint8Array();
|
||||
const now = () => new Date("2026-09-22T12:00:00");
|
||||
let seed = 0x2a;
|
||||
const random = () => {
|
||||
seed = (seed * 1103515245 + 12345) >>> 0;
|
||||
return (seed >>> 16) & 255;
|
||||
};
|
||||
const assets = existsSync(romPath) ? new CrystalAssets(bytes) : undefined;
|
||||
let world: GameWorld;
|
||||
const log: string[] = [];
|
||||
|
||||
/** A wild species to throw Poké Balls at instead of fighting. */
|
||||
let wanted = 0;
|
||||
/** The usable move with the most power, or the first with PP. */
|
||||
const strongest = (mon: { moves: readonly number[]; pp: readonly number[] }) => {
|
||||
let best = -1;
|
||||
mon.moves.forEach((move, i) => {
|
||||
if (!move || !(mon.pp[i] & 63)) return;
|
||||
if (best < 0 || assets!.pokemon.move(move).power > assets!.pokemon.move(mon.moves[best]).power)
|
||||
best = i;
|
||||
});
|
||||
return Math.max(0, best);
|
||||
};
|
||||
/** Run scripts and battles until the player is free again. Battles use
|
||||
* the strongest move with PP; a wild battle below half HP is run from, as
|
||||
* a cautious player would. New moves are learned when there is room,
|
||||
* and other questions take the queued answers or their defaults. */
|
||||
const play = (answers: (number | string)[] = []) => {
|
||||
for (let tick = 0; tick < 100_000; tick++) {
|
||||
expect(world.notice, world.diagnostic).toBe("");
|
||||
const battle = world.battle;
|
||||
if (battle) {
|
||||
if (battle.message && log.at(-1) !== battle.message.text)
|
||||
log.push(battle.message.text);
|
||||
const prompt = battle.prompt;
|
||||
if (prompt?.kind === "action") {
|
||||
const { engine } = battle,
|
||||
mon = engine.player.mon;
|
||||
const ball = world.state.bag.balls.findIndex((slot) => slot.item === C.POKE_BALL);
|
||||
if (
|
||||
engine.battleMode === C.WILD_BATTLE &&
|
||||
engine.enemy.mon.species === wanted &&
|
||||
!world.state.party.some((member) => member.species === wanted) &&
|
||||
ball >= 0
|
||||
)
|
||||
world.battleAction({ action: "item", item: C.POKE_BALL, slot: ball });
|
||||
else if (engine.battleMode === C.WILD_BATTLE && mon.hp * 2 < mon.maxHp)
|
||||
world.battleAction({ action: "run" });
|
||||
else
|
||||
world.battleAction({ action: "fight", move: strongest(mon) });
|
||||
} else if (prompt?.kind === "yesno") world.battleChoose(1);
|
||||
// SHIFT's party menu: keep the Pokémon out (or send the first
|
||||
// that can fight when one must go).
|
||||
else if (prompt?.kind === "party")
|
||||
world.battleChoose(
|
||||
prompt.cancel
|
||||
? -1
|
||||
: world.state.party.findIndex((mon, i) => i !== battle.engine.curBattleMon && !mon.egg && mon.hp > 0),
|
||||
);
|
||||
else if (prompt?.kind === "forget") world.battleChoose(4);
|
||||
else if (prompt?.kind === "name") world.battleName("");
|
||||
else if (prompt?.kind === "stats" || battle.message?.prompt)
|
||||
world.interact();
|
||||
else world.tick();
|
||||
continue;
|
||||
}
|
||||
const dialogue = world.dialogue;
|
||||
if (dialogue) {
|
||||
const page = dialogue.pages[dialogue.index];
|
||||
const last = dialogue.index === dialogue.pages.length - 1;
|
||||
if (log.at(-1) !== page) log.push(page);
|
||||
if (last && dialogue.choice) {
|
||||
const answer = answers.shift();
|
||||
if (dialogue.choice.kind === "name")
|
||||
world.choose(typeof answer === "string" ? answer : "");
|
||||
else
|
||||
world.choose(
|
||||
typeof answer === "number"
|
||||
? answer
|
||||
: dialogue.choice.kind === "yesno"
|
||||
? 1
|
||||
: dialogue.choice.kind === "clock"
|
||||
? dialogue.choice.selected
|
||||
: 0,
|
||||
);
|
||||
} else if (last && dialogue.holdTicks !== undefined) world.tick();
|
||||
else world.advanceDialogue();
|
||||
continue;
|
||||
}
|
||||
if (!world.busy) {
|
||||
world.tick(); // scene scripts and phone calls start on idle ticks
|
||||
if (!world.busy) return;
|
||||
continue;
|
||||
}
|
||||
world.tick();
|
||||
}
|
||||
throw new Error(`The world did not settle: ${world.diagnostic}`);
|
||||
};
|
||||
|
||||
const STEP: Record<Direction, [number, number]> = {
|
||||
up: [0, -1],
|
||||
down: [0, 1],
|
||||
left: [-1, 0],
|
||||
right: [1, 0],
|
||||
};
|
||||
/** Walk to a tile on the current map, replanning after ledges, roaming
|
||||
* NPCs and scenes that move the player. A warp target leaves the map. */
|
||||
const walk = (x: number, y: number) => {
|
||||
const map = world.mapId,
|
||||
warp = world.map.warps.some((warp) => warp.x === x && warp.y === y);
|
||||
for (let attempt = 0; attempt < 40; attempt++) {
|
||||
play();
|
||||
if (warp && world.mapId !== map) return;
|
||||
expect(world.mapId, `walking to ${x},${y}`).toBe(map);
|
||||
if (world.x === x && world.y === y) return;
|
||||
for (const direction of findPath(world, x, y)) {
|
||||
const [dx, dy] = STEP[direction];
|
||||
const from = [world.x, world.y];
|
||||
if (!world.move(direction)) {
|
||||
for (let tick = 0; tick < 64; tick++) world.tick();
|
||||
break;
|
||||
}
|
||||
play();
|
||||
if (
|
||||
world.mapId !== map ||
|
||||
world.x !== from[0] + dx ||
|
||||
world.y !== from[1] + dy
|
||||
)
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new Error(
|
||||
`Could not reach ${x},${y} on ${map} from ${world.x},${world.y}`,
|
||||
);
|
||||
};
|
||||
/** Step across a map connection from the nearest usable edge tile. */
|
||||
const cross = (direction: Direction, target: string) => {
|
||||
const map = world.mapId;
|
||||
const [dx, dy] = STEP[direction];
|
||||
const edge = Array.from(
|
||||
{ length: dx ? world.map.height : world.map.width },
|
||||
(_, i) =>
|
||||
dx
|
||||
? [dx < 0 ? 0 : world.map.width - 1, i]
|
||||
: [i, dy < 0 ? 0 : world.map.height - 1],
|
||||
).flatMap(([x, y]) => {
|
||||
try {
|
||||
return [{ x, y, length: findPath(world, x, y).length }];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
edge.sort((a, b) => a.length - b.length);
|
||||
for (const { x, y } of edge) {
|
||||
walk(x, y);
|
||||
if (world.move(direction)) {
|
||||
play();
|
||||
if (world.mapId === target) return;
|
||||
}
|
||||
if (world.mapId !== map) break;
|
||||
}
|
||||
throw new Error(
|
||||
`Could not cross ${direction} from ${map} to ${target}: now ${world.mapId}`,
|
||||
);
|
||||
};
|
||||
/** Stand in front of a warp leading to `target` and take it. */
|
||||
const enter = (target: string, direction: Direction) => {
|
||||
const warp = world.map.warps.find((warp) => warp.targetMap === target)!;
|
||||
expect(warp, `a warp to ${target}`).toBeDefined();
|
||||
const [dx, dy] = STEP[direction];
|
||||
walk(warp.x - dx, warp.y - dy);
|
||||
expect(world.move(direction)).toBe(true);
|
||||
play();
|
||||
expect(world.mapId).toBe(target);
|
||||
};
|
||||
/** Leave through an exit mat, which needs the exit direction pressed. */
|
||||
const exit = (target: string, direction: Direction = "down") => {
|
||||
const warp = world.map.warps.find((warp) => warp.targetMap === target)!;
|
||||
walk(warp.x, warp.y);
|
||||
if (world.mapId !== target) {
|
||||
expect(world.move(direction)).toBe(true);
|
||||
play();
|
||||
}
|
||||
expect(world.mapId).toBe(target);
|
||||
};
|
||||
const reload = () => {
|
||||
const saved = JSON.parse(JSON.stringify(world.save()));
|
||||
world = new GameWorld(assets!, now, random);
|
||||
world.restore(saved);
|
||||
expect(world.save()).toEqual(saved);
|
||||
};
|
||||
|
||||
const lead = () => world.state.party[0];
|
||||
/** With MAKE_TEST_SAVES, a backup for the board's manual checks, as
|
||||
* tests/human-test-saves.test.ts writes them (kept out of git). */
|
||||
const writeTestSave = (name: string) => {
|
||||
if (!process.env.MAKE_TEST_SAVES) return;
|
||||
mkdirSync("test-saves", { recursive: true });
|
||||
writeFileSync(
|
||||
`test-saves/${name}.crystal-save.json`,
|
||||
encodeSave({
|
||||
version: 1,
|
||||
romHash: CRYSTAL_ROM.sha1,
|
||||
coreId: "crystal-native-world-v1",
|
||||
savedAt: new Date().toISOString(),
|
||||
state: new TextEncoder().encode(JSON.stringify(world.save())),
|
||||
}),
|
||||
);
|
||||
};
|
||||
/** PokecenterNurseScript from in front of the counter, then back out. */
|
||||
const heal = (center: string, city: string) => {
|
||||
enter(center, "up");
|
||||
walk(3, 3);
|
||||
world.move("up"); // the counter: this only turns the player
|
||||
world.interact();
|
||||
play();
|
||||
expect(world.state.party.every((mon) => mon.egg || mon.hp === mon.stats[0])).toBe(true);
|
||||
exit(city);
|
||||
};
|
||||
/** Pace between two neighbouring grass tiles (the nearest pair) until
|
||||
* the lead reaches `level`. `rest` heals and comes back here. */
|
||||
const train = (level: number, rest: () => void) => {
|
||||
const map = world.mapId,
|
||||
grass = world.assets.grassCollisions();
|
||||
const isGrass = (x: number, y: number) =>
|
||||
x >= 0 && y >= 0 && x < world.map.width && y < world.map.height &&
|
||||
grass.includes(world.assets.collision(world.map, x, y));
|
||||
for (let round = 0; round < 2000 && lead().level < level; round++) {
|
||||
if (lead().hp * 2 < lead().stats[0]) {
|
||||
rest();
|
||||
expect(world.mapId).toBe(map);
|
||||
}
|
||||
const pairs: { x: number; y: number; length: number }[] = [];
|
||||
for (let y = 0; y < world.map.height; y++)
|
||||
for (let x = 0; x < world.map.width; x++)
|
||||
if (isGrass(x, y) && isGrass(x + 1, y))
|
||||
try {
|
||||
pairs.push({ x, y, length: findPath(world, x, y).length });
|
||||
} catch {
|
||||
/* unreachable */
|
||||
}
|
||||
pairs.sort((a, b) => a.length - b.length);
|
||||
const { x, y } = pairs[0];
|
||||
walk(x, y);
|
||||
walk(x + 1, y);
|
||||
}
|
||||
expect(lead().level).toBeGreaterThanOrEqual(level);
|
||||
};
|
||||
|
||||
/** Take the stairs (or another warp) to `target`, trying each. */
|
||||
const stairs = (target: string) => {
|
||||
for (const warp of world.map.warps.filter((warp) => warp.targetMap === target)) {
|
||||
try {
|
||||
findPath(world, warp.x, warp.y);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
walk(warp.x, warp.y);
|
||||
if (world.mapId === target) return;
|
||||
}
|
||||
throw new Error(`No way from ${world.mapId} to ${target}`);
|
||||
};
|
||||
/** Find a way through warps among `maps` to `target`, as a player
|
||||
* trying staircases would: depth first, backing out of dead ends. */
|
||||
const route = (
|
||||
target: string,
|
||||
maps: string[],
|
||||
depth = 6,
|
||||
goal?: { x: number; y: number },
|
||||
): boolean => {
|
||||
const reachable = () => {
|
||||
if (!goal) return true;
|
||||
try {
|
||||
findPath(world, goal.x, goal.y);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (world.mapId === target && reachable()) return true;
|
||||
if (!depth) return false;
|
||||
const here = world.save();
|
||||
for (const warp of world.map.warps) {
|
||||
if (!maps.includes(warp.targetMap) && warp.targetMap !== target) continue;
|
||||
try {
|
||||
findPath(world, warp.x, warp.y);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const from = world.mapId;
|
||||
walk(warp.x, warp.y);
|
||||
if (world.mapId !== from && route(target, maps, depth - 1, goal)) return true;
|
||||
world.restore(here);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
/** Advance to the next menu choice, keeping its pages in the log. */
|
||||
const toChoice = () => {
|
||||
for (let tick = 0; tick < 2000; tick++) {
|
||||
const dialogue = world.dialogue;
|
||||
if (dialogue) {
|
||||
const page = dialogue.pages[dialogue.index];
|
||||
if (log.at(-1) !== page) log.push(page);
|
||||
if (dialogue.index === dialogue.pages.length - 1 && dialogue.choice) return dialogue.choice;
|
||||
if (dialogue.holdTicks !== undefined) world.tick();
|
||||
else world.advanceDialogue();
|
||||
} else world.tick();
|
||||
}
|
||||
throw new Error(`No choice appeared: ${world.diagnostic}`);
|
||||
};
|
||||
/** Choose a menu item by its label (or a pattern). */
|
||||
const choose = (label: string | RegExp) => {
|
||||
const choice = toChoice();
|
||||
if (choice.kind !== "menu") throw new Error(`Expected a menu, got ${choice.kind}`);
|
||||
const index = choice.items.findIndex((item) => (typeof label === "string" ? item === label : label.test(item)));
|
||||
expect(index, `${label} in ${choice.items.join(", ")}`).toBeGreaterThanOrEqual(0);
|
||||
world.choose(index);
|
||||
};
|
||||
/** Choose an item in the pack. */
|
||||
const choosePack = (item: number) => {
|
||||
const choice = toChoice();
|
||||
if (choice.kind !== "pack") throw new Error(`Expected the pack, got ${choice.kind}`);
|
||||
for (const [pocket, { entries }] of choice.pockets.entries()) {
|
||||
const index = entries.findIndex((entry) => entry.item === item);
|
||||
if (index >= 0) return world.choosePackEntry(pocket, index);
|
||||
}
|
||||
throw new Error(`Item ${item} is not in the pack.`);
|
||||
};
|
||||
const assets = existsSync(romPath)
|
||||
? new CrystalAssets(new Uint8Array(readFileSync(romPath)))
|
||||
: undefined;
|
||||
const p = new Playthrough(assets!);
|
||||
const {
|
||||
play,
|
||||
walk,
|
||||
cross,
|
||||
enter,
|
||||
exit,
|
||||
reload,
|
||||
lead,
|
||||
writeTestSave,
|
||||
heal,
|
||||
train,
|
||||
stairs,
|
||||
route,
|
||||
toChoice,
|
||||
choose,
|
||||
choosePack,
|
||||
talkTo,
|
||||
} = p;
|
||||
/** From Route 31: through the gate to Violet's Pokémon Center and back. */
|
||||
const restInViolet = () => {
|
||||
exit(ROUTE_31_GATE, "left");
|
||||
@@ -389,56 +98,46 @@ describe.skipIf(!existsSync(romPath))(
|
||||
exit(ROUTE_31, "right");
|
||||
};
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
log.length = 0;
|
||||
p.log.length = 0;
|
||||
});
|
||||
const traceFailures = () =>
|
||||
onTestFailed(() => {
|
||||
console.log(
|
||||
`${world.mapId} ${world.x},${world.y}; party ${JSON.stringify(
|
||||
world.state.party.map(({ species, level, hp }) => ({
|
||||
species,
|
||||
level,
|
||||
hp,
|
||||
})),
|
||||
)}\n${log.slice(-30).join("\n---\n")}`,
|
||||
);
|
||||
});
|
||||
const traceFailures = () => onTestFailed(() => console.log(p.trace()));
|
||||
|
||||
it("plays the introduction and Mom's scene", () => {
|
||||
world = new GameWorld(assets!, now, random);
|
||||
p.start();
|
||||
traceFailures();
|
||||
world.beginIntro();
|
||||
p.world.beginIntro();
|
||||
play([0, "", 1, "", 1, 0, "KAWA"]);
|
||||
expect(world.intro).toBe(false);
|
||||
expect(world.name).toBe("KAWA");
|
||||
expect(p.world.intro).toBe(false);
|
||||
expect(p.world.name).toBe("KAWA");
|
||||
reload();
|
||||
walk(7, 0);
|
||||
expect(world.mapId).toBe("24:6");
|
||||
expect(p.world.mapId).toBe("24:6");
|
||||
walk(9, 3);
|
||||
expect(world.move("down")).toBe(true);
|
||||
expect(p.world.move("down")).toBe(true);
|
||||
play([1, 1, 1, 1, 1]);
|
||||
expect(log).toContain("KAWA received\nPOKéGEAR.");
|
||||
expect(p.log).toContain("KAWA received\nPOKéGEAR.");
|
||||
reload();
|
||||
});
|
||||
|
||||
it("meets Elm, takes Cyndaquil and the aide's Potion", () => {
|
||||
traceFailures();
|
||||
walk(6, 7);
|
||||
expect(world.move("down")).toBe(true);
|
||||
expect(p.world.move("down")).toBe(true);
|
||||
play();
|
||||
expect(world.mapId).toBe(NEW_BARK);
|
||||
expect(p.world.mapId).toBe(NEW_BARK);
|
||||
enter(ELMS_LAB, "up");
|
||||
play([0, 1]);
|
||||
walk(6, 4);
|
||||
world.move("up");
|
||||
world.interact();
|
||||
p.world.move("up");
|
||||
p.world.interact();
|
||||
play([1, 1, ""]);
|
||||
expect(world.state.party.map((mon) => mon.species)).toEqual([155]);
|
||||
expect(p.world.state.party.map((mon) => mon.species)).toEqual([155]);
|
||||
walk(4, 7);
|
||||
expect(world.move("down")).toBe(true);
|
||||
expect(p.world.move("down")).toBe(true);
|
||||
play();
|
||||
expect(world.state.bag.items).toEqual([{ item: 18, quantity: 1 }]);
|
||||
expect(p.world.state.bag.items).toEqual([{ item: 18, quantity: 1 }]);
|
||||
reload();
|
||||
});
|
||||
|
||||
@@ -451,24 +150,24 @@ describe.skipIf(!existsSync(romPath))(
|
||||
cross("up", ROUTE_30);
|
||||
enter(MR_POKEMONS_HOUSE, "up");
|
||||
play();
|
||||
expect(world.state.bag.keyItems).toEqual([0x45]); // MYSTERY_EGG
|
||||
expect(world.state.flags.has(11)).toBe(true); // the Pokédex
|
||||
expect(p.world.state.bag.keyItems).toEqual([0x45]); // MYSTERY_EGG
|
||||
expect(p.world.state.flags.has(11)).toBe(true); // the Pokédex
|
||||
reload();
|
||||
});
|
||||
|
||||
it("takes Elm's call outside and meets the rival in Cherrygrove", () => {
|
||||
traceFailures();
|
||||
exit(ROUTE_30);
|
||||
expect(log.join("\n")).toContain("It's a disaster!");
|
||||
expect(world.state.events.has(67)).toBe(true); // ELM_CALLED_ABOUT_STOLEN_POKEMON
|
||||
expect(p.log.join("\n")).toContain("It's a disaster!");
|
||||
expect(p.world.state.events.has(67)).toBe(true); // ELM_CALLED_ABOUT_STOLEN_POKEMON
|
||||
reload();
|
||||
cross("down", CHERRYGROVE);
|
||||
// The rival's scene blocks the way east to Route 29.
|
||||
cross("right", ROUTE_29);
|
||||
const rival = log.join("\n");
|
||||
const rival = p.log.join("\n");
|
||||
expect(rival).toContain("RIVAL ?");
|
||||
expect(rival).toContain("My name's ???.");
|
||||
expect(world.state.scenes[CHERRYGROVE]).toBe(0);
|
||||
expect(p.world.state.scenes[CHERRYGROVE]).toBe(0);
|
||||
reload();
|
||||
});
|
||||
|
||||
@@ -477,17 +176,17 @@ describe.skipIf(!existsSync(romPath))(
|
||||
cross("right", NEW_BARK);
|
||||
enter(ELMS_LAB, "up");
|
||||
walk(4, 6);
|
||||
expect(world.move("up")).toBe(true);
|
||||
expect(p.world.move("up")).toBe(true);
|
||||
play(["SILVER"]);
|
||||
expect(world.state.rivalName).toBe("SILVER");
|
||||
expect(p.world.state.rivalName).toBe("SILVER");
|
||||
reload();
|
||||
walk(5, 3);
|
||||
world.move("up"); // Elm stands at 5,2: this only turns the player.
|
||||
world.interact();
|
||||
p.world.move("up"); // Elm stands at 5,2: this only turns the player.
|
||||
p.world.interact();
|
||||
play();
|
||||
expect(world.state.bag.keyItems).toEqual([]);
|
||||
expect(p.world.state.bag.keyItems).toEqual([]);
|
||||
walk(4, 8);
|
||||
expect(world.state.bag.balls).toEqual([
|
||||
expect(p.world.state.bag.balls).toEqual([
|
||||
{ item: C.POKE_BALL, quantity: 5 },
|
||||
]);
|
||||
reload();
|
||||
@@ -498,13 +197,13 @@ describe.skipIf(!existsSync(romPath))(
|
||||
exit(NEW_BARK);
|
||||
cross("left", ROUTE_29);
|
||||
cross("left", CHERRYGROVE);
|
||||
const pages = log.join("\n").replace(/\n/g, " ");
|
||||
const pages = p.log.join("\n").replace(/\n/g, " ");
|
||||
expect(pages).toContain("show you how to catch POKéMON?");
|
||||
expect(pages).toContain("That's how you do it");
|
||||
expect(world.state.events.has(66)).toBe(true); // LEARNED_TO_CATCH_POKEMON
|
||||
expect(world.state.scenes[ROUTE_29]).toBe(0);
|
||||
expect(p.world.state.events.has(66)).toBe(true); // LEARNED_TO_CATCH_POKEMON
|
||||
expect(p.world.state.scenes[ROUTE_29]).toBe(0);
|
||||
reload();
|
||||
const save = world.save();
|
||||
const save = p.world.save();
|
||||
expect(save.party[0].species).toBe(155);
|
||||
expect(save.pokedex.caught).toContain(155);
|
||||
expect(save.rivalName).toBe("SILVER");
|
||||
@@ -528,9 +227,9 @@ describe.skipIf(!existsSync(romPath))(
|
||||
exit(ROUTE_31_GATE, "left");
|
||||
// Mom worries when the player has not come home since the Egg; the
|
||||
// call rings on a step after Route 31's callback queued it.
|
||||
expect(world.state.events.has(EVENT_TALKED_TO_MOM_AFTER_MYSTERY_EGG_QUEST), log.join("|")).toBe(true);
|
||||
expect(p.world.state.events.has(EVENT_TALKED_TO_MOM_AFTER_MYSTERY_EGG_QUEST), p.log.join("|")).toBe(true);
|
||||
exit(VIOLET, "left");
|
||||
expect(world.state.flags.size).toBeGreaterThan(0);
|
||||
expect(p.world.state.flags.size).toBeGreaterThan(0);
|
||||
reload();
|
||||
writeTestSave("violet-city");
|
||||
}, 120_000);
|
||||
@@ -546,12 +245,12 @@ describe.skipIf(!existsSync(romPath))(
|
||||
enter(SPROUT_1F, "up");
|
||||
expect(route(SPROUT_3F, [SPROUT_1F, SPROUT_2F])).toBe(true);
|
||||
walk(10, 3);
|
||||
world.move("up"); // Elder Li: this only turns the player
|
||||
world.interact();
|
||||
p.world.move("up"); // Elder Li: this only turns the player
|
||||
p.world.interact();
|
||||
play();
|
||||
const pages = log.join("\n").replace(/\n/g, " ");
|
||||
const pages = p.log.join("\n").replace(/\n/g, " ");
|
||||
expect(pages).toContain("FLASH");
|
||||
expect(world.state.events.has(EVENT_GOT_HM05_FLASH)).toBe(true);
|
||||
expect(p.world.state.events.has(EVENT_GOT_HM05_FLASH)).toBe(true);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
@@ -562,42 +261,42 @@ describe.skipIf(!existsSync(romPath))(
|
||||
heal(VIOLET_CENTER, VIOLET);
|
||||
enter(VIOLET_GYM, "up");
|
||||
walk(5, 2);
|
||||
world.move("up"); // Falkner: this only turns the player
|
||||
world.interact();
|
||||
p.world.move("up"); // Falkner: this only turns the player
|
||||
p.world.interact();
|
||||
play();
|
||||
expect(world.state.events.has(EVENT_BEAT_FALKNER), log.join("|")).toBe(true);
|
||||
expect(world.state.flags.has(ENGINE_ZEPHYRBADGE)).toBe(true);
|
||||
expect(world.state.events.has(EVENT_GOT_TM31_MUD_SLAP)).toBe(true);
|
||||
expect(world.state.bag.tmsHms[30]).toBe(1); // TM31
|
||||
expect(p.world.state.events.has(EVENT_BEAT_FALKNER), p.log.join("|")).toBe(true);
|
||||
expect(p.world.state.flags.has(ENGINE_ZEPHYRBADGE)).toBe(true);
|
||||
expect(p.world.state.events.has(EVENT_GOT_TM31_MUD_SLAP)).toBe(true);
|
||||
expect(p.world.state.bag.tmsHms[30]).toBe(1); // TM31
|
||||
reload();
|
||||
exit(VIOLET);
|
||||
// SPECIALCALL_ASSISTANT rings on a step: the aide waits in the
|
||||
// Pokémon Center with the Egg.
|
||||
enter(VIOLET_CENTER, "up");
|
||||
expect(log.join("\n").replace(/\n/g, " ")).toContain("POKéMON CENTER");
|
||||
expect(p.log.join("\n").replace(/\n/g, " ")).toContain("POKéMON CENTER");
|
||||
// The aide's object flag (EVENT_ELMS_AIDE_IN_VIOLET_POKEMON_CENTER).
|
||||
const aide = world.assets.map(VIOLET_CENTER).objects[4];
|
||||
expect(world.state.events.has(aide.eventFlag)).toBe(false);
|
||||
const aide = p.world.assets.map(VIOLET_CENTER).objects[4];
|
||||
expect(p.world.state.events.has(aide.eventFlag)).toBe(false);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
it("takes the Egg from Elm's aide", () => {
|
||||
traceFailures();
|
||||
walk(4, 4);
|
||||
world.move("up"); // the aide: this only turns the player
|
||||
world.interact();
|
||||
p.world.move("up"); // the aide: this only turns the player
|
||||
p.world.interact();
|
||||
play([1]);
|
||||
expect(world.state.events.has(EVENT_GOT_TOGEPI_EGG_FROM_ELMS_AIDE)).toBe(true);
|
||||
const egg = world.state.party.at(-1)!;
|
||||
expect(p.world.state.events.has(EVENT_GOT_TOGEPI_EGG_FROM_ELMS_AIDE)).toBe(true);
|
||||
const egg = p.world.state.party.at(-1)!;
|
||||
expect(egg).toMatchObject({
|
||||
species: TOGEPI,
|
||||
egg: true,
|
||||
nickname: "EGG",
|
||||
hp: 0,
|
||||
happiness: world.assets.pokemon.baseData(TOGEPI).eggCycles,
|
||||
happiness: p.world.assets.pokemon.baseData(TOGEPI).eggCycles,
|
||||
});
|
||||
// An Egg is neither seen nor caught.
|
||||
expect(world.state.pokedex.caught.has(TOGEPI)).toBe(false);
|
||||
expect(p.world.state.pokedex.caught.has(TOGEPI)).toBe(false);
|
||||
reload();
|
||||
});
|
||||
|
||||
@@ -606,30 +305,30 @@ describe.skipIf(!existsSync(romPath))(
|
||||
exit(VIOLET);
|
||||
exit(ROUTE_31_GATE, "right");
|
||||
exit(ROUTE_31, "right");
|
||||
wanted = BELLSPROUT;
|
||||
p.wanted = BELLSPROUT;
|
||||
try {
|
||||
for (let round = 0; round < 400 && !world.state.party.some((mon) => mon.species === BELLSPROUT); round++) {
|
||||
if (!world.state.bag.balls.length) break;
|
||||
for (let round = 0; round < 400 && !p.world.state.party.some((mon) => mon.species === BELLSPROUT); round++) {
|
||||
if (!p.world.state.bag.balls.length) break;
|
||||
train(lead().level + 1, restInViolet);
|
||||
}
|
||||
} finally {
|
||||
wanted = 0;
|
||||
p.wanted = 0;
|
||||
}
|
||||
const bellsprout = world.state.party.findIndex((mon) => mon.species === BELLSPROUT);
|
||||
expect(bellsprout, log.slice(-20).join("|")).toBeGreaterThan(0);
|
||||
const bellsprout = p.world.state.party.findIndex((mon) => mon.species === BELLSPROUT);
|
||||
expect(bellsprout, p.log.slice(-20).join("|")).toBeGreaterThan(0);
|
||||
exit(ROUTE_31_GATE, "left");
|
||||
exit(VIOLET, "left");
|
||||
enter(KYLES_HOUSE, "up");
|
||||
const kyle = world.objects().find((object) => object.sprite === world.assets.map(KYLES_HOUSE).objects[1].sprite && object.id === world.assets.map(KYLES_HOUSE).objects[1].id)!;
|
||||
const kyle = p.world.objects().find((object) => object.sprite === p.world.assets.map(KYLES_HOUSE).objects[1].sprite && object.id === p.world.assets.map(KYLES_HOUSE).objects[1].id)!;
|
||||
walk(kyle.x - 1, kyle.y);
|
||||
world.move("right");
|
||||
world.interact();
|
||||
p.world.move("right");
|
||||
p.world.interact();
|
||||
play([1, bellsprout]);
|
||||
const onix = world.state.party.at(-1)!;
|
||||
const onix = p.world.state.party.at(-1)!;
|
||||
expect(onix).toMatchObject({ species: ONIX, nickname: "ROCKY", ot: "KYLE", otId: 48926, dvs: 0x9666 });
|
||||
expect(world.state.party.some((mon) => mon.species === BELLSPROUT && !mon.egg)).toBe(false);
|
||||
expect(world.state.tradeFlags).toBe(1 << 1);
|
||||
expect(world.state.pokedex.caught.has(ONIX)).toBe(true);
|
||||
expect(p.world.state.party.some((mon) => mon.species === BELLSPROUT && !mon.egg)).toBe(false);
|
||||
expect(p.world.state.tradeFlags).toBe(1 << 1);
|
||||
expect(p.world.state.pokedex.caught.has(ONIX)).toBe(true);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
@@ -638,100 +337,165 @@ describe.skipIf(!existsSync(romPath))(
|
||||
exit(VIOLET);
|
||||
exit(ROUTE_31_GATE, "right");
|
||||
exit(ROUTE_31, "right");
|
||||
wanted = BELLSPROUT;
|
||||
p.wanted = BELLSPROUT;
|
||||
try {
|
||||
for (let round = 0; round < 400 && !world.state.party.some((mon) => mon.species === BELLSPROUT); round++)
|
||||
for (let round = 0; round < 400 && !p.world.state.party.some((mon) => mon.species === BELLSPROUT); round++)
|
||||
train(lead().level + 1, restInViolet);
|
||||
} finally {
|
||||
wanted = 0;
|
||||
p.wanted = 0;
|
||||
}
|
||||
const slot = world.state.party.findIndex((mon) => mon.species === BELLSPROUT);
|
||||
const slot = p.world.state.party.findIndex((mon) => mon.species === BELLSPROUT);
|
||||
expect(slot).toBeGreaterThan(0);
|
||||
const nickname = world.state.party[slot].nickname;
|
||||
const nickname = p.world.state.party[slot].nickname;
|
||||
// PACK, the TM/HM pocket's HM05, USE, YES, then the Bellsprout.
|
||||
expect(world.openStartMenu()).toBe(true);
|
||||
expect(p.world.openStartMenu()).toBe(true);
|
||||
choose("PACK");
|
||||
choosePack(HM05);
|
||||
choose("USE");
|
||||
expect(toChoice().kind).toBe("yesno");
|
||||
world.choose(1);
|
||||
p.world.choose(1);
|
||||
const party = toChoice();
|
||||
expect(party.kind === "menu" && party.details?.[slot]).toBe("ABLE");
|
||||
world.choose(slot);
|
||||
if (world.state.party[slot].moves.every(Boolean)) {
|
||||
p.world.choose(slot);
|
||||
if (p.world.state.party[slot].moves.every(Boolean)) {
|
||||
// A full move list asks which move to forget: the first one.
|
||||
expect(toChoice().kind).toBe("yesno");
|
||||
world.choose(1);
|
||||
p.world.choose(1);
|
||||
toChoice();
|
||||
world.choose(0);
|
||||
p.world.choose(0);
|
||||
}
|
||||
for (let i = 0; i < 10 && world.dialogue?.choice?.kind !== "pack"; i++) toChoice();
|
||||
expect(log.join("\n").replace(/\n/g, " ")).toContain("learned FLASH!");
|
||||
for (let i = 0; i < 10 && p.world.dialogue?.choice?.kind !== "pack"; i++) toChoice();
|
||||
expect(p.log.join("\n").replace(/\n/g, " ")).toContain("learned FLASH!");
|
||||
// The menus work on a draft that is kept once they close.
|
||||
for (let i = 0; i < 10 && world.busy; i++) {
|
||||
if (world.dialogue?.choice) world.advanceDialogue();
|
||||
else world.tick();
|
||||
for (let i = 0; i < 10 && p.world.busy; i++) {
|
||||
if (p.world.dialogue?.choice) p.world.advanceDialogue();
|
||||
else p.world.tick();
|
||||
}
|
||||
play();
|
||||
expect(world.state.party[slot].moves).toContain(FLASH);
|
||||
expect(world.state.bag.tmsHms[50 + 4]).toBe(1); // an HM is kept
|
||||
expect(p.world.state.party[slot].moves).toContain(FLASH);
|
||||
expect(p.world.state.bag.tmsHms[50 + 4]).toBe(1); // an HM is kept
|
||||
// Dark Cave is dark until FLASH, which the ZEPHYRBADGE allows.
|
||||
enter(DARK_CAVE, "up");
|
||||
expect(world.state.flash).toBe(false);
|
||||
expect(world.openStartMenu()).toBe(true);
|
||||
expect(p.world.state.flash).toBe(false);
|
||||
expect(p.world.openStartMenu()).toBe(true);
|
||||
choose("POKéMON");
|
||||
choose(nickname);
|
||||
choose("FLASH");
|
||||
play();
|
||||
expect(world.state.flash, log.slice(-6).join("|")).toBe(true);
|
||||
expect(p.world.state.flash, p.log.slice(-6).join("|")).toBe(true);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
it("registers Bug Catcher Wade's number and reads Earl's blackboard", () => {
|
||||
traceFailures();
|
||||
exit(ROUTE_31);
|
||||
// Talk to Wade wherever he stands (he walks up to battle on sight).
|
||||
// A trainer who spots the player on the way battles and moves, so
|
||||
// the approach is planned again.
|
||||
const talkTo = (id: number) => {
|
||||
for (let attempt = 0; attempt < 4; attempt++)
|
||||
for (const [dx, dy, face] of [[-1, 0, "right"], [1, 0, "left"], [0, 1, "up"], [0, -1, "down"]] as const) {
|
||||
const target = world.objects().find((object) => object.id === id)!;
|
||||
const x = target.x + dx,
|
||||
y = target.y + dy;
|
||||
try {
|
||||
if (!(world.x === x && world.y === y)) walk(x, y);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const now = world.objects().find((object) => object.id === id)!;
|
||||
if (now.x !== target.x || now.y !== target.y) break;
|
||||
world.move(face);
|
||||
world.interact();
|
||||
return;
|
||||
}
|
||||
throw new Error(`No way to talk to object ${id}`);
|
||||
};
|
||||
talkTo(world.map.objects[2].id);
|
||||
talkTo(p.world.map.objects[2].id);
|
||||
play([1]);
|
||||
const pages = log.join("\n").replace(/\n/g, " ");
|
||||
const pages = p.log.join("\n").replace(/\n/g, " ");
|
||||
expect(pages).toContain("BUG CATCHER WADE");
|
||||
expect(world.state.phone).toContain(PHONE_BUG_CATCHER_WADE);
|
||||
expect(p.world.state.phone).toContain(PHONE_BUG_CATCHER_WADE);
|
||||
reload();
|
||||
restInViolet();
|
||||
exit(ROUTE_31_GATE, "left");
|
||||
exit(VIOLET, "left");
|
||||
enter(EARLS_ACADEMY, "up");
|
||||
walk(3, 1);
|
||||
world.move("up");
|
||||
world.interact();
|
||||
p.world.move("up");
|
||||
p.world.interact();
|
||||
choose("PSN");
|
||||
toChoice();
|
||||
expect(log.join("\n").replace(/\n/g, " ")).toContain("steadily loses HP");
|
||||
expect(p.log.join("\n").replace(/\n/g, " ")).toContain("steadily loses HP");
|
||||
// B leaves the blackboard.
|
||||
world.choose(-1);
|
||||
p.world.choose(-1);
|
||||
play();
|
||||
expect(world.busy).toBe(false);
|
||||
expect(p.world.busy).toBe(false);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
it("takes Route 32 and Union Cave to Azalea Town", () => {
|
||||
traceFailures();
|
||||
exit(VIOLET);
|
||||
cross("down", ROUTE_32);
|
||||
// The man at Route 32's north end gives the Miracle Seed after the
|
||||
// ZEPHYRBADGE and the Egg.
|
||||
expect(p.world.state.bag.items.some((slot) => slot.item === MIRACLE_SEED)).toBe(false);
|
||||
p.talkTo(p.world.map.objects[7].id);
|
||||
play();
|
||||
expect(p.world.state.bag.items.some((slot) => slot.item === MIRACLE_SEED)).toBe(true);
|
||||
stairs(UNION_CAVE_1F);
|
||||
stairs(ROUTE_33);
|
||||
cross("left", AZALEA);
|
||||
reload();
|
||||
}, 240_000);
|
||||
|
||||
it("follows Kurt into the Slowpoke Well and drives out Team Rocket", () => {
|
||||
traceFailures();
|
||||
enter(KURTS_HOUSE, "up");
|
||||
talkTo(p.world.map.objects[0].id);
|
||||
play();
|
||||
expect(p.log.join(" ")).toContain("Old KURT is on his\nway!");
|
||||
exit(AZALEA);
|
||||
stairs(SLOWPOKE_WELL_B1F);
|
||||
// The three grunts, then the one by the boulder, whose defeat ends
|
||||
// the scene in Kurt's house.
|
||||
for (const index of [0, 2, 3, 1]) {
|
||||
const id = p.world.map.objects[index].id;
|
||||
if (!p.world.objects().some((object) => object.id === id)) continue;
|
||||
talkTo(id);
|
||||
play();
|
||||
}
|
||||
expect(p.world.mapId).toBe(KURTS_HOUSE);
|
||||
expect(p.world.state.events.has(EVENT_CLEARED_SLOWPOKE_WELL)).toBe(true);
|
||||
talkTo(p.world.map.objects[0].id);
|
||||
play();
|
||||
expect(p.world.state.bag.balls.some((slot) => slot.item === LURE_BALL)).toBe(true);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
it("beats Bugsy for the HIVEBADGE and the rival on the way to Ilex Forest", () => {
|
||||
traceFailures();
|
||||
exit(AZALEA);
|
||||
heal(AZALEA_CENTER, AZALEA);
|
||||
enter(AZALEA_GYM, "up");
|
||||
talkTo(p.world.map.objects[0].id);
|
||||
play();
|
||||
expect(p.world.state.events.has(EVENT_BEAT_BUGSY)).toBe(true);
|
||||
expect(p.world.state.flags.has(ENGINE_HIVEBADGE)).toBe(true);
|
||||
expect(p.world.state.bag.tmsHms[48]).toBe(1); // TM49 FURY CUTTER
|
||||
exit(AZALEA);
|
||||
heal(AZALEA_CENTER, AZALEA);
|
||||
// The rival waits at the town's west end (SCENE_AZALEATOWN_RIVAL_BATTLE).
|
||||
stairs(ILEX_GATE);
|
||||
expect(p.world.state.events.has(EVENT_RIVAL_AZALEA_TOWN)).toBe(true);
|
||||
reload();
|
||||
}, 120_000);
|
||||
|
||||
it("herds the Farfetch'd back in Ilex Forest and cuts through to Route 34", () => {
|
||||
traceFailures();
|
||||
stairs(ILEX_FOREST);
|
||||
const STEP = { up: [0, -1], down: [0, 1], left: [-1, 0], right: [1, 0] } as const;
|
||||
const bird = p.world.map.objects[0].id;
|
||||
// wFarfetchdPosition 1 → 2 from any side, 2 → 8 and 8 → 9 facing
|
||||
// down, then 9 → 10 facing left.
|
||||
for (const face of ["up", "down", "down", "left"] as const) {
|
||||
const at = p.world.objects().find((object) => object.id === bird)!;
|
||||
walk(at.x - STEP[face][0], at.y - STEP[face][1]);
|
||||
p.world.move(face);
|
||||
p.world.interact();
|
||||
play();
|
||||
}
|
||||
expect(p.world.state.memory.wFarfetchdPosition).toBe(10);
|
||||
expect(p.world.state.events.has(EVENT_HERDED_FARFETCHD)).toBe(true);
|
||||
talkTo(p.world.map.objects[2].id); // the charcoal master
|
||||
play();
|
||||
expect(p.world.state.bag.tmsHms[50]).toBe(1); // HM01
|
||||
reload();
|
||||
const bellsprout = p.world.state.party.findIndex((mon) => mon.species === BELLSPROUT);
|
||||
p.teach(HM01, bellsprout);
|
||||
expect(p.world.state.party[bellsprout].moves).toContain(CUT);
|
||||
p.cut(8, 25);
|
||||
expect(p.log).toContain("BELLSPROUT used\nCUT!");
|
||||
stairs(ROUTE_34_GATE);
|
||||
reload();
|
||||
}, 120_000);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user