Skip to content

Commit

Permalink
Fix weather suppression abilities suppressing weather while ending
Browse files Browse the repository at this point in the history
Fixes a few issues with protosynthesis as well.
  • Loading branch information
HoeenCoder committed Mar 16, 2024
1 parent 4e1b3de commit c2a033b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
10 changes: 6 additions & 4 deletions data/abilities.ts
Expand Up @@ -100,6 +100,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
this.eachEvent('WeatherChange', this.effect);
},
onEnd(pokemon) {
pokemon.abilityState.ending = true;

This comment has been minimized.

Copy link
@urkerab

urkerab Mar 16, 2024

Contributor

At what point should we do this for all abilities when we send the End event?

This comment has been minimized.

Copy link
@HoeenCoder

HoeenCoder Mar 17, 2024

Author Member

I wanted to do that but lacked time and the know how for that (wanted to ensure the patch was out quickly since I botched the previous commit). I agree its a good idea to flag all abilities that are ending with this flag though.

this.eachEvent('WeatherChange', this.effect);
},
suppressWeather: true,
Expand Down Expand Up @@ -544,6 +545,7 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
this.eachEvent('WeatherChange', this.effect);
},
onEnd(pokemon) {
pokemon.abilityState.ending = true;
this.eachEvent('WeatherChange', this.effect);
},
suppressWeather: true,
Expand Down Expand Up @@ -3420,11 +3422,11 @@ export const Abilities: {[abilityid: string]: AbilityData} = {
this.singleEvent('WeatherChange', this.effect, this.effectState, pokemon);
},
onWeatherChange(pokemon) {
// Protosynthesis is not affected by Utility Umbrella, or any weather supressing ability
// As a result, we check the weather directly instead of via field#isWeather which calls field#effectiveWeather
if (this.field.weather === 'sunnyday') {
// Protosynthesis is not affected by Utility Umbrella
if (this.field.isWeather('sunnyday')) {
pokemon.addVolatile('protosynthesis');
} else if (!pokemon.volatiles['protosynthesis']?.fromBooster) {
} else if (!pokemon.volatiles['protosynthesis']?.fromBooster && this.field.weather !== 'sunnyday') {
// Protosynthesis will not deactivite if Sun is suppressed, hence the direct ID check (isWeather respects supression)
pokemon.removeVolatile('protosynthesis');
}
},
Expand Down
3 changes: 2 additions & 1 deletion sim/field.ts
Expand Up @@ -106,7 +106,8 @@ export class Field {
suppressingWeather() {
for (const side of this.battle.sides) {
for (const pokemon of side.active) {
if (pokemon && !pokemon.fainted && !pokemon.ignoringAbility() && pokemon.getAbility().suppressWeather) {
if (pokemon && !pokemon.fainted && !pokemon.ignoringAbility() &&
pokemon.getAbility().suppressWeather && !pokemon.abilityState.ending) {
return true;
}
}
Expand Down
36 changes: 33 additions & 3 deletions test/sim/abilities/protosynthesis.js
Expand Up @@ -77,16 +77,46 @@ describe('Protosynthesis', function () {
assert.equal(tail.volatiles['protosynthesis'].bestStat, 'spd', `Scream Tail's SpD should have been boosted by Protosynthesis in Sun while holding Utility Umbrella`);
});

it(`should not be prevented from activating by weather suppressing abilities`, function () {
it(`should not be deactiviated by weather suppressing abilities`, function () {
battle = common.createBattle([[
{species: 'Scream Tail', ability: 'protosynthesis', moves: ['splash']},
], [
{species: 'Altaria', ability: 'cloudnine', moves: ['sunnyday']},
{species: 'Torkoal', ability: 'drought', moves: ['splash']},
{species: 'Psyduck', ability: 'cloudnine', moves: ['splash']},
]]);

const tail = battle.p1.active[0];
battle.makeChoices('move splash', 'switch 2');

assert.equal(tail.volatiles['protosynthesis'].bestStat, 'spd', `Scream Tail's SpD should have remained boosted by Protosynthesis in Sun even though a weather supressing ability was activated`);
});

it(`should not activate if weather is suppressed`, function () {
battle = common.createBattle([[
{species: 'Scream Tail', ability: 'protosynthesis', moves: ['splash']},
], [
{species: 'Psyduck', ability: 'cloudnine', moves: ['sunnyday']},
]]);

const tail = battle.p1.active[0];
battle.makeChoices('move splash', 'move sunnyday');

assert.equal(tail.volatiles['protosynthesis'], undefined, `Scream Tail should not have been boosted by Protosynthesis because a weather supressing ability was active when Sun started`);
});

it(`should activate when weather supression ends`, function () {
battle = common.createBattle([[
{species: 'Scream Tail', ability: 'protosynthesis', moves: ['splash']},
], [
{species: 'Psyduck', ability: 'cloudnine', moves: ['sunnyday']},
{species: 'Lotad', ability: 'swiftswim', moves: ['splash']},
]]);

const tail = battle.p1.active[0];
battle.makeChoices('move splash', 'move sunnyday');
assert.equal(tail.volatiles['protosynthesis'].bestStat, 'spd', `Scream Tail's SpD should have been boosted by Protosynthesis in Sun even though a weather supressing ability was active`);
battle.makeChoices('move splash', 'switch 2');

assert.equal(tail.volatiles['protosynthesis'].bestStat, 'spd', `Scream Tail should have been boosted by Protosynthesis because a weather supressing ability ended while Sun was active`);
});

it(`should have its boost nullified by Neutralizing Gas`, function () {
Expand Down

0 comments on commit c2a033b

Please sign in to comment.