refactoring solution to be more consistent with coding style

This commit is contained in:
PrabbyDD 2024-10-17 15:24:03 -07:00
parent 5f905689df
commit 667ca3283d
6 changed files with 16 additions and 22 deletions

View File

@ -3594,7 +3594,13 @@ export class PostTurnStatStageChangeAbAttr extends PostTurnAbAttr {
applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean { applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
if (!simulated) { if (!simulated) {
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.stages)); if (!pokemon.hasAbility(Abilities.SPEED_BOOST)) {
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.stages));
} else if (pokemon.hasAbility(Abilities.SPEED_BOOST) && !pokemon.turnData.switchedInThisTurn && !pokemon.turnData.failedRunAway) {
pokemon.scene.unshiftPhase(new StatStageChangePhase(pokemon.scene, pokemon.getBattlerIndex(), true, this.stats, this.stages));
} else {
this.showAbility = false;
}
} }
return true; return true;
} }

View File

@ -105,8 +105,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
public pauseEvolutions: boolean; public pauseEvolutions: boolean;
public pokerus: boolean; public pokerus: boolean;
public switchOutStatus: boolean; public switchOutStatus: boolean;
public switchedInThisTurn: boolean;
public failedRunAway: boolean;
public evoCounter: integer; public evoCounter: integer;
public fusionSpecies: PokemonSpecies | null; public fusionSpecies: PokemonSpecies | null;
@ -154,7 +152,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.pokeball = dataSource?.pokeball || PokeballType.POKEBALL; this.pokeball = dataSource?.pokeball || PokeballType.POKEBALL;
this.level = level; this.level = level;
this.switchOutStatus = false; this.switchOutStatus = false;
this.switchedInThisTurn = false;
// Determine the ability index // Determine the ability index
if (abilityIndex !== undefined) { if (abilityIndex !== undefined) {
@ -2254,10 +2251,6 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
this.switchOutStatus = status; this.switchOutStatus = status;
} }
setSwitchedInStatus(status: boolean): void {
this.switchedInThisTurn = status;
}
updateInfo(instant?: boolean): Promise<void> { updateInfo(instant?: boolean): Promise<void> {
return this.battleInfo.updateInfo(this, instant); return this.battleInfo.updateInfo(this, instant);
} }
@ -5073,6 +5066,8 @@ export class PokemonTurnData {
public statStagesDecreased: boolean = false; public statStagesDecreased: boolean = false;
public moveEffectiveness: TypeDamageMultiplier | null = null; public moveEffectiveness: TypeDamageMultiplier | null = null;
public combiningPledge?: Moves; public combiningPledge?: Moves;
public switchedInThisTurn: boolean = false;
public failedRunAway: boolean = false;
} }
export enum AiType { export enum AiType {

View File

@ -54,7 +54,7 @@ export class AttemptRunPhase extends PokemonPhase {
this.scene.pushPhase(new BattleEndPhase(this.scene)); this.scene.pushPhase(new BattleEndPhase(this.scene));
this.scene.pushPhase(new NewBattlePhase(this.scene)); this.scene.pushPhase(new NewBattlePhase(this.scene));
} else { } else {
playerPokemon.failedRunAway = true; playerPokemon.turnData.failedRunAway = true;
this.scene.queueMessage(i18next.t("battle:runAwayCannotEscape"), null, true, 500); this.scene.queueMessage(i18next.t("battle:runAwayCannotEscape"), null, true, 500);
} }

View File

@ -238,7 +238,10 @@ export class SummonPhase extends PartyMemberPokemonPhase {
this.scene.unshiftPhase(new ShinySparklePhase(this.scene, pokemon.getBattlerIndex())); this.scene.unshiftPhase(new ShinySparklePhase(this.scene, pokemon.getBattlerIndex()));
} }
/** Switch in status is set before the pokemon is summoned and the new turn begins, so it is preserved from switch-summon-phase */
const switchedInStatus = pokemon.turnData?.switchedInThisTurn;
pokemon.resetTurnData(); pokemon.resetTurnData();
pokemon.turnData.switchedInThisTurn = switchedInStatus;
if (!this.loaded || [ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(this.scene.currentBattle.battleType) || (this.scene.currentBattle.waveIndex % 10) === 1) { if (!this.loaded || [ BattleType.TRAINER, BattleType.MYSTERY_ENCOUNTER ].includes(this.scene.currentBattle.battleType) || (this.scene.currentBattle.waveIndex % 10) === 1) {
this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true); this.scene.triggerPokemonFormChange(pokemon, SpeciesFormChangeActiveTrigger, true);

View File

@ -106,9 +106,9 @@ export class SwitchSummonPhase extends SummonPhase {
const switchedInPokemon = party[this.slotIndex]; const switchedInPokemon = party[this.slotIndex];
this.lastPokemon = this.getPokemon(); this.lastPokemon = this.getPokemon();
if (this.switchType !== SwitchType.INITIAL_SWITCH) { if (this.switchType !== SwitchType.INITIAL_SWITCH) {
switchedInPokemon.setSwitchedInStatus(true); switchedInPokemon.resetTurnData();
switchedInPokemon.turnData.switchedInThisTurn = true;
} }
this.lastPokemon.setSwitchedInStatus(false);
applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, this.lastPokemon); applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, this.lastPokemon);
if (this.switchType === SwitchType.BATON_PASS && switchedInPokemon) { if (this.switchType === SwitchType.BATON_PASS && switchedInPokemon) {
(this.player ? this.scene.getEnemyField() : this.scene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.transferTagsBySourceId(this.lastPokemon.id, switchedInPokemon.id)); (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField()).forEach(enemyPokemon => enemyPokemon.transferTagsBySourceId(this.lastPokemon.id, switchedInPokemon.id));

View File

@ -10,7 +10,6 @@ import { TurnHealModifier, EnemyTurnHealModifier, EnemyStatusEffectHealChanceMod
import i18next from "i18next"; import i18next from "i18next";
import { FieldPhase } from "./field-phase"; import { FieldPhase } from "./field-phase";
import { PokemonHealPhase } from "./pokemon-heal-phase"; import { PokemonHealPhase } from "./pokemon-heal-phase";
import { Abilities } from "#app/enums/abilities";
export class TurnEndPhase extends FieldPhase { export class TurnEndPhase extends FieldPhase {
constructor(scene: BattleScene) { constructor(scene: BattleScene) {
@ -38,16 +37,7 @@ export class TurnEndPhase extends FieldPhase {
this.scene.applyModifier(EnemyStatusEffectHealChanceModifier, false, pokemon); this.scene.applyModifier(EnemyStatusEffectHealChanceModifier, false, pokemon);
} }
if (!pokemon.hasAbility(Abilities.SPEED_BOOST)) { applyPostTurnAbAttrs(PostTurnAbAttr, pokemon);
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); this.scene.applyModifiers(TurnStatusEffectModifier, pokemon.isPlayer(), pokemon);