Updated ForceSwitchOutAttr

Should fix issue #83
This commit is contained in:
EmoUsedHM01 2024-04-11 19:29:08 +01:00 committed by GitHub
parent 2c38849aa1
commit f0c2e62883
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,7 +12,7 @@ import * as Utils from "../utils";
import { WeatherType } from "./weather";
import { ArenaTagSide, ArenaTrapTag } from "./arena-tag";
import { ArenaTagType } from "./enums/arena-tag-type";
import { ProtectAbilityAbAttr, BlockRecoilDamageAttr, BlockOneHitKOAbAttr, IgnoreContactAbAttr, MaxMultiHitAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr, applyPreSwitchOutAbAttrs, PreSwitchOutAbAttr } from "./ability";
import { ProtectAbilityAbAttr, BlockRecoilDamageAttr, BlockOneHitKOAbAttr, IgnoreContactAbAttr, MaxMultiHitAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr, applyPreSwitchOutAbAttrs, PreSwitchOutAbAttr, PostDefendContactApplyStatusEffectAbAttr } from "./ability";
import { Abilities } from "./enums/abilities";
import { PokemonHeldItemModifier } from "../modifier/modifier";
import { BattlerIndex } from "../battle";
@ -2469,25 +2469,38 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
constructor(user?: boolean, batonPass?: boolean) {
super(false, MoveEffectTrigger.HIT, true);
this.user = !!user;
this.batonPass = !!batonPass;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
return new Promise(resolve => {
if (move.category !== MoveCategory.STATUS && !this.getSwitchOutCondition()(user, target, move))
// Check if the move category is not STATUS or if the switch out condition is not met
if (move.category !== MoveCategory.STATUS && !this.getSwitchOutCondition()(user, target, move)) {
// Apply effects that need to be executed before switch out
// For example, applying poison or any other status condition
this.applyEffectsBeforeSwitchOut(user, target, move);
// Resolve the Promise after the switch out is complete
return resolve(false);
}
// Move the switch out logic inside the conditional block
// This ensures that the switch out only happens when the conditions are met
const switchOutTarget = this.user ? user : target;
if (switchOutTarget instanceof PlayerPokemon) {
// Switch out logic for PlayerPokemon
// This includes applying any necessary effects before switching out
if (switchOutTarget.hp) {
applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, switchOutTarget);
(switchOutTarget as PlayerPokemon).switchOut(this.batonPass, true).then(() => resolve(true));
}
else
else {
resolve(false);
}
return;
} else if (user.scene.currentBattle.battleType) {
}
else if (user.scene.currentBattle.battleType) {
// Switch out logic for the battle type
switchOutTarget.resetTurnData();
switchOutTarget.resetSummonData();
switchOutTarget.hideInfo();
@ -2497,7 +2510,9 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
if (switchOutTarget.hp)
user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, switchOutTarget.getFieldIndex(), user.scene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot), false, this.batonPass, false));
} else {
}
else {
// Switch out logic for everything else
switchOutTarget.setVisible(false);
if (switchOutTarget.hp) {
@ -2520,6 +2535,15 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
});
}
// Function to apply any effects to the user/target before switching out
applyEffectsBeforeSwitchOut(user: Pokemon, target: Pokemon, move: Move) {
// Create an instance of PostDefendContactApplyStatusEffectAbAttr
const postDefendAttr = new PostDefendContactApplyStatusEffectAbAttr();
// Apply the effects based on the logic in PostDefendContactApplyStatusEffectAbAttr
postDefendAttr.applyPostDefend(user, target, move);
}
getCondition(): MoveConditionFunc {
return (user, target, move) => move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move);
}