Refactor apply function to follow the async/await pattern

This commit is contained in:
Christopher Schmidt 2024-08-26 16:23:53 -04:00
parent 37c97c02ef
commit 211e0fc1e0

View File

@ -2773,23 +2773,22 @@ export class ResetStatsAttr extends MoveEffectAttr {
super();
this.targetAllPokemon = targetAllPokemon;
}
apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
return new Promise<boolean>((resolve) => {
const promises: Promise<void>[] = [];
if (this.targetAllPokemon) { // Target all pokemon on the field when Freezy Frost or Haze are used
const activePokemon = user.scene.getField(true);
activePokemon.forEach(p => promises.push(this.resetStats(p)));
target.scene.queueMessage(i18next.t("moveTriggers:statEliminated"));
} else { // Affects only the single target when Clear Smog is used
promises.push(this.resetStats(target));
target.scene.queueMessage(i18next.t("moveTriggers:resetStats", {pokemonName: getPokemonNameWithAffix(target)}));
}
async apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): Promise<boolean> {
const promises: Promise<void>[] = [];
if (this.targetAllPokemon) { // Target all pokemon on the field when Freezy Frost or Haze are used
const activePokemon = user.scene.getField(true);
activePokemon.forEach(p => promises.push(this.resetStats(p)));
target.scene.queueMessage(i18next.t("moveTriggers:statEliminated"));
} else { // Affects only the single target when Clear Smog is used
promises.push(this.resetStats(target));
target.scene.queueMessage(i18next.t("moveTriggers:resetStats", {pokemonName: getPokemonNameWithAffix(target)}));
}
Promise.all(promises).then(() => resolve(true));
});
await Promise.all(promises);
return true;
}
resetStats(pokemon: Pokemon): Promise<void> {
async resetStats(pokemon: Pokemon): Promise<void> {
for (let s = 0; s < pokemon.summonData.battleStats.length; s++) {
pokemon.summonData.battleStats[s] = 0;
}