Skip to content

Commit

Permalink
Update PreLeaveFieldAbAttr
Browse files Browse the repository at this point in the history
  • Loading branch information
emdeann committed Feb 7, 2025
1 parent 8c82ced commit 574d181
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src/data/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2791,6 +2791,10 @@ export class PreSwitchOutFormChangeAbAttr extends PreSwitchOutAbAttr {
}

export class PreLeaveFieldAbAttr extends AbAttr {
canApplyPreLeaveField(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
return true;
}

applyPreLeaveField(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
return false;
}
Expand All @@ -2800,48 +2804,46 @@ export class PreLeaveFieldAbAttr extends AbAttr {
* Clears Desolate Land/Primordial Sea/Delta Stream upon the Pokemon switching out.
*/
export class PreLeaveFieldClearWeatherAbAttr extends PreLeaveFieldAbAttr {
/**
* @param pokemon The {@linkcode Pokemon} with the ability
* @param passive N/A
* @param args N/A
* @returns Returns `true` if the weather clears, otherwise `false`.
*/
applyPreLeaveField(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
const weatherType = globalScene.arena.weather?.weatherType;
let turnOffWeather = false;
private turnOffWeather: boolean;

canApplyPreLeaveField(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
this.turnOffWeather = false;
const weatherType = globalScene.arena.weather?.weatherType;
// 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)
&& globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DESOLATE_LAND)).length === 0) {
turnOffWeather = true;
return true;
}
break;
case (WeatherType.HEAVY_RAIN):
if (pokemon.hasAbility(Abilities.PRIMORDIAL_SEA)
&& globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.PRIMORDIAL_SEA)).length === 0) {
turnOffWeather = true;
return true;
}
break;
case (WeatherType.STRONG_WINDS):
if (pokemon.hasAbility(Abilities.DELTA_STREAM)
&& globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) {
turnOffWeather = true;
return true;
}
break;
}
return false;
}

if (simulated) {
return turnOffWeather;
}

if (turnOffWeather) {
/**
* @param pokemon The {@linkcode Pokemon} with the ability
* @param passive N/A
* @param args N/A
* @returns Returns `true` if the weather clears, otherwise `false`.
*/
applyPreLeaveField(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
if (!simulated) {
globalScene.arena.trySetWeather(WeatherType.NONE, false);
return true;
}

return false;
return true;
}
}

Expand Down Expand Up @@ -5396,7 +5398,8 @@ export function applyPreSwitchOutAbAttrs(attrType: Constructor<PreSwitchOutAbAtt

export function applyPreLeaveFieldAbAttrs(attrType: Constructor<PreLeaveFieldAbAttr>,
pokemon: Pokemon, simulated: boolean = false, ...args: any[]): Promise<void> {
return applyAbAttrsInternal<PreLeaveFieldAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreLeaveField(pokemon, passive, simulated, args), args, true, simulated);
return applyAbAttrsInternal<PreLeaveFieldAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreLeaveField(pokemon, passive, simulated, args),
(attr, passive) => attr.canApplyPreLeaveField(pokemon, passive, simulated, args), args, true, simulated);
}

export function applyPreStatStageChangeAbAttrs(attrType: Constructor<PreStatStageChangeAbAttr>,
Expand Down

0 comments on commit 574d181

Please sign in to comment.