mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-08-20 22:39:31 +02:00
moved and renamed shouldPreventSwitchOut, rewrote tests to account for U-turn changes, fix syntax error
This commit is contained in:
parent
7af47c94d5
commit
3f6f52bbbd
@ -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();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 () => {
|
||||
|
Loading…
Reference in New Issue
Block a user