From 80a8c659eeb8dddefbde615a694b472000a1ee73 Mon Sep 17 00:00:00 2001 From: innerthunder <168692175+innerthunder@users.noreply.github.com> Date: Sat, 2 Nov 2024 09:47:08 -0700 Subject: [PATCH] [P2] Add "no switch-in" fail condition for Shed Tail and Baton Pass (#4777) --- src/data/move.ts | 10 ++++++++-- src/test/moves/shed_tail.test.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 837602ca71a..e6695d64c48 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -5839,7 +5839,6 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { } } - export class ChillyReceptionAttr extends ForceSwitchOutAttr { apply(user: Pokemon, target: Pokemon, move: Move, args: any[]): boolean { user.scene.arena.trySetWeather(WeatherType.SNOW, true); @@ -7063,6 +7062,11 @@ const targetSleptOrComatoseCondition: MoveConditionFunc = (user: Pokemon, target const failIfLastCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => user.scene.phaseQueue.find(phase => phase instanceof MovePhase) !== undefined; +const failIfLastInPartyCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => { + const party: Pokemon[] = user.isPlayer() ? user.scene.getParty() : user.scene.getEnemyParty(); + return party.some(pokemon => pokemon.isActive() && !pokemon.isOnField()); +}; + export type MoveAttrFilter = (attr: MoveAttr) => boolean; function applyMoveAttrsInternal(attrFilter: MoveAttrFilter, user: Pokemon | null, target: Pokemon | null, move: Move, args: any[]): Promise { @@ -7972,6 +7976,7 @@ export function initMoves() { .attr(StatusEffectAttr, StatusEffect.PARALYSIS), new SelfStatusMove(Moves.BATON_PASS, Type.NORMAL, -1, 40, -1, 0, 2) .attr(ForceSwitchOutAttr, true, SwitchType.BATON_PASS) + .condition(failIfLastInPartyCondition) .hidesUser(), new StatusMove(Moves.ENCORE, Type.NORMAL, 100, 5, -1, 0, 2) .attr(AddBattlerTagAttr, BattlerTagType.ENCORE, false, true) @@ -10112,7 +10117,8 @@ export function initMoves() { .makesContact(), new SelfStatusMove(Moves.SHED_TAIL, Type.NORMAL, -1, 10, -1, 0, 9) .attr(AddSubstituteAttr, 0.5) - .attr(ForceSwitchOutAttr, true, SwitchType.SHED_TAIL), + .attr(ForceSwitchOutAttr, true, SwitchType.SHED_TAIL) + .condition(failIfLastInPartyCondition), new SelfStatusMove(Moves.CHILLY_RECEPTION, Type.ICE, -1, 10, -1, 0, 9) .attr(PreMoveMessageAttr, (user, move) => i18next.t("moveTriggers:chillyReception", { pokemonName: getPokemonNameWithAffix(user) })) .attr(ChillyReceptionAttr, true), diff --git a/src/test/moves/shed_tail.test.ts b/src/test/moves/shed_tail.test.ts index c4df6c574cb..4d761a8af24 100644 --- a/src/test/moves/shed_tail.test.ts +++ b/src/test/moves/shed_tail.test.ts @@ -1,4 +1,5 @@ import { SubstituteTag } from "#app/data/battler-tags"; +import { MoveResult } from "#app/field/pokemon"; import { Abilities } from "#enums/abilities"; import { Moves } from "#enums/moves"; import { Species } from "#enums/species"; @@ -53,4 +54,18 @@ describe("Moves - Shed Tail", () => { expect(substituteTag).toBeDefined(); expect(substituteTag?.hp).toBe(Math.floor(magikarp.getMaxHp() / 4)); }); + + it("should fail if no ally is available to switch in", async () => { + await game.classicMode.startBattle([ Species.MAGIKARP ]); + + const magikarp = game.scene.getPlayerPokemon()!; + expect(game.scene.getParty().length).toBe(1); + + game.move.select(Moves.SHED_TAIL); + + await game.phaseInterceptor.to("TurnEndPhase", false); + + expect(magikarp.isOnField()).toBeTruthy(); + expect(magikarp.getLastXMoves()[0].result).toBe(MoveResult.FAIL); + }); });