From d1b0bbb155087d174d053aeab4de643382878062 Mon Sep 17 00:00:00 2001 From: Sophia Date: Wed, 21 May 2025 08:14:16 +0100 Subject: [PATCH] [Bug]: Fix #5010: roar and whirlwind missing fail message when against a trainer (#5659) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [BUG] Fixes #5010 Roar and Whirlwind don´t display a fail message Roar and Whirlwind should now display a fail message when used against a trainer with only one pokémon left * Apply suggestions from code review made by SirzBenjie --- src/data/moves/move.ts | 15 +++++++++++++++ test/moves/whirlwind.test.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/data/moves/move.ts b/src/data/moves/move.ts index b190729621c..71807288abc 100644 --- a/src/data/moves/move.ts +++ b/src/data/moves/move.ts @@ -6390,8 +6390,23 @@ export class ForceSwitchOutAttr extends MoveEffectAttr { return (user, target, move) => { const switchOutTarget = (this.selfSwitch ? user : target); const player = switchOutTarget instanceof PlayerPokemon; + const forceSwitchAttr = move.getAttrs(ForceSwitchOutAttr).find(attr => attr.switchType === SwitchType.FORCE_SWITCH); if (!this.selfSwitch) { + if (move.hitsSubstitute(user, target)) { + return false; + } + + // Check if the move is Roar or Whirlwind and if there is a trainer with only Pokémon left. + if (forceSwitchAttr && globalScene.currentBattle.trainer) { + const enemyParty = globalScene.getEnemyParty(); + // Filter out any Pokémon that are not allowed in battle (e.g. fainted ones) + const remainingPokemon = enemyParty.filter(p => p.hp > 0 && p.isAllowedInBattle()); + if (remainingPokemon.length <= 1) { + return false; + } + } + // Dondozo with an allied Tatsugiri in its mouth cannot be forced out const commandedTag = switchOutTarget.getTag(BattlerTagType.COMMANDED); if (commandedTag?.getSourcePokemon()?.isActive(true)) { diff --git a/test/moves/whirlwind.test.ts b/test/moves/whirlwind.test.ts index 6b5133ec7b1..67ffb77612c 100644 --- a/test/moves/whirlwind.test.ts +++ b/test/moves/whirlwind.test.ts @@ -10,6 +10,7 @@ import Phaser from "phaser"; import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; import { Status } from "#app/data/status-effect"; import { StatusEffect } from "#enums/status-effect"; +import { globalScene } from "#app/global-scene"; import { BattlerIndex } from "#app/battle"; import { BattleType } from "#enums/battle-type"; import { TrainerType } from "#enums/trainer-type"; @@ -161,6 +162,37 @@ describe("Moves - Whirlwind", () => { expect(eevee.isOnField()).toBe(false); }); + it("should fail when player uses Whirlwind against an opponent with only one available Pokémon", async () => { + // Set up the battle scenario with the player knowing Whirlwind + game.override.startingWave(5).enemySpecies(Species.PIDGEY).moveset([Moves.WHIRLWIND]); + await game.classicMode.startBattle(); + + const enemyParty = game.scene.getEnemyParty(); + + // Ensure the opponent has only one available Pokémon + if (enemyParty.length > 1) { + enemyParty.slice(1).forEach(p => { + p.hp = 0; + p.status = new Status(StatusEffect.FAINT); + }); + } + const eligibleEnemy = enemyParty.filter(p => p.hp > 0 && p.isAllowedInBattle()); + expect(eligibleEnemy.length).toBe(1); + + // Spy on the queueMessage function + const queueSpy = vi.spyOn(globalScene, "queueMessage"); + + // Player uses Whirlwind; opponent uses Splash + game.move.select(Moves.WHIRLWIND); + await game.forceEnemyMove(Moves.SPLASH); + await game.toNextTurn(); + + // Verify that the failure message is displayed for Whirlwind + expect(queueSpy).toHaveBeenCalledWith(expect.stringContaining("But it failed")); + // Verify the opponent's Splash message + expect(queueSpy).toHaveBeenCalledWith(expect.stringContaining("But nothing happened!")); + }); + it("should not pull in the other trainer's pokemon in a partner trainer battle", async () => { game.override .startingWave(2)