pokerogue/src/data/berry.ts

59 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-04-20 20:46:05 +01:00
import { MessagePhase, PokemonHealPhase } from "../battle-phases";
import { getPokemonMessage } from "../messages";
import Pokemon from "../pokemon";
2023-04-22 00:30:04 +01:00
import { BattlerTagType } from "./battler-tag";
2023-04-20 20:46:05 +01:00
import { getStatusEffectHealText } from "./status-effect";
export enum BerryType {
SITRUS,
LUM
}
export function getBerryName(berryType: BerryType) {
switch (berryType) {
case BerryType.SITRUS:
return 'SITRUS BERRY';
case BerryType.LUM:
return 'LUM 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';
}
}
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:
2023-04-22 00:30:04 +01:00
return (pokemon: Pokemon) => !!pokemon.status || !!pokemon.getTag(BattlerTagType.CONFUSED);
2023-04-20 20:46:05 +01:00
}
}
export type BerryEffectFunc = (pokemon: Pokemon) => void;
export function getBerryEffectFunc(berryType: BerryType): BerryEffectFunc {
switch (berryType) {
case BerryType.SITRUS:
return (pokemon: Pokemon) => {
2023-04-21 00:44:56 +01:00
pokemon.scene.unshiftPhase(new PokemonHealPhase(pokemon.scene, pokemon.isPlayer(), Math.floor(pokemon.getMaxHp() / 4), getPokemonMessage(pokemon, `'s ${getBerryName(berryType)}\nrestored its HP!`), true));
2023-04-20 20:46:05 +01:00
};
case BerryType.LUM:
return (pokemon: Pokemon) => {
if (pokemon.status) {
2023-04-22 00:30:04 +01:00
pokemon.scene.queueMessage(getPokemonMessage(pokemon, getStatusEffectHealText(pokemon.status.effect)));
2023-04-20 20:46:05 +01:00
pokemon.resetStatus();
pokemon.updateInfo();
2023-04-22 00:30:04 +01:00
} else if (pokemon.getTag(BattlerTagType.CONFUSED))
pokemon.lapseTag(BattlerTagType.CONFUSED);
2023-04-20 20:46:05 +01:00
};
}
}