pokerogue/src/phases/weather-effect-phase.ts
schmidtc1 40e1e7fd4e
[Bug] Fix Reviver Seed and endure triggering on indirect damage (#5182)
* 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>
2025-03-23 22:59:19 +00:00

95 lines
3.0 KiB
TypeScript

import { globalScene } from "#app/global-scene";
import {
applyPreWeatherEffectAbAttrs,
SuppressWeatherEffectAbAttr,
PreWeatherDamageAbAttr,
applyAbAttrs,
BlockNonDirectDamageAbAttr,
applyPostWeatherLapseAbAttrs,
PostWeatherLapseAbAttr,
} from "#app/data/ability";
import { CommonAnim } from "#app/data/battle-anims";
import type { Weather } from "#app/data/weather";
import { getWeatherDamageMessage, getWeatherLapseMessage } from "#app/data/weather";
import { BattlerTagType } from "#app/enums/battler-tag-type";
import { WeatherType } from "#app/enums/weather-type";
import type Pokemon from "#app/field/pokemon";
import { HitResult } from "#app/field/pokemon";
import * as Utils from "#app/utils";
import { CommonAnimPhase } from "./common-anim-phase";
export class WeatherEffectPhase extends CommonAnimPhase {
public weather: Weather | null;
constructor() {
super(
undefined,
undefined,
CommonAnim.SUNNY + ((globalScene?.arena?.weather?.weatherType || WeatherType.NONE) - 1),
);
this.weather = globalScene?.arena?.weather;
}
start() {
// Update weather state with any changes that occurred during the turn
this.weather = globalScene?.arena?.weather;
if (!this.weather) {
this.end();
return;
}
this.setAnimation(CommonAnim.SUNNY + (this.weather.weatherType - 1));
if (this.weather.isDamaging()) {
const cancelled = new Utils.BooleanHolder(false);
this.executeForAll((pokemon: Pokemon) =>
applyPreWeatherEffectAbAttrs(SuppressWeatherEffectAbAttr, pokemon, this.weather, cancelled),
);
if (!cancelled.value) {
const inflictDamage = (pokemon: Pokemon) => {
const cancelled = new Utils.BooleanHolder(false);
applyPreWeatherEffectAbAttrs(PreWeatherDamageAbAttr, pokemon, this.weather, cancelled);
applyAbAttrs(BlockNonDirectDamageAbAttr, pokemon, cancelled);
if (
cancelled.value ||
pokemon.getTag(BattlerTagType.UNDERGROUND) ||
pokemon.getTag(BattlerTagType.UNDERWATER)
) {
return;
}
const damage = Utils.toDmgValue(pokemon.getMaxHp() / 16);
globalScene.queueMessage(getWeatherDamageMessage(this.weather?.weatherType!, pokemon)!); // TODO: are those bangs correct?
pokemon.damageAndUpdate(damage, { result: HitResult.INDIRECT, ignoreSegments: true });
};
this.executeForAll((pokemon: Pokemon) => {
const immune =
!pokemon ||
!!pokemon.getTypes(true, true).filter(t => this.weather?.isTypeDamageImmune(t)).length ||
pokemon.switchOutStatus;
if (!immune) {
inflictDamage(pokemon);
}
});
}
}
globalScene.ui.showText(getWeatherLapseMessage(this.weather.weatherType) ?? "", null, () => {
this.executeForAll((pokemon: Pokemon) => {
if (!pokemon.switchOutStatus) {
applyPostWeatherLapseAbAttrs(PostWeatherLapseAbAttr, pokemon, this.weather);
}
});
super.start();
});
}
}