From 145b80f4911834ced81acdec7f354ae333140944 Mon Sep 17 00:00:00 2001 From: innerthunder <168692175+innerthunder@users.noreply.github.com> Date: Mon, 30 Sep 2024 10:14:38 -0700 Subject: [PATCH] [P2] Fix Substitute blocking field effects (#4504) Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --- src/data/move.ts | 3 +- src/test/moves/substitute.test.ts | 79 ++++++++++++++++++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/data/move.ts b/src/data/move.ts index 35b5ad56927..d4b2b2f0e75 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -341,7 +341,8 @@ export default class Move implements Localizable { * @returns `true` if the move can bypass the target's Substitute; `false` otherwise. */ hitsSubstitute(user: Pokemon, target: Pokemon | null): boolean { - if (this.moveTarget === MoveTarget.USER || !target?.getTag(BattlerTagType.SUBSTITUTE)) { + if ([MoveTarget.USER, MoveTarget.USER_SIDE, MoveTarget.ENEMY_SIDE, MoveTarget.BOTH_SIDES].includes(this.moveTarget) + || !target?.getTag(BattlerTagType.SUBSTITUTE)) { return false; } diff --git a/src/test/moves/substitute.test.ts b/src/test/moves/substitute.test.ts index d185c0ab471..3099446f081 100644 --- a/src/test/moves/substitute.test.ts +++ b/src/test/moves/substitute.test.ts @@ -1,13 +1,15 @@ import { BattlerIndex } from "#app/battle"; +import { ArenaTagSide } from "#app/data/arena-tag"; import { SubstituteTag, TrappedTag } from "#app/data/battler-tags"; import { allMoves, StealHeldItemChanceAttr } from "#app/data/move"; import { StatusEffect } from "#app/data/status-effect"; -import { Abilities } from "#app/enums/abilities"; -import { BattlerTagType } from "#app/enums/battler-tag-type"; -import { BerryType } from "#app/enums/berry-type"; -import { Moves } from "#app/enums/moves"; -import { Species } from "#app/enums/species"; -import { Stat } from "#app/enums/stat"; +import { Abilities } from "#enums/abilities"; +import { ArenaTagType } from "#enums/arena-tag-type"; +import { BattlerTagType } from "#enums/battler-tag-type"; +import { BerryType } from "#enums/berry-type"; +import { Moves } from "#enums/moves"; +import { Species } from "#enums/species"; +import { Stat } from "#enums/stat"; import { MoveResult } from "#app/field/pokemon"; import { CommandPhase } from "#app/phases/command-phase"; import GameManager from "#app/test/utils/gameManager"; @@ -194,6 +196,71 @@ describe("Moves - Substitute", () => { } ); + it( + "shouldn't block moves that target the user's side of the field", + async () => { + game.override.moveset(Moves.LIGHT_SCREEN); + + await game.classicMode.startBattle([Species.BLASTOISE]); + + const leadPokemon = game.scene.getPlayerPokemon()!; + vi.spyOn(leadPokemon, "getMoveEffectiveness"); + + leadPokemon.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, leadPokemon.id); + + game.move.select(Moves.LIGHT_SCREEN); + + await game.toNextTurn(); + + expect(leadPokemon.getMoveEffectiveness).not.toHaveReturnedWith(0); + expect(game.scene.arena.getTagOnSide(ArenaTagType.LIGHT_SCREEN, ArenaTagSide.PLAYER)).toBeDefined(); + } + ); + + it( + "shouldn't block the opponent from setting hazards", + async () => { + game.override.enemyMoveset(Moves.STEALTH_ROCK); + + await game.classicMode.startBattle([Species.BLASTOISE]); + + const leadPokemon = game.scene.getPlayerPokemon()!; + vi.spyOn(leadPokemon, "getMoveEffectiveness"); + + game.move.select(Moves.SUBSTITUTE); + + await game.toNextTurn(); + + expect(leadPokemon.getMoveEffectiveness).not.toHaveReturnedWith(0); + expect(game.scene.arena.getTagOnSide(ArenaTagType.STEALTH_ROCK, ArenaTagSide.PLAYER)).toBeDefined(); + } + ); + + it( + "shouldn't block moves that target both sides of the field", + async () => { + game.override + .moveset(Moves.TRICK_ROOM) + .enemyMoveset(Moves.GRAVITY); + + await game.classicMode.startBattle([Species.BLASTOISE]); + + const pokemon = game.scene.getField(true); + pokemon.forEach(p => { + vi.spyOn(p, "getMoveEffectiveness"); + p.addTag(BattlerTagType.SUBSTITUTE, 0, Moves.NONE, p.id); + }); + + game.move.select(Moves.TRICK_ROOM); + + await game.toNextTurn(); + + pokemon.forEach(p => expect(p.getMoveEffectiveness).not.toHaveReturnedWith(0)); + expect(game.scene.arena.getTag(ArenaTagType.TRICK_ROOM)).toBeDefined(); + expect(game.scene.arena.getTag(ArenaTagType.GRAVITY)).toBeDefined(); + } + ); + it( "should protect the user from flinching", async () => {