From 97124c271052c1280a5458d9f765bf03b23f1902 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 26 Dec 2023 12:29:18 -0500 Subject: [PATCH] Add shiny sparkle animation to egg hatch scene Add shiny sparkle animation to egg hatch scene; implement missing logic for same seed trainer party member generation --- src/egg-hatch-phase.ts | 17 +++++++++++++++-- src/pokemon.ts | 38 ++++++++++++++++++++++---------------- src/trainer.ts | 2 +- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/egg-hatch-phase.ts b/src/egg-hatch-phase.ts index 493c39c68..48ab1f4d9 100644 --- a/src/egg-hatch-phase.ts +++ b/src/egg-hatch-phase.ts @@ -26,6 +26,7 @@ export class EggHatchPhase extends BattlePhase { private eggCrackSprite: Phaser.GameObjects.Sprite; private eggLightraysOverlay: Phaser.GameObjects.Sprite; private pokemonSprite: Phaser.GameObjects.Sprite; + private pokemonShinySparkle: Phaser.GameObjects.Sprite; private infoContainer: Phaser.GameObjects.Container; private statsContainer: StatsContainer; @@ -80,6 +81,11 @@ export class EggHatchPhase extends BattlePhase { this.eggHatchContainer.add((this.pokemonSprite = getPokemonSprite())); + this.pokemonShinySparkle = this.scene.add.sprite(this.pokemonSprite.x, this.pokemonSprite.y, 'shiny'); + this.pokemonShinySparkle.setVisible(false); + + this.eggHatchContainer.add(this.pokemonShinySparkle); + this.eggHatchOverlay = this.scene.add.rectangle(0, -this.scene.game.canvas.height / 6, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0xFFFFFF); this.eggHatchOverlay.setOrigin(0, 0); this.eggHatchOverlay.setAlpha(0); @@ -173,18 +179,25 @@ export class EggHatchPhase extends BattlePhase { ease: 'Cubic.easeIn' }); this.scene.time.delayedCall(Utils.fixedInt(1500), () => { + const isShiny = pokemon.isShiny(); if (pokemon.species.mythical) this.scene.validateAchv(achvs.HATCH_MYTHICAL); if (pokemon.species.legendary) this.scene.validateAchv(achvs.HATCH_LEGENDARY); - if (pokemon.isShiny()) + if (isShiny) this.scene.validateAchv(achvs.HATCH_SHINY); this.eggContainer.setVisible(false); this.pokemonSprite.play(pokemon.getSpriteKey(true)); this.pokemonSprite.setVisible(true); this.scene.time.delayedCall(Utils.fixedInt(1000), () => { pokemon.cry(); - this.scene.time.delayedCall(Utils.fixedInt(1250), () => { + if (isShiny) { + this.scene.time.delayedCall(Utils.fixedInt(1250), () => { + this.pokemonShinySparkle.play('sparkle'); + this.scene.playSound('sparkle'); + }); + } + this.scene.time.delayedCall(Utils.fixedInt(!isShiny ? 1250 : 1750), () => { this.scene.tweens.add({ targets: this.infoContainer, duration: Utils.fixedInt(750), diff --git a/src/pokemon.ts b/src/pokemon.ts index e0c202336..0553e00de 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -197,22 +197,8 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { this.add(sprite); this.add(tintSprite); - if (this.shiny) { - const shinySparkle = this.scene.add.sprite(0, 0, 'shiny'); - shinySparkle.setVisible(false); - shinySparkle.setOrigin(0.5, 1); - const frameNames = this.scene.anims.generateFrameNames('shiny', { suffix: '.png', end: 34 }); - this.scene.anims.create({ - key: 'sparkle', - frames: frameNames, - frameRate: 32, - showOnStart: true, - hideOnComplete: true, - }); - this.add(shinySparkle); - - this.shinySparkle = shinySparkle; - } + if (this.isShiny() && !this.shinySparkle) + this.initShinySparkle(); } isOnField(): boolean { @@ -388,6 +374,23 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { : this.maskSprite; } + initShinySparkle(): void { + const shinySparkle = this.scene.add.sprite(0, 0, 'shiny'); + shinySparkle.setVisible(false); + shinySparkle.setOrigin(0.5, 1); + const frameNames = this.scene.anims.generateFrameNames('shiny', { suffix: '.png', end: 34 }); + this.scene.anims.create({ + key: 'sparkle', + frames: frameNames, + frameRate: 32, + showOnStart: true, + hideOnComplete: true, + }); + this.add(shinySparkle); + + this.shinySparkle = shinySparkle; + } + playAnim(): void { this.getSprite().play(this.getBattleSpriteKey()); this.getTintSprite().play(this.getBattleSpriteKey()); @@ -729,6 +732,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { if ((E ^ F) < 32) console.log('REAL SHINY!!'); + if (this.shiny) + this.initShinySparkle(); + return this.shiny; } diff --git a/src/trainer.ts b/src/trainer.ts index 64c5efae2..0e625ebda 100644 --- a/src/trainer.ts +++ b/src/trainer.ts @@ -140,7 +140,7 @@ export default class Trainer extends Phaser.GameObjects.Container { : this.genNewPartyMemberSpecies(level); ret = new EnemyPokemon(this.scene, species, level, true); - }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : this.scene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + ((index + 1) << 8)); + }, this.config.hasStaticParty ? this.config.getDerivedType() + ((index + 1) << 8) : this.scene.currentBattle.waveIndex + (this.config.getDerivedType() << 10) + (((!this.config.useSameSeedForAllMembers ? index : 0) + 1) << 8)); return ret; }