Add evolution cancelling

pull/14/head
Flashfyre 2023-12-14 11:54:56 -05:00
parent 01a5fe18dd
commit 1a4d51d060
4 changed files with 120 additions and 60 deletions

View File

@ -1165,11 +1165,14 @@ export class CommandPhase extends FieldPhase {
if (!isSwitch && this.fieldIndex) if (!isSwitch && this.fieldIndex)
this.scene.currentBattle.turnCommands[this.fieldIndex - 1].skip = true; this.scene.currentBattle.turnCommands[this.fieldIndex - 1].skip = true;
} else if (trapTag) { } else if (trapTag) {
this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); if (!isSwitch) {
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex);
this.scene.ui.setMode(Mode.MESSAGE);
}
this.scene.ui.showText(`${this.scene.getPokemonById(trapTag.sourceId).name}'s ${trapTag.getMoveName()}\nprevents ${isSwitch ? 'switching' : 'fleeing'}!`, null, () => { this.scene.ui.showText(`${this.scene.getPokemonById(trapTag.sourceId).name}'s ${trapTag.getMoveName()}\nprevents ${isSwitch ? 'switching' : 'fleeing'}!`, null, () => {
this.scene.ui.showText(null, 0); this.scene.ui.showText(null, 0);
this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex); if (!isSwitch)
this.scene.ui.setMode(Mode.COMMAND, this.fieldIndex);
}, null, true); }, null, true);
} }
} }

View File

@ -42,7 +42,9 @@ export class EvolutionPhase extends BattlePhase {
this.scene.fadeOutBgm(null, false); this.scene.fadeOutBgm(null, false);
this.evolutionContainer = (this.scene.ui.getHandler() as EvolutionSceneHandler).evolutionContainer; const evolutionHandler = this.scene.ui.getHandler() as EvolutionSceneHandler;
this.evolutionContainer = evolutionHandler.evolutionContainer;
this.evolutionBaseBg = this.scene.add.image(0, 0, 'default_bg'); this.evolutionBaseBg = this.scene.add.image(0, 0, 'default_bg');
this.evolutionBaseBg.setOrigin(0, 0); this.evolutionBaseBg.setOrigin(0, 0);
@ -93,22 +95,17 @@ export class EvolutionPhase extends BattlePhase {
this.scene.ui.showText(`What?\n${preName} is evolving!`, null, () => { this.scene.ui.showText(`What?\n${preName} is evolving!`, null, () => {
pokemon.cry(); pokemon.cry();
pokemon.evolve(this.evolution).then(() => { const evolvedPokemon = pokemon.getPossibleEvolution(this.evolution);
[ this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => {
sprite.play(pokemon.getSpriteKey(true)); [ this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => {
[ 'spriteColors', 'fusionSpriteColors' ].map(k => { sprite.play(evolvedPokemon.getSpriteKey(true));
if (pokemon.summonData?.speciesForm) [ 'spriteColors', 'fusionSpriteColors' ].map(k => {
k += 'Base'; if (evolvedPokemon.summonData?.speciesForm)
sprite.pipelineData[k] = pokemon.getSprite().pipelineData[k]; k += 'Base';
}); sprite.pipelineData[k] = evolvedPokemon.getSprite().pipelineData[k];
}); });
}); });
const levelMoves = pokemon.getLevelMoves(this.lastLevel + 1, true);
for (let lm of levelMoves)
this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm));
this.scene.unshiftPhase(new EndEvolutionPhase(this.scene));
this.scene.time.delayedCall(1000, () => { this.scene.time.delayedCall(1000, () => {
const evolutionBgm = this.scene.playSoundWithoutBgm('evolution'); const evolutionBgm = this.scene.playSoundWithoutBgm('evolution');
this.scene.tweens.add({ this.scene.tweens.add({
@ -144,50 +141,87 @@ export class EvolutionPhase extends BattlePhase {
this.scene.time.delayedCall(1500, () => { this.scene.time.delayedCall(1500, () => {
this.pokemonEvoTintSprite.setScale(0.25); this.pokemonEvoTintSprite.setScale(0.25);
this.pokemonEvoTintSprite.setVisible(true); this.pokemonEvoTintSprite.setVisible(true);
this.doCycle(1).then(() => { evolutionHandler.canCancel = true;
this.doCycle(1).then(success => {
if (!success) {
this.pokemonSprite.setVisible(true);
this.pokemonTintSprite.setScale(1);
this.scene.tweens.add({
targets: [ this.evolutionBg, this.pokemonTintSprite, this.pokemonEvoSprite, this.pokemonEvoTintSprite ],
alpha: 0,
duration: 250,
onComplete: () => {
this.evolutionBg.setVisible(false);
}
});
SoundFade.fadeOut(this.scene, evolutionBgm, 100);
this.scene.unshiftPhase(new EndEvolutionPhase(this.scene));
this.scene.ui.showText(`${preName} stopped evolving.`, null, () => {
this.scene.playBgm();
evolvedPokemon.destroy();
this.end();
}, null, true, 3000);
return;
}
this.scene.playSound('sparkle'); this.scene.playSound('sparkle');
this.pokemonEvoSprite.setVisible(true); this.pokemonEvoSprite.setVisible(true);
this.doCircleInward(); this.doCircleInward();
this.scene.time.delayedCall(900, () => { this.scene.time.delayedCall(900, () => {
this.scene.playSound('shine'); evolutionHandler.canCancel = false;
this.doSpray();
this.scene.tweens.add({ pokemon.evolve(this.evolution).then(() => {
targets: this.evolutionOverlay, const levelMoves = pokemon.getLevelMoves(this.lastLevel + 1, true);
alpha: 1, for (let lm of levelMoves)
duration: 250, this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.partyMemberIndex, lm));
easing: 'Sine.easeIn', this.scene.unshiftPhase(new EndEvolutionPhase(this.scene));
onComplete: () => {
this.evolutionBgOverlay.setAlpha(1); this.scene.playSound('shine');
this.evolutionBg.setVisible(false); this.doSpray();
this.scene.tweens.add({ this.scene.tweens.add({
targets: [ this.evolutionOverlay, this.pokemonEvoTintSprite ], targets: this.evolutionOverlay,
alpha: 0, alpha: 1,
duration: 2000, duration: 250,
delay: 150, easing: 'Sine.easeIn',
easing: 'Sine.easeIn', onComplete: () => {
onComplete: () => { this.evolutionBgOverlay.setAlpha(1);
this.scene.tweens.add({ this.evolutionBg.setVisible(false);
targets: this.evolutionBgOverlay, this.scene.tweens.add({
alpha: 0, targets: [ this.evolutionOverlay, this.pokemonEvoTintSprite ],
duration: 250, alpha: 0,
onComplete: () => { duration: 2000,
SoundFade.fadeOut(this.scene, evolutionBgm, 100); delay: 150,
this.scene.time.delayedCall(250, () => { easing: 'Sine.easeIn',
pokemon.cry(); onComplete: () => {
this.scene.time.delayedCall(1250, () => { this.scene.tweens.add({
this.scene.playSoundWithoutBgm('evolution_fanfare'); targets: this.evolutionBgOverlay,
if (this.evolution.evoFormKey && this.evolution.evoFormKey.indexOf(SpeciesFormKey.MEGA) > -1) alpha: 0,
this.scene.validateAchv(achvs.MEGA_EVOLVE); duration: 250,
this.scene.ui.showText(`Congratulations! Your ${preName}\nevolved into ${pokemon.name}!`, null, () => this.end(), null, true, 3000); onComplete: () => {
this.scene.time.delayedCall(Utils.fixedInt(4250), () => this.scene.playBgm()); SoundFade.fadeOut(this.scene, evolutionBgm, 100);
this.scene.time.delayedCall(250, () => {
pokemon.cry();
this.scene.time.delayedCall(1250, () => {
this.scene.playSoundWithoutBgm('evolution_fanfare');
if (this.evolution.evoFormKey && this.evolution.evoFormKey.indexOf(SpeciesFormKey.MEGA) > -1)
this.scene.validateAchv(achvs.MEGA_EVOLVE);
evolvedPokemon.destroy();
this.scene.ui.showText(`Congratulations! Your ${preName}\nevolved into ${pokemon.name}!`, null, () => this.end(), null, true, 3000);
this.scene.time.delayedCall(Utils.fixedInt(4250), () => this.scene.playBgm());
});
}); });
}); }
} });
}); }
} });
}); }
} });
}) });
}); });
}); });
}); });
@ -245,8 +279,9 @@ export class EvolutionPhase extends BattlePhase {
}); });
} }
doCycle(l: number): Promise<void> { doCycle(l: number): Promise<boolean> {
return new Promise(resolve => { return new Promise(resolve => {
const evolutionHandler = this.scene.ui.getHandler() as EvolutionSceneHandler;
const isLastCycle = l === 15; const isLastCycle = l === 15;
this.scene.tweens.add({ this.scene.tweens.add({
targets: this.pokemonTintSprite, targets: this.pokemonTintSprite,
@ -262,11 +297,13 @@ export class EvolutionPhase extends BattlePhase {
duration: 500 / l, duration: 500 / l,
yoyo: !isLastCycle, yoyo: !isLastCycle,
onComplete: () => { onComplete: () => {
if (evolutionHandler.cancelled)
return resolve(false);
if (l < 15) if (l < 15)
this.doCycle(l + 0.5).then(() => resolve()); this.doCycle(l + 0.5).then(success => resolve(success));
else { else {
this.pokemonTintSprite.setVisible(false); this.pokemonTintSprite.setVisible(false);
resolve(); resolve(true);
} }
} }
}); });

View File

@ -1715,6 +1715,12 @@ export class PlayerPokemon extends Pokemon {
}, PartyUiHandler.FilterNonFainted); }, PartyUiHandler.FilterNonFainted);
}); });
} }
getPossibleEvolution(evolution: SpeciesEvolution): Pokemon {
const species = getPokemonSpecies(evolution.speciesId);
const formIndex = Math.max(this.species.forms.findIndex(f => f.formKey === evolution.evoFormKey), 0);
return new PlayerPokemon(this.scene, species, this.level, this.abilityIndex, formIndex, this.gender, this.shiny, this.ivs, this);
}
evolve(evolution: SpeciesEvolution): Promise<void> { evolve(evolution: SpeciesEvolution): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {

View File

@ -4,23 +4,35 @@ import UiHandler from "./uiHandler";
export default class EvolutionSceneHandler extends UiHandler { export default class EvolutionSceneHandler extends UiHandler {
public evolutionContainer: Phaser.GameObjects.Container; public evolutionContainer: Phaser.GameObjects.Container;
public canCancel: boolean;
public cancelled: boolean;
private cleanupFunc: Function;
constructor(scene: BattleScene) { constructor(scene: BattleScene) {
super(scene, Mode.EVOLUTION_SCENE); super(scene, Mode.EVOLUTION_SCENE);
} }
setup() { setup() {
this.canCancel = false;
this.cancelled = false;
this.evolutionContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); this.evolutionContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6);
this.scene.fieldUI.add(this.evolutionContainer); this.scene.fieldUI.add(this.evolutionContainer);
} }
show(_args: any[]): void { show(_args: any[]): void {
super.show(_args); super.show(_args);
this.scene.fieldUI.bringToTop(this.evolutionContainer); this.scene.fieldUI.bringToTop(this.evolutionContainer);
} }
processInput(button: Button): boolean { processInput(button: Button): boolean {
if (this.canCancel && !this.cancelled && button === Button.CANCEL) {
this.cancelled = true;
return true;
}
return this.scene.ui.getMessageHandler().processInput(button); return this.scene.ui.getMessageHandler().processInput(button);
} }
@ -29,6 +41,8 @@ export default class EvolutionSceneHandler extends UiHandler {
} }
clear() { clear() {
this.canCancel = false;
this.cancelled = false;
this.evolutionContainer.removeAll(true); this.evolutionContainer.removeAll(true);
} }
} }