From fbcd372068ac3177233fe836fa793492cb06f9bc Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Sat, 2 Dec 2023 10:30:23 -0500 Subject: [PATCH] Refactor logic for summons and returns --- src/battle-phases.ts | 48 +++++++++++++++++++++++++++++++++++--------- src/battle-scene.ts | 40 +++++------------------------------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index 9320c75e1..893e8be5a 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -34,7 +34,6 @@ import { Species } from "./data/species"; import { HealAchv, LevelAchv, MoneyAchv, achvs } from "./system/achv"; import { DexEntry } from "./system/game-data"; import { pokemonPrevolutions } from "./data/pokemon-evolutions"; -import { getPokemonSpecies } from "./data/pokemon-species"; export class CheckLoadPhase extends BattlePhase { private loaded: boolean; @@ -79,16 +78,19 @@ export class CheckLoadPhase extends BattlePhase { } else this.scene.playBgm(); - const availablePartyMembers = this.scene.getParty().filter(p => !p.isFainted()).length; - this.scene.pushPhase(new EncounterPhase(this.scene, this.loaded)); - this.scene.pushPhase(new SummonPhase(this.scene, 0)); - if (this.scene.currentBattle.double && availablePartyMembers > 1) - this.scene.pushPhase(new SummonPhase(this.scene, 1)); - if (this.scene.currentBattle.waveIndex > 1 && this.scene.currentBattle.battleType !== BattleType.TRAINER) { - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); + + if (this.loaded) { + const availablePartyMembers = this.scene.getParty().filter(p => !p.isFainted()).length; + + this.scene.pushPhase(new SummonPhase(this.scene, 0)); if (this.scene.currentBattle.double && availablePartyMembers > 1) - this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + this.scene.pushPhase(new SummonPhase(this.scene, 1)); + if (this.scene.currentBattle.waveIndex > 1 && this.scene.currentBattle.battleType !== BattleType.TRAINER) { + this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); + if (this.scene.currentBattle.double && availablePartyMembers > 1) + this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + } } super.end(); @@ -370,8 +372,9 @@ export class EncounterPhase extends BattlePhase { ease: 'Sine.easeInOut', duration: 750 }); + const availablePartyMembers = this.scene.getEnemyParty().filter(p => !p.isFainted()).length; this.scene.unshiftPhase(new SummonPhase(this.scene, 0, false)); - if (this.scene.currentBattle.double) + if (this.scene.currentBattle.double && availablePartyMembers > 1) this.scene.unshiftPhase(new SummonPhase(this.scene, 1, false)); this.end(); }, 1500, true); @@ -407,6 +410,31 @@ export class EncounterPhase extends BattlePhase { if (ivScannerModifier) enemyField.map(p => this.scene.pushPhase(new ScanIvsPhase(this.scene, p.getBattlerIndex(), Math.min(ivScannerModifier.getStackCount(), 6)))); } + + if (!this.loaded) { + const availablePartyMembers = this.scene.getParty().filter(p => !p.isFainted()); + + if (!availablePartyMembers[0].isOnField()) + this.scene.pushPhase(new SummonPhase(this.scene, 0)); + + if (this.scene.currentBattle.double) { + if (availablePartyMembers.length > 1) { + this.scene.pushPhase(new ToggleDoublePositionPhase(this.scene, true)); + if (!availablePartyMembers[1].isOnField()) + this.scene.pushPhase(new SummonPhase(this.scene, 1)); + } + } else { + if (availablePartyMembers.length > 1 && availablePartyMembers[1].isOnField()) + this.scene.pushPhase(new ReturnPhase(this.scene, 1)); + this.scene.pushPhase(new ToggleDoublePositionPhase(this.scene, false)); + } + + if (this.scene.currentBattle.waveIndex > startingWave && this.scene.currentBattle.battleType !== BattleType.TRAINER) { + this.scene.pushPhase(new CheckSwitchPhase(this.scene, 0, this.scene.currentBattle.double)); + if (this.scene.currentBattle.double && availablePartyMembers.length > 1) + this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); + } + } // TODO: Remove //this.scene.unshiftPhase(new SelectModifierPhase(this.scene)); diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 21b781fba..af4160219 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1,7 +1,7 @@ import Phaser from 'phaser'; import { Biome } from './data/biome'; import UI, { Mode } from './ui/ui'; -import { EncounterPhase, SummonPhase, NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, MessagePhase, CheckLoadPhase, TurnInitPhase, ReturnPhase, ToggleDoublePositionPhase, CheckSwitchPhase, LevelCapPhase, TestMessagePhase, ShowTrainerPhase } from './battle-phases'; +import { EncounterPhase, SummonPhase, NextEncounterPhase, NewBiomeEncounterPhase, SelectBiomePhase, MessagePhase, CheckLoadPhase, TurnInitPhase, ReturnPhase, LevelCapPhase, TestMessagePhase, ShowTrainerPhase } from './battle-phases'; import Pokemon, { PlayerPokemon, EnemyPokemon } from './pokemon'; import PokemonSpecies, { PokemonSpeciesFilter, allSpecies, getPokemonSpecies, initSpecies } from './data/pokemon-species'; import * as Utils from './utils'; @@ -675,7 +675,6 @@ export default class BattleScene extends Phaser.Scene { if (!waveIndex) { const isNewBiome = !lastBattle || !(lastBattle.waveIndex % 10); const showTrainer = isNewBiome || this.currentBattle.battleType === BattleType.TRAINER; - const availablePartyMemberCount = this.getParty().filter(p => !p.isFainted()).length; if (lastBattle) { this.getEnemyParty().forEach(enemyPokemon => enemyPokemon.destroy()); this.trySpreadPokerus(); @@ -697,39 +696,10 @@ export default class BattleScene extends Phaser.Scene { if (newMaxExpLevel > maxExpLevel) this.pushPhase(new LevelCapPhase(this)); } - if (showTrainer) { - this.pushPhase(new SummonPhase(this, 0)); - if (this.currentBattle.double && availablePartyMemberCount > 1) - this.pushPhase(new SummonPhase(this, 1)); - } - } else { - if (!this.quickStart) - this.pushPhase(new CheckLoadPhase(this)); - else { - this.pushPhase(new EncounterPhase(this)); - this.pushPhase(new SummonPhase(this, 0)); - } - } - - if (!showTrainer && (lastBattle?.double || false) !== newDouble) { - if (newDouble) { - if (availablePartyMemberCount > 1) { - this.pushPhase(new ToggleDoublePositionPhase(this, true)); - this.pushPhase(new SummonPhase(this, 1)); - } - } else { - if (availablePartyMemberCount > 1) - this.pushPhase(new ReturnPhase(this, 1)); - this.pushPhase(new ToggleDoublePositionPhase(this, false)); - } - } - - if (lastBattle && this.currentBattle.battleType !== BattleType.TRAINER) { - const availablePartyMembers = this.getParty().filter(p => !p.isFainted()).length; - this.pushPhase(new CheckSwitchPhase(this, 0, newDouble)); - if (newDouble && availablePartyMembers > 1) - this.pushPhase(new CheckSwitchPhase(this, 1, newDouble)); - } + } else if (!this.quickStart) + this.pushPhase(new CheckLoadPhase(this)); + else + this.pushPhase(new EncounterPhase(this)); } return this.currentBattle;