pokerogue/src/phases/switch-biome-phase.ts
2024-10-04 13:08:31 +08:00

66 lines
2.1 KiB
TypeScript

import BattleScene from "#app/battle-scene";
import { Biome } from "#app/enums/biome";
import { getBiomeKey } from "#app/field/arena";
import { BattlePhase } from "./battle-phase";
export class SwitchBiomePhase extends BattlePhase {
private nextBiome: Biome;
constructor(scene: BattleScene, nextBiome: Biome) {
super(scene);
this.nextBiome = nextBiome;
}
start() {
super.start();
if (this.nextBiome === undefined) {
return this.end();
}
this.scene.tweens.add({
targets: [ this.scene.arenaEnemy, this.scene.lastEnemyTrainer ],
x: "+=300",
duration: 2000,
onComplete: () => {
this.scene.arenaEnemy.setX(this.scene.arenaEnemy.x - 600);
this.scene.newArena(this.nextBiome);
const biomeKey = getBiomeKey(this.nextBiome);
const bgTexture = `${biomeKey}_bg`;
this.scene.arenaBgTransition.setTexture(bgTexture);
this.scene.arenaBgTransition.setAlpha(0);
this.scene.arenaBgTransition.setVisible(true);
this.scene.arenaPlayerTransition.setBiome(this.nextBiome);
this.scene.arenaPlayerTransition.setAlpha(0);
this.scene.arenaPlayerTransition.setVisible(true);
this.scene.tweens.add({
targets: [ this.scene.arenaPlayer, this.scene.arenaBgTransition, this.scene.arenaPlayerTransition ],
duration: 1000,
delay: 1000,
ease: "Sine.easeInOut",
alpha: (target: any) => target === this.scene.arenaPlayer ? 0 : 1,
onComplete: () => {
this.scene.arenaBg.setTexture(bgTexture);
this.scene.arenaPlayer.setBiome(this.nextBiome);
this.scene.arenaPlayer.setAlpha(1);
this.scene.arenaEnemy.setBiome(this.nextBiome);
this.scene.arenaEnemy.setAlpha(1);
this.scene.arenaNextEnemy.setBiome(this.nextBiome);
this.scene.arenaBgTransition.setVisible(false);
this.scene.arenaPlayerTransition.setVisible(false);
if (this.scene.lastEnemyTrainer) {
this.scene.lastEnemyTrainer.destroy();
}
this.end();
}
});
}
});
}
}