diff --git a/src/data/ability.ts b/src/data/ability.ts index e0bd24b4e62..c93a6ef35e8 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1436,6 +1436,16 @@ export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr { } } +export class PreSwitchOutWeatherChangeAbAttr extends PreSwitchOutAbAttr { + applyPreSwitchOut(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise { + if (pokemon.scene.arena.weather?.isImmutable()) { + return pokemon.scene.arena.weather?.isAbilityOnField(pokemon.scene) ? false : pokemon.scene.arena.trySetWeather(WeatherType.NONE, true); + } + + return false; + } +} + export class PreStatChangeAbAttr extends AbAttr { applyPreStatChange(pokemon: Pokemon, passive: boolean, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean | Promise { return false; @@ -2896,12 +2906,15 @@ export function initAbilities() { .ignorable(), new Ability(Abilities.PRIMORDIAL_SEA, "Primordial Sea", "The Pokémon changes the weather to nullify Fire-type attacks.", 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.HEAVY_RAIN) + .attr(PreSwitchOutWeatherChangeAbAttr) .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.HEAVY_RAIN), new Ability(Abilities.DESOLATE_LAND, "Desolate Land", "The Pokémon changes the weather to nullify Water-type attacks.", 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.HARSH_SUN) + .attr(PreSwitchOutWeatherChangeAbAttr) .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.HARSH_SUN), new Ability(Abilities.DELTA_STREAM, "Delta Stream", "The Pokémon changes the weather to eliminate all of the Flying type's weaknesses.", 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.STRONG_WINDS) + .attr(PreSwitchOutWeatherChangeAbAttr) .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.STRONG_WINDS), new Ability(Abilities.STAMINA, "Stamina", "Boosts the Defense stat when hit by an attack.", 7) .attr(PostDefendStatChangeAbAttr, (target, user, move) => move.category !== MoveCategory.STATUS, BattleStat.DEF, 1), diff --git a/src/data/weather.ts b/src/data/weather.ts index 1409920a1bc..14d78e649d2 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -7,6 +7,7 @@ import * as Utils from "../utils"; import BattleScene from "../battle-scene"; import { SuppressWeatherEffectAbAttr } from "./ability"; import { TerrainType } from "./terrain"; +import { Abilities } from "./enums/abilities"; export enum WeatherType { NONE, @@ -116,6 +117,39 @@ export class Weather { return false; } + + isAbilityOnField(scene: BattleScene): boolean { + const field = scene.getField(true); + let abilitiesOnField = 0; + + for (let pokemon of field) { + let ability = pokemon.getAbility(); + switch (this.weatherType) { + case WeatherType.HARSH_SUN: + if (ability.id === Abilities.DESOLATE_LAND) + abilitiesOnField++ + if (pokemon.hasPassive() && pokemon.getPassiveAbility().id === Abilities.DESOLATE_LAND) + abilitiesOnField++ + break; + case WeatherType.HEAVY_RAIN: + if (ability.id === Abilities.PRIMORDIAL_SEA) + abilitiesOnField++ + if (pokemon.hasPassive() && pokemon.getPassiveAbility().id === Abilities.PRIMORDIAL_SEA) + abilitiesOnField++ + break; + case WeatherType.STRONG_WINDS: + if (ability.id === Abilities.DELTA_STREAM) + abilitiesOnField++ + if (pokemon.hasPassive() && pokemon.getPassiveAbility().id === Abilities.DELTA_STREAM) + abilitiesOnField++ + break; + default: + break; + } + } + + return abilitiesOnField > 1; + } } export function getWeatherStartMessage(weatherType: WeatherType): string {