From 0917049fea41d3f4a79838293a22a55124a6e123 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Wed, 21 Feb 2024 12:38:07 -0500 Subject: [PATCH] Fix issues with out of bounds form indexes --- src/battle-phases.ts | 2 +- src/data/pokemon-species.ts | 2 +- src/system/pokemon-data.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index fdde003e385..e3b89507c45 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -284,7 +284,7 @@ export class SelectStarterPhase extends BattlePhase { const loadPokemonAssets: Promise[] = []; for (let starter of starters) { const starterProps = this.scene.gameData.getSpeciesDexAttrProps(starter.species, starter.dexAttr); - const starterFormIndex = Math.min(starterProps.formIndex, starter.species.forms.length - 1); + const starterFormIndex = Math.min(starterProps.formIndex, Math.max(starter.species.forms.length - 1, 0)); const starterGender = starter.species.malePercent !== null ? !starterProps.female ? Gender.MALE : Gender.FEMALE : Gender.GENDERLESS; diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index cec9e062a50..e566e67dde1 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -352,7 +352,7 @@ export default class PokemonSpecies extends PokemonSpeciesForm { getName(formIndex?: integer): string { if (formIndex !== undefined && this.forms.length) { - const form = this.forms[Math.min(formIndex, this.forms.length - 1)]; + const form = this.forms[formIndex]; switch (form.formKey) { case SpeciesFormKey.MEGA: case SpeciesFormKey.ETERNAMAX: diff --git a/src/system/pokemon-data.ts b/src/system/pokemon-data.ts index 3d8cc97a808..46cd439b0ea 100644 --- a/src/system/pokemon-data.ts +++ b/src/system/pokemon-data.ts @@ -7,7 +7,7 @@ import { PokeballType } from "../data/pokeball"; import { getPokemonSpecies } from "../data/pokemon-species"; import { Species } from "../data/enums/species"; import { Status } from "../data/status-effect"; -import Pokemon, { EnemyPokemon, PlayerPokemon, PokemonMove, PokemonSummonData } from "../pokemon"; +import Pokemon, { EnemyPokemon, PokemonMove, PokemonSummonData } from "../pokemon"; export default class PokemonData { public id: integer; @@ -48,7 +48,7 @@ export default class PokemonData { this.id = source.id; this.player = sourcePokemon ? sourcePokemon.isPlayer() : source.player; this.species = sourcePokemon ? sourcePokemon.species.speciesId : source.species; - this.formIndex = source.formIndex; + this.formIndex = Math.max(Math.min(source.formIndex, getPokemonSpecies(this.species).forms.length - 1), 0); this.abilityIndex = source.abilityIndex; this.shiny = source.shiny; this.pokeball = source.pokeball;