diff --git a/src/data/moves/move-utils.ts b/src/data/moves/move-utils.ts index a0baf7ff9b7..241144599e5 100644 --- a/src/data/moves/move-utils.ts +++ b/src/data/moves/move-utils.ts @@ -27,6 +27,28 @@ export function isFieldTargeted(move: Move): boolean { return false; } +/** + * Determine whether a move is a spread move. + * + * @param move - The {@linkcode Move} to check + * @returns Whether {@linkcode move} is spread-targeted. + * @remarks + * Examples include: + * - Moves targeting all adjacent Pokemon (like Surf) + * - Moves targeting all adjacent enemies (like Air Cutter) + */ + +export function isSpreadMove(move: Move): boolean { + switch (move.moveTarget) { + case MoveTarget.ALL_ENEMIES: + case MoveTarget.ALL_NEAR_ENEMIES: + case MoveTarget.ALL_OTHERS: + case MoveTarget.ALL_NEAR_OTHERS: + return true; + } + return false; +} + export function getMoveTargets(user: Pokemon, move: MoveId, replaceTarget?: MoveTarget): MoveTargetSet { const variableTarget = new NumberHolder(0); user.getOpponents(false).forEach(p => applyMoveAttrs("VariableTargetAttr", user, p, allMoves[move], variableTarget)); diff --git a/src/data/terrain.ts b/src/data/terrain.ts index f5382b1c3ec..7906450d0ea 100644 --- a/src/data/terrain.ts +++ b/src/data/terrain.ts @@ -3,6 +3,7 @@ import type { BattlerIndex } from "#enums/battler-index"; import { PokemonType } from "#enums/pokemon-type"; import type { Pokemon } from "#field/pokemon"; import type { Move } from "#moves/move"; +import { isFieldTargeted, isSpreadMove } from "#moves/move-utils"; import i18next from "i18next"; export enum TerrainType { @@ -60,13 +61,19 @@ export class Terrain { isMoveTerrainCancelled(user: Pokemon, targets: BattlerIndex[], move: Move): boolean { switch (this.terrainType) { case TerrainType.PSYCHIC: - if (!move.hasAttr("ProtectAttr")) { - // Cancels move if the move has positive priority and targets a Pokemon grounded on the Psychic Terrain - return ( - move.getPriority(user) > 0 && - user.getOpponents(true).some(o => targets.includes(o.getBattlerIndex()) && o.isGrounded()) - ); - } + // Cf https://bulbapedia.bulbagarden.net/wiki/Psychic_Terrain_(move)#Generation_VII + // Psychic terrain will only cancel a move if it: + return ( + // ... is neither spread nor field-targeted, + !isFieldTargeted(move) && + !isSpreadMove(move) && + // .. has positive final priority, + move.getPriority(user) > 0 && + // ...and is targeting at least 1 grounded opponent + user + .getOpponents(true) + .some(o => targets.includes(o.getBattlerIndex()) && o.isGrounded()) + ); } return false; diff --git a/test/arena/psychic-terrain.test.ts b/test/arena/psychic-terrain.test.ts new file mode 100644 index 00000000000..82232cd8d05 --- /dev/null +++ b/test/arena/psychic-terrain.test.ts @@ -0,0 +1,59 @@ +import { AbilityId } from "#enums/ability-id"; +import { MoveId } from "#enums/move-id"; +import { SpeciesId } from "#enums/species-id"; +import { StatusEffect } from "#enums/status-effect"; +import { WeatherType } from "#enums/weather-type"; +import { GameManager } from "#test/test-utils/game-manager"; +import Phaser from "phaser"; +import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest"; + +describe("Arena - Psychic Terrain", () => { + let phaserGame: Phaser.Game; + let game: GameManager; + beforeAll(() => { + phaserGame = new Phaser.Game({ + type: Phaser.HEADLESS, + }); + }); + + afterEach(() => { + game.phaseInterceptor.restoreOg(); + }); + + beforeEach(() => { + game = new GameManager(phaserGame); + game.override + .battleStyle("single") + .criticalHits(false) + .enemyLevel(1) + .enemySpecies(SpeciesId.SHUCKLE) + .enemyAbility(AbilityId.STURDY) + .enemyMoveset(MoveId.SPLASH) + .moveset([MoveId.PSYCHIC_TERRAIN, MoveId.RAIN_DANCE, MoveId.DARK_VOID]) + .ability(AbilityId.NO_GUARD); + }); + + it("Dark Void with Prankster is not blocked", async () => { + await game.classicMode.startBattle([SpeciesId.MAGIKARP]); + + game.move.select(MoveId.PSYCHIC_TERRAIN); + await game.toNextTurn(); + + game.move.select(MoveId.DARK_VOID); + await game.toEndOfTurn(); + + expect(game.scene.getEnemyPokemon()!.status?.effect).toBe(StatusEffect.SLEEP); + }); + + it("Rain Dance with Prankster is not blocked", async () => { + await game.classicMode.startBattle([SpeciesId.MAGIKARP]); + + game.move.select(MoveId.PSYCHIC_TERRAIN); + await game.toNextTurn(); + + game.move.select(MoveId.RAIN_DANCE); + await game.toEndOfTurn(); + + expect(game.scene.arena.weather?.weatherType).toBe(WeatherType.RAIN); + }); +});