From d06e5d2fc68427f699365f68ebd7357e582c1d91 Mon Sep 17 00:00:00 2001 From: Xavion3 Date: Sun, 9 Jun 2024 22:37:33 +1000 Subject: [PATCH] Fix doubles battles bugs with challenges (#1986) * Fix doubles battles bugs with challenges * Make a fully illegal party gameover instead of error --- src/field/trainer.ts | 2 +- src/phases.ts | 10 +++++++--- src/ui/party-ui-handler.ts | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/field/trainer.ts b/src/field/trainer.ts index 5a86d5c4502..940929cc79a 100644 --- a/src/field/trainer.ts +++ b/src/field/trainer.ts @@ -426,7 +426,7 @@ export default class Trainer extends Phaser.GameObjects.Container { const party = this.scene.getEnemyParty(); const nonFaintedPartyMembers = party.slice(this.scene.currentBattle.getBattlerCount()).filter(p => !p.isFainted()).filter(p => !trainerSlot || p.trainerSlot === trainerSlot); const partyMemberScores = nonFaintedPartyMembers.map(p => { - const playerField = this.scene.getPlayerField(); + const playerField = this.scene.getPlayerField().filter(p => p.isActive(true)); let score = 0; for (const playerPokemon of playerField) { score += p.getMatchupScore(playerPokemon); diff --git a/src/phases.ts b/src/phases.ts index f83f90a626b..d5e64ebae2d 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -1336,7 +1336,11 @@ export class SummonPhase extends PartyMemberPokemonPhase { const legalIndex = party.findIndex((p, i) => i > this.partyMemberIndex && p.isAllowedInBattle()); if (legalIndex === -1) { console.error("Party Details:\n", party); - throw new Error("All available Pokemon were fainted or illegal!"); + console.error("All available Pokemon were fainted or illegal!"); + this.scene.clearPhaseQueue(); + this.scene.unshiftPhase(new GameOverPhase(this.scene)); + this.end(); + return; } // Swaps the fainted Pokemon and the first non-fainted legal Pokemon in the party @@ -4291,12 +4295,12 @@ export class SwitchPhase extends BattlePhase { super.start(); // Skip modal switch if impossible - if (this.isModal && !this.scene.getParty().filter(p => !p.isAllowedInBattle() && !p.isActive(true)).length) { + if (this.isModal && !this.scene.getParty().filter(p => p.isAllowedInBattle() && !p.isActive(true)).length) { return super.end(); } // Check if there is any space still in field - if (this.isModal && this.scene.getPlayerField().filter(p => !p.isAllowedInBattle() && p.isActive(true)).length >= this.scene.currentBattle.getBattlerCount()) { + if (this.isModal && this.scene.getPlayerField().filter(p => p.isAllowedInBattle() && p.isActive(true)).length >= this.scene.currentBattle.getBattlerCount()) { return super.end(); } diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 9192ffc47bc..d965345d3de 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -388,7 +388,7 @@ export default class PartyUiHandler extends MessageUiHandler { } else if (option === PartyOption.RELEASE) { this.clearOptions(); ui.playSelect(); - if (this.cursor >= this.scene.currentBattle.getBattlerCount()) { + if (this.cursor >= this.scene.currentBattle.getBattlerCount() || !pokemon.isAllowedInBattle()) { this.showText(`Do you really want to release ${pokemon.name}?`, null, () => { ui.setModeWithoutClear(Mode.CONFIRM, () => { ui.setMode(Mode.PARTY);