From a214e815bc06a2f49dbd3fb147796ec323445293 Mon Sep 17 00:00:00 2001 From: LaukkaE <73663099+LaukkaE@users.noreply.github.com> Date: Fri, 5 Apr 2024 17:32:36 +0300 Subject: [PATCH] implement Regenerator (#37) * implement Regenerator * fix --- src/data/ability.ts | 16 +++++++++++++++- src/data/move.ts | 6 ++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 29a05d62c..9346d090d 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -942,6 +942,19 @@ export class PreSwitchOutResetStatusAbAttr extends PreSwitchOutAbAttr { } } +export class PreSwitchOutHealAbAttr extends PreSwitchOutAbAttr { + applyPreSwitchOut(pokemon: Pokemon, args: any[]): boolean | Promise { + if (pokemon.getHpRatio() < 1 ) { + const healAmount = Math.floor(pokemon.getMaxHp() * 0.33); + pokemon.heal(healAmount); + pokemon.updateInfo(); + return true; + } + + return false; + } +} + export class PreStatChangeAbAttr extends AbAttr { applyPreStatChange(pokemon: Pokemon, stat: BattleStat, cancelled: Utils.BooleanHolder, args: any[]): boolean | Promise { return false; @@ -2359,7 +2372,8 @@ export function initAbilities() { .ignorable(), new Ability(Abilities.POISON_TOUCH, "Poison Touch", "May poison a target when the Pokémon makes contact.", 5) .attr(PostAttackContactApplyStatusEffectAbAttr, 30, StatusEffect.POISON), - new Ability(Abilities.REGENERATOR, "Regenerator (N)", "Restores a little HP when withdrawn from battle.", 5), + new Ability(Abilities.REGENERATOR, "Regenerator", "Restores a little HP when withdrawn from battle.", 5) + .attr(PreSwitchOutHealAbAttr), new Ability(Abilities.BIG_PECKS, "Big Pecks", "Protects the Pokémon from Defense-lowering effects.", 5) .attr(ProtectStatAbAttr, BattleStat.DEF) .ignorable(), diff --git a/src/data/move.ts b/src/data/move.ts index 589974664..8ac38c5ff 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -12,7 +12,7 @@ import * as Utils from "../utils"; import { WeatherType } from "./weather"; import { ArenaTagSide, ArenaTrapTag } from "./arena-tag"; import { ArenaTagType } from "./enums/arena-tag-type"; -import { Abilities, ProtectAbilityAbAttr, BlockRecoilDamageAttr, BlockOneHitKOAbAttr, IgnoreContactAbAttr, MaxMultiHitAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr } from "./ability"; +import { Abilities, ProtectAbilityAbAttr, BlockRecoilDamageAttr, BlockOneHitKOAbAttr, IgnoreContactAbAttr, MaxMultiHitAbAttr, applyAbAttrs, BlockNonDirectDamageAbAttr, applyPreSwitchOutAbAttrs, PreSwitchOutAbAttr } from "./ability"; import { PokemonHeldItemModifier } from "../modifier/modifier"; import { BattlerIndex } from "../battle"; import { Stat } from "./pokemon-stat"; @@ -2272,8 +2272,10 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { return resolve(false); const switchOutTarget = this.user ? user : target; if (switchOutTarget instanceof PlayerPokemon) { - if (switchOutTarget.hp) + if (switchOutTarget.hp) { + applyPreSwitchOutAbAttrs(PreSwitchOutAbAttr, switchOutTarget); (switchOutTarget as PlayerPokemon).switchOut(this.batonPass, true).then(() => resolve(true)); + } else resolve(false); return;