[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 <info@laptop>
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
Mumble 2024-09-21 13:27:19 -07:00 committed by GitHub
parent 4fb76fd117
commit 50dc438930
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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..."); console.log("Rerolling party member...");
ret = this.genNewPartyMemberSpecies(level, strength, (attempt || 0) + 1); ret = this.genNewPartyMemberSpecies(level, strength, (attempt ?? 0) + 1);
} }
return ret; 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][] { getPartyMemberMatchupScores(trainerSlot: TrainerSlot = TrainerSlot.NONE, forSwitch: boolean = false): [integer, integer][] {
if (trainerSlot && !this.isDouble()) { if (trainerSlot && !this.isDouble()) {
trainerSlot = TrainerSlot.NONE; trainerSlot = TrainerSlot.NONE;