[Dev] Allow forcing all trainer variants in trainer override (#6391)

This commit is contained in:
Fabi 2025-09-16 17:48:19 +02:00 committed by GitHub
parent e25db16326
commit 37e6371eef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 12 deletions

View File

@ -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);
}

View File

@ -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<TrainerType, TrainerType.UNKNOWN>;
/* 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 */

View File

@ -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]);