[P2] Fix Substitute blocking field effects (#4504)

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
innerthunder 2024-09-30 10:14:38 -07:00 committed by GitHub
parent 8a8adad7fe
commit 145b80f491
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 75 additions and 7 deletions

View File

@ -341,7 +341,8 @@ export default class Move implements Localizable {
* @returns `true` if the move can bypass the target's Substitute; `false` otherwise. * @returns `true` if the move can bypass the target's Substitute; `false` otherwise.
*/ */
hitsSubstitute(user: Pokemon, target: Pokemon | null): boolean { 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; return false;
} }

View File

@ -1,13 +1,15 @@
import { BattlerIndex } from "#app/battle"; import { BattlerIndex } from "#app/battle";
import { ArenaTagSide } from "#app/data/arena-tag";
import { SubstituteTag, TrappedTag } from "#app/data/battler-tags"; import { SubstituteTag, TrappedTag } from "#app/data/battler-tags";
import { allMoves, StealHeldItemChanceAttr } from "#app/data/move"; import { allMoves, StealHeldItemChanceAttr } from "#app/data/move";
import { StatusEffect } from "#app/data/status-effect"; import { StatusEffect } from "#app/data/status-effect";
import { Abilities } from "#app/enums/abilities"; import { Abilities } from "#enums/abilities";
import { BattlerTagType } from "#app/enums/battler-tag-type"; import { ArenaTagType } from "#enums/arena-tag-type";
import { BerryType } from "#app/enums/berry-type"; import { BattlerTagType } from "#enums/battler-tag-type";
import { Moves } from "#app/enums/moves"; import { BerryType } from "#enums/berry-type";
import { Species } from "#app/enums/species"; import { Moves } from "#enums/moves";
import { Stat } from "#app/enums/stat"; import { Species } from "#enums/species";
import { Stat } from "#enums/stat";
import { MoveResult } from "#app/field/pokemon"; import { MoveResult } from "#app/field/pokemon";
import { CommandPhase } from "#app/phases/command-phase"; import { CommandPhase } from "#app/phases/command-phase";
import GameManager from "#app/test/utils/gameManager"; 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( it(
"should protect the user from flinching", "should protect the user from flinching",
async () => { async () => {