From 50dc438930b5900671dd2adfdd1d58e867fa3aec Mon Sep 17 00:00:00 2001 From: Mumble <171087428+frutescens@users.noreply.github.com> Date: Sat, 21 Sep 2024 13:27:19 -0700 Subject: [PATCH] [Bug] Preventing Duplicate Species in Trainer Battles (#4368) * no trainer repeats * Update src/field/trainer.ts Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: frutescens Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/field/trainer.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/field/trainer.ts b/src/field/trainer.ts index 1973d7216a6..b1d0263f604 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -425,14 +425,32 @@ export default class Trainer extends Phaser.GameObjects.Container { } } - if (retry && (attempt || 0) < 10) { + // Prompts reroll of party member species if species already present in the enemy party + if (this.checkDuplicateSpecies(ret)) { + console.log("Duplicate species detected, prompting reroll..."); + retry = true; + } + + if (retry && (attempt ?? 0) < 10) { console.log("Rerolling party member..."); - ret = this.genNewPartyMemberSpecies(level, strength, (attempt || 0) + 1); + ret = this.genNewPartyMemberSpecies(level, strength, (attempt ?? 0) + 1); } return ret; } + /** + * Checks if the enemy trainer already has the Pokemon species in their party + * @param {PokemonSpecies} species {@linkcode PokemonSpecies} + * @returns `true` if the species is already present in the party + */ + checkDuplicateSpecies(species: PokemonSpecies): boolean { + const currentPartySpecies = this.scene.getEnemyParty().map(p => { + return p.species.speciesId; + }); + return currentPartySpecies.includes(species.speciesId); + } + getPartyMemberMatchupScores(trainerSlot: TrainerSlot = TrainerSlot.NONE, forSwitch: boolean = false): [integer, integer][] { if (trainerSlot && !this.isDouble()) { trainerSlot = TrainerSlot.NONE;