mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-06-21 17:12:44 +02:00
Refactor form change phase
This commit is contained in:
parent
75511354ee
commit
9a601b80a2
@ -1,9 +1,9 @@
|
|||||||
import { globalScene } from "#app/global-scene";
|
import { globalScene } from "#app/global-scene";
|
||||||
import { fixedInt } from "#app/utils/common";
|
import { FixedInt, fixedInt } from "#app/utils/common";
|
||||||
import { achvs } from "../system/achv";
|
import { achvs } from "../system/achv";
|
||||||
import type { SpeciesFormChange } from "../data/pokemon-forms";
|
import type { SpeciesFormChange } from "../data/pokemon-forms";
|
||||||
import { getSpeciesFormChangeMessage } from "#app/data/pokemon-forms/form-change-triggers";
|
import { getSpeciesFormChangeMessage } from "#app/data/pokemon-forms/form-change-triggers";
|
||||||
import type { PlayerPokemon } from "../field/pokemon";
|
import type { default as Pokemon, PlayerPokemon } from "../field/pokemon";
|
||||||
import { UiMode } from "#enums/ui-mode";
|
import { UiMode } from "#enums/ui-mode";
|
||||||
import type PartyUiHandler from "../ui/party-ui-handler";
|
import type PartyUiHandler from "../ui/party-ui-handler";
|
||||||
import { getPokemonNameWithAffix } from "../messages";
|
import { getPokemonNameWithAffix } from "../messages";
|
||||||
@ -34,146 +34,158 @@ export class FormChangePhase extends EvolutionPhase {
|
|||||||
return globalScene.ui.setOverlayMode(UiMode.EVOLUTION_SCENE);
|
return globalScene.ui.setOverlayMode(UiMode.EVOLUTION_SCENE);
|
||||||
}
|
}
|
||||||
|
|
||||||
doEvolution(): void {
|
/**
|
||||||
const preName = getPokemonNameWithAffix(this.pokemon);
|
* Commence the tweens that play after the form change animation finishes
|
||||||
|
* @param transformedPokemon - The Pokemon after the evolution
|
||||||
this.pokemon.getPossibleForm(this.formChange).then(transformedPokemon => {
|
* @param preName - The name of the Pokemon before the evolution
|
||||||
[this.pokemonEvoSprite, this.pokemonEvoTintSprite].map(sprite => {
|
*/
|
||||||
const spriteKey = transformedPokemon.getSpriteKey(true);
|
private postFormChangeTweens(transformedPokemon: Pokemon, preName: string): void {
|
||||||
try {
|
globalScene.tweens.chain({
|
||||||
sprite.play(spriteKey);
|
targets: null,
|
||||||
} catch (err: unknown) {
|
tweens: [
|
||||||
console.error(`Failed to play animation for ${spriteKey}`, err);
|
{
|
||||||
|
targets: this.evolutionOverlay,
|
||||||
|
alpha: 1,
|
||||||
|
duration: 250,
|
||||||
|
easing: "Sine.easeIn",
|
||||||
|
onComplete: () => {
|
||||||
|
this.evolutionBgOverlay.setAlpha(1);
|
||||||
|
this.evolutionBg.setVisible(false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: [this.evolutionOverlay, this.pokemonEvoTintSprite],
|
||||||
|
alpha: 0,
|
||||||
|
duration: 2000,
|
||||||
|
delay: 150,
|
||||||
|
easing: "Sine.easeIn",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
targets: this.evolutionBgOverlay,
|
||||||
|
alpha: 0,
|
||||||
|
duration: 250,
|
||||||
|
completeDelay: 250,
|
||||||
|
onComplete: () => this.pokemon.cry(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// 1.25 seconds after the pokemon cry
|
||||||
|
completeDelay: 1250,
|
||||||
|
onComplete: () => {
|
||||||
|
let playEvolutionFanfare = false;
|
||||||
|
if (this.formChange.formKey.indexOf(SpeciesFormKey.MEGA) > -1) {
|
||||||
|
globalScene.validateAchv(achvs.MEGA_EVOLVE);
|
||||||
|
playEvolutionFanfare = true;
|
||||||
|
} else if (
|
||||||
|
this.formChange.formKey.indexOf(SpeciesFormKey.GIGANTAMAX) > -1 ||
|
||||||
|
this.formChange.formKey.indexOf(SpeciesFormKey.ETERNAMAX) > -1
|
||||||
|
) {
|
||||||
|
globalScene.validateAchv(achvs.GIGANTAMAX);
|
||||||
|
playEvolutionFanfare = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite.setPipelineData("ignoreTimeTint", true);
|
const delay = playEvolutionFanfare ? 4000 : 1750;
|
||||||
sprite.setPipelineData("spriteKey", transformedPokemon.getSpriteKey());
|
globalScene.playSoundWithoutBgm(playEvolutionFanfare ? "evolution_fanfare" : "minor_fanfare");
|
||||||
sprite.setPipelineData("shiny", transformedPokemon.shiny);
|
transformedPokemon.destroy();
|
||||||
sprite.setPipelineData("variant", transformedPokemon.variant);
|
globalScene.ui.showText(
|
||||||
["spriteColors", "fusionSpriteColors"].map(k => {
|
getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName),
|
||||||
if (transformedPokemon.summonData.speciesForm) {
|
null,
|
||||||
k += "Base";
|
() => this.end(),
|
||||||
}
|
null,
|
||||||
sprite.pipelineData[k] = transformedPokemon.getSprite().pipelineData[k];
|
true,
|
||||||
});
|
fixedInt(delay),
|
||||||
});
|
);
|
||||||
|
globalScene.time.delayedCall(fixedInt(delay + 250), () => globalScene.playBgm());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
globalScene.time.delayedCall(250, () => {
|
/**
|
||||||
globalScene.tweens.add({
|
* Commence the animations that occur once the form change evolution cycle ({@linkcode doCycle}) is complete
|
||||||
|
*
|
||||||
|
* @privateRemarks
|
||||||
|
* This would prefer {@linkcode doCycle} to be refactored and de-promisified so this can be moved into {@linkcode beginTweens}
|
||||||
|
* @param preName - The name of the Pokemon before the evolution
|
||||||
|
* @param transformedPokemon - The Pokemon being transformed into
|
||||||
|
*/
|
||||||
|
private afterCycle(preName: string, transformedPokemon: Pokemon): void {
|
||||||
|
globalScene.playSound("se/sparkle");
|
||||||
|
this.pokemonEvoSprite.setVisible(true);
|
||||||
|
this.doCircleInward();
|
||||||
|
globalScene.time.delayedCall(900, () => {
|
||||||
|
this.pokemon.changeForm(this.formChange).then(() => {
|
||||||
|
if (!this.modal) {
|
||||||
|
globalScene.phaseManager.unshiftNew("EndEvolutionPhase");
|
||||||
|
}
|
||||||
|
globalScene.playSound("se/shine");
|
||||||
|
this.doSpray();
|
||||||
|
this.postFormChangeTweens(transformedPokemon, preName);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commence the sequence of tweens and events that occur during the evolution animation
|
||||||
|
* @param preName The name of the Pokemon before the evolution
|
||||||
|
* @param transformedPokemon The Pokemon after the evolution
|
||||||
|
*/
|
||||||
|
private beginTweens(preName: string, transformedPokemon: Pokemon): void {
|
||||||
|
globalScene.tweens.chain({
|
||||||
|
// Starts 250ms after sprites have been configured
|
||||||
|
delay: 250,
|
||||||
|
targets: null,
|
||||||
|
tweens: [
|
||||||
|
// Step 1: Fade in the background overlay
|
||||||
|
{
|
||||||
targets: this.evolutionBgOverlay,
|
targets: this.evolutionBgOverlay,
|
||||||
alpha: 1,
|
alpha: 1,
|
||||||
delay: 500,
|
|
||||||
duration: 1500,
|
duration: 1500,
|
||||||
ease: "Sine.easeOut",
|
ease: "Sine.easeOut",
|
||||||
|
// We want the backkground overlay to fade out after it fades in
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
globalScene.time.delayedCall(1000, () => {
|
globalScene.tweens.add({
|
||||||
globalScene.tweens.add({
|
targets: this.evolutionBgOverlay,
|
||||||
targets: this.evolutionBgOverlay,
|
alpha: 0,
|
||||||
alpha: 0,
|
duration: 250,
|
||||||
duration: 250,
|
delay: fixedInt(1000),
|
||||||
});
|
|
||||||
this.evolutionBg.setVisible(true);
|
|
||||||
this.evolutionBg.play();
|
|
||||||
});
|
});
|
||||||
|
this.evolutionBg.setVisible(true).play();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// Step 2: Play the sounds and fade in the tint sprite
|
||||||
|
{
|
||||||
|
targets: this.pokemonTintSprite,
|
||||||
|
alpha: { from: 0, to: 1 },
|
||||||
|
duration: 2000,
|
||||||
|
onStart: () => {
|
||||||
globalScene.playSound("se/charge");
|
globalScene.playSound("se/charge");
|
||||||
this.doSpiralUpward();
|
this.doSpiralUpward();
|
||||||
globalScene.tweens.addCounter({
|
|
||||||
from: 0,
|
|
||||||
to: 1,
|
|
||||||
duration: 2000,
|
|
||||||
onUpdate: t => {
|
|
||||||
this.pokemonTintSprite.setAlpha(t.getValue());
|
|
||||||
},
|
|
||||||
onComplete: () => {
|
|
||||||
this.pokemonSprite.setVisible(false);
|
|
||||||
globalScene.time.delayedCall(1100, () => {
|
|
||||||
globalScene.playSound("se/beam");
|
|
||||||
this.doArcDownward();
|
|
||||||
globalScene.time.delayedCall(1000, () => {
|
|
||||||
this.pokemonEvoTintSprite.setScale(0.25);
|
|
||||||
this.pokemonEvoTintSprite.setVisible(true);
|
|
||||||
this.doCycle(1, 1).then(_success => {
|
|
||||||
globalScene.playSound("se/sparkle");
|
|
||||||
this.pokemonEvoSprite.setVisible(true);
|
|
||||||
this.doCircleInward();
|
|
||||||
globalScene.time.delayedCall(900, () => {
|
|
||||||
this.pokemon.changeForm(this.formChange).then(() => {
|
|
||||||
if (!this.modal) {
|
|
||||||
globalScene.phaseManager.unshiftNew("EndEvolutionPhase");
|
|
||||||
}
|
|
||||||
|
|
||||||
globalScene.playSound("se/shine");
|
|
||||||
this.doSpray();
|
|
||||||
globalScene.tweens.add({
|
|
||||||
targets: this.evolutionOverlay,
|
|
||||||
alpha: 1,
|
|
||||||
duration: 250,
|
|
||||||
easing: "Sine.easeIn",
|
|
||||||
onComplete: () => {
|
|
||||||
this.evolutionBgOverlay.setAlpha(1);
|
|
||||||
this.evolutionBg.setVisible(false);
|
|
||||||
globalScene.tweens.add({
|
|
||||||
targets: [this.evolutionOverlay, this.pokemonEvoTintSprite],
|
|
||||||
alpha: 0,
|
|
||||||
duration: 2000,
|
|
||||||
delay: 150,
|
|
||||||
easing: "Sine.easeIn",
|
|
||||||
onComplete: () => {
|
|
||||||
globalScene.tweens.add({
|
|
||||||
targets: this.evolutionBgOverlay,
|
|
||||||
alpha: 0,
|
|
||||||
duration: 250,
|
|
||||||
onComplete: () => {
|
|
||||||
globalScene.time.delayedCall(250, () => {
|
|
||||||
this.pokemon.cry();
|
|
||||||
globalScene.time.delayedCall(1250, () => {
|
|
||||||
let playEvolutionFanfare = false;
|
|
||||||
if (this.formChange.formKey.indexOf(SpeciesFormKey.MEGA) > -1) {
|
|
||||||
globalScene.validateAchv(achvs.MEGA_EVOLVE);
|
|
||||||
playEvolutionFanfare = true;
|
|
||||||
} else if (
|
|
||||||
this.formChange.formKey.indexOf(SpeciesFormKey.GIGANTAMAX) > -1 ||
|
|
||||||
this.formChange.formKey.indexOf(SpeciesFormKey.ETERNAMAX) > -1
|
|
||||||
) {
|
|
||||||
globalScene.validateAchv(achvs.GIGANTAMAX);
|
|
||||||
playEvolutionFanfare = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const delay = playEvolutionFanfare ? 4000 : 1750;
|
|
||||||
globalScene.playSoundWithoutBgm(
|
|
||||||
playEvolutionFanfare ? "evolution_fanfare" : "minor_fanfare",
|
|
||||||
);
|
|
||||||
|
|
||||||
transformedPokemon.destroy();
|
|
||||||
globalScene.ui.showText(
|
|
||||||
getSpeciesFormChangeMessage(this.pokemon, this.formChange, preName),
|
|
||||||
null,
|
|
||||||
() => this.end(),
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
fixedInt(delay),
|
|
||||||
);
|
|
||||||
globalScene.time.delayedCall(fixedInt(delay + 250), () =>
|
|
||||||
globalScene.playBgm(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
onComplete: () => {
|
||||||
|
this.pokemonSprite.setVisible(false);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
// Step 3: Commence the form change animation via doCycle then continue the animation chain with afterCycle
|
||||||
|
completeDelay: new FixedInt(1100),
|
||||||
|
onComplete: () => {
|
||||||
|
globalScene.playSound("se/beam");
|
||||||
|
this.doArcDownward();
|
||||||
|
globalScene.time.delayedCall(1000, () => {
|
||||||
|
this.pokemonEvoTintSprite.setScale(0.25).setVisible(true);
|
||||||
|
this.doCycle(1, 1).then(() => this.afterCycle(preName, transformedPokemon));
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doEvolution(): void {
|
||||||
|
const preName = getPokemonNameWithAffix(this.pokemon, false);
|
||||||
|
|
||||||
|
this.pokemon.getPossibleForm(this.formChange).then(transformedPokemon => {
|
||||||
|
this.configureSprite(transformedPokemon, this.pokemonEvoSprite, false);
|
||||||
|
this.configureSprite(transformedPokemon, this.pokemonEvoTintSprite, false);
|
||||||
|
this.beginTweens(preName, transformedPokemon);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user