Add scripted trainer battle foundation and native move AI
Checks / web (push) Canceled after 0s

This commit is contained in:
Sébastien QUEROL committed 2026-09-24 09:33:33 +02:00
1 parent 6a74f59e46
commit 3e92936cb9
20 files changed
+1417 -32

No files matched your search

+19
View File
@@ -1,4 +1,5 @@
import { CrystalAssets } from "../rom/assets";
import { TrainerData } from "../rom/trainers";
import { INITIAL_POSITION, NUM_FRUIT_TREES, SYMBOLS } from "../rom/profile";
import {
PLAYER,
@@ -1006,6 +1007,19 @@ export class GameWorld {
return false;
case "battle": {
const draft = script.run.state;
const trainers = new TrainerData(this.assets.reader);
const opponent = effect.trainer && trainers.trainer(effect.trainer.classId, effect.trainer.id);
if (opponent?.attributes.items.some((item) => item !== 0))
throw new Error("Trainer item AI is not ported.");
const trainer = opponent && {
name: opponent.name,
className: opponent.className,
party: trainers.createParty(opponent, { otId: this.playerId, ot: this.name }),
aiFlags: opponent.attributes.aiMoveFlags,
reward: opponent.reward,
winText: effect.trainer?.winText,
lossText: effect.trainer?.lossText,
};
const engine = new Battle({
data: this.assets.pokemon,
party: draft.party,
@@ -1015,6 +1029,8 @@ export class GameWorld {
timeOfDay: this.clockTimeOfDay,
random: () => this.random() & 0xff,
wild: effect.wild,
trainer,
canLose: effect.canLose,
text: () => this.host(PLAYER).text(),
});
this.battle = { engine, selected: 1 };
@@ -1226,6 +1242,9 @@ export class GameWorld {
input = undefined;
view.prompt = undefined;
if (next.done) {
if (this.script && next.value.prizeMoney)
this.script.run.state.money = Math.min(C.MAX_MONEY,
this.script.run.state.money + next.value.prizeMoney);
this.battle = undefined;
this.battleRun = undefined;
this.pump(next.value.result);