From 3f6f52bbbd14e7b306b6047237c2523409219f58 Mon Sep 17 00:00:00 2001 From: muscode13 Date: Sat, 2 Nov 2024 14:26:03 -0600 Subject: [PATCH] moved and renamed shouldPreventSwitchOut, rewrote tests to account for U-turn changes, fix syntax error --- src/data/ability.ts | 4 ++-- src/data/move.ts | 37 +++++++++++++++-------------- src/test/abilities/wimp_out.test.ts | 11 ++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/data/ability.ts b/src/data/ability.ts index a4627e94fd3..fc4c6f34b48 100644 --- a/src/data/ability.ts +++ b/src/data/ability.ts @@ -9,7 +9,7 @@ import { StatusEffect, getNonVolatileStatusEffects, getStatusEffectDescriptor, g import { Gender } from "./gender"; import Move, { AttackMove, MoveCategory, MoveFlags, MoveTarget, FlinchAttr, OneHitKOAttr, HitHealAttr, allMoves, StatusMove, SelfStatusMove, VariablePowerAttr, applyMoveAttrs, IncrementMovePriorityAttr, VariableMoveTypeAttr, RandomMovesetMoveAttr, RandomMoveAttr, NaturePowerAttr, CopyMoveAttr, MoveAttr, MultiHitAttr, SacrificialAttr, SacrificialAttrOnHit, NeutralDamageAgainstFlyingTypeMultiplierAttr, FixedDamageAttr } from "./move"; import { ArenaTagSide, ArenaTrapTag } from "./arena-tag"; -import { BerryModifier, HitHealModifier, PokemonHeldItemModifier, PokemonMultiHitModifier } from "../modifier/modifier"; +import { BerryModifier, HitHealModifier, PokemonHeldItemModifier } from "../modifier/modifier"; import { TerrainType } from "./terrain"; import { SpeciesFormChangeManualTrigger, SpeciesFormChangeRevertWeatherFormTrigger, SpeciesFormChangeWeatherTrigger } from "./pokemon-forms"; import i18next from "i18next"; @@ -4938,7 +4938,7 @@ class ForceSwitchOutHelper { } const party = player ? pokemon.scene.getParty() : pokemon.scene.getEnemyParty(); - return (!player && pokemon.scene.currentBattle.battleType !== BattleType.WILD) + return (!player && pokemon.scene.currentBattle.battleType === BattleType.WILD) || party.filter(p => p.isAllowedInBattle() && (player || (p as EnemyPokemon).trainerSlot === (switchOutTarget as EnemyPokemon).trainerSlot)).length > pokemon.scene.currentBattle.getBattlerCount(); } diff --git a/src/data/move.ts b/src/data/move.ts index 2775e527cec..be9b4fef84a 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -5761,20 +5761,6 @@ export class RevivalBlessingAttr extends MoveEffectAttr { } } -/** -* Helper function to check if the Pokémon's health is below half after taking damage. -* Used for an edge case interaction with Wimp Out/Emergency Exit. -* If the Ability activates due to being hit by U-turn or Volt Switch, the user of that move will not be switched out. -*/ -function shouldPreventSwitchOut(target: Pokemon): boolean { - const pokemonHealth = target.hp; - const maxPokemonHealth = target.getMaxHp(); - const damageTaken = target.turnData.damageTaken; - const initialHealth = pokemonHealth + damageTaken; - - // Check if the Pokémon's health has dropped below half after the damage - return initialHealth >= maxPokemonHealth / 2 && pokemonHealth < maxPokemonHealth / 2; -} export class ForceSwitchOutAttr extends MoveEffectAttr { constructor( @@ -5801,8 +5787,8 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { */ if (switchOutTarget instanceof PlayerPokemon) { if (target.getAbility().hasAttr(PostDamageForceSwitchAbAttr) && - (move.id === Moves.U_TURN || move.id === Moves.VOLT_SWITCH)) { - if (shouldPreventSwitchOut(target)) { + (move.id === Moves.U_TURN || move.id === Moves.VOLT_SWITCH || move.id === Moves.FLIP_TURN)) { + if (this.hpDroppedBelowHalf(target)) { return false; } } @@ -5836,8 +5822,8 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { * If it did, the user of U-turn or Volt Switch will not be switched out. */ if (target.getAbility().hasAttr(PostDamageForceSwitchAbAttr) && - (move.id === Moves.U_TURN || move.id === Moves.VOLT_SWITCH)) { - if (shouldPreventSwitchOut(target)) { + (move.id === Moves.U_TURN || move.id === Moves.VOLT_SWITCH) || move.id === Moves.FLIP_TURN) { + if (this.hpDroppedBelowHalf(target)) { return false; } } @@ -5934,6 +5920,21 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { } return ret; } + + /** + * Helper function to check if the Pokémon's health is below half after taking damage. + * Used for an edge case interaction with Wimp Out/Emergency Exit. + * If the Ability activates due to being hit by U-turn or Volt Switch, the user of that move will not be switched out. + */ + hpDroppedBelowHalf(target: Pokemon): boolean { + const pokemonHealth = target.hp; + const maxPokemonHealth = target.getMaxHp(); + const damageTaken = target.turnData.damageTaken; + const initialHealth = pokemonHealth + damageTaken; + + // Check if the Pokémon's health has dropped below half after the damage + return initialHealth >= maxPokemonHealth / 2 && pokemonHealth < maxPokemonHealth / 2; + } } export class ChillyReceptionAttr extends ForceSwitchOutAttr { diff --git a/src/test/abilities/wimp_out.test.ts b/src/test/abilities/wimp_out.test.ts index 46922a930c4..ee943befc16 100644 --- a/src/test/abilities/wimp_out.test.ts +++ b/src/test/abilities/wimp_out.test.ts @@ -93,6 +93,7 @@ describe("Abilities - Wimp Out", () => { ]); const enemyPokemon = game.scene.getEnemyPokemon()!; + enemyPokemon.hp *= 0.52; game.move.select(Moves.FALSE_SWIPE); await game.phaseInterceptor.to("BerryPhase"); @@ -160,18 +161,16 @@ describe("Abilities - Wimp Out", () => { it("If this Ability does not activate due to being hit by U-turn or Volt Switch, the user of that move will be switched out.", async () => { game.override .startingLevel(190) + .startingWave(8) .enemyMoveset([ Moves.U_TURN ]); await game.classicMode.startBattle([ Species.GOLISOPOD, Species.TYRUNT ]); - + const RIVAL_NINJASK1 = game.scene.getEnemyPokemon()?.id; game.move.select(Moves.SPLASH); - await game.phaseInterceptor.to("TurnEndPhase"); - - const enemyPokemon = game.scene.getEnemyPokemon()!; - const hasFled = enemyPokemon.switchOutStatus; - expect(hasFled).toBe(true); + await game.phaseInterceptor.to("BerryPhase", false); + expect(game.scene.getEnemyPokemon()?.id !== RIVAL_NINJASK1); }); it("Dragon Tail and Circle Throw switch out Pokémon before the Ability activates.", async () => {