From f4bd1218ef1c5ef559619f796b86ef57a643ce7a Mon Sep 17 00:00:00 2001 From: alchemis Date: Mon, 20 May 2024 16:21:44 -0300 Subject: [PATCH] made enigma berries and lum berries able to proc more than once per turn. --- src/data/berry.ts | 10 +++++----- src/phases.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/data/berry.ts b/src/data/berry.ts index e13d4532b3e..12ce146a8dc 100644 --- a/src/data/berry.ts +++ b/src/data/berry.ts @@ -1,4 +1,4 @@ -import { PokemonHealPhase, StatChangePhase } from "../phases"; +import { PokemonHealPhase, StatChangePhase, TurnEndPhase } from "../phases"; import { getPokemonMessage } from "../messages"; import Pokemon, { HitResult } from "../field/pokemon"; import { getBattleStatName } from "./battle-stat"; @@ -36,7 +36,7 @@ export type BerryPredicate = (pokemon: Pokemon) => boolean; export function getBerryPredicate(berryType: BerryType): BerryPredicate { switch (berryType) { case BerryType.SITRUS: - return (pokemon: Pokemon) => pokemon.getHpRatio() < 0.5; + return (pokemon: Pokemon) => pokemon.getHpRatio() < 0.5 && pokemon.scene.getCurrentPhase() instanceof TurnEndPhase; case BerryType.LUM: return (pokemon: Pokemon) => !!pokemon.status || !!pokemon.getTag(BattlerTagType.CONFUSED); case BerryType.ENIGMA: @@ -50,19 +50,19 @@ export function getBerryPredicate(berryType: BerryType): BerryPredicate { const threshold = new Utils.NumberHolder(0.25); const battleStat = (berryType - BerryType.LIECHI) as BattleStat; applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, threshold); - return pokemon.getHpRatio() < threshold.value && pokemon.summonData.battleStats[battleStat] < 6; + return pokemon.getHpRatio() < threshold.value && pokemon.summonData.battleStats[battleStat] < 6 && pokemon.scene.getCurrentPhase() instanceof TurnEndPhase; }; case BerryType.LANSAT: return (pokemon: Pokemon) => { const threshold = new Utils.NumberHolder(0.25); applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, threshold); - return pokemon.getHpRatio() < 0.25 && !pokemon.getTag(BattlerTagType.CRIT_BOOST); + return pokemon.getHpRatio() < 0.25 && !pokemon.getTag(BattlerTagType.CRIT_BOOST) && pokemon.scene.getCurrentPhase() instanceof TurnEndPhase; }; case BerryType.STARF: return (pokemon: Pokemon) => { const threshold = new Utils.NumberHolder(0.25); applyAbAttrs(ReduceBerryUseThresholdAbAttr, pokemon, null, threshold); - return pokemon.getHpRatio() < 0.25; + return pokemon.getHpRatio() < 0.25 && pokemon.scene.getCurrentPhase() instanceof TurnEndPhase; }; case BerryType.LEPPA: return (pokemon: Pokemon) => { diff --git a/src/phases.ts b/src/phases.ts index de40e1abe6b..5160f5bfca2 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -2584,8 +2584,20 @@ export class MoveEffectPhase extends PokemonPhase { } end() { + + + if (this.getTarget()?.isActive()) { + const target = this.getTarget() + const hasUsableBerry = !!this.scene.findModifier(m => m instanceof BerryModifier && m.shouldApply([ target ]), target.isPlayer()); + if (hasUsableBerry) + this.scene.unshiftPhase(new BerryPhase(this.scene, target.getBattlerIndex())); + } + const user = this.getUserPokemon(); if (user) { + const hasUsableBerry = !!this.scene.findModifier(m => m instanceof BerryModifier && m.shouldApply([ user ]), user.isPlayer()); + if (hasUsableBerry) + this.scene.unshiftPhase(new BerryPhase(this.scene, user.getBattlerIndex())); if (--user.turnData.hitsLeft >= 1 && this.getTarget()?.isActive()) this.scene.unshiftPhase(this.getNewHitPhase()); else {