From 8d7db2b1cc8761b39b7a5b5dacfd9086bf0470d0 Mon Sep 17 00:00:00 2001 From: AJ Fontaine Date: Tue, 25 Feb 2025 12:03:50 -0500 Subject: [PATCH] Remove obsolete tera index code --- src/data/trainer-config.ts | 53 ++++++++++++++++++++++++-------------- src/field/trainer.ts | 29 +++++---------------- 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/data/trainer-config.ts b/src/data/trainer-config.ts index ffb350d5901..b2db4bad6b3 100644 --- a/src/data/trainer-config.ts +++ b/src/data/trainer-config.ts @@ -215,7 +215,7 @@ export class TrainerAI { /** * Sets a pokemon on this AI to just instantly Tera on first move used - * @param index The index of the pokemon to instantly tera. Negative value sets the nth-to-last party member to tera. + * @param index The index of the pokemon to instantly tera. Wraps based on party size. */ public setInstantTera(index: number) { this.teraMode = TeraAIMode.INSTANT_TERA; @@ -257,7 +257,6 @@ export class TrainerConfig { public specialtyType: Type = Type.UNKNOWN; public hasVoucher: boolean = false; public trainerAI: TrainerAI; - public minTeraWave: number = 0; public encounterMessages: string[] = []; public victoryMessages: string[] = []; @@ -597,9 +596,32 @@ export class TrainerConfig { return this; } + /** + * Sets random pokemon from the trainers team to instant tera. Also sets Tera type to specialty type and checks for Shedinja as appropriate. + * @param minWave The minimum wave to start using tera + * @param slot Optional, a specified slot that should be terastallized. + * @returns this + */ + setRandomTeraModifiers(minWave: number = 0, slot?: number): TrainerConfig { + this.genAIFuncs.push((party: EnemyPokemon[]) => { + if (minWave > globalScene.currentBattle.waveIndex) { + return; + } + let randomIndex = !Utils.isNullOrUndefined(slot) ? Phaser.Math.Wrap(slot, 0, party.length - 1) : Utils.randSeedInt(party.length); // Tera the last slot if first slot... yeah... + if (this.specialtyType > Type.UNKNOWN) { + if (party[randomIndex].species.speciesId === Species.SHEDINJA && this.specialtyType !== Type.BUG) { + randomIndex = Phaser.Math.Wrap(randomIndex - 1, 0, party.length - 1); // Shedinja can only Tera Bug, so choose an earlier party slot + } + party[randomIndex].teraType = this.specialtyType; + } + this.trainerAI.setInstantTera(randomIndex); + }); + return this; + } + /** * Sets a specific pokemon to instantly Tera - * @param index The index within the team to have instant Tera. Negative value sets nth-to-last party member. + * @param index The index within the team to have instant Tera. * @returns this */ setInstantTera(index: number): TrainerConfig { @@ -866,7 +888,7 @@ export class TrainerConfig { * @param isMale Whether the Gym Leader is Male or Not (for localization of the title). * @param {Type} specialtyType The specialty type for the Gym Leader. * @param ignoreMinTeraWave Whether the Gym Leader always uses Tera (true), or only Teras after {@linkcode GYM_LEADER_TERA_WAVE} (false). Defaults to false. - * @param teraSlot Optional, sets the party member in this slot to Terastallize. Negative value means the nth-to-last party member Teras. + * @param teraSlot Optional, sets the party member in this slot to Terastallize. Wraps based on party size. * @returns {TrainerConfig} The updated TrainerConfig instance. * **/ initForGymLeader(signatureSpecies: (Species | Species[])[], isMale: boolean, specialtyType: Type = Type.UNKNOWN, ignoreMinTeraWave: boolean = false, teraSlot?: number): TrainerConfig { @@ -911,12 +933,7 @@ export class TrainerConfig { this.setHasVoucher(true); this.setBattleBgm("battle_unova_gym"); this.setVictoryBgm("victory_gym"); - if (!ignoreMinTeraWave) { - this.minTeraWave = GYM_LEADER_TERA_WAVE; - } - if (!Utils.isNullOrUndefined(teraSlot)) { - this.setInstantTera(teraSlot); - } + this.setRandomTeraModifiers(ignoreMinTeraWave ? 0 : GYM_LEADER_TERA_WAVE, teraSlot); return this; } @@ -926,7 +943,7 @@ export class TrainerConfig { * @param {Species | Species[]} signatureSpecies The signature species for the Elite Four member. * @param isMale Whether the Elite Four Member is Male or Female (for localization of the title). * @param {Type} The specialty type for the Elite Four member. - * @param teraSlot Optional, sets the party member in this slot to Terastallize. Negative value means the nth-to-last party member Teras. + * @param teraSlot Optional, sets the party member in this slot to Terastallize. * @returns {TrainerConfig} The updated TrainerConfig instance. **/ initForEliteFour(signatureSpecies: (Species | Species[])[], isMale: boolean, specialtyType: Type = Type.UNKNOWN, teraSlot?: number): TrainerConfig { @@ -973,9 +990,7 @@ export class TrainerConfig { this.setHasVoucher(true); this.setBattleBgm("battle_unova_elite"); this.setVictoryBgm("victory_gym"); - if (!Utils.isNullOrUndefined(teraSlot)) { - this.setInstantTera(teraSlot); - } + this.setRandomTeraModifiers(0, teraSlot); return this; } @@ -1799,7 +1814,7 @@ export const trainerConfigs: TrainerConfigs = { p.generateName(); p.gender = Gender.MALE; })) - .setInstantTera(3), // Tera Rock Rhyperior / Electric Electivire / Fire Magmortar + .setInstantTera(3), // Tera Ground or Rock Rhyperior / Electric Electivire / Fire Magmortar [TrainerType.RED]: new TrainerConfig(++t).initForChampion(true).setBattleBgm("battle_johto_champion").setMixedBattleBgm("battle_johto_champion").setHasDouble("red_blue_double").setDoubleTrainerType(TrainerType.BLUE).setDoubleTitle("champion_double") .setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.PIKACHU ], TrainerSlot.TRAINER, true, p => { p.formIndex = 8; // G-Max Pikachu @@ -1906,7 +1921,7 @@ export const trainerConfigs: TrainerConfigs = { p.generateName(); p.gender = Gender.FEMALE; })) - .setInstantTera(3), // Tera Water Milotic / Grass Roserade / Fire Hisui-Arcanine + .setInstantTera(3), // Tera Water Milotic / Grass Roserade / Fire Hisuian Arcanine [TrainerType.ALDER]: new TrainerConfig(++t).initForChampion(true).setHasDouble("alder_iris_double").setDoubleTrainerType(TrainerType.IRIS).setDoubleTitle("champion_double").setBattleBgm("battle_champion_alder").setMixedBattleBgm("battle_champion_alder") .setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.BOUFFALANT, Species.BRAVIARY ])) .setPartyMemberFunc(1, getRandomPartyMemberFunc([ Species.HISUI_LILLIGANT, Species.HISUI_ZOROARK, Species.BASCULEGION ], TrainerSlot.TRAINER, true, p => { @@ -1984,7 +1999,7 @@ export const trainerConfigs: TrainerConfigs = { })) .setPartyMemberFunc(1, getRandomPartyMemberFunc([ Species.MAGNEZONE, Species.ALOLA_NINETALES ])) .setPartyMemberFunc(2, getRandomPartyMemberFunc([ Species.TORNADUS, Species.THUNDURUS, Species.LANDORUS ], TrainerSlot.TRAINER, true, p => { - p.formIndex = 1; // Therian Forms + p.formIndex = 1; // Therian Formes p.generateAndPopulateMoveset(); p.pokeball = PokeballType.ULTRA_BALL; })) @@ -2002,7 +2017,7 @@ export const trainerConfigs: TrainerConfigs = { p.gender = Gender.MALE; p.teraType = p.species.type2!; })) - .setInstantTera(5), // Tera Dark Incineroar / Fighting Hisui-Decidueye + .setInstantTera(5), // Tera Dark Incineroar / Fighting Hisuian Decidueye [TrainerType.HAU]: new TrainerConfig(++t).initForChampion(true).setMixedBattleBgm("battle_alola_champion") .setPartyMemberFunc(0, getRandomPartyMemberFunc([ Species.ALOLA_RAICHU ], TrainerSlot.TRAINER, true, p => { p.generateAndPopulateMoveset(); @@ -2619,7 +2634,7 @@ export const trainerConfigs: TrainerConfigs = { })) .setPartyMemberFunc(2, getRandomPartyMemberFunc([ Species.CRAWDAUNT, Species.HISUI_SAMUROTT ], TrainerSlot.TRAINER, true, p => { p.generateAndPopulateMoveset(); - p.abilityIndex = 2; // Sharpness Hisui Samurott, Adaptability Crawdaunt + p.abilityIndex = 2; // Sharpness Hisuian Samurott, Adaptability Crawdaunt })) .setPartyMemberFunc(3, getRandomPartyMemberFunc([ Species.XURKITREE ], TrainerSlot.TRAINER, true, p => { p.generateAndPopulateMoveset(); diff --git a/src/field/trainer.ts b/src/field/trainer.ts index ba841c3d9dd..1cfb6f89315 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -39,7 +39,6 @@ export default class Trainer extends Phaser.GameObjects.Container { public name: string; public partnerName: string; public originalIndexes: { [key: number]: number } = {}; - public teraIndexes: number[] = []; constructor(trainerType: TrainerType, variant: TrainerVariant, partyTemplateIndex?: number, name?: string, partnerName?: string, trainerConfigOverride?: TrainerConfig) { super(globalScene, -72, 80); @@ -70,13 +69,6 @@ export default class Trainer extends Phaser.GameObjects.Container { } } - if (this.config.trainerAI.teraMode === TeraAIMode.INSTANT_TERA) { // For INSTANT_TERA Trainers, set the mons to Tera. Get a random index if none are specified. - this.teraIndexes.push(...this.config.trainerAI.instantTeras.map(i => i < 0 ? this.getPartyTemplate().size + i : i)); // Tera index of (-n) means nth-to-last party member - if (this.teraIndexes.length === 0) { - this.teraIndexes.push(Utils.randSeedInt(this.getPartyTemplate().size)); - } - } - switch (this.variant) { case TrainerVariant.FEMALE: if (!this.config.hasGenders) { @@ -388,15 +380,6 @@ export default class Trainer extends Phaser.GameObjects.Container { ret = globalScene.addEnemyPokemon(species, level, !this.isDouble() || !(index % 2) ? TrainerSlot.TRAINER : TrainerSlot.TRAINER_PARTNER); }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : globalScene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + (((!this.config.useSameSeedForAllMembers ? index : 0) + 1) << 8)); - if (ret!.species.speciesId === Species.SHEDINJA && this.teraIndexes.includes(index) && this.config.specialtyType !== Type.BUG) { - this.teraIndexes.pop(); - this.teraIndexes.push(index + 1); // If it's Shedinja and it's set to tera to something other than Bug, set tera index to the next mon - } - - if (this.config.specialtyType !== Type.UNKNOWN) { - ret!.teraType = this.config.specialtyType; - } - return ret!; // TODO: is this bang correct? } @@ -703,11 +686,11 @@ export default class Trainer extends Phaser.GameObjects.Container { * @returns boolean Whether the EnemyPokemon should Terastalize this turn */ shouldTera(pokemon: EnemyPokemon): boolean { - return ( - this.config.trainerAI.teraMode === TeraAIMode.INSTANT_TERA - && globalScene.currentBattle.waveIndex >= this.config.minTeraWave - && !pokemon.isTerastallized - && this.teraIndexes.includes(pokemon.initialTeamIndex) - ); + if (this.config.trainerAI.teraMode === TeraAIMode.INSTANT_TERA) { + if (!pokemon.isTerastallized && this.config.trainerAI.instantTeras.includes(pokemon.initialTeamIndex)) { + return true; + } + } + return false; } }