Updated ForceSwitchOutAttr (#90)
* Updated ForceSwitchOutAttr Should fix issue #83 * Removed the additional indents * Updated the import and fixed the ForceSwitchOutAttr coding errors * Removed the rest of the indents * Updated formattingpull/101/head
parent
20b6612cd1
commit
fba98ffa0c
113
src/data/move.ts
113
src/data/move.ts
|
@ -12,7 +12,7 @@ import * as Utils from "../utils";
|
||||||
import { WeatherType } from "./weather";
|
import { WeatherType } from "./weather";
|
||||||
import { ArenaTagSide, ArenaTrapTag } from "./arena-tag";
|
import { ArenaTagSide, ArenaTrapTag } from "./arena-tag";
|
||||||
import { ArenaTagType } from "./enums/arena-tag-type";
|
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, applyPostDefendAbAttrs, PostDefendContactApplyStatusEffectAbAttr } from "./ability";
|
||||||
import { Abilities } from "./enums/abilities";
|
import { Abilities } from "./enums/abilities";
|
||||||
import { PokemonHeldItemModifier } from "../modifier/modifier";
|
import { PokemonHeldItemModifier } from "../modifier/modifier";
|
||||||
import { BattlerIndex } from "../battle";
|
import { BattlerIndex } from "../battle";
|
||||||
|
@ -2500,61 +2500,76 @@ export class AddArenaTrapTagAttr extends AddArenaTagAttr {
|
||||||
export class ForceSwitchOutAttr extends MoveEffectAttr {
|
export class ForceSwitchOutAttr extends MoveEffectAttr {
|
||||||
private user: boolean;
|
private user: boolean;
|
||||||
private batonPass: boolean;
|
private batonPass: boolean;
|
||||||
|
|
||||||
constructor(user?: boolean, batonPass?: boolean) {
|
constructor(user?: boolean, batonPass?: boolean) {
|
||||||
super(false, MoveEffectTrigger.HIT, true);
|
super(false, MoveEffectTrigger.HIT, true);
|
||||||
|
|
||||||
this.user = !!user;
|
this.user = !!user;
|
||||||
this.batonPass = !!batonPass;
|
this.batonPass = !!batonPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
|
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
|
||||||
return new Promise(resolve => {
|
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
|
||||||
return resolve(false);
|
if (move.category !== MoveCategory.STATUS && !this.getSwitchOutCondition()(user, target, move)) {
|
||||||
const switchOutTarget = this.user ? user : target;
|
//Apply effects that need to be executed before switch out
|
||||||
if (switchOutTarget instanceof PlayerPokemon) {
|
//For example, applying poison or any other status condition
|
||||||
if (switchOutTarget.hp) {
|
applyPostDefendAbAttrs(PostDefendContactApplyStatusEffectAbAttr, target, user, move);
|
||||||
applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, switchOutTarget);
|
//Resolve the Promise after the switch out is complete
|
||||||
(switchOutTarget as PlayerPokemon).switchOut(this.batonPass, true).then(() => resolve(true));
|
return resolve(false);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
resolve(false);
|
// Move the switch out logic inside the conditional block
|
||||||
return;
|
// This ensures that the switch out only happens when the conditions are met
|
||||||
} else if (user.scene.currentBattle.battleType) {
|
const switchOutTarget = this.user ? user : target;
|
||||||
switchOutTarget.resetTurnData();
|
if (switchOutTarget instanceof PlayerPokemon) {
|
||||||
switchOutTarget.resetSummonData();
|
// Switch out logic for PlayerPokemon
|
||||||
switchOutTarget.hideInfo();
|
// This includes applying any necessary effects before switching out
|
||||||
switchOutTarget.setVisible(false);
|
if (switchOutTarget.hp) {
|
||||||
switchOutTarget.scene.field.remove(switchOutTarget);
|
applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, switchOutTarget);
|
||||||
user.scene.triggerPokemonFormChange(switchOutTarget, SpeciesFormChangeActiveTrigger, true);
|
(switchOutTarget as PlayerPokemon).switchOut(this.batonPass, true).then(() => resolve(true));
|
||||||
|
}
|
||||||
if (switchOutTarget.hp)
|
else {
|
||||||
user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, switchOutTarget.getFieldIndex(), user.scene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot), false, this.batonPass, false));
|
resolve(false);
|
||||||
} else {
|
}
|
||||||
switchOutTarget.setVisible(false);
|
return;
|
||||||
|
}
|
||||||
if (switchOutTarget.hp) {
|
else if (user.scene.currentBattle.battleType) {
|
||||||
switchOutTarget.hideInfo().then(() => switchOutTarget.destroy());
|
// Switch out logic for the battle type
|
||||||
switchOutTarget.scene.field.remove(switchOutTarget);
|
switchOutTarget.resetTurnData();
|
||||||
user.scene.queueMessage(getPokemonMessage(switchOutTarget, ' fled!'), null, true, 500);
|
switchOutTarget.resetSummonData();
|
||||||
}
|
switchOutTarget.hideInfo();
|
||||||
|
switchOutTarget.setVisible(false);
|
||||||
if (!switchOutTarget.getAlly()?.isActive(true)) {
|
switchOutTarget.scene.field.remove(switchOutTarget);
|
||||||
user.scene.clearEnemyHeldItemModifiers();
|
user.scene.triggerPokemonFormChange(switchOutTarget, SpeciesFormChangeActiveTrigger, true);
|
||||||
|
|
||||||
if (switchOutTarget.hp) {
|
if (switchOutTarget.hp)
|
||||||
user.scene.pushPhase(new BattleEndPhase(user.scene));
|
user.scene.unshiftPhase(new SwitchSummonPhase(user.scene, switchOutTarget.getFieldIndex(), user.scene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot), false, this.batonPass, false));
|
||||||
user.scene.pushPhase(new NewBattlePhase(user.scene));
|
}
|
||||||
}
|
else {
|
||||||
}
|
// Switch out logic for everything else
|
||||||
}
|
switchOutTarget.setVisible(false);
|
||||||
|
|
||||||
resolve(true);
|
if (switchOutTarget.hp) {
|
||||||
});
|
switchOutTarget.hideInfo().then(() => switchOutTarget.destroy());
|
||||||
}
|
switchOutTarget.scene.field.remove(switchOutTarget);
|
||||||
|
user.scene.queueMessage(getPokemonMessage(switchOutTarget, ' fled!'), null, true, 500);
|
||||||
getCondition(): MoveConditionFunc {
|
}
|
||||||
|
|
||||||
|
if (!switchOutTarget.getAlly()?.isActive(true)) {
|
||||||
|
user.scene.clearEnemyHeldItemModifiers();
|
||||||
|
|
||||||
|
if (switchOutTarget.hp) {
|
||||||
|
user.scene.pushPhase(new BattleEndPhase(user.scene));
|
||||||
|
user.scene.pushPhase(new NewBattlePhase(user.scene));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getCondition(): MoveConditionFunc {
|
||||||
return (user, target, move) => move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move);
|
return (user, target, move) => move.category !== MoveCategory.STATUS || this.getSwitchOutCondition()(user, target, move);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue