From 93a7af853be463425897fd78b6176779fcb48bfb Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Mon, 25 Mar 2024 00:21:00 -0400 Subject: [PATCH] Berries activate simultaneously --- src/battle-scene.ts | 9 +++++++-- src/phases.ts | 18 ++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 39f47fe05..b30a0ac7b 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1862,12 +1862,17 @@ export default class BattleScene extends Phaser.Scene { return (player ? this.modifiers : this.enemyModifiers).find(m => (modifierFilter as ModifierPredicate)(m)); } - applyModifiers(modifierType: { new(...args: any[]): Modifier }, player: boolean = true, ...args: any[]): void { + applyModifiers(modifierType: { new(...args: any[]): Modifier }, player: boolean = true, ...args: any[]): PersistentModifier[] { + const appliedModifiers: PersistentModifier[] = []; const modifiers = (player ? this.modifiers : this.enemyModifiers).filter(m => m instanceof modifierType && m.shouldApply(args)); for (let modifier of modifiers) { - if (modifier.apply(args)) + if (modifier.apply(args)) { console.log('Applied', modifier.type.name, !player ? '(enemy)' : ''); + appliedModifiers.push(modifier); + } } + + return appliedModifiers; } applyModifier(modifierType: { new(...args: any[]): Modifier }, player: boolean = true, ...args: any[]): PersistentModifier { diff --git a/src/phases.ts b/src/phases.ts index 6cdc55034..7e4e76ca1 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3455,15 +3455,17 @@ export class BerryPhase extends CommonAnimPhase { } start() { - let berryModifier: BerryModifier; + let berryModifiers: BerryModifier[]; - if ((berryModifier = this.scene.applyModifier(BerryModifier, this.player, this.getPokemon()) as BerryModifier)) { - if (berryModifier.consumed) { - if (!--berryModifier.stackCount) - this.scene.removeModifier(berryModifier); - else - berryModifier.consumed = false; - this.scene.updateModifiers(this.player); + if ((berryModifiers = this.scene.applyModifiers(BerryModifier, this.player, this.getPokemon()) as BerryModifier[])) { + for (let berryModifier of berryModifiers) { + if (berryModifier.consumed) { + if (!--berryModifier.stackCount) + this.scene.removeModifier(berryModifier); + else + berryModifier.consumed = false; + this.scene.updateModifiers(this.player); + } } return super.start(); }