From d2c5a283d1cf1ab75fba2732fd07f771a952f217 Mon Sep 17 00:00:00 2001 From: Ethan <71776311+EvasiveAce@users.noreply.github.com> Date: Thu, 30 May 2024 18:58:40 -0400 Subject: [PATCH] [Ability] Implement Poison Heal (#1245) * Implement Poison Heal Ability * Removed unneeded import * Fix some comments, as well as make Poison Heal only notify when healing * Eslint fix * Revert Phases * Pushing for sake of reviewing; PR IS NOT DONE IT NEEDS TO BE TESTED AND COMMENTED AGAIN * Changed the way healing is done, through a heal phase instead of heal(); Also added better documentation * Changed healing, as well as making abilityTriggers updated --- src/data/ability.ts | 69 ++++++++++++++++++++++++++++++- src/locales/en/ability-trigger.ts | 3 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 502c72dbd92..d2f76b6b1b5 100755 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -2069,6 +2069,37 @@ export class BlockNonDirectDamageAbAttr extends AbAttr { } } +/** + * This attribute will block any status damage that you put in the parameter. + */ +export class BlockStatusDamageAbAttr extends BlockNonDirectDamageAbAttr { + private effects: StatusEffect[]; + + /** + * @param {StatusEffect[]} effects The status effect(s) that will be blocked from damaging the ability pokemon + */ + constructor(...effects: StatusEffect[]) { + super(false); + + this.effects = effects; + } + + /** + * @param {Pokemon} pokemon The pokemon with the ability + * @param {boolean} passive N/A + * @param {Utils.BooleanHolder} cancelled Whether to cancel the status damage + * @param {any[]} args N/A + * @returns Returns true if status damage is blocked + */ + apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { + if (this.effects.includes(pokemon.status.effect)) { + cancelled.value = true; + return true; + } + return false; + } +} + export class BlockOneHitKOAbAttr extends AbAttr { apply(pokemon: Pokemon, passive: boolean, cancelled: Utils.BooleanHolder, args: any[]): boolean { cancelled.value = true; @@ -2383,6 +2414,41 @@ export class PostTurnAbAttr extends AbAttr { } } +/** + * This attribute will heal 1/8th HP if the ability pokemon has the correct status. + */ +export class PostTurnStatusHealAbAttr extends PostTurnAbAttr { + private effects: StatusEffect[]; + + /** + * @param {StatusEffect[]} effects The status effect(s) that will qualify healing the ability pokemon + */ + constructor(...effects: StatusEffect[]) { + super(false); + + this.effects = effects; + } + + /** + * @param {Pokemon} pokemon The pokemon with the ability that will receive the healing + * @param {Boolean} passive N/A + * @param {any[]} args N/A + * @returns Returns true if healed from status, false if not + */ + applyPostTurn(pokemon: Pokemon, passive: boolean, args: any[]): boolean | Promise { + if (this.effects.includes(pokemon.status.effect)) { + if (pokemon.getMaxHp() !== pokemon.hp) { + const scene = pokemon.scene; + const abilityName = (!passive ? pokemon.getAbility() : pokemon.getPassiveAbility()).name; + scene.unshiftPhase(new PokemonHealPhase(scene, pokemon.getBattlerIndex(), + Math.max(Math.floor(pokemon.getMaxHp() / 8), 1), i18next.t("abilityTriggers:poisonHeal", { pokemonName: pokemon.name, abilityName: abilityName}), true)); + return true; + } + } + return false; + } +} + /** * After the turn ends, resets the status of either the ability holder or their ally * @param {boolean} allyTarget Whether to target ally, defaults to false (self-target) @@ -3732,7 +3798,8 @@ export function initAbilities() { new Ability(Abilities.IRON_FIST, 4) .attr(MovePowerBoostAbAttr, (user, target, move) => move.hasFlag(MoveFlags.PUNCHING_MOVE), 1.2), new Ability(Abilities.POISON_HEAL, 4) - .unimplemented(), + .attr(PostTurnStatusHealAbAttr, StatusEffect.TOXIC, StatusEffect.POISON) + .attr(BlockStatusDamageAbAttr, StatusEffect.TOXIC, StatusEffect.POISON), new Ability(Abilities.ADAPTABILITY, 4) .attr(StabBoostAbAttr), new Ability(Abilities.SKILL_LINK, 4) diff --git a/src/locales/en/ability-trigger.ts b/src/locales/en/ability-trigger.ts index 36aee70de47..b6e4c7c67fd 100644 --- a/src/locales/en/ability-trigger.ts +++ b/src/locales/en/ability-trigger.ts @@ -4,5 +4,6 @@ export const abilityTriggers: SimpleTranslationEntries = { "blockRecoilDamage" : "{{pokemonName}}'s {{abilityName}}\nprotected it from recoil!", "badDreams": "{{pokemonName}} is tormented!", "windPowerCharged": "Being hit by {{moveName}} charged {{pokemonName}} with power!", - "perishBody": "{{pokemonName}}'s {{abilityName}}\n will faint both pokemon in 3 turns!", + "perishBody": "{{pokemonName}}'s {{abilityName}}\nwill faint both pokemon in 3 turns!", + "poisonHeal": "{{pokemonName}}'s {{abilityName}}\nrestored its HP a little!" } as const;