From 3b852c5bf2a37875d53f3dd370fb7fd0cb2053b2 Mon Sep 17 00:00:00 2001 From: ImperialSympathizer <110984302+ben-lear@users.noreply.github.com> Date: Thu, 30 May 2024 13:07:28 -0400 Subject: [PATCH] [Bug] Fix weather effects to work on the first turn of being cast (#1503) * update weather phase so weather effects proc properly * remove redundant weather replace phase logic --------- Co-authored-by: ImperialSympathizer --- src/field/arena.ts | 4 +--- src/phases.ts | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) 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);