[Bug] fixed switch out bug when fainted single -> double (#3288)

Mirror of PR #1333. Thanks to 0zuzu (https://github.com/0zuzu) for providing the original fix.

Co-authored-by: 0zuzu <63069680+0zuzu@users.noreply.github.com>
This commit is contained in:
flx-sta 2024-08-01 19:10:43 -07:00 committed by GitHub
parent 17cc8b5c5e
commit 89d38a3b6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -4449,9 +4449,10 @@ export class SwitchPhase extends BattlePhase {
start() { start() {
super.start(); super.start();
const availablePartyMembers = this.scene.getParty().filter(p => !p.isFainted());
// Skip modal switch if impossible // Skip modal switch if impossible
if (this.isModal && !this.scene.getParty().filter(p => p.isAllowedInBattle() && !p.isActive(true)).length) { if (this.isModal && (!availablePartyMembers.filter(p => !p.isActive(true)).length || (!this.scene.currentBattle.started && availablePartyMembers.length === 1))) {
return super.end(); return super.end();
} }
@ -4461,7 +4462,7 @@ export class SwitchPhase extends BattlePhase {
} }
// Override field index to 0 in case of double battle where 2/3 remaining legal party members fainted at once // Override field index to 0 in case of double battle where 2/3 remaining legal party members fainted at once
const fieldIndex = this.scene.currentBattle.getBattlerCount() === 1 || this.scene.getParty().filter(p => p.isAllowedInBattle()).length > 1 ? this.fieldIndex : 0; const fieldIndex = this.scene.currentBattle.getBattlerCount() === 1 || availablePartyMembers.length > 1 ? this.fieldIndex : 0;
this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, fieldIndex, (slotIndex: integer, option: PartyOption) => { this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.FAINT_SWITCH : PartyUiMode.POST_BATTLE_SWITCH, fieldIndex, (slotIndex: integer, option: PartyOption) => {
if (slotIndex >= this.scene.currentBattle.getBattlerCount() && slotIndex < 6) { if (slotIndex >= this.scene.currentBattle.getBattlerCount() && slotIndex < 6) {