From 72f431143dfbe4b037e24f65de0ac3cee8eaaceb Mon Sep 17 00:00:00 2001 From: NightKev <34855794+DayKev@users.noreply.github.com> Date: Fri, 29 Nov 2024 22:37:32 -0800 Subject: [PATCH] Add additional checks to prevent damage to pokemon not on the field --- src/data/ability.ts | 12 ++++++------ src/data/arena-tag.ts | 2 +- src/data/move.ts | 2 +- src/phases/weather-effect-phase.ts | 8 ++++++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index 3103c08cee6..3948b4040cc 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -3720,16 +3720,16 @@ export class PostTurnHurtIfSleepingAbAttr extends PostTurnAbAttr { /** * Deals damage to all sleeping opponents equal to 1/8 of their max hp (min 1) - * @param {Pokemon} pokemon Pokemon that has this ability - * @param {boolean} passive N/A - * @param {boolean} simulated true if applying in a simulated call. - * @param {any[]} args N/A - * @returns {boolean} true if any opponents are sleeping + * @param pokemon Pokemon that has this ability + * @param passive N/A + * @param simulated `true` if applying in a simulated call. + * @param args N/A + * @returns `true` if any opponents are sleeping */ applyPostTurn(pokemon: Pokemon, passive: boolean, simulated: boolean, args: any[]): boolean | Promise { let hadEffect: boolean = false; for (const opp of pokemon.getOpponents()) { - if ((opp.status?.effect === StatusEffect.SLEEP || opp.hasAbility(Abilities.COMATOSE)) && !opp.hasAbilityWithAttr(BlockNonDirectDamageAbAttr)) { + if ((opp.status?.effect === StatusEffect.SLEEP || opp.hasAbility(Abilities.COMATOSE)) && !opp.hasAbilityWithAttr(BlockNonDirectDamageAbAttr) && !opp.switchOutStatus) { if (!simulated) { opp.damageAndUpdate(Utils.toDmgValue(opp.getMaxHp() / 8), HitResult.OTHER); pokemon.scene.queueMessage(i18next.t("abilityTriggers:badDreams", { pokemonName: getPokemonNameWithAffix(opp) })); diff --git a/src/data/arena-tag.ts b/src/data/arena-tag.ts index 2f57650c65d..8bb74d29a4e 100644 --- a/src/data/arena-tag.ts +++ b/src/data/arena-tag.ts @@ -1144,7 +1144,7 @@ class FireGrassPledgeTag extends ArenaTag { ? arena.scene.getPlayerField() : arena.scene.getEnemyField(); - field.filter(pokemon => !pokemon.isOfType(Type.FIRE)).forEach(pokemon => { + field.filter(pokemon => !pokemon.isOfType(Type.FIRE) && !pokemon.switchOutStatus).forEach(pokemon => { // "{pokemonNameWithAffix} was hurt by the sea of fire!" pokemon.scene.queueMessage(i18next.t("arenaTag:fireGrassPledgeLapse", { pokemonNameWithAffix: getPokemonNameWithAffix(pokemon) })); // TODO: Replace this with a proper animation diff --git a/src/data/move.ts b/src/data/move.ts index 2ac4d74b712..04124117391 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -1843,7 +1843,7 @@ export class FlameBurstAttr extends MoveEffectAttr { applyAbAttrs(BlockNonDirectDamageAbAttr, targetAlly, cancelled); } - if (cancelled.value || !targetAlly) { + if (cancelled.value || !targetAlly || targetAlly.switchOutStatus) { return false; } diff --git a/src/phases/weather-effect-phase.ts b/src/phases/weather-effect-phase.ts index d358a114874..442bafa0ca7 100644 --- a/src/phases/weather-effect-phase.ts +++ b/src/phases/weather-effect-phase.ts @@ -59,8 +59,12 @@ export class WeatherEffectPhase extends CommonAnimPhase { } } - this.scene.ui.showText(getWeatherLapseMessage(this.weather.weatherType)!, null, () => { // TODO: is this bang correct? - this.executeForAll((pokemon: Pokemon) => applyPostWeatherLapseAbAttrs(PostWeatherLapseAbAttr, pokemon, this.weather)); + this.scene.ui.showText(getWeatherLapseMessage(this.weather.weatherType) ?? "", null, () => { + this.executeForAll((pokemon: Pokemon) => { + if (!pokemon.switchOutStatus) { + applyPostWeatherLapseAbAttrs(PostWeatherLapseAbAttr, pokemon, this.weather); + } + }); super.start(); });