pokerogue/src/phases/post-turn-status-effect-phase.ts
Sirz Benjie ff44cbfa97
[Refactor] Refactor ability file part 1 (#5589)
* Move ability.ts to subfolder

* Extract types out of ability.ts

* Update imports in ability.ts and friends

* Cleanup imports in ability.ts

* Re-add imports lost during sort

* Update imports forgotten during rebase

* Re-import proper type from enums

* Update biome.jsonc

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Add commit to force tests to rerun

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-04-15 14:08:35 +00:00

73 lines
2.8 KiB
TypeScript

import { globalScene } from "#app/global-scene";
import type { BattlerIndex } from "#app/battle";
import {
applyAbAttrs,
applyPostDamageAbAttrs,
BlockNonDirectDamageAbAttr,
BlockStatusDamageAbAttr,
PostDamageAbAttr,
ReduceBurnDamageAbAttr,
} from "#app/data/abilities/ability";
import { CommonBattleAnim, CommonAnim } from "#app/data/battle-anims";
import { getStatusEffectActivationText } from "#app/data/status-effect";
import { BattleSpec } from "#app/enums/battle-spec";
import { StatusEffect } from "#app/enums/status-effect";
import { getPokemonNameWithAffix } from "#app/messages";
import { BooleanHolder, NumberHolder } from "#app/utils";
import { PokemonPhase } from "./pokemon-phase";
export class PostTurnStatusEffectPhase extends PokemonPhase {
// biome-ignore lint/complexity/noUselessConstructor: Not unnecessary as it makes battlerIndex required
constructor(battlerIndex: BattlerIndex) {
super(battlerIndex);
}
start() {
const pokemon = this.getPokemon();
if (pokemon?.isActive(true) && pokemon.status && pokemon.status.isPostTurn() && !pokemon.switchOutStatus) {
pokemon.status.incrementTurn();
const cancelled = new BooleanHolder(false);
applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled);
applyAbAttrs(BlockStatusDamageAbAttr, pokemon, cancelled);
if (!cancelled.value) {
globalScene.queueMessage(
getStatusEffectActivationText(pokemon.status.effect, getPokemonNameWithAffix(pokemon)),
);
const damage = new NumberHolder(0);
switch (pokemon.status.effect) {
case StatusEffect.POISON:
damage.value = Math.max(pokemon.getMaxHp() >> 3, 1);
break;
case StatusEffect.TOXIC:
damage.value = Math.max(Math.floor((pokemon.getMaxHp() / 16) * pokemon.status.toxicTurnCount), 1);
break;
case StatusEffect.BURN:
damage.value = Math.max(pokemon.getMaxHp() >> 4, 1);
applyAbAttrs(ReduceBurnDamageAbAttr, pokemon, null, false, damage);
break;
}
if (damage.value) {
// Set preventEndure flag to avoid pokemon surviving thanks to focus band, sturdy, endure ...
globalScene.damageNumberHandler.add(this.getPokemon(), pokemon.damage(damage.value, false, true));
pokemon.updateInfo();
applyPostDamageAbAttrs(PostDamageAbAttr, pokemon, damage.value, pokemon.hasPassive(), false, []);
}
new CommonBattleAnim(CommonAnim.POISON + (pokemon.status.effect - 1), pokemon).play(false, () => this.end());
} else {
this.end();
}
} else {
this.end();
}
}
override end() {
if (globalScene.currentBattle.battleSpec === BattleSpec.FINAL_BOSS) {
globalScene.initFinalBossPhaseTwo(this.getPokemon());
} else {
super.end();
}
}
}