mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-24 22:15:51 +02:00
* Create new turnData field for tracking damageResults, check for HitResult in Reviver Seed modifier * Optional chaining for cases like stealth rock * Adds HitResult.SELF for confusion to distinguish from indirect damage * Adds HitResult.SELF to damage sound effect switch * Cover edge case of salt cure, insert HitResult for ALL damage regardless of optional variable * Change Liquid Ooze HitResult to OTHER from HEAL * Adjust OHKO moves to not bypass endure or RSeed * Add tests for reviver seed * Fixes endure to no longer block indirect damage, updates weather damage to be HitResult.OTHER, adds/fixes unit test * Change destiny bond to HitResult.OTHER so it doesn't trigger rseed * Adds destiny bond unit test * Creates additional unit tests for endure * Rename SELF hitresult to CONFUSION * Update CONFUSION enum * Refactors implementation per Wlowscha's suggestions: removes damageSources array and preventEndure variable * Rename HitResult.OTHER to INDIRECT, create INDIRECT_KO for PSong/DBond, add functionality for INDIRECT_KO to damageanim/number handler * Fixes hit result for stealth rock * Removes unnecessary check, makes DamageResult default to EFFECTIVE, updates remaining damageAndUpdate calls to use INDIRECT * Refactors damageAndUpdate to replace optional parameters with object parameter * Fixes based on Kev's suggestions * Updates tsdocs for damageAndUpdate * Fix merge conflict --------- Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com>
133 lines
4.5 KiB
TypeScript
133 lines
4.5 KiB
TypeScript
import { globalScene } from "#app/global-scene";
|
|
import type { BattlerIndex } from "#app/battle";
|
|
import { CommonAnim } from "#app/data/battle-anims";
|
|
import { getStatusEffectHealText } from "#app/data/status-effect";
|
|
import { StatusEffect } from "#app/enums/status-effect";
|
|
import { HitResult } from "#app/field/pokemon";
|
|
import { getPokemonNameWithAffix } from "#app/messages";
|
|
import { HealingBoosterModifier } from "#app/modifier/modifier";
|
|
import { HealAchv } from "#app/system/achv";
|
|
import i18next from "i18next";
|
|
import * as Utils from "#app/utils";
|
|
import { CommonAnimPhase } from "./common-anim-phase";
|
|
import { BattlerTagType } from "#app/enums/battler-tag-type";
|
|
import type { HealBlockTag } from "#app/data/battler-tags";
|
|
|
|
export class PokemonHealPhase extends CommonAnimPhase {
|
|
private hpHealed: number;
|
|
private message: string | null;
|
|
private showFullHpMessage: boolean;
|
|
private skipAnim: boolean;
|
|
private revive: boolean;
|
|
private healStatus: boolean;
|
|
private preventFullHeal: boolean;
|
|
private fullRestorePP: boolean;
|
|
|
|
constructor(
|
|
battlerIndex: BattlerIndex,
|
|
hpHealed: number,
|
|
message: string | null,
|
|
showFullHpMessage: boolean,
|
|
skipAnim = false,
|
|
revive = false,
|
|
healStatus = false,
|
|
preventFullHeal = false,
|
|
fullRestorePP = false,
|
|
) {
|
|
super(battlerIndex, undefined, CommonAnim.HEALTH_UP);
|
|
|
|
this.hpHealed = hpHealed;
|
|
this.message = message;
|
|
this.showFullHpMessage = showFullHpMessage;
|
|
this.skipAnim = skipAnim;
|
|
this.revive = revive;
|
|
this.healStatus = healStatus;
|
|
this.preventFullHeal = preventFullHeal;
|
|
this.fullRestorePP = fullRestorePP;
|
|
}
|
|
|
|
start() {
|
|
if (!this.skipAnim && (this.revive || this.getPokemon().hp) && !this.getPokemon().isFullHp()) {
|
|
super.start();
|
|
} else {
|
|
this.end();
|
|
}
|
|
}
|
|
|
|
end() {
|
|
const pokemon = this.getPokemon();
|
|
|
|
if (!pokemon.isOnField() || (!this.revive && !pokemon.isActive())) {
|
|
return super.end();
|
|
}
|
|
|
|
const hasMessage = !!this.message;
|
|
const healOrDamage = !pokemon.isFullHp() || this.hpHealed < 0;
|
|
const healBlock = pokemon.getTag(BattlerTagType.HEAL_BLOCK) as HealBlockTag;
|
|
let lastStatusEffect = StatusEffect.NONE;
|
|
|
|
if (healBlock && this.hpHealed > 0) {
|
|
globalScene.queueMessage(healBlock.onActivation(pokemon));
|
|
this.message = null;
|
|
return super.end();
|
|
}
|
|
if (healOrDamage) {
|
|
const hpRestoreMultiplier = new Utils.NumberHolder(1);
|
|
if (!this.revive) {
|
|
globalScene.applyModifiers(HealingBoosterModifier, this.player, hpRestoreMultiplier);
|
|
}
|
|
const healAmount = new Utils.NumberHolder(Math.floor(this.hpHealed * hpRestoreMultiplier.value));
|
|
if (healAmount.value < 0) {
|
|
pokemon.damageAndUpdate(healAmount.value * -1, { result: HitResult.INDIRECT });
|
|
healAmount.value = 0;
|
|
}
|
|
// Prevent healing to full if specified (in case of healing tokens so Sturdy doesn't cause a softlock)
|
|
if (this.preventFullHeal && pokemon.hp + healAmount.value >= pokemon.getMaxHp()) {
|
|
healAmount.value = pokemon.getMaxHp() - pokemon.hp - 1;
|
|
}
|
|
healAmount.value = pokemon.heal(healAmount.value);
|
|
if (healAmount.value) {
|
|
globalScene.damageNumberHandler.add(pokemon, healAmount.value, HitResult.HEAL);
|
|
}
|
|
if (pokemon.isPlayer()) {
|
|
globalScene.validateAchvs(HealAchv, healAmount);
|
|
if (healAmount.value > globalScene.gameData.gameStats.highestHeal) {
|
|
globalScene.gameData.gameStats.highestHeal = healAmount.value;
|
|
}
|
|
}
|
|
if (this.healStatus && !this.revive && pokemon.status) {
|
|
lastStatusEffect = pokemon.status.effect;
|
|
pokemon.resetStatus();
|
|
}
|
|
if (this.fullRestorePP) {
|
|
for (const move of this.getPokemon().getMoveset()) {
|
|
if (move) {
|
|
move.ppUsed = 0;
|
|
}
|
|
}
|
|
}
|
|
pokemon.updateInfo().then(() => super.end());
|
|
} else if (this.healStatus && !this.revive && pokemon.status) {
|
|
lastStatusEffect = pokemon.status.effect;
|
|
pokemon.resetStatus();
|
|
pokemon.updateInfo().then(() => super.end());
|
|
} else if (this.showFullHpMessage) {
|
|
this.message = i18next.t("battle:hpIsFull", {
|
|
pokemonName: getPokemonNameWithAffix(pokemon),
|
|
});
|
|
}
|
|
|
|
if (this.message) {
|
|
globalScene.queueMessage(this.message);
|
|
}
|
|
|
|
if (this.healStatus && lastStatusEffect && !hasMessage) {
|
|
globalScene.queueMessage(getStatusEffectHealText(lastStatusEffect, getPokemonNameWithAffix(pokemon)));
|
|
}
|
|
|
|
if (!healOrDamage && !lastStatusEffect) {
|
|
super.end();
|
|
}
|
|
}
|
|
}
|