From 3961550f62cb652ad0e33a33893f969828fbebf3 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 11 Apr 2024 20:40:16 -0400 Subject: [PATCH] Fix fusion move learning bug and inaccurate HP in battle info --- src/battle-scene.ts | 10 +++++++--- src/field/pokemon.ts | 9 ++++++--- src/modifier/modifier.ts | 10 +++++----- src/phases.ts | 14 ++++++++++---- src/ui/battle-info.ts | 4 ++-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 27166347039..12d7d5d1d 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1558,6 +1558,7 @@ export default class BattleScene extends SceneBase { const soundName = modifier.type.soundName; this.validateAchvs(ModifierAchv, modifier); const modifiersToRemove: PersistentModifier[] = []; + const modifierPromises: Promise[] = []; if (modifier instanceof PersistentModifier) { if (modifier instanceof TerastallizeModifier) modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId))); @@ -1596,11 +1597,14 @@ export default class BattleScene extends SceneBase { } else if (modifier instanceof FusePokemonModifier) args.push(this.getPokemonById(modifier.fusePokemonId) as PlayerPokemon); - if (modifier.shouldApply(args)) - modifier.apply(args); + if (modifier.shouldApply(args)) { + const result = modifier.apply(args); + if (result instanceof Promise) + modifierPromises.push(result); + } } - return Promise.allSettled(this.party.map(p => p.updateInfo(instant))).then(() => resolve()); + return Promise.allSettled([this.party.map(p => p.updateInfo(instant)), ...modifierPromises]).then(() => resolve()); } else { const args = [ this ]; if (modifier.shouldApply(args)) diff --git a/src/field/pokemon.ts b/src/field/pokemon.ts index 06ff004b1..9dc560d80 100644 --- a/src/field/pokemon.ts +++ b/src/field/pokemon.ts @@ -601,8 +601,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container { return this.getMaxHp() - this.hp; } - getHpRatio(): number { - return Math.floor((this.hp / this.getMaxHp()) * 100) / 100; + getHpRatio(precise: boolean = false): number { + return precise + ? this.hp / this.getMaxHp() + : ((this.hp / this.getMaxHp()) * 100) / 100; } generateGender(): void { @@ -2324,7 +2326,6 @@ export class PlayerPokemon extends Pokemon { let partyMemberIndex = this.scene.getParty().indexOf(this); if (partyMemberIndex > fusedPartyMemberIndex) partyMemberIndex--; - pokemon.getMoveset(true).map(m => this.scene.unshiftPhase(new LearnMovePhase(this.scene, partyMemberIndex, m.getMove().id))); const fusedPartyMemberHeldModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier && (m as PokemonHeldItemModifier).pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; const transferModifiers: Promise[] = []; @@ -2334,6 +2335,8 @@ export class PlayerPokemon extends Pokemon { this.scene.updateModifiers(true, true).then(() => { this.scene.removePartyMemberModifiers(fusedPartyMemberIndex); this.scene.getParty().splice(fusedPartyMemberIndex, 1)[0]; + const newPartyMemberIndex = this.scene.getParty().indexOf(this); + pokemon.getMoveset(true).map(m => this.scene.unshiftPhase(new LearnMovePhase(this.scene, newPartyMemberIndex, m.getMove().id))); pokemon.destroy(); this.updateFusionPalette(); resolve(); diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index 115273db7..de4477a3e 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -109,7 +109,7 @@ export abstract class Modifier { return true; } - abstract apply(args: any[]): boolean; + abstract apply(args: any[]): boolean | Promise; } export abstract class PersistentModifier extends Modifier { @@ -1203,10 +1203,10 @@ export class FusePokemonModifier extends ConsumablePokemonModifier { return super.shouldApply(args) && args[1] instanceof PlayerPokemon && this.fusePokemonId === (args[1] as PlayerPokemon).id; } - apply(args: any[]): boolean { - (args[0] as PlayerPokemon).fuse(args[1] as PlayerPokemon); - - return true; + apply(args: any[]): Promise { + return new Promise(resolve => { + (args[0] as PlayerPokemon).fuse(args[1] as PlayerPokemon).then(() => resolve(true)); + }); } } diff --git a/src/phases.ts b/src/phases.ts index ccc9318f8..015c487f5 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -4102,16 +4102,22 @@ export class SelectModifierPhase extends BattlePhase { } const applyModifier = (modifier: Modifier, playSound: boolean = false) => { - this.scene.addModifier(modifier, false, playSound); + const result = this.scene.addModifier(modifier, false, playSound); if (cost) { this.scene.money -= cost; this.scene.updateMoneyText(); this.scene.playSound('buy'); (this.scene.ui.getHandler() as ModifierSelectUiHandler).updateCostText(); } else { - this.scene.ui.clearText(); - this.scene.ui.setMode(Mode.MESSAGE); - super.end(); + const doEnd = () => { + this.scene.ui.clearText(); + this.scene.ui.setMode(Mode.MESSAGE); + super.end(); + }; + if (result instanceof Promise) + result.then(() => doEnd()); + else + doEnd(); } }; diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index ce6c101f1..71f048310 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -193,7 +193,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.updateBossSegmentDividers(pokemon as EnemyPokemon); } - this.hpBar.setScale(pokemon.getHpRatio(), 1); + this.hpBar.setScale(pokemon.getHpRatio(true), 1); this.lastHpFrame = this.hpBar.scaleX > 0.5 ? 'high' : this.hpBar.scaleX > 0.25 ? 'medium' : 'low'; this.hpBar.setFrame(this.lastHpFrame); if (this.player) @@ -356,7 +356,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.scene.tweens.add({ targets: this.hpBar, ease: 'Sine.easeOut', - scaleX: pokemon.getHpRatio(), + scaleX: pokemon.getHpRatio(true), duration: duration, onUpdate: () => { if (this.player && this.lastHp !== pokemon.hp) {