fixing speed boost for pokemon being switched in and for if failed escape

This commit is contained in:
PrabbyDD 2024-10-16 16:26:50 -07:00
parent e7a4d4055f
commit df4e362771
6 changed files with 27 additions and 3 deletions

View File

@ -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 */

View File

@ -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<void> {
return this.battleInfo.updateInfo(this, instant);
}

View File

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

View File

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

View File

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

View File

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