pokerogue/src/evolution-phase.ts

545 lines
19 KiB
TypeScript
Raw Normal View History

2023-04-10 17:54:06 +00:00
import SoundFade from "phaser3-rex-plugins/plugins/soundfade";
import { Phase } from "./phase";
2023-04-10 17:54:06 +00:00
import BattleScene from "./battle-scene";
import { SpeciesFormEvolution } from "./data/pokemon-evolutions";
2023-04-10 17:54:06 +00:00
import EvolutionSceneHandler from "./ui/evolution-scene-handler";
import * as Utils from "./utils";
import { Mode } from "./ui/ui";
import { LearnMovePhase } from "./phases";
2024-03-01 01:08:50 +00:00
import { cos, sin } from "./field/anims";
import { PlayerPokemon } from "./field/pokemon";
import { getTypeRgb } from "./data/type";
import i18next from "i18next";
2023-04-10 17:54:06 +00:00
export class EvolutionPhase extends Phase {
2024-01-10 04:34:43 +00:00
protected pokemon: PlayerPokemon;
protected lastLevel: integer;
2024-05-23 23:45:04 +00:00
private evolution: SpeciesFormEvolution;
2024-01-10 04:34:43 +00:00
protected evolutionContainer: Phaser.GameObjects.Container;
protected evolutionBaseBg: Phaser.GameObjects.Image;
protected evolutionBg: Phaser.GameObjects.Video;
protected evolutionBgOverlay: Phaser.GameObjects.Rectangle;
protected evolutionOverlay: Phaser.GameObjects.Rectangle;
protected pokemonSprite: Phaser.GameObjects.Sprite;
protected pokemonTintSprite: Phaser.GameObjects.Sprite;
protected pokemonEvoSprite: Phaser.GameObjects.Sprite;
protected pokemonEvoTintSprite: Phaser.GameObjects.Sprite;
constructor(scene: BattleScene, pokemon: PlayerPokemon, evolution: SpeciesFormEvolution, lastLevel: integer) {
2023-04-10 17:54:06 +00:00
super(scene);
2024-01-10 04:34:43 +00:00
this.pokemon = pokemon;
2023-04-10 17:54:06 +00:00
this.evolution = evolution;
this.lastLevel = lastLevel;
}
2024-01-10 04:34:43 +00:00
validate(): boolean {
return !!this.evolution;
}
setMode(): Promise<void> {
return this.scene.ui.setModeForceTransition(Mode.EVOLUTION_SCENE);
}
2023-04-10 17:54:06 +00:00
start() {
super.start();
2024-01-10 04:34:43 +00:00
this.setMode().then(() => {
2023-04-10 17:54:06 +00:00
if (!this.validate()) {
2023-12-07 22:43:56 +00:00
return this.end();
}
2023-04-10 17:54:06 +00:00
this.scene.fadeOutBgm(null, false);
2023-04-10 17:54:06 +00:00
2023-12-14 16:54:56 +00:00
const evolutionHandler = this.scene.ui.getHandler() as EvolutionSceneHandler;
this.evolutionContainer = evolutionHandler.evolutionContainer;
2023-04-10 17:54:06 +00:00
this.evolutionBaseBg = this.scene.add.image(0, 0, "default_bg");
2023-04-10 17:54:06 +00:00
this.evolutionBaseBg.setOrigin(0, 0);
this.evolutionContainer.add(this.evolutionBaseBg);
this.evolutionBg = this.scene.add.video(0, 0, "evo_bg").stop();
2023-04-10 17:54:06 +00:00
this.evolutionBg.setOrigin(0, 0);
this.evolutionBg.setScale(0.4359673025);
this.evolutionBg.setVisible(false);
this.evolutionContainer.add(this.evolutionBg);
this.evolutionBgOverlay = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x262626);
this.evolutionBgOverlay.setOrigin(0, 0);
this.evolutionBgOverlay.setAlpha(0);
this.evolutionContainer.add(this.evolutionBgOverlay);
const getPokemonSprite = () => {
const ret = this.scene.addPokemonSprite(this.pokemon, this.evolutionBaseBg.displayWidth / 2, this.evolutionBaseBg.displayHeight / 2, "pkmn__sub");
ret.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true });
return ret;
};
2023-04-10 17:54:06 +00:00
this.evolutionContainer.add((this.pokemonSprite = getPokemonSprite()));
this.evolutionContainer.add((this.pokemonTintSprite = getPokemonSprite()));
this.evolutionContainer.add((this.pokemonEvoSprite = getPokemonSprite()));
this.evolutionContainer.add((this.pokemonEvoTintSprite = getPokemonSprite()));
this.pokemonTintSprite.setAlpha(0);
this.pokemonTintSprite.setTintFill(0xFFFFFF);
this.pokemonEvoSprite.setVisible(false);
this.pokemonEvoTintSprite.setVisible(false);
this.pokemonEvoTintSprite.setTintFill(0xFFFFFF);
2024-01-10 04:34:43 +00:00
this.evolutionOverlay = this.scene.add.rectangle(0, -this.scene.game.canvas.height / 6, this.scene.game.canvas.width / 6, (this.scene.game.canvas.height / 6) - 48, 0xFFFFFF);
2023-04-10 17:54:06 +00:00
this.evolutionOverlay.setOrigin(0, 0);
this.evolutionOverlay.setAlpha(0);
2024-01-10 04:34:43 +00:00
this.scene.ui.add(this.evolutionOverlay);
2023-04-10 17:54:06 +00:00
[ this.pokemonSprite, this.pokemonTintSprite, this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => {
2024-01-10 04:34:43 +00:00
sprite.play(this.pokemon.getSpriteKey(true));
sprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], hasShadow: false, teraColor: getTypeRgb(this.pokemon.getTeraType()) });
sprite.setPipelineData("ignoreTimeTint", true);
sprite.setPipelineData("spriteKey", this.pokemon.getSpriteKey());
sprite.setPipelineData("shiny", this.pokemon.shiny);
sprite.setPipelineData("variant", this.pokemon.variant);
[ "spriteColors", "fusionSpriteColors" ].map(k => {
if (this.pokemon.summonData?.speciesForm) {
k += "Base";
}
2024-01-10 04:34:43 +00:00
sprite.pipelineData[k] = this.pokemon.getSprite().pipelineData[k];
});
});
2023-04-10 17:54:06 +00:00
2024-01-10 04:34:43 +00:00
this.doEvolution();
});
}
2024-01-10 04:34:43 +00:00
doEvolution(): void {
const evolutionHandler = this.scene.ui.getHandler() as EvolutionSceneHandler;
const preName = this.pokemon.name;
2024-05-23 23:45:04 +00:00
this.scene.ui.showText(i18next.t("menu:evolving", { pokemonName: preName }), null, () => {
2024-01-10 04:34:43 +00:00
this.pokemon.cry();
this.pokemon.getPossibleEvolution(this.evolution).then(evolvedPokemon => {
[ this.pokemonEvoSprite, this.pokemonEvoTintSprite ].map(sprite => {
sprite.play(evolvedPokemon.getSpriteKey(true));
sprite.setPipelineData("ignoreTimeTint", true);
sprite.setPipelineData("spriteKey", evolvedPokemon.getSpriteKey());
sprite.setPipelineData("shiny", evolvedPokemon.shiny);
sprite.setPipelineData("variant", evolvedPokemon.variant);
[ "spriteColors", "fusionSpriteColors" ].map(k => {
if (evolvedPokemon.summonData?.speciesForm) {
k += "Base";
}
2024-01-10 04:34:43 +00:00
sprite.pipelineData[k] = evolvedPokemon.getSprite().pipelineData[k];
});
2024-01-10 04:34:43 +00:00
});
2023-04-10 17:54:06 +00:00
2024-01-10 04:34:43 +00:00
this.scene.time.delayedCall(1000, () => {
const evolutionBgm = this.scene.playSoundWithoutBgm("evolution");
2024-01-10 04:34:43 +00:00
this.scene.tweens.add({
targets: this.evolutionBgOverlay,
alpha: 1,
delay: 500,
duration: 1500,
ease: "Sine.easeOut",
2024-01-10 04:34:43 +00:00
onComplete: () => {
this.scene.time.delayedCall(1000, () => {
this.scene.tweens.add({
targets: this.evolutionBgOverlay,
alpha: 0,
duration: 250
2023-04-10 17:54:06 +00:00
});
2024-01-10 04:34:43 +00:00
this.evolutionBg.setVisible(true);
this.evolutionBg.play();
});
this.scene.playSound("charge");
2024-01-10 04:34:43 +00:00
this.doSpiralUpward();
this.scene.tweens.addCounter({
from: 0,
to: 1,
duration: 2000,
onUpdate: t => {
this.pokemonTintSprite.setAlpha(t.getValue());
},
onComplete: () => {
this.pokemonSprite.setVisible(false);
this.scene.time.delayedCall(1100, () => {
this.scene.playSound("beam");
2024-01-10 04:34:43 +00:00
this.doArcDownward();
this.scene.time.delayedCall(1500, () => {
this.pokemonEvoTintSprite.setScale(0.25);
this.pokemonEvoTintSprite.setVisible(true);
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(i18next.t("menu:stoppedEvolving", { pokemonName: preName }), null, () => {
this.scene.ui.showText(i18next.t("menu:pauseEvolutionsQuestion", { pokemonName: preName }), null, () => {
2024-01-10 04:34:43 +00:00
const end = () => {
this.scene.ui.showText(null, 0);
this.scene.playBgm();
evolvedPokemon.destroy();
this.end();
};
this.scene.ui.setOverlayMode(Mode.CONFIRM, () => {
this.scene.ui.revertMode();
this.pokemon.pauseEvolutions = true;
this.scene.ui.showText(i18next.t("menu:evolutionsPaused", { pokemonName: preName }), null, end, 3000);
2024-01-10 04:34:43 +00:00
}, () => {
this.scene.ui.revertMode();
this.scene.time.delayedCall(3000, end);
});
});
}, null, true);
return;
}
2024-05-23 23:45:04 +00:00
this.scene.playSound("sparkle");
2024-01-10 04:34:43 +00:00
this.pokemonEvoSprite.setVisible(true);
this.doCircleInward();
this.scene.time.delayedCall(900, () => {
evolutionHandler.canCancel = false;
this.pokemon.evolve(this.evolution).then(() => {
const levelMoves = this.pokemon.getLevelMoves(this.lastLevel + 1, true);
for (const lm of levelMoves) {
this.scene.unshiftPhase(new LearnMovePhase(this.scene, this.scene.getParty().indexOf(this.pokemon), lm[1]));
2024-05-23 23:45:04 +00:00
}
2024-01-10 04:34:43 +00:00
this.scene.unshiftPhase(new EndEvolutionPhase(this.scene));
this.scene.playSound("shine");
2024-01-10 04:34:43 +00:00
this.doSpray();
2023-12-14 16:54:56 +00:00
this.scene.tweens.add({
2024-01-10 04:34:43 +00:00
targets: this.evolutionOverlay,
alpha: 1,
2023-12-14 16:54:56 +00:00
duration: 250,
easing: "Sine.easeIn",
2023-12-14 16:54:56 +00:00
onComplete: () => {
2024-01-10 04:34:43 +00:00
this.evolutionBgOverlay.setAlpha(1);
2023-12-14 16:54:56 +00:00
this.evolutionBg.setVisible(false);
2024-01-10 04:34:43 +00:00
this.scene.tweens.add({
targets: [ this.evolutionOverlay, this.pokemonEvoTintSprite ],
alpha: 0,
duration: 2000,
delay: 150,
easing: "Sine.easeIn",
2024-01-10 04:34:43 +00:00
onComplete: () => {
this.scene.tweens.add({
targets: this.evolutionBgOverlay,
alpha: 0,
duration: 250,
onComplete: () => {
SoundFade.fadeOut(this.scene, evolutionBgm, 100);
this.scene.time.delayedCall(250, () => {
this.pokemon.cry();
this.scene.time.delayedCall(1250, () => {
this.scene.playSoundWithoutBgm("evolution_fanfare");
2024-05-23 23:45:04 +00:00
2024-01-10 04:34:43 +00:00
evolvedPokemon.destroy();
this.scene.ui.showText(i18next.t("menu:evolutionDone", { pokemonName: preName, evolvedPokemonName: this.pokemon.name }), null, () => this.end(), null, true, Utils.fixedInt(4000));
2024-01-10 04:34:43 +00:00
this.scene.time.delayedCall(Utils.fixedInt(4250), () => this.scene.playBgm());
});
2024-01-10 04:34:43 +00:00
});
}
});
}
});
}
});
2023-12-14 16:54:56 +00:00
});
2023-04-10 17:54:06 +00:00
});
});
});
2024-01-10 04:34:43 +00:00
});
}
});
2024-01-10 04:34:43 +00:00
}
2023-04-10 17:54:06 +00:00
});
});
2024-01-10 04:34:43 +00:00
});
}, 1000);
2023-04-10 17:54:06 +00:00
}
doSpiralUpward() {
let f = 0;
2024-05-23 23:45:04 +00:00
2023-04-10 17:54:06 +00:00
this.scene.tweens.addCounter({
repeat: 64,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
if (f < 64) {
if (!(f & 7)) {
for (let i = 0; i < 4; i++) {
2023-04-10 17:54:06 +00:00
this.doSpiralUpwardParticle((f & 120) * 2 + i * 64);
}
2023-04-10 17:54:06 +00:00
}
f++;
}
}
});
}
doArcDownward() {
let f = 0;
2024-05-23 23:45:04 +00:00
2023-04-10 17:54:06 +00:00
this.scene.tweens.addCounter({
repeat: 96,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
if (f < 96) {
if (f < 6) {
for (let i = 0; i < 9; i++) {
2023-04-10 17:54:06 +00:00
this.doArcDownParticle(i * 16);
}
2023-04-10 17:54:06 +00:00
}
f++;
}
}
});
}
2024-01-10 04:34:43 +00:00
doCycle(l: number, lastCycle: integer = 15): Promise<boolean> {
2023-04-10 17:54:06 +00:00
return new Promise(resolve => {
2023-12-14 16:54:56 +00:00
const evolutionHandler = this.scene.ui.getHandler() as EvolutionSceneHandler;
2024-01-10 04:34:43 +00:00
const isLastCycle = l === lastCycle;
2023-04-10 17:54:06 +00:00
this.scene.tweens.add({
targets: this.pokemonTintSprite,
scale: 0.25,
ease: "Cubic.easeInOut",
2023-04-10 17:54:06 +00:00
duration: 500 / l,
yoyo: !isLastCycle
});
this.scene.tweens.add({
targets: this.pokemonEvoTintSprite,
scale: 1,
ease: "Cubic.easeInOut",
2023-04-10 17:54:06 +00:00
duration: 500 / l,
yoyo: !isLastCycle,
onComplete: () => {
if (evolutionHandler.cancelled) {
2023-12-14 16:54:56 +00:00
return resolve(false);
}
if (l < lastCycle) {
2024-01-10 04:34:43 +00:00
this.doCycle(l + 0.5, lastCycle).then(success => resolve(success));
} else {
2023-04-10 17:54:06 +00:00
this.pokemonTintSprite.setVisible(false);
2023-12-14 16:54:56 +00:00
resolve(true);
2023-04-10 17:54:06 +00:00
}
}
});
});
}
doCircleInward() {
let f = 0;
2024-05-23 23:45:04 +00:00
2023-04-10 17:54:06 +00:00
this.scene.tweens.addCounter({
repeat: 48,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
if (!f) {
for (let i = 0; i < 16; i++) {
2023-04-10 17:54:06 +00:00
this.doCircleInwardParticle(i * 16, 4);
}
2023-04-10 17:54:06 +00:00
} else if (f === 32) {
for (let i = 0; i < 16; i++) {
2023-04-10 17:54:06 +00:00
this.doCircleInwardParticle(i * 16, 8);
}
2023-04-10 17:54:06 +00:00
}
f++;
}
});
}
doSpray() {
let f = 0;
2024-05-23 23:45:04 +00:00
2023-04-10 17:54:06 +00:00
this.scene.tweens.addCounter({
repeat: 48,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
if (!f) {
for (let i = 0; i < 8; i++) {
2023-04-10 17:54:06 +00:00
this.doSprayParticle(i);
}
} else if (f < 50) {
2023-04-10 17:54:06 +00:00
this.doSprayParticle(Utils.randInt(8));
}
2023-04-10 17:54:06 +00:00
f++;
}
});
}
doSpiralUpwardParticle(trigIndex: integer) {
const initialX = this.evolutionBaseBg.displayWidth / 2;
const particle = this.scene.add.image(initialX, 0, "evo_sparkle");
2023-04-10 17:54:06 +00:00
this.evolutionContainer.add(particle);
let f = 0;
let amp = 48;
const particleTimer = this.scene.tweens.addCounter({
repeat: -1,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
updateParticle();
}
});
const updateParticle = () => {
if (!f || particle.y > 8) {
particle.setPosition(initialX, 88 - (f * f) / 80);
particle.y += sin(trigIndex, amp) / 4;
particle.x += cos(trigIndex, amp);
2023-04-10 17:54:06 +00:00
particle.setScale(1 - (f / 80));
trigIndex += 4;
if (f & 1) {
2023-04-10 17:54:06 +00:00
amp--;
}
2023-04-10 17:54:06 +00:00
f++;
} else {
particle.destroy();
particleTimer.remove();
}
};
updateParticle();
}
doArcDownParticle(trigIndex: integer) {
const initialX = this.evolutionBaseBg.displayWidth / 2;
const particle = this.scene.add.image(initialX, 0, "evo_sparkle");
2023-04-10 17:54:06 +00:00
particle.setScale(0.5);
this.evolutionContainer.add(particle);
let f = 0;
let amp = 8;
const particleTimer = this.scene.tweens.addCounter({
repeat: -1,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
updateParticle();
}
});
const updateParticle = () => {
if (!f || particle.y < 88) {
particle.setPosition(initialX, 8 + (f * f) / 5);
particle.y += sin(trigIndex, amp) / 4;
particle.x += cos(trigIndex, amp);
amp = 8 + sin(f * 4, 40);
2023-04-10 17:54:06 +00:00
f++;
} else {
particle.destroy();
particleTimer.remove();
}
};
updateParticle();
}
doCircleInwardParticle(trigIndex: integer, speed: integer) {
const initialX = this.evolutionBaseBg.displayWidth / 2;
const initialY = this.evolutionBaseBg.displayHeight / 2;
const particle = this.scene.add.image(initialX, initialY, "evo_sparkle");
2023-04-10 17:54:06 +00:00
this.evolutionContainer.add(particle);
let amp = 120;
const particleTimer = this.scene.tweens.addCounter({
repeat: -1,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
updateParticle();
}
});
const updateParticle = () => {
if (amp > 8) {
particle.setPosition(initialX, initialY);
particle.y += sin(trigIndex, amp);
particle.x += cos(trigIndex, amp);
2023-04-10 17:54:06 +00:00
amp -= speed;
trigIndex += 4;
} else {
particle.destroy();
particleTimer.remove();
}
};
updateParticle();
}
doSprayParticle(trigIndex: integer) {
const initialX = this.evolutionBaseBg.displayWidth / 2;
const initialY = this.evolutionBaseBg.displayHeight / 2;
const particle = this.scene.add.image(initialX, initialY, "evo_sparkle");
2023-04-10 17:54:06 +00:00
this.evolutionContainer.add(particle);
let f = 0;
let yOffset = 0;
const speed = 3 - Utils.randInt(8);
const amp = 48 + Utils.randInt(64);
2023-04-10 17:54:06 +00:00
const particleTimer = this.scene.tweens.addCounter({
repeat: -1,
2023-06-05 01:47:43 +00:00
duration: Utils.getFrameMs(1),
2023-04-10 17:54:06 +00:00
onRepeat: () => {
updateParticle();
}
});
const updateParticle = () => {
if (!(f & 3)) {
2023-04-10 17:54:06 +00:00
yOffset++;
}
2023-04-10 17:54:06 +00:00
if (trigIndex < 128) {
particle.setPosition(initialX + (speed * f) / 3, initialY + yOffset);
particle.y += -sin(trigIndex, amp);
if (f > 108) {
2023-04-10 17:54:06 +00:00
particle.setScale((1 - (f - 108) / 20));
}
2023-04-10 17:54:06 +00:00
trigIndex++;
f++;
} else {
particle.destroy();
particleTimer.remove();
}
};
updateParticle();
}
}
export class EndEvolutionPhase extends Phase {
Add Challenges (#1459) * Initial challenge framework * Add type localisation * Change how challenges are tracked Also fixes the difficulty total text * MVP Renames challenge types, temporarily hides difficulty, and implements challenge saving. * Attempt to fix one legal pokemon in a double battle * Make monotype ignore type changing effects * Make isOfType correctly detect normal types * Try to fix double battles again * Make challenge function more like classic * Add helper function for fainted or not allowed * Add framework for fresh start challenge and improve comments * Try to fix evolution issues * Make form changing items only usable from rewards screen * Update localisation * Additional localisation change * Add achievements for completing challenges * Fix initialisation bug with challenge achievements * Add support for gamemode specific fixed battles Also make monogen challenges face the e4 of their generation * Add better support for mobile in challenges * Localise illegal evolution/form change message * Update achievement names * Make alternate forms count for monogen * Update monotype achievement icons * Add more comments * Improve comments * Fix mid battle form changes * Reorder mode list * Remove currently unused localisation entry * Add type overrides for monotype challenges Meloetta always counts for psychic and castform always counts for normal * Change how form changes are handled Now attempts a switch at the start of each turn instead of immediately * Add start button to challenge select screen * Make starter select back out to challenge screen if using challenges * Fix daily runs * Update tests to new game mode logic
2024-06-08 05:07:23 +00:00
constructor(scene: BattleScene) {
super(scene);
}
start() {
super.start();
this.scene.ui.setModeForceTransition(Mode.MESSAGE).then(() => this.end());
}
}