diff --git a/src/data/ability.ts b/src/data/ability.ts index 57d1402ad..12f8d7b51 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -20,6 +20,8 @@ import { SpeciesFormChangeManualTrigger } from "./pokemon-forms"; import { Abilities } from "./enums/abilities"; import i18next, { Localizable } from "#app/plugins/i18n.js"; import { Command } from "../ui/command-ui-handler"; +import PokemonSpecies from "./pokemon-species"; +import { BattleType } from "#app/battle.js"; export class Ability implements Localizable { public id: Abilities; @@ -2055,6 +2057,28 @@ export class PostTurnFormChangeAbAttr extends PostTurnAbAttr { } } +export class PreSwitchOutFormChangeAbAttr extends PreSwitchOutAbAttr { + private formFunc: (p: Pokemon) => integer; + + constructor(formFunc: ((p: Pokemon) => integer)) { + super(); + + this.formFunc = formFunc; + } + + applyPreSwitchOut(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise { + console.log(pokemon.getFormKey()) + + const formIndex = this.formFunc(pokemon); + if (formIndex !== pokemon.formIndex) { + pokemon.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeManualTrigger, false); + return true; + } + + return false; + } +} + export class PostBiomeChangeAbAttr extends AbAttr { } export class PostBiomeChangeWeatherChangeAbAttr extends PostBiomeChangeAbAttr { @@ -3446,7 +3470,9 @@ export function initAbilities() { .attr(UnsuppressableAbilityAbAttr) .attr(NoTransformAbilityAbAttr) .attr(NoFusionAbilityAbAttr) - .unimplemented(), + .attr(PreSwitchOutFormChangeAbAttr, p => p.getFormKey() ? 1 : 0) + .attr(PostBattleInitFormChangeAbAttr, p => p.battleData.switchesMade === 0 && p.scene.currentBattle.battleType === BattleType.TRAINER ? 0 : 1) + .attr(PostSummonFormChangeAbAttr,p => p.battleData.switchesMade === 0 && p.scene.currentBattle.battleType === BattleType.TRAINER? 0 : 1), new Ability(Abilities.COMMANDER, 9) .attr(UncopiableAbilityAbAttr) .attr(UnswappableAbilityAbAttr) diff --git a/src/data/pokemon-forms.ts b/src/data/pokemon-forms.ts index 9a38ed81e..9792fc79b 100644 --- a/src/data/pokemon-forms.ts +++ b/src/data/pokemon-forms.ts @@ -691,6 +691,10 @@ export const pokemonFormChanges: PokemonFormChanges = { [Species.ENAMORUS]: [ new SpeciesFormChange(Species.ENAMORUS, SpeciesFormKey.INCARNATE, SpeciesFormKey.THERIAN, new SpeciesFormChangeItemTrigger(FormChangeItem.REVEAL_GLASS)) ], + [Species.PALAFIN]: [ + new SpeciesFormChange(Species.PALAFIN, 'zero', 'hero', new SpeciesFormChangeManualTrigger(), true), + new SpeciesFormChange(Species.PALAFIN, 'hero', 'zero', new SpeciesFormChangeManualTrigger(), true), + ], [Species.OGERPON]: [ new SpeciesFormChange(Species.OGERPON, 'teal-mask', 'wellspring-mask', new SpeciesFormChangeItemTrigger(FormChangeItem.WELLSPRING_MASK)), new SpeciesFormChange(Species.OGERPON, 'teal-mask', 'hearthflame-mask', new SpeciesFormChangeItemTrigger(FormChangeItem.HEARTHFLAME_MASK)), diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 606185e09..36b4239d9 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -3106,6 +3106,7 @@ export class PokemonBattleData { public hitCount: integer = 0; public endured: boolean = false; public berriesEaten: BerryType[] = []; + public switchesMade: integer = 0; } export class PokemonBattleSummonData { diff --git a/src/phases.ts b/src/phases.ts index 6f1ebc261..b941fbbe4 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -1446,6 +1446,7 @@ export class SwitchSummonPhase extends SummonPhase { if (this.batonPass && pokemon) pokemon.transferSummon(this.lastPokemon); + this.lastPokemon.battleData.switchesMade++; this.lastPokemon?.resetSummonData(); this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true);