Fix being able to buy Sacred Ash without fainted party members

pull/156/head
Flashfyre 2024-04-16 12:04:52 -04:00
parent 4b77ba8c39
commit 257e222b83
3 changed files with 29 additions and 14 deletions

View File

@ -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<void> {
addModifier(modifier: Modifier, ignoreUpdate?: boolean, playSound?: boolean, virtual?: boolean, instant?: boolean): Promise<boolean> {
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);
});
}

View File

@ -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;
}
}

View File

@ -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();