From 37e6371eefeb391e0c2006b92340d48a848412ce Mon Sep 17 00:00:00 2001 From: Fabi <192151969+fabske0@users.noreply.github.com> Date: Tue, 16 Sep 2025 17:48:19 +0200 Subject: [PATCH] [Dev] Allow forcing all trainer variants in trainer override (#6391) --- src/battle-scene.ts | 25 ++++++++++++++++--------- src/overrides.ts | 9 +++++++-- test/moves/whirlwind.test.ts | 3 ++- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 374cf3f270f..cbda368782e 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1332,13 +1332,12 @@ export class BattleScene extends SceneBase { if (newBattleType === BattleType.TRAINER) { const trainerType = Overrides.RANDOM_TRAINER_OVERRIDE?.trainerType ?? this.arena.randomTrainerType(newWaveIndex); + const hasDouble = trainerConfigs[trainerType].hasDouble; let doubleTrainer = false; if (trainerConfigs[trainerType].doubleOnly) { doubleTrainer = true; - } else if (trainerConfigs[trainerType].hasDouble) { - doubleTrainer = - Overrides.RANDOM_TRAINER_OVERRIDE?.alwaysDouble - || !randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); + } else if (hasDouble) { + doubleTrainer = !randSeedInt(this.getDoubleBattleChance(newWaveIndex, playerField)); // Add a check that special trainers can't be double except for tate and liza - they should use the normal double chance if ( trainerConfigs[trainerType].trainerTypeDouble @@ -1347,11 +1346,19 @@ export class BattleScene extends SceneBase { doubleTrainer = false; } } - const variant = doubleTrainer - ? TrainerVariant.DOUBLE - : randSeedInt(2) - ? TrainerVariant.FEMALE - : TrainerVariant.DEFAULT; + + // Forcing a double battle on wave 1 causes a bug where only one enemy is sent out, + // making it impossible to complete the fight without a reload + const overrideVariant = + Overrides.RANDOM_TRAINER_OVERRIDE?.trainerVariant === TrainerVariant.DOUBLE + && (!hasDouble || newWaveIndex <= 1) + ? TrainerVariant.DEFAULT + : Overrides.RANDOM_TRAINER_OVERRIDE?.trainerVariant; + + const variant = + overrideVariant + ?? (doubleTrainer ? TrainerVariant.DOUBLE : randSeedInt(2) ? TrainerVariant.FEMALE : TrainerVariant.DEFAULT); + newTrainer = trainerData !== undefined ? trainerData.toTrainer() : new Trainer(trainerType, variant); this.field.add(newTrainer); } diff --git a/src/overrides.ts b/src/overrides.ts index 9f6b4ced3a2..3f61196f0b4 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -18,6 +18,7 @@ import { Stat } from "#enums/stat"; import { StatusEffect } from "#enums/status-effect"; import { TimeOfDay } from "#enums/time-of-day"; import { TrainerType } from "#enums/trainer-type"; +import { TrainerVariant } from "#enums/trainer-variant"; import { Unlockables } from "#enums/unlockables"; import { VariantTier } from "#enums/variant-tier"; import { WeatherType } from "#enums/weather-type"; @@ -311,8 +312,12 @@ export type BattleStyle = "double" | "single" | "even-doubles" | "odd-doubles"; export type RandomTrainerOverride = { /** The Type of trainer to force */ trainerType: Exclude; - /* If the selected trainer type has a double version, it will always use its double version. */ - alwaysDouble?: boolean; + /** + * The {@linkcode TrainerVariant} to force. + * @remarks + * `TrainerVariant.DOUBLE` cannot be forced on the first wave of a game due to issues with trainer party generation. + */ + trainerVariant?: TrainerVariant; }; /** The type of the {@linkcode DefaultOverrides} class */ diff --git a/test/moves/whirlwind.test.ts b/test/moves/whirlwind.test.ts index 61c05a30322..ac112f01ea3 100644 --- a/test/moves/whirlwind.test.ts +++ b/test/moves/whirlwind.test.ts @@ -10,6 +10,7 @@ import { PokemonType } from "#enums/pokemon-type"; import { SpeciesId } from "#enums/species-id"; import { StatusEffect } from "#enums/status-effect"; import { TrainerType } from "#enums/trainer-type"; +import { TrainerVariant } from "#enums/trainer-variant"; import { GameManager } from "#test/test-utils/game-manager"; import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; @@ -193,7 +194,7 @@ describe("Moves - Whirlwind", () => { .battleType(BattleType.TRAINER) .randomTrainer({ trainerType: TrainerType.BREEDER, - alwaysDouble: true, + trainerVariant: TrainerVariant.DOUBLE, }) .enemyMoveset([MoveId.SPLASH, MoveId.LUNAR_DANCE]) .moveset([MoveId.WHIRLWIND, MoveId.SPLASH]);