From 2a22b31129cfde2ae49dd6e5f88cca4bcc1b21be Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 4 Apr 2023 21:10:11 -0400 Subject: [PATCH] Fix animation not resuming after faint --- src/battle-phase.ts | 3 +++ src/modifier.ts | 50 ++++++++++++++++++++++++++++++++++++++------- src/pokemon.ts | 10 ++++++--- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/battle-phase.ts b/src/battle-phase.ts index f9f643177..aa7d4f4eb 100644 --- a/src/battle-phase.ts +++ b/src/battle-phase.ts @@ -235,6 +235,7 @@ export class SummonPhase extends BattlePhase { this.scene.add.existing(playerPokemon); this.scene.field.add(playerPokemon); playerPokemon.showInfo(); + playerPokemon.playAnim(); playerPokemon.setVisible(true); playerPokemon.setScale(0.5); playerPokemon.tint(getPokeballTintColor(playerPokemon.pokeball)); @@ -968,12 +969,14 @@ export class SelectModifierPhase extends BattlePhase { if (slotIndex < 6) { this.scene.ui.setMode(Mode.MODIFIER_SELECT); this.scene.addModifier(types[cursor].newModifier(this.scene.getParty()[slotIndex])).then(() => super.end()); + this.scene.ui.clearText(); this.scene.ui.setMode(Mode.MESSAGE); } else this.scene.ui.setMode(Mode.MODIFIER_SELECT); }, pokemonModifierType.selectFilter); } else { this.scene.addModifier(types[cursor].newModifier()).then(() => super.end()); + this.scene.ui.clearText(); this.scene.ui.setMode(Mode.MESSAGE); } }); diff --git a/src/modifier.ts b/src/modifier.ts index 57e5cbfac..509b7ceab 100644 --- a/src/modifier.ts +++ b/src/modifier.ts @@ -242,6 +242,29 @@ export class PokemonHpRestoreModifier extends ConsumablePokemonModifier { } } +export class PokemonPpRestoreModifier extends ConsumablePokemonModifier { + private restorePoints: integer; + + constructor(type: ModifierType, pokemonId: integer, restorePoints: integer) { + super(type, pokemonId); + + this.restorePoints = restorePoints; + } + + shouldApply(args: any[]): boolean { + return super.shouldApply(args) && args.length > 1 && typeof(args[1]) === 'number'; + } + + apply(args: any[]): boolean { + const pokemon = args[0] as Pokemon; + const moveIndex = args[1] as integer; + const move = pokemon.moveset[moveIndex]; + move.ppUsed = this.restorePoints >= 0 ? Math.max(move.ppUsed - this.restorePoints, 0) : 0; + + return true; + } +} + export class PokemonLevelIncrementModifier extends ConsumablePokemonModifier { constructor(type: ModifierType, pokemonId: integer) { super(type, pokemonId); @@ -409,13 +432,6 @@ export class PokemonHpRestoreModifierType extends PokemonModifierType { } } -export class PokemonLevelIncrementModifierType extends PokemonModifierType { - constructor(name: string, iconImage?: string) { - super(name, `Increase a POKéMON\'s level by 1`, (type, args) => new PokemonLevelIncrementModifier(type, (args[0] as PlayerPokemon).id), - (_pokemon: PlayerPokemon) => null, iconImage); - } -} - export class PokemonReviveModifierType extends PokemonHpRestoreModifierType { constructor(name: string, restorePercent: integer, iconImage?: string) { super(name, restorePercent, (_type, args) => new PokemonHpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePercent, true), @@ -434,6 +450,26 @@ export class PokemonReviveModifierType extends PokemonHpRestoreModifierType { } } +export class PokemonLevelIncrementModifierType extends PokemonModifierType { + constructor(name: string, iconImage?: string) { + super(name, `Increase a POKéMON\'s level by 1`, (_type, args) => new PokemonLevelIncrementModifier(this, (args[0] as PlayerPokemon).id), + (_pokemon: PlayerPokemon) => null, iconImage); + } +} + +export class PokemonPpRestoreModifierType extends PokemonModifierType { + protected restorePoints: integer; + + constructor(name: string, restorePoints: integer, iconImage?: string) { + super(name, `Restore ${restorePoints} PP for one POKéMON's move`, (_type, args) => new PokemonPpRestoreModifier(this, (args[0] as PlayerPokemon).id, this.restorePoints), + (pokemon: PlayerPokemon) => { + return null; + }, iconImage); + + this.restorePoints = this.restorePoints; + } +} + export class PokemonBaseStatBoosterModifierType extends PokemonModifierType { private stat: Stat; diff --git a/src/pokemon.ts b/src/pokemon.ts index 196e02735..58b171294 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -173,9 +173,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { frameRate: 12, repeat: -1 }); - this.getSprite().play(this.getSpriteKey()); - this.getTintSprite().play(this.getSpriteKey()); - this.getZoomSprite().play(this.getSpriteKey()); + this.playAnim(); resolve(); }); if (!this.scene.load.isLoading()) @@ -220,6 +218,12 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.getAt(2) as Phaser.GameObjects.Sprite; } + playAnim() { + this.getSprite().play(this.getSpriteKey()); + this.getTintSprite().play(this.getSpriteKey()); + this.getZoomSprite().play(this.getSpriteKey()); + } + calculateStats() { if (!this.stats) this.stats = [ 0, 0, 0, 0, 0, 0 ];