Fix issues with out of bounds form indexes

pull/16/head
Flashfyre 2024-02-21 12:38:07 -05:00
parent 355fbac9c3
commit 0917049fea
3 changed files with 4 additions and 4 deletions

View File

@ -284,7 +284,7 @@ export class SelectStarterPhase extends BattlePhase {
const loadPokemonAssets: Promise<void>[] = [];
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;

View File

@ -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:

View File

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