From ac4e72c87a886bae4af90ed72515830ea3d8510f Mon Sep 17 00:00:00 2001 From: Jannik Tappert <38758606+CodeTappert@users.noreply.github.com> Date: Thu, 30 May 2024 00:33:18 +0200 Subject: [PATCH] Fix double battle named trainers having unevolved Pokemon (#1582) --- src/data/trainer-config.ts | 13 +++++++++---- src/field/trainer.ts | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/data/trainer-config.ts b/src/data/trainer-config.ts index 9ad7556415e..99e013dc00e 100644 --- a/src/data/trainer-config.ts +++ b/src/data/trainer-config.ts @@ -233,7 +233,8 @@ export class TrainerConfig { } // If a special double trainer class was set, set it as the sprite key if (this.trainerTypeDouble && female && isDouble) { - ret = TrainerType[this.trainerTypeDouble].toString().toLowerCase(); + // Get the derived type for the double trainer since the sprite key is based on the derived type + ret = TrainerType[this.getDerivedType(this.trainerTypeDouble)].toString().toLowerCase(); } return ret; } @@ -271,9 +272,13 @@ export class TrainerConfig { } - - getDerivedType(): TrainerType { - let trainerType = this.trainerType; + /** + * Returns the derived trainer type for a given trainer type. + * @param trainerTypeToDeriveFrom - The trainer type to derive from. (If null, the this.trainerType property will be used.) + * @returns {TrainerType} - The derived trainer type. + */ + getDerivedType(trainerTypeToDeriveFrom: TrainerType = null): TrainerType { + let trainerType = trainerTypeToDeriveFrom ? trainerTypeToDeriveFrom : this.trainerType; switch (trainerType) { case TrainerType.RIVAL_2: case TrainerType.RIVAL_3: diff --git a/src/field/trainer.ts b/src/field/trainer.ts index 00b7bdf527a..dea8dd8182b 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -328,12 +328,17 @@ export default class Trainer extends Phaser.GameObjects.Container { } // If useNewSpeciesPool is true, we need to generate a new species from the new species pool, otherwise we generate a random species - const species = useNewSpeciesPool + let species = useNewSpeciesPool ? getPokemonSpecies(newSpeciesPool[Math.floor(Math.random() * newSpeciesPool.length)]) : template.isSameSpecies(index) && index > offset ? getPokemonSpecies(battle.enemyParty[offset].species.getTrainerSpeciesForLevel(level, false, template.getStrength(offset))) : this.genNewPartyMemberSpecies(level, strength); + // If the species is from newSpeciesPool, we need to adjust it based on the level and strength + if (newSpeciesPool) { + species = getPokemonSpecies(species.getSpeciesForLevel(level, true, true, strength)); + } + ret = this.scene.addEnemyPokemon(species, level, !this.isDouble() || !(index % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : this.scene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + (((!this.config.useSameSeedForAllMembers ? index : 0) + 1) << 8));