Update PreSwitchOut

This commit is contained in:
Dean 2025-02-01 21:36:26 -08:00
parent cf4166d0d6
commit e65ae7dfe4

View File

@ -2667,14 +2667,21 @@ export class PreSwitchOutAbAttr extends AbAttr {
super(true); super(true);
} }
willSucceedPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
return true;
}
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> { applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
return false; return false;
} }
} }
export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr { export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr {
willSucceedPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
return !Utils.isNullOrUndefined(pokemon.status);
}
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> { applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
if (pokemon.status) {
if (!simulated) { if (!simulated) {
pokemon.resetStatus(); pokemon.resetStatus();
pokemon.updateInfo(); pokemon.updateInfo();
@ -2682,15 +2689,43 @@ export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr {
return true; return true;
} }
return false;
}
} }
/** /**
* Clears Desolate Land/Primordial Sea/Delta Stream upon the Pokemon switching out. * Clears Desolate Land/Primordial Sea/Delta Stream upon the Pokemon switching out.
*/ */
export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr { export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr {
private turnOffWeather: boolean;
willSucceedPreSwitchOut(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) {
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) {
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) {
return true;
}
break;
}
return false;
}
/** /**
* @param pokemon The {@linkcode Pokemon} with the ability * @param pokemon The {@linkcode Pokemon} with the ability
@ -2699,47 +2734,19 @@ export class PreSwitchOutClearWeatherAbAttr extends PreSwitchOutAbAttr {
* @returns {boolean} Returns true if the weather clears, otherwise false. * @returns {boolean} Returns true if the weather clears, otherwise false.
*/ */
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> { applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
const weatherType = globalScene.arena.weather?.weatherType; if (!simulated) {
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)
&& globalScene.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)
&& globalScene.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)
&& globalScene.getField(true).filter(p => p !== pokemon).filter(p => p.hasAbility(Abilities.DELTA_STREAM)).length === 0) {
turnOffWeather = true;
}
break;
}
if (simulated) {
return turnOffWeather;
}
if (turnOffWeather) {
globalScene.arena.trySetWeather(WeatherType.NONE, false); globalScene.arena.trySetWeather(WeatherType.NONE, false);
return true;
} }
return true;
return false;
} }
} }
export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr { export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr {
willSucceedPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
return !pokemon.isFullHp();
}
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> { applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
if (!pokemon.isFullHp()) {
if (!simulated) { if (!simulated) {
const healAmount = Utils.toDmgValue(pokemon.getMaxHp() * 0.33); const healAmount = Utils.toDmgValue(pokemon.getMaxHp() * 0.33);
pokemon.heal(healAmount); pokemon.heal(healAmount);
@ -2748,9 +2755,6 @@ export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr {
return true; return true;
} }
return false;
}
} }
/** /**
@ -2767,6 +2771,10 @@ export class PreSwitchOutFormChangeAbAttr extends PreSwitchOutAbAttr {
this.formFunc = formFunc; this.formFunc = formFunc;
} }
willSucceedPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
return this.formFunc(pokemon) !== pokemon.formIndex;
}
/** /**
* On switch out, trigger the form change to the one defined in the ability * On switch out, trigger the form change to the one defined in the ability
* @param pokemon The pokemon switching out and changing form {@linkcode Pokemon} * @param pokemon The pokemon switching out and changing form {@linkcode Pokemon}
@ -2775,17 +2783,12 @@ export class PreSwitchOutFormChangeAbAttr extends PreSwitchOutAbAttr {
* @returns true if the form change was successful * @returns true if the form change was successful
*/ */
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> { applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
const formIndex = this.formFunc(pokemon);
if (formIndex !== pokemon.formIndex) {
if (!simulated) { if (!simulated) {
globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeAbilityTrigger, false); globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeAbilityTrigger, false);
} }
return true; return true;
} }
return false;
}
} }
export class PreStatStageChangeAbAttr extends AbAttr { export class PreStatStageChangeAbAttr extends AbAttr {
@ -5313,7 +5316,8 @@ export function applyPostSummonAbAttrs(attrType: Constructor<PostSummonAbAttr>,
export function applyPreSwitchOutAbAttrs(attrType: Constructor<PreSwitchOutAbAttr>, export function applyPreSwitchOutAbAttrs(attrType: Constructor<PreSwitchOutAbAttr>,
pokemon: Pokemon, simulated: boolean = false, ...args: any[]): Promise<void> { pokemon: Pokemon, simulated: boolean = false, ...args: any[]): Promise<void> {
return applyAbAttrsInternal<PreSwitchOutAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreSwitchOut(pokemon, passive, simulated, args), args, true, simulated); return applyAbAttrsInternal<PreSwitchOutAbAttr>(attrType, pokemon, (attr, passive) => attr.applyPreSwitchOut(pokemon, passive, simulated, args),
(attr, passive) => attr.willSucceedPreSwitchOut(pokemon, passive, simulated, args), args, true, simulated);
} }
export function applyPreStatStageChangeAbAttrs(attrType: Constructor<PreStatStageChangeAbAttr>, export function applyPreStatStageChangeAbAttrs(attrType: Constructor<PreStatStageChangeAbAttr>,