Fix fusion move learning bug and inaccurate HP in battle info

This commit is contained in:
Flashfyre 2024-04-11 20:40:16 -04:00
parent 3e9fdc2d0a
commit 3961550f62
5 changed files with 30 additions and 17 deletions

View File

@ -1558,6 +1558,7 @@ export default class BattleScene extends SceneBase {
const soundName = modifier.type.soundName; const soundName = modifier.type.soundName;
this.validateAchvs(ModifierAchv, modifier); this.validateAchvs(ModifierAchv, modifier);
const modifiersToRemove: PersistentModifier[] = []; const modifiersToRemove: PersistentModifier[] = [];
const modifierPromises: Promise<boolean>[] = [];
if (modifier instanceof PersistentModifier) { if (modifier instanceof PersistentModifier) {
if (modifier instanceof TerastallizeModifier) if (modifier instanceof TerastallizeModifier)
modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId))); 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) } else if (modifier instanceof FusePokemonModifier)
args.push(this.getPokemonById(modifier.fusePokemonId) as PlayerPokemon); args.push(this.getPokemonById(modifier.fusePokemonId) as PlayerPokemon);
if (modifier.shouldApply(args)) if (modifier.shouldApply(args)) {
modifier.apply(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 { } else {
const args = [ this ]; const args = [ this ];
if (modifier.shouldApply(args)) if (modifier.shouldApply(args))

View File

@ -601,8 +601,10 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
return this.getMaxHp() - this.hp; return this.getMaxHp() - this.hp;
} }
getHpRatio(): number { getHpRatio(precise: boolean = false): number {
return Math.floor((this.hp / this.getMaxHp()) * 100) / 100; return precise
? this.hp / this.getMaxHp()
: ((this.hp / this.getMaxHp()) * 100) / 100;
} }
generateGender(): void { generateGender(): void {
@ -2324,7 +2326,6 @@ export class PlayerPokemon extends Pokemon {
let partyMemberIndex = this.scene.getParty().indexOf(this); let partyMemberIndex = this.scene.getParty().indexOf(this);
if (partyMemberIndex > fusedPartyMemberIndex) if (partyMemberIndex > fusedPartyMemberIndex)
partyMemberIndex--; 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 const fusedPartyMemberHeldModifiers = this.scene.findModifiers(m => m instanceof PokemonHeldItemModifier
&& (m as PokemonHeldItemModifier).pokemonId === pokemon.id, true) as PokemonHeldItemModifier[]; && (m as PokemonHeldItemModifier).pokemonId === pokemon.id, true) as PokemonHeldItemModifier[];
const transferModifiers: Promise<boolean>[] = []; const transferModifiers: Promise<boolean>[] = [];
@ -2334,6 +2335,8 @@ export class PlayerPokemon extends Pokemon {
this.scene.updateModifiers(true, true).then(() => { this.scene.updateModifiers(true, true).then(() => {
this.scene.removePartyMemberModifiers(fusedPartyMemberIndex); this.scene.removePartyMemberModifiers(fusedPartyMemberIndex);
this.scene.getParty().splice(fusedPartyMemberIndex, 1)[0]; 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(); pokemon.destroy();
this.updateFusionPalette(); this.updateFusionPalette();
resolve(); resolve();

View File

@ -109,7 +109,7 @@ export abstract class Modifier {
return true; return true;
} }
abstract apply(args: any[]): boolean; abstract apply(args: any[]): boolean | Promise<boolean>;
} }
export abstract class PersistentModifier extends Modifier { 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; return super.shouldApply(args) && args[1] instanceof PlayerPokemon && this.fusePokemonId === (args[1] as PlayerPokemon).id;
} }
apply(args: any[]): boolean { apply(args: any[]): Promise<boolean> {
(args[0] as PlayerPokemon).fuse(args[1] as PlayerPokemon); return new Promise<boolean>(resolve => {
(args[0] as PlayerPokemon).fuse(args[1] as PlayerPokemon).then(() => resolve(true));
return true; });
} }
} }

View File

@ -4102,16 +4102,22 @@ export class SelectModifierPhase extends BattlePhase {
} }
const applyModifier = (modifier: Modifier, playSound: boolean = false) => { const applyModifier = (modifier: Modifier, playSound: boolean = false) => {
this.scene.addModifier(modifier, false, playSound); const result = this.scene.addModifier(modifier, false, playSound);
if (cost) { if (cost) {
this.scene.money -= cost; this.scene.money -= cost;
this.scene.updateMoneyText(); this.scene.updateMoneyText();
this.scene.playSound('buy'); this.scene.playSound('buy');
(this.scene.ui.getHandler() as ModifierSelectUiHandler).updateCostText(); (this.scene.ui.getHandler() as ModifierSelectUiHandler).updateCostText();
} else { } else {
const doEnd = () => {
this.scene.ui.clearText(); this.scene.ui.clearText();
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
super.end(); super.end();
};
if (result instanceof Promise)
result.then(() => doEnd());
else
doEnd();
} }
}; };

View File

@ -193,7 +193,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.updateBossSegmentDividers(pokemon as EnemyPokemon); 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.lastHpFrame = this.hpBar.scaleX > 0.5 ? 'high' : this.hpBar.scaleX > 0.25 ? 'medium' : 'low';
this.hpBar.setFrame(this.lastHpFrame); this.hpBar.setFrame(this.lastHpFrame);
if (this.player) if (this.player)
@ -356,7 +356,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.scene.tweens.add({ this.scene.tweens.add({
targets: this.hpBar, targets: this.hpBar,
ease: 'Sine.easeOut', ease: 'Sine.easeOut',
scaleX: pokemon.getHpRatio(), scaleX: pokemon.getHpRatio(true),
duration: duration, duration: duration,
onUpdate: () => { onUpdate: () => {
if (this.player && this.lastHp !== pokemon.hp) { if (this.player && this.lastHp !== pokemon.hp) {