Fix conditionals checking SwitchType

Use `prependToPhase()` instead of `unshiftPhase()`
This commit is contained in:
NightKev 2024-11-15 19:34:51 -08:00
parent 656a51bcc8
commit 8d1cbfb2c5
2 changed files with 59 additions and 39 deletions

View File

@ -5979,10 +5979,11 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
return false;
}
if (switchOutTarget.hp && SwitchType.FORCE_SWITCH) {
switchOutTarget.leaveField(this.switchType === SwitchType.FORCE_SWITCH);
if (switchOutTarget.hp > 0) {
if (this.switchType === SwitchType.FORCE_SWITCH) {
switchOutTarget.leaveField(true);
const slotIndex = Utils.randIntRange(user.scene.currentBattle.getBattlerCount(), user.scene.getPlayerParty().length);
user.scene.unshiftPhase(
user.scene.prependToPhase(
new SwitchSummonPhase(
user.scene,
this.switchType,
@ -5990,24 +5991,35 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
slotIndex,
false,
true
)
),
MoveEndPhase
);
}
if (switchOutTarget.hp > 0 && !SwitchType.FORCE_SWITCH) {
} else {
switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH);
user.scene.prependToPhase(new SwitchPhase(user.scene, this.switchType, switchOutTarget.getFieldIndex(), true, true), MoveEndPhase);
user.scene.prependToPhase(
new SwitchPhase(
user.scene,
this.switchType,
switchOutTarget.getFieldIndex(),
true,
true
),
MoveEndPhase
);
return true;
}
}
return false;
} else if (user.scene.currentBattle.battleType !== BattleType.WILD) {
// Switch out logic for trainer battles
if (switchOutTarget.scene.getEnemyParty().filter((p) => p.isAllowedInBattle() && !p.isOnField()).length < 1) {
return false;
}
if (switchOutTarget.hp && SwitchType.FORCE_SWITCH) {
switchOutTarget.leaveField(this.switchType === SwitchType.FORCE_SWITCH);
if (switchOutTarget.hp > 0) {
if (this.switchType === SwitchType.FORCE_SWITCH) {
switchOutTarget.leaveField(true);
const slotIndex = Utils.randIntRange(user.scene.currentBattle.getBattlerCount(), user.scene.getEnemyParty().length);
user.scene.unshiftPhase(
user.scene.prependToPhase(
new SwitchSummonPhase(
user.scene,
this.switchType,
@ -6015,15 +6027,24 @@ export class ForceSwitchOutAttr extends MoveEffectAttr {
slotIndex,
false,
false
)
),
MoveEndPhase
);
}
if (switchOutTarget.hp > 0 && !SwitchType.FORCE_SWITCH) {
} else {
// for opponent switching out
switchOutTarget.leaveField(this.switchType === SwitchType.SWITCH);
user.scene.prependToPhase(new SwitchSummonPhase(user.scene, this.switchType, switchOutTarget.getFieldIndex(),
user.scene.prependToPhase(
new SwitchSummonPhase(
user.scene,
this.switchType,
switchOutTarget.getFieldIndex(),
(user.scene.currentBattle.trainer ? user.scene.currentBattle.trainer.getNextSummonIndex((switchOutTarget as EnemyPokemon).trainerSlot) : 0),
false, false), MoveEndPhase);
false,
false
),
MoveEndPhase
);
}
}
} else {
/**

View File

@ -12,6 +12,5 @@ export enum SwitchType {
/** Transfers the returning Pokemon's Substitute to the switched in Pokemon */
SHED_TAIL,
/** Force switchout to a random party member */
FORCE_SWITCH
FORCE_SWITCH,
}