From 7c3ace7204950809b0a07f135cda08d744445828 Mon Sep 17 00:00:00 2001 From: Arxalc <63990624+Arxalc@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:22:06 -0400 Subject: [PATCH] [Bug] Fixed primal weather interaction. (#1744) * Fixed primal weather interaction. * Made adjustments * Improved code readability --- src/data/ability.ts | 114 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 4 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 77fb31b9a6d..017a89145ec 100755 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -1726,7 +1726,9 @@ export class PostSummonWeatherChangeAbAttr extends PostSummonAbAttr { } applyPostSummon(pokemon: Pokemon, passive: boolean, args: any[]): boolean { - if (!pokemon.scene.arena.weather?.isImmutable()) { + if ((this.weatherType === WeatherType.HEAVY_RAIN || + this.weatherType === WeatherType.HARSH_SUN || + this.weatherType === WeatherType.STRONG_WINDS) || !pokemon.scene.arena.weather?.isImmutable()) { return pokemon.scene.arena.trySetWeather(this.weatherType, true); } @@ -1854,6 +1856,52 @@ export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr { } } +/** + * Clears Desolate Land/Primordial Sea/Delta Stream upon the Pokemon switching out. + */ +export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr { + + /** + * @param pokemon The {@linkcode Pokemon} with the ability + * @param passive N/A + * @param args N/A + * @returns {boolean} Returns true if the weather clears, otherwise false. + */ + applyPreSwitchOut(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise { + const weatherType = pokemon.scene.arena.weather.weatherType; + let turnOffWeather = false; + + // Clear weather only if user's ability matches the weather and no other pokemon has the ability. + switch (weatherType) { + case (WeatherType.HARSH_SUN): + if (pokemon.hasAbility(Abilities.DESOLATE_LAND) + && pokemon.scene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) { + turnOffWeather = true; + } + break; + case (WeatherType.HEAVY_RAIN): + if (pokemon.hasAbility(Abilities.PRIMORDIAL_SEA) + && pokemon.scene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) { + turnOffWeather = true; + } + break; + case (WeatherType.STRONG_WINDS): + if (pokemon.hasAbility(Abilities.DELTA_STREAM) + && pokemon.scene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) { + turnOffWeather = true; + } + break; + } + + if (turnOffWeather) { + pokemon.scene.arena.trySetWeather(WeatherType.NONE, false); + return true; + } + + return false; + } +} + export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr { applyPreSwitchOut(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise { if (pokemon.getHpRatio() < 1 ) { @@ -2985,6 +3033,55 @@ export class PostFaintAbAttr extends AbAttr { } } +/** + * Clears Desolate Land/Primordial Sea/Delta Stream upon the Pokemon fainting + */ +export class PostFaintClearWeatherAbAttr extends PostFaintAbAttr { + + /** + * @param pokemon The {@linkcode Pokemon} with the ability + * @param passive N/A + * @param attacker N/A + * @param move N/A + * @param hitResult N/A + * @param args N/A + * @returns {boolean} Returns true if the weather clears, otherwise false. + */ + applyPostFaint(pokemon: Pokemon, passive: boolean, attacker: Pokemon, move: PokemonMove, hitResult: HitResult, args: any[]): boolean { + const weatherType = pokemon.scene.arena.weather.weatherType; + let turnOffWeather = false; + + // Clear weather only if user's ability matches the weather and no other pokemon has the ability. + switch (weatherType) { + case (WeatherType.HARSH_SUN): + if (pokemon.hasAbility(Abilities.DESOLATE_LAND) + && pokemon.scene.getField(true).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) { + turnOffWeather = true; + } + break; + case (WeatherType.HEAVY_RAIN): + if (pokemon.hasAbility(Abilities.PRIMORDIAL_SEA) + && pokemon.scene.getField(true).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) { + turnOffWeather = true; + } + break; + case (WeatherType.STRONG_WINDS): + if (pokemon.hasAbility(Abilities.DELTA_STREAM) + && pokemon.scene.getField(true).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) { + turnOffWeather = true; + } + break; + } + + if (turnOffWeather) { + pokemon.scene.arena.trySetWeather(WeatherType.NONE, false); + return true; + } + + return false; + } +} + export class PostFaintContactDamageAbAttr extends PostFaintAbAttr { private damageRatio: integer; @@ -4161,13 +4258,22 @@ export function initAbilities() { .unimplemented(), new Ability(Abilities.PRIMORDIAL_SEA, 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.HEAVY_RAIN) - .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.HEAVY_RAIN), + .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.HEAVY_RAIN) + .attr(PreSwitchOutClearWeatherAbAttr) + .attr(PostFaintClearWeatherAbAttr) + .bypassFaint(), new Ability(Abilities.DESOLATE_LAND, 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.HARSH_SUN) - .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.HARSH_SUN), + .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.HARSH_SUN) + .attr(PreSwitchOutClearWeatherAbAttr) + .attr(PostFaintClearWeatherAbAttr) + .bypassFaint(), new Ability(Abilities.DELTA_STREAM, 6) .attr(PostSummonWeatherChangeAbAttr, WeatherType.STRONG_WINDS) - .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.STRONG_WINDS), + .attr(PostBiomeChangeWeatherChangeAbAttr, WeatherType.STRONG_WINDS) + .attr(PreSwitchOutClearWeatherAbAttr) + .attr(PostFaintClearWeatherAbAttr) + .bypassFaint(), new Ability(Abilities.STAMINA, 7) .attr(PostDefendStatChangeAbAttr, (target, user, move) => move.category !== MoveCategory.STATUS, BattleStat.DEF, 1), new Ability(Abilities.WIMP_OUT, 7)