mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-21 07:42:25 +02:00
Update PreSwitchOut
This commit is contained in:
parent
cf4166d0d6
commit
e65ae7dfe4
@ -2667,23 +2667,27 @@ 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 {
|
||||||
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
|
willSucceedPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
|
||||||
if (pokemon.status) {
|
return !Utils.isNullOrUndefined(pokemon.status);
|
||||||
if (!simulated) {
|
}
|
||||||
pokemon.resetStatus();
|
|
||||||
pokemon.updateInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
|
||||||
|
if (!simulated) {
|
||||||
|
pokemon.resetStatus();
|
||||||
|
pokemon.updateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2691,6 +2695,37 @@ export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr {
|
|||||||
* 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,57 +2734,26 @@ 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 {
|
||||||
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
|
willSucceedPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean {
|
||||||
if (!pokemon.isFullHp()) {
|
return !pokemon.isFullHp();
|
||||||
if (!simulated) {
|
}
|
||||||
const healAmount = Utils.toDmgValue(pokemon.getMaxHp() * 0.33);
|
|
||||||
pokemon.heal(healAmount);
|
|
||||||
pokemon.updateInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
applyPreSwitchOut(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise<boolean> {
|
||||||
|
if (!simulated) {
|
||||||
|
const healAmount = Utils.toDmgValue(pokemon.getMaxHp() * 0.33);
|
||||||
|
pokemon.heal(healAmount);
|
||||||
|
pokemon.updateInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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,15 +2783,10 @@ 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 (!simulated) {
|
||||||
if (formIndex !== pokemon.formIndex) {
|
globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeAbilityTrigger, false);
|
||||||
if (!simulated) {
|
|
||||||
globalScene.triggerPokemonFormChange(pokemon, SpeciesFormChangeAbilityTrigger, false);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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>,
|
||||||
|
Loading…
Reference in New Issue
Block a user