Files
Crystal/tests/battle-fixture.ts
T
Sébastien QUEROLandClaude Opus 5.5 9ac111f262
Checks / web (push) Canceled after 0s
Checks / web (pull_request) Canceled after 0s
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>
2026-09-24 20:57:36 +02:00

39 lines
1.6 KiB
TypeScript

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" | "catch";
/** Test-only encounters on an existing floor: production maps stay gated.
* Everything after selection runs through the ROM's real wild-battle script. */
export function battleFixtureWorld(assets: CrystalAssets, scenario: BattleScenario = "win") {
assets.grassCollisions = () => [assets.collision(assets.map("24:7"), 3, 2)];
assets.grassWildMons = (id) => id === "24:7" ? {
rates: [256, 256, 256],
slots: [0, 1, 2].map(() => Array.from({ length: 7 }, () => ({ species: 16, level: 3 }))),
} : undefined;
let seed = 1;
const world = new GameWorld(assets, () => new Date("2026-09-22T12:00:00"), () => {
seed = (seed * 1103515245 + 12345) >>> 0;
return (seed >>> 16) & 255;
});
const mon = generatePartyMon(assets.pokemon, {
species: 155, level: 5, item: 0, otId: world.playerId,
ot: "CHRIS", dvs: 0x823b, caughtData: 0,
});
mon.exp = 178; // One battle away from level 6 and Smokescreen.
if (scenario === "loss") mon.hp = 1;
if (scenario === "unsupported") {
mon.moves = [144, 0, 0, 0]; // Transform is explicitly refused.
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;
return world;
}
export const ENCOUNTER_WALK = ["up", "right", "right", "right", "right"] as const;