From c2cb433409871b50c906880d0395badd28162ae1 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Fri, 20 Oct 2023 23:00:08 -0400 Subject: [PATCH] Fix crash from accessing modifier types before initialization --- src/data/trainer-type.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/data/trainer-type.ts b/src/data/trainer-type.ts index eb5b3f40c45..53c106347a2 100644 --- a/src/data/trainer-type.ts +++ b/src/data/trainer-type.ts @@ -414,7 +414,11 @@ export class TrainerConfig { } setModifierRewardFuncs(...modifierTypeFuncs: (() => ModifierType)[]): TrainerConfig { - this.modifierRewardFuncs = modifierTypeFuncs; + this.modifierRewardFuncs = modifierTypeFuncs.map(modifierTypeFunc => () => { + const modifierType = modifierTypeFunc(); + modifierType.id = Object.keys(modifierTypes).find(k => modifierTypes[k] === modifierTypeFunc); + return modifierType; + }); return this; } @@ -525,14 +529,6 @@ function getSpeciesFilterRandomPartyMemberFunc(speciesFilter: PokemonSpeciesFilt }; } -function getModifierRewardFunc(modifierTypeFunc: () => ModifierType): () => ModifierType { - return () => { - const modifierType = modifierTypeFunc(); - modifierType.id = Object.keys(modifierTypes).find(k => modifierTypes[k] === modifierTypeFunc); - return modifierType; - }; -} - export const trainerConfigs: TrainerConfigs = { [TrainerType.ACE_TRAINER]: new TrainerConfig(++t).setHasGenders().setEncounterBgm(TrainerType.ACE_TRAINER) .setPartyTemplateFunc(scene => getWavePartyTemplate(scene, trainerPartyTemplates.THREE_WEAK_BALANCED, trainerPartyTemplates.FOUR_WEAK_BALANCED, trainerPartyTemplates.FIVE_WEAK_BALANCED, trainerPartyTemplates.SIX_WEAK_BALANCED)), @@ -686,7 +682,7 @@ export const trainerConfigs: TrainerConfigs = { $Just kidding! I lost fair and square, and now I know you'll do fine out there. $By the way, the professor wanted me to give you some items. Hopefully they're helpful! $Do your best like always! I believe in you!` - ]).setModifierRewardFuncs(getModifierRewardFunc(modifierTypes.EXP_CHARM()), getModifierRewardFunc(modifierTypes.EXP_SHARE())).setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE, Species.CHIKORITA, Species.CYNDAQUIL, Species.TOTODILE, Species.TREECKO, Species.TORCHIC, Species.MUDKIP, Species.TURTWIG, Species.CHIMCHAR, Species.PIPLUP, Species.SNIVY, Species.TEPIG, Species.OSHAWOTT ])) + ]).setModifierRewardFuncs(() => modifierTypes.EXP_CHARM(), () => modifierTypes.EXP_SHARE()).setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.BULBASAUR, Species.CHARMANDER, Species.SQUIRTLE, Species.CHIKORITA, Species.CYNDAQUIL, Species.TOTODILE, Species.TREECKO, Species.TORCHIC, Species.MUDKIP, Species.TURTWIG, Species.CHIMCHAR, Species.PIPLUP, Species.SNIVY, Species.TEPIG, Species.OSHAWOTT ])) .setPartyMemberFunc(1, getRandomPartyMemberFunc([ Species.PIDGEY, Species.HOOTHOOT, Species.TAILLOW, Species.STARLY, Species.PIDOVE ])), [TrainerType.RIVAL_2]: new TrainerConfig(++t).setStaticParty().setEncounterBgm(TrainerType.RIVAL).setBattleBgm('battle_rival').setPartyTemplates(trainerPartyTemplates.RIVAL_2).setEncounterMessages([ `Oh, fancy meeting you here. Looks like you're still undefeated. Right on!