Refactor logic for summons and returns

This commit is contained in:
Flashfyre 2023-12-02 10:30:23 -05:00
parent 5ec3991cb3
commit fbcd372068
2 changed files with 43 additions and 45 deletions

View File

@ -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);
@ -408,6 +411,31 @@ export class EncounterPhase extends BattlePhase {
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));

View File

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