From 4f1a88d35fc40ca44139d1f7e8ce5898492b5549 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Thu, 16 May 2024 15:22:05 -0400 Subject: [PATCH] Partially implement Cheek Pouch ability --- src/data/ability.ts | 35 ++++++++++++++++++++++++++++++++++- src/phases.ts | 9 +++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index a257525efd0..a1c84ab3eb7 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -2330,6 +2330,38 @@ export class PreventBerryUseAbAttr extends AbAttr { } } +/** + * A Pokemon with this ability heals by a percentage of their maximum hp after eating a berry + * @param healPercent - Percent of Max HP to heal + * @see {@linkcode apply()} for implementation + */ +export class HealFromBerryUseAbAttr extends AbAttr { + /** Percent of Max HP to heal */ + private healPercent: number; + + constructor(healPercent: number) { + super() + + // Clamp healPercent so its between [0,1]. + this.healPercent = Math.max(Math.min(healPercent, 1), 0); + } + + apply(pokemon: Pokemon, passive: boolean, ...args: [Utils.BooleanHolder, any[]]): boolean { + const { name: abilityName } = passive ? pokemon.getPassiveAbility() : pokemon.getAbility() + pokemon.scene.unshiftPhase( + new PokemonHealPhase( + pokemon.scene, + pokemon.getBattlerIndex(), + Math.max(Math.floor(pokemon.getMaxHp() * this.healPercent), 1), + getPokemonMessage(pokemon, `'s ${abilityName}\nrestored its HP!`), + true + ) + ); + + return true + } +} + export class RunSuccessAbAttr extends AbAttr { apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { (args[0] as Utils.IntegerHolder).value = 256; @@ -3369,7 +3401,8 @@ export function initAbilities() { .ignorable() .unimplemented(), new Ability(Abilities.CHEEK_POUCH, 6) - .unimplemented(), + .attr(HealFromBerryUseAbAttr, 1/3) + .partial(), new Ability(Abilities.PROTEAN, 6) .unimplemented(), new Ability(Abilities.FUR_COAT, 6) diff --git a/src/phases.ts b/src/phases.ts index e2755328c69..a36f2fa97f3 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -30,7 +30,7 @@ import { Weather, WeatherType, getRandomWeatherType, getTerrainBlockMessage, get import { TempBattleStat } from "./data/temp-battle-stat"; import { ArenaTagSide, ArenaTrapTag, MistTag, TrickRoomTag } from "./data/arena-tag"; import { ArenaTagType } from "./data/enums/arena-tag-type"; -import { CheckTrappedAbAttr, IgnoreOpponentStatChangesAbAttr, PostAttackAbAttr, PostBattleAbAttr, PostDefendAbAttr, PostSummonAbAttr, PostTurnAbAttr, PostWeatherLapseAbAttr, PreSwitchOutAbAttr, PreWeatherDamageAbAttr, ProtectStatAbAttr, RedirectMoveAbAttr, BlockRedirectAbAttr, RunSuccessAbAttr, StatChangeMultiplierAbAttr, SuppressWeatherEffectAbAttr, SyncEncounterNatureAbAttr, applyAbAttrs, applyCheckTrappedAbAttrs, applyPostAttackAbAttrs, applyPostBattleAbAttrs, applyPostDefendAbAttrs, applyPostSummonAbAttrs, applyPostTurnAbAttrs, applyPostWeatherLapseAbAttrs, applyPreStatChangeAbAttrs, applyPreSwitchOutAbAttrs, applyPreWeatherEffectAbAttrs, BattleStatMultiplierAbAttr, applyBattleStatMultiplierAbAttrs, IncrementMovePriorityAbAttr, applyPostVictoryAbAttrs, PostVictoryAbAttr, applyPostBattleInitAbAttrs, PostBattleInitAbAttr, BlockNonDirectDamageAbAttr as BlockNonDirectDamageAbAttr, applyPostKnockOutAbAttrs, PostKnockOutAbAttr, PostBiomeChangeAbAttr, applyPostFaintAbAttrs, PostFaintAbAttr, IncreasePpAbAttr, PostStatChangeAbAttr, applyPostStatChangeAbAttrs, AlwaysHitAbAttr, PreventBerryUseAbAttr, StatChangeCopyAbAttr } from "./data/ability"; +import { CheckTrappedAbAttr, IgnoreOpponentStatChangesAbAttr, PostAttackAbAttr, PostBattleAbAttr, PostDefendAbAttr, PostSummonAbAttr, PostTurnAbAttr, PostWeatherLapseAbAttr, PreSwitchOutAbAttr, PreWeatherDamageAbAttr, ProtectStatAbAttr, RedirectMoveAbAttr, BlockRedirectAbAttr, RunSuccessAbAttr, StatChangeMultiplierAbAttr, SuppressWeatherEffectAbAttr, SyncEncounterNatureAbAttr, applyAbAttrs, applyCheckTrappedAbAttrs, applyPostAttackAbAttrs, applyPostBattleAbAttrs, applyPostDefendAbAttrs, applyPostSummonAbAttrs, applyPostTurnAbAttrs, applyPostWeatherLapseAbAttrs, applyPreStatChangeAbAttrs, applyPreSwitchOutAbAttrs, applyPreWeatherEffectAbAttrs, BattleStatMultiplierAbAttr, applyBattleStatMultiplierAbAttrs, IncrementMovePriorityAbAttr, applyPostVictoryAbAttrs, PostVictoryAbAttr, applyPostBattleInitAbAttrs, PostBattleInitAbAttr, BlockNonDirectDamageAbAttr as BlockNonDirectDamageAbAttr, applyPostKnockOutAbAttrs, PostKnockOutAbAttr, PostBiomeChangeAbAttr, applyPostFaintAbAttrs, PostFaintAbAttr, IncreasePpAbAttr, PostStatChangeAbAttr, applyPostStatChangeAbAttrs, AlwaysHitAbAttr, PreventBerryUseAbAttr, StatChangeCopyAbAttr, HealFromBerryUseAbAttr } from "./data/ability"; import { Unlockables, getUnlockableName } from "./system/unlockables"; import { getBiomeKey } from "./field/arena"; import { BattleType, BattlerIndex, TurnCommand } from "./battle"; @@ -4010,9 +4010,14 @@ export class BerryPhase extends CommonAnimPhase { this.scene.removeModifier(berryModifier); else berryModifier.consumed = false; - this.scene.updateModifiers(this.player); } } + this.scene.updateModifiers(this.player); + + if (pokemon.hasAbilityWithAttr(HealFromBerryUseAbAttr)) { + applyAbAttrs(HealFromBerryUseAbAttr, pokemon, cancelled); + } + return super.start(); }