diff --git a/src/battle-scene.ts b/src/battle-scene.ts index bb4803a9eb1..c94522d3af5 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1653,8 +1653,9 @@ export default class BattleScene extends SceneBase { return Math.floor(moneyValue / 10) * 10; } - addModifier(modifier: Modifier, ignoreUpdate?: boolean, playSound?: boolean, virtual?: boolean, instant?: boolean): Promise { + addModifier(modifier: Modifier, ignoreUpdate?: boolean, playSound?: boolean, virtual?: boolean, instant?: boolean): Promise { return new Promise(resolve => { + let success = false; const soundName = modifier.type.soundName; this.validateAchvs(ModifierAchv, modifier); const modifiersToRemove: PersistentModifier[] = []; @@ -1664,20 +1665,20 @@ export default class BattleScene extends SceneBase { modifiersToRemove.push(...(this.findModifiers(m => m instanceof TerastallizeModifier && m.pokemonId === modifier.pokemonId))); if ((modifier as PersistentModifier).add(this.modifiers, !!virtual, this)) { if (modifier instanceof PokemonFormChangeItemModifier || modifier instanceof TerastallizeModifier) - modifier.apply([ this.getPokemonById(modifier.pokemonId), true ]); + success = modifier.apply([ this.getPokemonById(modifier.pokemonId), true ]); if (playSound && !this.sound.get(soundName)) this.playSound(soundName); } else if (!virtual) { const defaultModifierType = getDefaultModifierTypeForTier(modifier.type.tier); this.queueMessage(`The stack for this item is full.\n You will receive ${defaultModifierType.name} instead.`, null, true); - return this.addModifier(defaultModifierType.newModifier(), ignoreUpdate, playSound, false, instant).then(() => resolve()); + return this.addModifier(defaultModifierType.newModifier(), ignoreUpdate, playSound, false, instant).then(success => resolve(success)); } for (let rm of modifiersToRemove) this.removeModifier(rm); if (!ignoreUpdate && !virtual) - return this.updateModifiers(true, instant).then(() => resolve()); + return this.updateModifiers(true, instant).then(() => resolve(success)); } else if (modifier instanceof ConsumableModifier) { if (playSound && !this.sound.get(soundName)) this.playSound(soundName); @@ -1700,19 +1701,26 @@ export default class BattleScene extends SceneBase { if (modifier.shouldApply(args)) { const result = modifier.apply(args); if (result instanceof Promise) - modifierPromises.push(result); + modifierPromises.push(result.then(s => success ||= s)); + else + success ||= result; } } - return Promise.allSettled([this.party.map(p => p.updateInfo(instant)), ...modifierPromises]).then(() => resolve()); + return Promise.allSettled([this.party.map(p => p.updateInfo(instant)), ...modifierPromises]).then(() => resolve(success)); } else { const args = [ this ]; - if (modifier.shouldApply(args)) - modifier.apply(args); + if (modifier.shouldApply(args)) { + const result = modifier.apply(args); + if (result instanceof Promise) { + return result.then(success => resolve(success)); + } else + success ||= result; + } } } - resolve(); + resolve(success); }); } diff --git a/src/modifier/modifier.ts b/src/modifier/modifier.ts index de4477a3e68..1dde041b782 100644 --- a/src/modifier/modifier.ts +++ b/src/modifier/modifier.ts @@ -1001,9 +1001,11 @@ export class PokemonHpRestoreModifier extends ConsumablePokemonModifier { if (this.fainted || this.healStatus) pokemon.resetStatus(); pokemon.hp = Math.min(pokemon.hp + Math.max(Math.ceil(Math.max(Math.floor((this.restorePercent * 0.01) * pokemon.getMaxHp()), restorePoints)), 1), pokemon.getMaxHp()); + + return true; } - return true; + return false; } } diff --git a/src/phases.ts b/src/phases.ts index f668278d273..08e4f1d6999 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -4162,10 +4162,15 @@ export class SelectModifierPhase extends BattlePhase { const applyModifier = (modifier: Modifier, playSound: boolean = false) => { 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(); + result.then(success => { + if (success) { + this.scene.money -= cost; + this.scene.updateMoneyText(); + this.scene.playSound('buy'); + (this.scene.ui.getHandler() as ModifierSelectUiHandler).updateCostText(); + } else + this.scene.ui.playError(); + }); } else { const doEnd = () => { this.scene.ui.clearText();