From df4e362771383c86960afc5562a8f6a535e068b2 Mon Sep 17 00:00:00 2001 From: PrabbyDD Date: Wed, 16 Oct 2024 16:26:50 -0700 Subject: [PATCH] fixing speed boost for pokemon being switched in and for if failed escape --- src/enums/switch-type.ts | 2 ++ src/field/pokemon.ts | 7 +++++++ src/phases/attempt-run-phase.ts | 1 + src/phases/check-switch-phase.ts | 2 +- src/phases/switch-summon-phase.ts | 6 +++++- src/phases/turn-end-phase.ts | 12 +++++++++++- 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/enums/switch-type.ts b/src/enums/switch-type.ts index b25ba6ad119..752c0902636 100644 --- a/src/enums/switch-type.ts +++ b/src/enums/switch-type.ts @@ -3,6 +3,8 @@ * or {@linkcode SwitchSummonPhase} will carry out. */ export enum SwitchType { + /** Switchout specifically for when combat starts and the player is prompted if they will switch Pokemon */ + INITIAL_SWITCH, /** Basic switchout where the Pokemon to switch in is selected */ SWITCH, /** Transfers stat stages and other effects from the returning Pokemon to the switched in Pokemon */ diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 0204672cabd..aee75b10101 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -105,6 +105,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { public pauseEvolutions: boolean; public pokerus: boolean; public switchOutStatus: boolean; + public switchedInThisTurn: boolean; + public failedRunAway: boolean; public evoCounter: integer; public fusionSpecies: PokemonSpecies | null; @@ -152,6 +154,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.pokeball = dataSource?.pokeball || PokeballType.POKEBALL; this.level = level; this.switchOutStatus = false; + this.switchedInThisTurn = false; // Determine the ability index if (abilityIndex !== undefined) { @@ -2251,6 +2254,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.switchOutStatus = status; } + setSwitchedInStatus(status: boolean): void { + this.switchedInThisTurn = status; + } + updateInfo(instant?: boolean): Promise { return this.battleInfo.updateInfo(this, instant); } diff --git a/src/phases/attempt-run-phase.ts b/src/phases/attempt-run-phase.ts index e0dd7fa72fd..4cd6bcc2740 100644 --- a/src/phases/attempt-run-phase.ts +++ b/src/phases/attempt-run-phase.ts @@ -51,6 +51,7 @@ export class AttemptRunPhase extends PokemonPhase { this.scene.pushPhase(new BattleEndPhase(this.scene)); this.scene.pushPhase(new NewBattlePhase(this.scene)); } else { + playerPokemon.failedRunAway = true; this.scene.queueMessage(i18next.t("battle:runAwayCannotEscape"), null, true, 500); } diff --git a/src/phases/check-switch-phase.ts b/src/phases/check-switch-phase.ts index 8849d304435..5e459d0e6b5 100644 --- a/src/phases/check-switch-phase.ts +++ b/src/phases/check-switch-phase.ts @@ -51,7 +51,7 @@ export class CheckSwitchPhase extends BattlePhase { this.scene.ui.setMode(Mode.CONFIRM, () => { this.scene.ui.setMode(Mode.MESSAGE); this.scene.tryRemovePhase(p => p instanceof PostSummonPhase && p.player && p.fieldIndex === this.fieldIndex); - this.scene.unshiftPhase(new SwitchPhase(this.scene, SwitchType.SWITCH, this.fieldIndex, false, true)); + this.scene.unshiftPhase(new SwitchPhase(this.scene, SwitchType.INITIAL_SWITCH, this.fieldIndex, false, true)); this.end(); }, () => { this.scene.ui.setMode(Mode.MESSAGE); diff --git a/src/phases/switch-summon-phase.ts b/src/phases/switch-summon-phase.ts index 07761b10d6e..c3b22dadc79 100644 --- a/src/phases/switch-summon-phase.ts +++ b/src/phases/switch-summon-phase.ts @@ -65,7 +65,7 @@ export class SwitchSummonPhase extends SummonPhase { const pokemon = this.getPokemon(); - if (this.switchType === SwitchType.SWITCH) { + if (this.switchType === SwitchType.SWITCH || this.switchType === SwitchType.INITIAL_SWITCH) { (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.removeTagsBySourceId(pokemon.id)); const substitute = pokemon.getTag(SubstituteTag); if (substitute) { @@ -105,6 +105,10 @@ export class SwitchSummonPhase extends SummonPhase { const party = this.player ? this.getParty() : this.scene.getEnemyParty(); const switchedInPokemon = party[this.slotIndex]; this.lastPokemon = this.getPokemon(); + if (this.switchType !== SwitchType.INITIAL_SWITCH) { + switchedInPokemon.setSwitchedInStatus(true); + } + this.lastPokemon.setSwitchedInStatus(false); applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, this.lastPokemon); if (this.switchType === SwitchType.BATON_PASS && switchedInPokemon) { (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.transferTagsBySourceId(this.lastPokemon.id, switchedInPokemon.id)); diff --git a/src/phases/turn-end-phase.ts b/src/phases/turn-end-phase.ts index 60a2e6600db..4c8e87b538b 100644 --- a/src/phases/turn-end-phase.ts +++ b/src/phases/turn-end-phase.ts @@ -10,6 +10,7 @@ import { TurnHealModifier, EnemyTurnHealModifier, EnemyStatusEffectHealChanceMod import i18next from "i18next"; import { FieldPhase } from "./field-phase"; import { PokemonHealPhase } from "./pokemon-heal-phase"; +import { Abilities } from "#app/enums/abilities"; export class TurnEndPhase extends FieldPhase { constructor(scene: BattleScene) { @@ -37,7 +38,16 @@ export class TurnEndPhase extends FieldPhase { this.scene.applyModifier(EnemyStatusEffectHealChanceModifier, false, pokemon); } - applyPostTurnAbAttrs(PostTurnAbAttr, pokemon); + if (!pokemon.hasAbility(Abilities.SPEED_BOOST)) { + applyPostTurnAbAttrs(PostTurnAbAttr, pokemon); + } else if (pokemon.hasAbility(Abilities.SPEED_BOOST) && !pokemon.switchedInThisTurn && !pokemon.failedRunAway) { + pokemon.setSwitchedInStatus(false); + pokemon.failedRunAway = false; + applyPostTurnAbAttrs(PostTurnAbAttr, pokemon); + } else { + pokemon.failedRunAway = false; + pokemon.setSwitchedInStatus(false); + } this.scene.applyModifiers(TurnStatusEffectModifier, pokemon.isPlayer(), pokemon);