2023-04-25 06:32:48 +01:00
import { PokemonHealPhase , StatChangePhase } from "../battle-phases" ;
2023-04-20 20:46:05 +01:00
import { getPokemonMessage } from "../messages" ;
2023-04-25 06:32:48 +01:00
import Pokemon , { MoveResult } from "../pokemon" ;
import { getBattleStatName } from "./battle-stat" ;
import { BattleStat } from "./battle-stat" ;
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 ,
2023-04-25 06:32:48 +01:00
LUM ,
ENIGMA ,
LIECHI ,
GANLON ,
SALAC ,
PETAYA ,
APICOT ,
LANSAT ,
STARF
2023-04-20 20:46:05 +01:00
}
export function getBerryName ( berryType : BerryType ) {
2023-04-25 06:32:48 +01:00
return ` ${ BerryType [ berryType ] } BERRY ` ;
2023-04-20 20:46:05 +01:00
}
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' ;
2023-04-25 06:32:48 +01:00
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%' ;
2023-04-20 20:46:05 +01:00
}
}
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-25 06:32:48 +01:00
case BerryType . ENIGMA :
return ( pokemon : Pokemon ) = > {
2023-05-04 17:57:55 +01:00
const opponent = pokemon . getOpponent ( ) ;
2023-04-25 06:32:48 +01:00
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 ;
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 :
2023-04-25 06:32:48 +01:00
case BerryType . ENIGMA :
2023-04-20 20:46:05 +01:00
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
} ;
2023-04-25 06:32:48 +01:00
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 ;
2023-04-27 04:33:13 +01:00
pokemon . scene . unshiftPhase ( new StatChangePhase ( pokemon . scene , pokemon . isPlayer ( ) , true , [ battleStat ] , 1 ) ) ;
2023-04-25 06:32:48 +01:00
} ;
case BerryType . LANSAT :
return ( pokemon : Pokemon ) = > {
pokemon . addTag ( BattlerTagType . CRIT_BOOST ) ;
} ;
case BerryType . STARF :
2023-04-27 04:33:13 +01:00
return ( pokemon : Pokemon ) = > pokemon . scene . unshiftPhase ( new StatChangePhase ( pokemon . scene , pokemon . isPlayer ( ) , true , [ BattleStat . RAND ] , 2 ) ) ;
2023-04-20 20:46:05 +01:00
}
}