Port capture and the Route 29 catching tutorial
Battle PACK opens the Balls pocket and runs PokeBallEffect: the Poké, Great, Ultra and Master Ball multipliers, the original HP arithmetic (including the overflow above 341 maximum HP), the sleep/freeze bonus (BRN/PSN/PAR add nothing), HELD_CATCH_CHANCE and the catch draw. GetPokeBallWobble draws per shake from WobbleProbabilities and picks the break-free text. Trainer battles block the ball but still use it and the turn. A catch reloads the Pokémon as LoadEnemyMon does (the wild item roll is redrawn, then the item restored), keeps its HP, status, item and DVs, restores the moves and PP it appeared with, adds it to the party with SetCaughtData, registers it and offers a nickname with InitName's default. A catch with six Pokémon needs the PC and is refused. catchtutorial runs BATTLETYPE_TUTORIAL as "DUDE": no send-out, an automatic catch that keeps nothing and prompts that continue on their own. Both Route 29 triggers, declining and the Dude's repeat offer run from the ROM. The text reader now handles TX_LOW. PLAN.md gains a status overview and done/remaining checklists; the README, help dialog, routine map and handoff describe the milestone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc10343520
commit
9ac111f262
20 files changed
+1101
-65
No files matched your search
@@ -111,6 +111,8 @@ test("keyboard and touch D-pad navigate battle moves, cancel and run", async ({
|
||||
await expect(menu.getByRole("button", { name: "FIGHT", exact: true })).toBeVisible();
|
||||
// A real pointer press on the on-screen D-pad (synthetic events cannot be captured).
|
||||
await page.locator('[data-game-button="down"]').click();
|
||||
await expect(menu.getByRole("button", { name: "PACK", exact: true })).toHaveClass(/battle-selected/);
|
||||
await page.keyboard.press("ArrowDown");
|
||||
await expect(menu.getByRole("button", { name: "RUN", exact: true })).toHaveClass(/battle-selected/);
|
||||
await page.keyboard.press("KeyX");
|
||||
expect(await finish(page, "run")).toContain("Got away safely");
|
||||
@@ -155,3 +157,52 @@ test("an unsupported battle effect closes the UI without persisting partial chan
|
||||
expect(state.pokedex.seen).not.toContain(16);
|
||||
expect(state.money).toBe(3001);
|
||||
});
|
||||
|
||||
test("battle PACK throws Poké Balls, names the catch and saves it", async ({ page }) => {
|
||||
await start(page, "catch");
|
||||
const menu = page.locator("#battle-menu");
|
||||
const messages: string[] = [];
|
||||
let named = false;
|
||||
for (let guard = 0; guard < 120 && !named; guard++) {
|
||||
messages.push(await page.locator("#battle-text").innerText());
|
||||
const pack = menu.getByRole("button", { name: "PACK", exact: true });
|
||||
const nickname = menu.getByRole("textbox");
|
||||
if (await nickname.count()) {
|
||||
await expect(page.locator("#battle-text")).toHaveText("PIDGEY'S\nNICKNAME?");
|
||||
await nickname.fill("PIDGE");
|
||||
await menu.getByRole("button", { name: "OK", exact: true }).click();
|
||||
named = true;
|
||||
} else if (await pack.count()) {
|
||||
await pack.click();
|
||||
const ball = menu.getByRole("button", { name: /POKé BALL/ });
|
||||
await expect(ball).toContainText("×");
|
||||
await ball.click();
|
||||
} else if (await menu.getByRole("button", { name: "YES", exact: true }).count()) {
|
||||
await menu.getByRole("button", { name: "YES", exact: true }).click();
|
||||
} else if (await menu.getByRole("button", { name: /Continue/ }).count()) {
|
||||
await menu.getByRole("button", { name: /Continue/ }).click();
|
||||
} else await page.clock.runFor(1200);
|
||||
}
|
||||
expect(named).toBe(true);
|
||||
expect(messages.join("\n")).toContain("Gotcha!");
|
||||
await finish(page);
|
||||
await expect(page.locator("#battle")).toBeHidden();
|
||||
const { state } = await exportState(page);
|
||||
expect(state.party).toHaveLength(2);
|
||||
expect(state.party[1]).toMatchObject({ species: 16, nickname: "PIDGE", level: 3 });
|
||||
expect(state.pokedex.caught).toContain(16);
|
||||
expect(state.bag.balls[0].quantity).toBeLessThan(10);
|
||||
});
|
||||
|
||||
test("battle PACK closes with B and returns to the command menu", async ({ page }) => {
|
||||
await start(page, "catch");
|
||||
const menu = page.locator("#battle-menu");
|
||||
for (let tick = 0; tick < 10 && !(await menu.getByRole("button", { name: "PACK", exact: true }).count()); tick++) {
|
||||
if (await menu.getByRole("button", { name: /Continue/ }).count()) await page.keyboard.press("KeyX");
|
||||
await page.clock.runFor(1200);
|
||||
}
|
||||
await menu.getByRole("button", { name: "PACK", exact: true }).click();
|
||||
await expect(menu.getByRole("button", { name: /POKé BALL/ })).toBeVisible();
|
||||
await page.keyboard.press("KeyZ");
|
||||
await expect(menu.getByRole("button", { name: "FIGHT", exact: true })).toBeVisible();
|
||||
});
|
||||
@@ -2,7 +2,7 @@ import { CrystalAssets } from "../src/game/rom/assets";
|
||||
import { generatePartyMon } from "../src/game/party/pokemon";
|
||||
import { GameWorld } from "../src/game/world/world";
|
||||
|
||||
export type BattleScenario = "win" | "loss" | "unsupported";
|
||||
export type BattleScenario = "win" | "loss" | "unsupported" | "catch";
|
||||
|
||||
/** Test-only encounters on an existing floor: production maps stay gated.
|
||||
* Everything after selection runs through the ROM's real wild-battle script. */
|
||||
@@ -28,6 +28,7 @@ export function battleFixtureWorld(assets: CrystalAssets, scenario: BattleScenar
|
||||
mon.pp = [10, 0, 0, 0];
|
||||
}
|
||||
world.state.party.push(mon);
|
||||
if (scenario === "catch") world.state.bag.balls = [{ item: 5, quantity: 10 }]; // POKé BALL
|
||||
world.state.pokedex.seen.add(155);
|
||||
world.state.pokedex.caught.add(155);
|
||||
world.state.money = 3001;
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { CrystalAssets } from "../src/game/rom/assets";
|
||||
import {
|
||||
Battle,
|
||||
UnsupportedBattle,
|
||||
catchRate,
|
||||
type BattleInput,
|
||||
type BattleOptions,
|
||||
type BattleOutcome,
|
||||
} from "../src/game/battle/battle";
|
||||
import { C } from "../src/game/battle/constants";
|
||||
import { generatePartyMon, validPartyMon, type PartyMon } from "../src/game/party/pokemon";
|
||||
import type { Bag } from "../src/game/party/bag";
|
||||
import { defaultTextContext } from "../src/game/scripts/text";
|
||||
|
||||
const romPath =
|
||||
process.env.CRYSTAL_ROM_PATH ?? "Pokemon - Crystal Version (UE) (V1.1) [C][!].gbc";
|
||||
|
||||
describe("catch rate formula", () => {
|
||||
const none = { effect: 0, parameter: 0 };
|
||||
const rate = (input: Partial<Parameters<typeof catchRate>[0]>) =>
|
||||
catchRate({ rate: 255, ball: C.POKE_BALL, hp: 20, maxHp: 20, status: 0, held: none, ...input });
|
||||
|
||||
it("follows PokeBallEffect's HP term and ball multipliers", () => {
|
||||
expect(rate({})).toBe(85); // 255 * (60 - 40) / 60
|
||||
expect(rate({ hp: 1 })).toBe(246); // 255 * 58 / 60
|
||||
expect(rate({ rate: 45, ball: C.GREAT_BALL, hp: 10 })).toBe(44); // 67 * 40 / 60
|
||||
expect(rate({ rate: 200, ball: C.ULTRA_BALL })).toBe(85); // doubled, capped at 255
|
||||
expect(rate({ rate: 1 })).toBe(1); // a zero quotient becomes 1
|
||||
// Above 255 (3 * max HP), both terms are divided by four; a zero HP
|
||||
// byte becomes 1.
|
||||
expect(rate({ hp: 1, maxHp: 100 })).toBe(251); // 255 * (75 - 1) / 75
|
||||
});
|
||||
|
||||
it("keeps the original status, held-item and high-HP bugs", () => {
|
||||
expect(rate({ status: 1 })).toBe(95); // sleep: +10
|
||||
expect(rate({ status: 1 << C.FRZ })).toBe(95);
|
||||
for (const status of [1 << 3, 1 << 4, 1 << 6]) expect(rate({ status })).toBe(85); // PSN/BRN/PAR
|
||||
expect(rate({ held: { effect: C.HELD_CATCH_CHANCE, parameter: 5 } })).toBe(90);
|
||||
// Max HP 400: the low bytes wrap, so a full-HP Pokémon gets 67, not 85.
|
||||
expect(rate({ hp: 400, maxHp: 400 })).toBe(67);
|
||||
// Max HP 342 divides by zero in the original.
|
||||
expect(rate({ hp: 342, maxHp: 342 })).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(!existsSync(romPath))("capture with the local ROM", () => {
|
||||
let data: CrystalAssets["pokemon"];
|
||||
beforeAll(() => {
|
||||
data = new CrystalAssets(new Uint8Array(readFileSync(romPath))).pokemon;
|
||||
});
|
||||
const RATTATA = 19,
|
||||
CYNDAQUIL = 155,
|
||||
TACKLE = 33;
|
||||
const starter = (): PartyMon => {
|
||||
const mon = generatePartyMon(data, {
|
||||
species: CYNDAQUIL, level: 5, item: 0, otId: 1234, ot: "CHRIS", dvs: 0x823b, caughtData: 0,
|
||||
});
|
||||
mon.moves = [TACKLE, 0, 0, 0];
|
||||
mon.pp = [35, 0, 0, 0];
|
||||
return mon;
|
||||
};
|
||||
const setup = (options: Partial<BattleOptions> & { seed?: number } = {}) => {
|
||||
let seed = options.seed ?? 1,
|
||||
draws = 0;
|
||||
const bag: Bag = options.bag ?? { items: [], balls: [{ item: C.POKE_BALL, quantity: 5 }], keyItems: [] };
|
||||
const pokedex = { seen: new Set<number>(), caught: new Set<number>() };
|
||||
const party = options.party ?? [starter()];
|
||||
const battle = new Battle({
|
||||
data,
|
||||
party,
|
||||
pokedex,
|
||||
playerId: 1234,
|
||||
playerName: "CHRIS",
|
||||
timeOfDay: 1,
|
||||
random: () => {
|
||||
draws++;
|
||||
seed = (seed * 1103515245 + 12345) >>> 0;
|
||||
return (seed >>> 16) & 255;
|
||||
},
|
||||
wild: { species: RATTATA, level: 3 },
|
||||
text: () => defaultTextContext("CHRIS"),
|
||||
bag,
|
||||
hasPokedex: true,
|
||||
caughtData: (level) => 0x4000 | (level << 8) | 1,
|
||||
...options,
|
||||
});
|
||||
return { battle, bag, pokedex, party, draws: () => draws };
|
||||
};
|
||||
/** Run a battle: `actions` answer the battle menu, `answers` the Yes/No
|
||||
* and naming prompts. Returns the texts and the outcome. */
|
||||
const play = (
|
||||
battle: Battle,
|
||||
actions: BattleInput[],
|
||||
answers: BattleInput[] = [],
|
||||
until?: () => boolean,
|
||||
) => {
|
||||
const run = battle.run();
|
||||
const texts: string[] = [];
|
||||
let input: BattleInput;
|
||||
for (let guard = 0; guard < 2000; guard++) {
|
||||
const next = run.next(input);
|
||||
input = undefined;
|
||||
if (next.done) return { texts, outcome: next.value as BattleOutcome };
|
||||
const effect = next.value;
|
||||
if (effect.kind === "text") texts.push(effect.text.replace(/\n/g, " "));
|
||||
else if (effect.kind === "action") {
|
||||
if (until?.() || !actions.length) return { texts, outcome: undefined };
|
||||
input = actions.shift();
|
||||
} else if (effect.kind === "yesno" || effect.kind === "name") input = answers.shift();
|
||||
else if (effect.kind === "forget") input = 4;
|
||||
}
|
||||
throw new Error("The battle did not finish.");
|
||||
};
|
||||
const ball = (slot = 0) => ({ action: "item" as const, item: C.POKE_BALL, slot });
|
||||
|
||||
it("catches a wild Pokémon into the party with its original moves, PP and current HP", () => {
|
||||
// Weaken it first so the seeded throws succeed.
|
||||
for (let seed = 1; seed < 50; seed++) {
|
||||
const { battle, bag, pokedex, party } = setup({ seed });
|
||||
const { texts, outcome } = play(
|
||||
battle,
|
||||
[{ action: "fight", move: 0 }, ball(), ball(), ball(), ball(), ball()],
|
||||
[1, "RATTY"],
|
||||
);
|
||||
if (!outcome || party.length !== 2) continue;
|
||||
expect(outcome.result).toBe(C.WIN);
|
||||
expect(texts).toContain("CHRIS used the POKé BALL.");
|
||||
expect(texts.some((text) => text.startsWith("Gotcha! RATTATA was caught!"))).toBe(true);
|
||||
expect(texts).toContain("RATTATA's data was newly added to the #DEX.".replace("#", "POKé"));
|
||||
expect(texts).toContain("Give a nickname to RATTATA?");
|
||||
const caught = party[1];
|
||||
const enemy = battle.enemy.mon;
|
||||
expect(caught).toMatchObject({
|
||||
species: RATTATA,
|
||||
nickname: "RATTY",
|
||||
level: 3,
|
||||
otId: 1234,
|
||||
ot: "CHRIS",
|
||||
dvs: enemy.dvs,
|
||||
hp: enemy.hp,
|
||||
status: enemy.status,
|
||||
item: enemy.item,
|
||||
happiness: C.BASE_HAPPINESS,
|
||||
caughtData: 0x4000 | (3 << 8) | 1,
|
||||
exp: data.expAtLevel(data.baseData(RATTATA).growthRate, 3),
|
||||
statExp: [0, 0, 0, 0, 0],
|
||||
});
|
||||
expect(caught.hp).toBeLessThan(caught.stats[0]);
|
||||
// wWildMonMoves and wWildMonPP: full PP of the moves it appeared with.
|
||||
expect(caught.pp).toEqual(caught.moves.map((move) => (move ? data.move(move).pp : 0)));
|
||||
expect(validPartyMon(data, caught)).toBe(true);
|
||||
expect(pokedex.caught.has(RATTATA)).toBe(true);
|
||||
const thrown = texts.filter((text) => text === "CHRIS used the POKé BALL.").length;
|
||||
expect(bag.balls).toEqual(thrown === 5 ? [] : [{ item: C.POKE_BALL, quantity: 5 - thrown }]);
|
||||
return;
|
||||
}
|
||||
throw new Error("No seed caught the Pokémon.");
|
||||
});
|
||||
|
||||
it("uses the turn when the Pokémon breaks free, with the wobble message", () => {
|
||||
const messages = [
|
||||
"Oh no! The POKéMON broke free!",
|
||||
"Aww! It appeared to be caught!",
|
||||
"Aargh! Almost had it!",
|
||||
"Shoot! It was so close too!",
|
||||
];
|
||||
const seen = new Set<string>();
|
||||
for (let seed = 1; seed < 200 && seen.size < 4; seed++) {
|
||||
const { battle, bag, party } = setup({ seed });
|
||||
const { texts } = play(battle, [ball()], [], () => bag.balls[0]?.quantity === 4);
|
||||
if (party.length !== 1) continue;
|
||||
const failure = messages.find((message) => texts.includes(message));
|
||||
expect(failure, texts.join(" | ")).toBeDefined();
|
||||
seen.add(failure!);
|
||||
// The wild Pokémon then moves, and the ball is gone.
|
||||
expect(texts.some((text) => text.startsWith("Enemy RATTATA used")), texts.join(" | ")).toBe(true);
|
||||
expect(bag.balls).toEqual([{ item: C.POKE_BALL, quantity: 4 }]);
|
||||
}
|
||||
expect(seen.size).toBe(4);
|
||||
});
|
||||
|
||||
it("catches with a Master Ball without drawing a catch or wobble random", () => {
|
||||
const { battle, bag, party, draws } = setup({
|
||||
bag: { items: [], balls: [{ item: C.MASTER_BALL, quantity: 1 }], keyItems: [] },
|
||||
});
|
||||
let before = 0;
|
||||
const run = battle.run();
|
||||
let input: BattleInput;
|
||||
for (let guard = 0; guard < 100; guard++) {
|
||||
const next = run.next(input);
|
||||
input = undefined;
|
||||
if (next.done) break;
|
||||
if (next.value.kind === "action") {
|
||||
before = draws();
|
||||
input = { action: "item", item: C.MASTER_BALL, slot: 0 };
|
||||
} else if (next.value.kind === "yesno") input = 0;
|
||||
}
|
||||
// Only LoadEnemyMon's wild item roll (one or two draws) remains.
|
||||
expect(draws() - before).toBeGreaterThanOrEqual(1);
|
||||
expect(draws() - before).toBeLessThanOrEqual(2);
|
||||
expect(party).toHaveLength(2);
|
||||
expect(party[1].nickname).toBe("RATTATA");
|
||||
expect(bag.balls).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps the species name for a blank nickname and skips the Pokédex text without a Pokédex", () => {
|
||||
const { battle, party } = setup({
|
||||
hasPokedex: false,
|
||||
bag: { items: [], balls: [{ item: C.MASTER_BALL, quantity: 1 }], keyItems: [] },
|
||||
});
|
||||
const { texts } = play(battle, [{ action: "item", item: C.MASTER_BALL, slot: 0 }], [1, " "]);
|
||||
expect(party[1].nickname).toBe("RATTATA");
|
||||
expect(texts.join(" ")).not.toContain("newly added");
|
||||
});
|
||||
|
||||
it("ignores a slot that does not hold the ball", () => {
|
||||
const { battle, bag } = setup();
|
||||
const { outcome } = play(battle, [{ action: "item", item: C.GREAT_BALL, slot: 0 }, { action: "run" }]);
|
||||
expect(outcome).toBeDefined();
|
||||
expect(bag.balls).toEqual([{ item: C.POKE_BALL, quantity: 5 }]);
|
||||
});
|
||||
|
||||
it("refuses to send a Pokémon to the PC with a full party", () => {
|
||||
const { battle } = setup({ party: Array.from({ length: 6 }, starter) });
|
||||
expect(() => play(battle, [ball()])).toThrow(UnsupportedBattle);
|
||||
});
|
||||
|
||||
it("blocks balls in trainer battles and still uses the ball and turn", () => {
|
||||
const joey = generatePartyMon(data, {
|
||||
species: RATTATA, level: 2, item: 0, otId: 0, ot: "JOEY", dvs: 0x9888, caughtData: 0,
|
||||
});
|
||||
const { battle, bag, party } = setup({
|
||||
trainer: {
|
||||
name: "JOEY", className: "YOUNGSTER", party: [joey], aiFlags: 0, switchFlags: 0, reward: 10,
|
||||
},
|
||||
});
|
||||
const { texts } = play(battle, [ball()], [], () => bag.balls[0]?.quantity === 4);
|
||||
expect(texts).toContain("The trainer blocked the BALL!");
|
||||
expect(texts).toContain("Don't be a thief!");
|
||||
expect(texts.join(" ")).not.toContain("used the POKé BALL");
|
||||
expect(texts.some((text) => text.includes("RATTATA used"))).toBe(true);
|
||||
expect(bag.balls).toEqual([{ item: C.POKE_BALL, quantity: 4 }]);
|
||||
expect(party).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("runs the Dude's tutorial without touching the player's party or pack", () => {
|
||||
const { battle, bag, party, pokedex } = setup({ tutorial: true, bag: undefined });
|
||||
const { texts, outcome } = play(battle, []);
|
||||
expect(outcome?.result).toBe(C.WIN);
|
||||
expect(texts).toEqual([
|
||||
"Wild RATTATA appeared!",
|
||||
"DUDE used the POKé BALL.",
|
||||
"Gotcha! RATTATA was caught!",
|
||||
]);
|
||||
expect(party).toHaveLength(1);
|
||||
expect(bag.balls).toEqual([{ item: C.POKE_BALL, quantity: 5 }]);
|
||||
expect(pokedex.seen.has(RATTATA)).toBe(true);
|
||||
expect(pokedex.caught.has(RATTATA)).toBe(false);
|
||||
expect(battle.player.mon).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,185 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { CrystalAssets } from "../src/game/rom/assets";
|
||||
import { GameWorld } from "../src/game/world/world";
|
||||
import { generatePartyMon, validPartyMon } from "../src/game/party/pokemon";
|
||||
import { C } from "../src/game/battle/constants";
|
||||
import { battleFixtureWorld, ENCOUNTER_WALK } from "./battle-fixture";
|
||||
import { settle } from "./world-driver";
|
||||
|
||||
const romPath =
|
||||
process.env.CRYSTAL_ROM_PATH ?? "Pokemon - Crystal Version (UE) (V1.1) [C][!].gbc";
|
||||
const ROUTE_29 = "24:3",
|
||||
DUDE = 2,
|
||||
RATTATA = 19,
|
||||
PIDGEY = 16;
|
||||
const EVENT_GOT_A_POKEMON_FROM_ELM = 26,
|
||||
EVENT_GAVE_MYSTERY_EGG_TO_ELM = 31,
|
||||
EVENT_DUDE_TALKED_TO_YOU = 65,
|
||||
EVENT_LEARNED_TO_CATCH_POKEMON = 66;
|
||||
|
||||
describe.skipIf(!existsSync(romPath))("the catching tutorial and capture in the world", () => {
|
||||
const assets = () => new CrystalAssets(new Uint8Array(readFileSync(romPath)));
|
||||
/** After returning the Egg: Route 29 is in its catching-tutorial scene. */
|
||||
const tutorialWorld = (position = { x: 54, y: 8 }) => {
|
||||
let seed = 3;
|
||||
const world = new GameWorld(assets(), () => new Date("2026-09-24T12:00:00"), () => {
|
||||
seed = (seed * 1103515245 + 12345) >>> 0;
|
||||
return (seed >>> 16) & 255;
|
||||
});
|
||||
const mon = generatePartyMon(world.assets.pokemon, {
|
||||
species: 158, level: 8, item: 0, otId: world.playerId, ot: "CHRIS", dvs: 0xffff, caughtData: 0,
|
||||
});
|
||||
world.state.party = [mon];
|
||||
world.state.pokedex.seen.add(158);
|
||||
world.state.pokedex.caught.add(158);
|
||||
for (const event of [EVENT_GOT_A_POKEMON_FROM_ELM, EVENT_GAVE_MYSTERY_EGG_TO_ELM])
|
||||
world.state.events.add(event);
|
||||
world.state.bag.balls = [{ item: C.POKE_BALL, quantity: 5 }];
|
||||
world.restore({ ...world.save(), map: ROUTE_29, ...position, direction: "left", scenes: { [ROUTE_29]: 1 } });
|
||||
return world;
|
||||
};
|
||||
const dude = (world: GameWorld) => world.objects().find((object) => object.id === DUDE)!;
|
||||
|
||||
it.each([
|
||||
[8, "Tutorial1"],
|
||||
[9, "Tutorial2"],
|
||||
])("runs the Dude's demonstration from the trigger at y=%i (%s)", (y) => {
|
||||
const world = tutorialWorld({ x: 54, y });
|
||||
const before = world.save();
|
||||
expect(world.move("left")).toBe(true);
|
||||
const pages = settle(world).join("\n").replace(/\n/g, " ");
|
||||
expect(world.notice, world.diagnostic).toBe("");
|
||||
expect(pages).toContain("show you how to catch POKéMON?");
|
||||
expect(pages).toContain("That's how you do it");
|
||||
expect(world.state.events.has(EVENT_DUDE_TALKED_TO_YOU)).toBe(true);
|
||||
expect(world.state.events.has(EVENT_LEARNED_TO_CATCH_POKEMON)).toBe(true);
|
||||
expect(world.state.scenes[ROUTE_29]).toBe(0);
|
||||
// Only the Pokédex sighting remains; the Dude's catch is not kept.
|
||||
expect(world.state.pokedex.seen.has(RATTATA)).toBe(true);
|
||||
expect(world.state.pokedex.caught.has(RATTATA)).toBe(false);
|
||||
expect(world.state.party).toEqual(before.party);
|
||||
expect(world.state.bag).toEqual(before.bag);
|
||||
expect(dude(world)).toMatchObject({ x: 50, y: 12 });
|
||||
// Nothing replays after reload.
|
||||
world.restore(world.save());
|
||||
expect(settle(world)).toEqual([]);
|
||||
});
|
||||
|
||||
it("shows the battle as the Dude with automatic messages", () => {
|
||||
const world = tutorialWorld();
|
||||
expect(world.move("left")).toBe(true);
|
||||
const messages: string[] = [];
|
||||
for (let tick = 0; tick < 5000 && !world.battle; tick++) {
|
||||
if (world.dialogue?.choice) world.choose(1);
|
||||
else if (world.dialogue) world.advanceDialogue();
|
||||
else world.tick();
|
||||
}
|
||||
expect(world.battle?.engine.player.mon).toBeUndefined();
|
||||
// A save during the battle holds the state before the scene.
|
||||
const saved = world.save();
|
||||
expect(saved.events).not.toContain(EVENT_DUDE_TALKED_TO_YOU);
|
||||
expect(saved.pokedex.seen).not.toContain(RATTATA);
|
||||
while (world.battle) {
|
||||
const text = world.battle.message?.text;
|
||||
if (text && messages.at(-1) !== text) messages.push(text);
|
||||
expect(world.battle.prompt).toBeUndefined();
|
||||
expect(world.battle.message?.prompt).not.toBe(true);
|
||||
world.tick();
|
||||
}
|
||||
expect(messages.map((text) => text.replace(/\n/g, " "))).toEqual([
|
||||
"Wild RATTATA appeared!",
|
||||
"DUDE used the POKé BALL.",
|
||||
"Gotcha! RATTATA was caught!",
|
||||
]);
|
||||
settle(world);
|
||||
expect(world.notice, world.diagnostic).toBe("");
|
||||
// Reloading the mid-battle save replays the whole scene.
|
||||
world.restore(saved);
|
||||
expect(world.x).toBe(54);
|
||||
expect(world.move("left")).toBe(true);
|
||||
settle(world);
|
||||
expect(world.state.events.has(EVENT_LEARNED_TO_CATCH_POKEMON)).toBe(true);
|
||||
});
|
||||
|
||||
it("lets the player decline, then offers the demonstration again when talked to", () => {
|
||||
const world = tutorialWorld();
|
||||
expect(world.move("left")).toBe(true);
|
||||
const declined = settle(world, [0]).join("\n").replace(/\n/g, " ");
|
||||
expect(world.notice, world.diagnostic).toBe("");
|
||||
expect(declined).toContain("Oh. Fine, then");
|
||||
expect(world.state.scenes[ROUTE_29]).toBe(0);
|
||||
expect(world.state.events.has(EVENT_LEARNED_TO_CATCH_POKEMON)).toBe(false);
|
||||
expect(dude(world)).toMatchObject({ x: 50, y: 12 });
|
||||
|
||||
// CatchingTutorialDudeScript: stand below him and talk.
|
||||
world.restore({ ...world.save(), x: 50, y: 13, direction: "up" });
|
||||
world.interact();
|
||||
const pages = settle(world).join("\n").replace(/\n/g, " ");
|
||||
expect(world.notice, world.diagnostic).toBe("");
|
||||
expect(pages).toContain("That's how you do it");
|
||||
expect(world.state.events.has(EVENT_LEARNED_TO_CATCH_POKEMON)).toBe(true);
|
||||
expect(world.state.pokedex.seen.has(RATTATA)).toBe(true);
|
||||
});
|
||||
|
||||
it("catches a wild Pokémon through the world and keeps it after reload", () => {
|
||||
const world = battleFixtureWorld(assets());
|
||||
world.state.bag.balls = [{ item: C.POKE_BALL, quantity: 10 }];
|
||||
for (const direction of ENCOUNTER_WALK) expect(world.move(direction)).toBe(true);
|
||||
expect(world.battle).toBeDefined();
|
||||
let named = false;
|
||||
for (let tick = 0; tick < 20_000 && world.busy; tick++) {
|
||||
const view = world.battle;
|
||||
if (!view) {
|
||||
if (world.dialogue) world.advanceDialogue();
|
||||
else world.tick();
|
||||
continue;
|
||||
}
|
||||
const prompt = view.prompt;
|
||||
if (prompt?.kind === "action")
|
||||
world.battleAction({ action: "item", item: C.POKE_BALL, slot: 0 });
|
||||
else if (prompt?.kind === "yesno") world.battleChoose(1);
|
||||
else if (prompt?.kind === "name") {
|
||||
expect(prompt.title).toBe("PIDGEY'S\nNICKNAME?");
|
||||
world.battleName("PIDGE");
|
||||
named = true;
|
||||
} else if (view.message?.prompt) world.interact();
|
||||
else world.tick();
|
||||
}
|
||||
expect(world.notice, world.diagnostic).toBe("");
|
||||
expect(named).toBe(true);
|
||||
expect(world.state.party).toHaveLength(2);
|
||||
const caught = world.state.party[1];
|
||||
expect(caught).toMatchObject({ species: PIDGEY, nickname: "PIDGE", level: 3, ot: world.name });
|
||||
// SetCaughtData: day (2 << 6 | level), Chris, New Bark Town's landmark.
|
||||
expect(caught.caughtData >> 8).toBe((2 << 6) | 3);
|
||||
expect(caught.caughtData & 0x80).toBe(0);
|
||||
expect(caught.caughtData & 0x7f).toBe(world.assets.map("24:7").landmark);
|
||||
expect(world.state.pokedex.caught.has(PIDGEY)).toBe(true);
|
||||
expect(world.state.bag.balls[0].quantity).toBeLessThan(10);
|
||||
const saved = world.save();
|
||||
world.restore(saved);
|
||||
expect(world.save()).toEqual(saved);
|
||||
expect(validPartyMon(world.assets.pokemon, world.state.party[1])).toBe(true);
|
||||
});
|
||||
|
||||
it("rolls back the whole battle when a full party would need the PC", () => {
|
||||
const world = battleFixtureWorld(assets());
|
||||
const mon = world.state.party[0];
|
||||
world.state.party = Array.from({ length: 6 }, () => structuredClone(mon));
|
||||
world.state.bag.balls = [{ item: C.POKE_BALL, quantity: 10 }];
|
||||
const before = world.save();
|
||||
for (const direction of ENCOUNTER_WALK) expect(world.move(direction)).toBe(true);
|
||||
world.battleAction({ action: "item", item: C.POKE_BALL, slot: 0 });
|
||||
for (let tick = 0; tick < 200 && world.battle; tick++) {
|
||||
if (world.battle.prompt?.kind === "action")
|
||||
world.battleAction({ action: "item", item: C.POKE_BALL, slot: 0 });
|
||||
else if (world.battle.message?.prompt) world.interact();
|
||||
else world.tick();
|
||||
}
|
||||
expect(world.battle).toBeUndefined();
|
||||
expect(world.notice).toMatch(/not been ported/);
|
||||
expect(world.state.bag).toEqual({ ...before.bag });
|
||||
expect(world.state.party).toHaveLength(6);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user