Fix doubles battles bugs with challenges (#1986)

* Fix doubles battles bugs with challenges

* Make a fully illegal party gameover instead of error
This commit is contained in:
Xavion3 2024-06-09 22:37:33 +10:00 committed by GitHub
parent c1405c7fd6
commit d06e5d2fc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View File

@ -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);

View File

@ -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();
}

View File

@ -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);