Enable Route 38 and its Ecruteak gate, Route 39 with the MooMoo farm, Olivine City and its buildings, the Lighthouse's six floors, Routes 40 and 41, and Cianwood City with its gym, pharmacy, Photo Studio, Mania's house, the Poke Seer and the Lugia speech house. Olivine's port, the Battle Tower gate and Whirl Islands stay closed. The story runs from the rival in Olivine through Jasmine and Amphy, Suicune and Eusine, the SecretPotion, Chuck's boulders, the STORMBADGE, TM01 and HM02, back to Amphy's cure, Jasmine, the MINERALBADGE and TM23. Port GiveShuckle and ReturnShuckie with every return code and Mania's wrong last-Pokemon speech, PokeSeer with its high-byte-only OT check and reused caught level, PhotoStudio's no-printer path (Printer Error 2), and PlaySlowCry. wMooMooBerries joins the saved script bytes. Port trainer item AI: the 13 healing, status and X items, the highest-level gate, item use while Mean Look or Wrap prevents switching, and the original's random and state quirks, checked against the ROM over 5,632 states. Leaders with items are no longer refused. Game Corner sprites match the original frame by frame: cursor and reel positions, Golem's whole-frame flips, frame timing, the frame a removed sprite is still drawn, and the Golem roll's screen shake. The Burned Tower rival's garbage trainer header is documented as a boundary: its seen text dispatches text command $7f into home code before any battle. The playthrough continues for six stages to Jasmine; its driver can Surf, fish and travel through floors joined by holes. New tests cover trainer items, Olivine and Cianwood side content, and reference checks for trainer items, trainer sight and Game Corner animations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
3.9 KiB
TypeScript
139 lines
3.9 KiB
TypeScript
import type { CrystalAssets } from "../src/game/rom/assets";
|
|
import type { TrainerData } from "../src/game/rom/trainers";
|
|
import type {
|
|
Battle,
|
|
BattleEffect,
|
|
BattleInput,
|
|
BattleOptions,
|
|
} from "../src/game/battle/battle";
|
|
import type { Bag } from "../src/game/party/bag";
|
|
import { generatePartyMon, type PartyMon } from "../src/game/party/pokemon";
|
|
import { defaultTextContext } from "../src/game/scripts/text";
|
|
|
|
export const partyMon = (
|
|
assets: CrystalAssets,
|
|
species: number,
|
|
level: number,
|
|
): PartyMon =>
|
|
generatePartyMon(assets.pokemon, {
|
|
species,
|
|
level,
|
|
item: 0,
|
|
otId: 1234,
|
|
ot: "CHRIS",
|
|
dvs: 0x823b,
|
|
caughtData: 0,
|
|
});
|
|
|
|
/** Battle options for a wild Pokémon or a ROM trainer, with a seeded
|
|
* stand-in for the hardware Random routine. */
|
|
export function battleOptions(
|
|
assets: CrystalAssets,
|
|
trainers: TrainerData,
|
|
party: PartyMon[],
|
|
enemy:
|
|
| { wild: { species: number; level: number } }
|
|
| { trainer: [number, number] },
|
|
{ seed = 1, bag }: { seed?: number; bag?: Bag } = {},
|
|
): BattleOptions {
|
|
const base = {
|
|
data: assets.pokemon,
|
|
party,
|
|
bag,
|
|
playerId: 1234,
|
|
playerName: "CHRIS",
|
|
timeOfDay: 1,
|
|
pokedex: { seen: new Set<number>(), caught: new Set<number>() },
|
|
random: () => {
|
|
seed = (seed * 1103515245 + 12345) >>> 0;
|
|
return (seed >>> 16) & 255;
|
|
},
|
|
text: () => defaultTextContext("CHRIS"),
|
|
};
|
|
if ("wild" in enemy) return { ...base, wild: enemy.wild };
|
|
const trainer = trainers.trainer(...enemy.trainer);
|
|
return {
|
|
...base,
|
|
trainer: {
|
|
name: trainer.name,
|
|
className: trainer.className,
|
|
party: trainers.createParty(trainer),
|
|
aiFlags: trainer.attributes.aiMoveFlags,
|
|
switchFlags: trainer.attributes.aiItemSwitchFlags,
|
|
items: [...trainer.attributes.items] as [number, number],
|
|
baseReward: trainer.attributes.baseReward,
|
|
reward: trainer.reward,
|
|
},
|
|
};
|
|
}
|
|
|
|
/** Run a battle. Menus take queued answers per prompt kind, then the
|
|
* defaults: the first move, YES, cancelling a move to forget, and the
|
|
* first party slot or move slot. */
|
|
export function playBattle(
|
|
battle: Battle,
|
|
queued: Partial<Record<BattleEffect["kind"], BattleInput[]>> = {},
|
|
) {
|
|
const texts: string[] = [],
|
|
prompts: BattleEffect[] = [];
|
|
const run = battle.run();
|
|
let input: BattleInput;
|
|
for (let step = 0; step < 3000; step++) {
|
|
const next = run.next(input);
|
|
if (next.done) return { texts, prompts, result: next.value.result };
|
|
const effect = next.value;
|
|
input = undefined;
|
|
if (effect.kind === "text") texts.push(effect.text.replace(/\n/g, " "));
|
|
else if (effect.kind !== "hud") {
|
|
prompts.push(effect);
|
|
const answer = queued[effect.kind]?.shift();
|
|
input =
|
|
answer !== undefined
|
|
? answer
|
|
: effect.kind === "action"
|
|
? { action: "fight", move: 0 }
|
|
: effect.kind === "yesno"
|
|
? 1
|
|
: effect.kind === "forget"
|
|
? 4
|
|
: effect.kind === "party" || effect.kind === "move"
|
|
? 0
|
|
: undefined;
|
|
}
|
|
}
|
|
throw new Error("Battle did not end.");
|
|
}
|
|
|
|
/** Step a battle by hand: texts are collected up to each prompt, and
|
|
* `answer` feeds the current prompt's input. */
|
|
export function battleSteps(battle: Battle) {
|
|
const run = battle.run();
|
|
const texts: string[] = [];
|
|
let next = run.next();
|
|
const collect = () => {
|
|
while (
|
|
!next.done &&
|
|
(next.value.kind === "text" || next.value.kind === "hud")
|
|
) {
|
|
if (next.value.kind === "text")
|
|
texts.push(next.value.text.replace(/\n/g, " "));
|
|
next = run.next();
|
|
}
|
|
};
|
|
collect();
|
|
return {
|
|
texts,
|
|
get prompt(): BattleEffect | undefined {
|
|
return next.done ? undefined : next.value;
|
|
},
|
|
get done() {
|
|
return Boolean(next.done);
|
|
},
|
|
answer(input: BattleInput) {
|
|
next = run.next(input);
|
|
collect();
|
|
return this;
|
|
},
|
|
};
|
|
}
|