Fix crashing on faint in double battles

pull/2/head
Flashfyre 2023-07-04 18:27:07 -04:00
parent 2cb718de94
commit 10b49b5dcb
2 changed files with 6 additions and 8 deletions

View File

@ -78,7 +78,6 @@ export class CheckLoadPhase extends BattlePhase {
this.scene.pushPhase(new SummonPhase(this.scene, 0)); this.scene.pushPhase(new SummonPhase(this.scene, 0));
if (this.scene.currentBattle.double && this.scene.getParty().filter(p => !p.isFainted()).length > 1) if (this.scene.currentBattle.double && this.scene.getParty().filter(p => !p.isFainted()).length > 1)
this.scene.pushPhase(new SummonPhase(this.scene, 1)); this.scene.pushPhase(new SummonPhase(this.scene, 1));
this.scene.getEnemyField().map(p => this.scene.pushPhase(new PostSummonPhase(this.scene, p.getBattlerIndex())));
super.end(); super.end();
} }
@ -277,7 +276,7 @@ export class EncounterPhase extends BattlePhase {
this.scene.unshiftPhase(new ShinySparklePhase(this.scene, BattlerIndex.ENEMY + e)); this.scene.unshiftPhase(new ShinySparklePhase(this.scene, BattlerIndex.ENEMY + e));
}); });
enemyField.forEach(enemyPokemon => this.scene.arena.applyTags(ArenaTrapTag, enemyPokemon)); enemyField.map(p => this.scene.pushPhase(new PostSummonPhase(this.scene, p.getBattlerIndex())));
// TODO: Remove // TODO: Remove
//this.scene.unshiftPhase(new SelectModifierPhase(this.scene)); //this.scene.unshiftPhase(new SelectModifierPhase(this.scene));
@ -1779,7 +1778,7 @@ export class FaintPhase extends PokemonPhase {
this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex)); this.scene.unshiftPhase(new VictoryPhase(this.scene, this.battlerIndex));
pokemon.lapseTags(BattlerTagLapseType.FAINT); pokemon.lapseTags(BattlerTagLapseType.FAINT);
this.scene.getField().filter(p => p && p !== pokemon).forEach(p => p.removeTagsBySourceId(pokemon.id)); this.scene.getField().filter(p => p !== pokemon && p?.isActive(true)).forEach(p => p.removeTagsBySourceId(pokemon.id));
pokemon.faintCry(() => { pokemon.faintCry(() => {
pokemon.hideInfo(); pokemon.hideInfo();

View File

@ -515,7 +515,7 @@ export default class BattleScene extends Phaser.Scene {
let newDouble: boolean; let newDouble: boolean;
if (double === undefined) { if (double === undefined) {
const doubleChance = new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8); const doubleChance = newWaveIndex > 1 && new Utils.IntegerHolder(newWaveIndex % 10 === 0 ? 32 : 8);
this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance); this.applyModifiers(DoubleBattleChanceBoosterModifier, true, doubleChance);
this.getPlayerField().forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, doubleChance)); this.getPlayerField().forEach(p => applyAbAttrs(DoubleBattleChanceAbAttr, p, null, doubleChance));
newDouble = !Utils.randInt(doubleChance.value); newDouble = !Utils.randInt(doubleChance.value);
@ -549,9 +549,10 @@ export default class BattleScene extends Phaser.Scene {
if ((lastBattle?.double || false) !== newDouble) { if ((lastBattle?.double || false) !== newDouble) {
const availablePartyMemberCount = this.getParty().filter(p => !p.isFainted()).length; const availablePartyMemberCount = this.getParty().filter(p => !p.isFainted()).length;
if (newDouble) { if (newDouble) {
this.pushPhase(new ToggleDoublePositionPhase(this, true)); if (availablePartyMemberCount > 1) {
if (availablePartyMemberCount > 1) this.pushPhase(new ToggleDoublePositionPhase(this, true));
this.pushPhase(new SummonPhase(this, 1)); this.pushPhase(new SummonPhase(this, 1));
}
} else { } else {
if (availablePartyMemberCount > 1) if (availablePartyMemberCount > 1)
this.pushPhase(new ReturnPhase(this, 1)); this.pushPhase(new ReturnPhase(this, 1));
@ -564,8 +565,6 @@ export default class BattleScene extends Phaser.Scene {
if (newDouble) if (newDouble)
this.pushPhase(new CheckSwitchPhase(this, 1, newDouble)); this.pushPhase(new CheckSwitchPhase(this, 1, newDouble));
} }
this.getField().filter(p => p?.isActive(true)).map(p => this.pushPhase(new PostSummonPhase(this, p.getBattlerIndex())));
} }
return this.currentBattle; return this.currentBattle;