diff --git a/src/field/arena.ts b/src/field/arena.ts index 2e8506931fc..817e5d5eaad 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -5,7 +5,7 @@ import * as Utils from "../utils"; import PokemonSpecies, { getPokemonSpecies } from "../data/pokemon-species"; import { Species } from "../data/enums/species"; import { Weather, WeatherType, getTerrainClearMessage, getTerrainStartMessage, getWeatherClearMessage, getWeatherStartMessage } from "../data/weather"; -import { CommonAnimPhase, WeatherEffectPhase } from "../phases"; +import { CommonAnimPhase } from "../phases"; import { CommonAnim } from "../data/battle-anims"; import { Type } from "../data/type"; import Move from "../data/move"; @@ -302,11 +302,9 @@ export class Arena { this.weather = weather ? new Weather(weather, hasPokemonSource ? 5 : 0) : null; if (this.weather) { - this.scene.tryReplacePhase(phase => phase instanceof WeatherEffectPhase && phase.weather.weatherType === oldWeatherType, new WeatherEffectPhase(this.scene, this.weather)); this.scene.unshiftPhase(new CommonAnimPhase(this.scene, undefined, undefined, CommonAnim.SUNNY + (weather - 1))); this.scene.queueMessage(getWeatherStartMessage(weather)); } else { - this.scene.tryRemovePhase(phase => phase instanceof WeatherEffectPhase && phase.weather.weatherType === oldWeatherType); this.scene.queueMessage(getWeatherClearMessage(oldWeatherType)); } diff --git a/src/phases.ts b/src/phases.ts index f10a8f92d08..b9fdc095107 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2194,9 +2194,7 @@ export class TurnStartPhase extends FieldPhase { } - if (this.scene.arena.weather) { - this.scene.pushPhase(new WeatherEffectPhase(this.scene, this.scene.arena.weather)); - } + this.scene.pushPhase(new WeatherEffectPhase(this.scene)); for (const o of order) { if (field[o].status && field[o].status.isPostTurn()) { @@ -2379,6 +2377,10 @@ export class CommonAnimPhase extends PokemonPhase { this.targetIndex = targetIndex; } + setAnimation(anim: CommonAnim) { + this.anim = anim; + } + start() { new CommonBattleAnim(this.anim, this.getPokemon(), this.targetIndex !== undefined ? (this.player ? this.scene.getEnemyField() : this.scene.getPlayerField())[this.targetIndex] : this.getPokemon()).play(this.scene, () => { this.end(); @@ -3202,12 +3204,22 @@ export class StatChangePhase extends PokemonPhase { export class WeatherEffectPhase extends CommonAnimPhase { public weather: Weather; - constructor(scene: BattleScene, weather: Weather) { - super(scene, undefined, undefined, CommonAnim.SUNNY + (weather.weatherType - 1)); - this.weather = weather; + constructor(scene: BattleScene) { + super(scene, undefined, undefined, CommonAnim.SUNNY + ((scene?.arena?.weather?.weatherType || WeatherType.NONE) - 1)); + this.weather = scene?.arena?.weather; } start() { + // Update weather state with any changes that occurred during the turn + this.weather = this.scene?.arena?.weather; + + if (!this.weather) { + this.end(); + return; + } + + this.setAnimation(CommonAnim.SUNNY + (this.weather.weatherType - 1)); + if (this.weather.isDamaging()) { const cancelled = new Utils.BooleanHolder(false);