From b2048148c9f62703b29f814b44108f62fa27c5e4 Mon Sep 17 00:00:00 2001 From: innerthunder <168692175+innerthunder@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:52:13 -0700 Subject: [PATCH] [Bug] Fix Make It Rain not applying effect on KO (#2670) --- src/data/move.ts | 12 +++++++++++- src/test/moves/make_it_rain.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/data/move.ts b/src/data/move.ts index 07490290bea..3161dec0c60 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -5513,11 +5513,21 @@ const userSleptOrComatoseCondition: MoveConditionFunc = (user: Pokemon, target: const targetSleptOrComatoseCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => target.status?.effect === StatusEffect.SLEEP || target.hasAbility(Abilities.COMATOSE); +/** + * Condition to apply effects only upon applying the move to its last target. + * Currently only used for Make It Rain. + * @param {Pokemon} user The user of the move. + * @param {Pokemon} target The current target of the move. + * @param {Move} move The move to which this condition applies. + * @returns true if the target is the last target to which the move applies. + */ const lastTargetOnlyCondition: MoveConditionFunc = (user: Pokemon, target: Pokemon, move: Move) => { const effectPhase = user.scene.getCurrentPhase(); + const targetIndex = target.getFieldIndex() + (target.isPlayer() ? 0 : BattlerIndex.ENEMY); if (effectPhase instanceof MoveEffectPhase) { - return target === effectPhase.getTargets().at(-1); + const activeTargets = effectPhase.getTargets(); + return (activeTargets.length === 0 || targetIndex >= activeTargets.at(-1).getBattlerIndex()); } return false; }; diff --git a/src/test/moves/make_it_rain.test.ts b/src/test/moves/make_it_rain.test.ts index 1fe1bb4008b..b46efecab79 100644 --- a/src/test/moves/make_it_rain.test.ts +++ b/src/test/moves/make_it_rain.test.ts @@ -6,6 +6,7 @@ import { Species } from "#enums/species"; import { CommandPhase, MoveEndPhase, + StatChangePhase, } from "#app/phases"; import { Moves } from "#enums/moves"; import { getMovePosition } from "#app/test/utils/gameManagerUtils"; @@ -57,4 +58,25 @@ describe("Moves - Make It Rain", () => { expect(playerPokemon[0].summonData.battleStats[BattleStat.SPATK]).toBe(-1); }); + + it("should apply effects even if the target faints", async () => { + vi.spyOn(overrides, "OPP_LEVEL_OVERRIDE", "get").mockReturnValue(1); // ensures the enemy will faint + vi.spyOn(overrides, "DOUBLE_BATTLE_OVERRIDE", "get").mockReturnValue(false); + vi.spyOn(overrides, "SINGLE_BATTLE_OVERRIDE", "get").mockReturnValue(true); + + await game.startBattle([Species.CHARIZARD]); + + const playerPokemon = game.scene.getPlayerPokemon(); + expect(playerPokemon).toBeDefined(); + + const enemyPokemon = game.scene.getEnemyPokemon(); + expect(enemyPokemon).toBeDefined(); + + game.doAttack(getMovePosition(game.scene, 0, Moves.MAKE_IT_RAIN)); + + await game.phaseInterceptor.to(StatChangePhase); + + expect(enemyPokemon.isFainted()).toBe(true); + expect(playerPokemon.summonData.battleStats[BattleStat.SPATK]).toBe(-1); + }); });