Skip to content

Commit

Permalink
[Bug] Fix weather effects to work on the first turn of being cast (pa…
Browse files Browse the repository at this point in the history
…gefaultgames#1503)

* update weather phase so weather effects proc properly

* remove redundant weather replace phase logic

---------

Co-authored-by: ImperialSympathizer <[email protected]>
  • Loading branch information
ben-lear and ImperialSympathizer authored May 30, 2024
1 parent b1c208c commit 3b852c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/field/arena.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
}

Expand Down
24 changes: 18 additions & 6 deletions src/phases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3b852c5

Please sign in to comment.