import { PokemonHealPhase, StatChangePhase } from "../battle-phases"; import { getPokemonMessage } from "../messages"; import Pokemon, { MoveResult } from "../pokemon"; import { getBattleStatName } from "./battle-stat"; import { BattleStat } from "./battle-stat"; import { BattlerTagType } from "./battler-tag"; import { getStatusEffectHealText } from "./status-effect"; export enum BerryType { SITRUS, LUM, ENIGMA, LIECHI, GANLON, SALAC, PETAYA, APICOT, LANSAT, STARF } export function getBerryName(berryType: BerryType) { return `${BerryType[berryType]} BERRY`; } export function getBerryEffectDescription(berryType: BerryType) { switch (berryType) { case BerryType.SITRUS: return 'Restores 25% HP if HP is below 50%'; case BerryType.LUM: return 'Cures any non-volatile status condition and confusion'; case BerryType.ENIGMA: return 'Restores 25% HP if hit by a super effective move'; case BerryType.LIECHI: case BerryType.GANLON: case BerryType.SALAC: case BerryType.PETAYA: case BerryType.APICOT: const stat = (berryType - BerryType.LIECHI) as BattleStat; return `Raises ${getBattleStatName(stat)} if HP is below 25%`; case BerryType.LANSAT: return 'Raises critical hit ratio if HP is below 25%'; case BerryType.STARF: return 'Sharply raises a random stat if HP is below 25%'; } } export type BerryPredicate = (pokemon: Pokemon) => boolean; export function getBerryPredicate(berryType: BerryType): BerryPredicate { switch (berryType) { case BerryType.SITRUS: return (pokemon: Pokemon) => pokemon.getHpRatio() < 0.5; case BerryType.LUM: return (pokemon: Pokemon) => !!pokemon.status || !!pokemon.getTag(BattlerTagType.CONFUSED); case BerryType.ENIGMA: return (pokemon: Pokemon) => { const opponent = pokemon.getOpponent(); const opponentLastMove = opponent ? opponent.getLastXMoves(1).find(() => true) : null; // TODO: Update so this works even if opponent has fainted return opponentLastMove && opponentLastMove.turn === pokemon.scene.currentBattle?.turn - 1 && opponentLastMove.result === MoveResult.SUPER_EFFECTIVE; }; case BerryType.LIECHI: case BerryType.GANLON: case BerryType.SALAC: case BerryType.PETAYA: case BerryType.APICOT: return (pokemon: Pokemon) => { const battleStat = (berryType - BerryType.LIECHI) as BattleStat; return pokemon.getHpRatio() < 0.25 && pokemon.summonData.battleStats[battleStat] < 6; }; case BerryType.LANSAT: return (pokemon: Pokemon) => pokemon.getHpRatio() < 0.25 && !pokemon.getTag(BattlerTagType.CRIT_BOOST); case BerryType.STARF: return (pokemon: Pokemon) => pokemon.getHpRatio() < 0.25; } } export type BerryEffectFunc = (pokemon: Pokemon) => void; export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc { switch (berryType) { case BerryType.SITRUS: case BerryType.ENIGMA: return (pokemon: Pokemon) => { pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.isPlayer(), Math.floor(pokemon.getMaxHp() / 4), getPokemonMessage(pokemon, `'s ${getBerryName(berryType)}\nrestored its HP!`), true)); }; case BerryType.LUM: return (pokemon: Pokemon) => { if (pokemon.status) { pokemon.scene.queueMessage(getPokemonMessage(pokemon, getStatusEffectHealText(pokemon.status.effect))); pokemon.resetStatus(); pokemon.updateInfo(); } else if (pokemon.getTag(BattlerTagType.CONFUSED)) pokemon.lapseTag(BattlerTagType.CONFUSED); }; case BerryType.LIECHI: case BerryType.GANLON: case BerryType.SALAC: case BerryType.PETAYA: case BerryType.APICOT: return (pokemon: Pokemon) => { const battleStat = (berryType - BerryType.LIECHI) as BattleStat; pokemon.scene.unshiftPhase(new StatChangePhase(pokemon.scene, pokemon.isPlayer(), true, [ battleStat ], 1)); }; case BerryType.LANSAT: return (pokemon: Pokemon) => { pokemon.addTag(BattlerTagType.CRIT_BOOST); }; case BerryType.STARF: return (pokemon: Pokemon) => pokemon.scene.unshiftPhase(new StatChangePhase(pokemon.scene, pokemon.isPlayer(), true, [ BattleStat.RAND ], 2)); } }