From aa1e1a480fdfa182fa65782aaa176addb8abc993 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Mon, 18 Mar 2024 18:03:13 -0400 Subject: [PATCH] Add Psychic Terrain priority block effect and terrain messages --- src/data/terrain.ts | 10 ++++++++++ src/data/weather.ts | 32 ++++++++++++++++++++++++++------ src/field/arena.ts | 4 ++++ src/phases.ts | 13 +++++++++---- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/data/terrain.ts b/src/data/terrain.ts index 28ebba7046e..8e66a0d8f6d 100644 --- a/src/data/terrain.ts +++ b/src/data/terrain.ts @@ -1,3 +1,4 @@ +import Move from "./move"; import { Type } from "./type"; export enum TerrainType { @@ -42,6 +43,15 @@ export class Terrain { return 1; } + + isMoveTerrainCancelled(move: Move): boolean { + switch (this.terrainType) { + case TerrainType.PSYCHIC: + return move.priority > 0; + } + + return false; + } } export function getTerrainColor(terrainType: TerrainType): [ integer, integer, integer ] { diff --git a/src/data/weather.ts b/src/data/weather.ts index 6605ccd4259..b030df32ee1 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -194,15 +194,35 @@ export function getWeatherClearMessage(weatherType: WeatherType): string { } export function getTerrainStartMessage(terrainType: TerrainType): string { - return terrainType - ? `The terrain became ${Utils.toReadableString(TerrainType[terrainType])}!` - : null; + switch (terrainType) { + case TerrainType.MISTY: + return 'Mist swirled around the battlefield!'; + case TerrainType.ELECTRIC: + return 'An electric current ran across the battlefield!'; + case TerrainType.GRASSY: + return 'Grass grew to cover the battlefield!'; + case TerrainType.PSYCHIC: + return 'The battlefield got weird!'; + } } export function getTerrainClearMessage(terrainType: TerrainType): string { - return terrainType - ? `The ${Utils.toReadableString(TerrainType[terrainType])} terrain faded.` - : null; + switch (terrainType) { + case TerrainType.MISTY: + return 'The mist disappeared from the battlefield.'; + case TerrainType.ELECTRIC: + return 'The electricity disappeared from the battlefield.'; + case TerrainType.GRASSY: + return 'The grass disappeared from the battlefield.'; + case TerrainType.PSYCHIC: + return 'The weirdness disappeared from the battlefield!'; + } +} + +export function getTerrainBlockMessage(pokemon: Pokemon, terrainType: TerrainType): string { + if (terrainType === TerrainType.MISTY) + return getPokemonMessage(pokemon, ` surrounds itself with a protective mist!`); + return getPokemonMessage(pokemon, ` is protected by the ${Utils.toReadableString(TerrainType[terrainType])} Terrain!`); } interface WeatherPoolEntry { diff --git a/src/field/arena.ts b/src/field/arena.ts index 8ccdf08e2d4..41cf01f1179 100644 --- a/src/field/arena.ts +++ b/src/field/arena.ts @@ -298,6 +298,10 @@ export class Arena { return this.weather && !this.weather.isEffectSuppressed(this.scene) && this.weather.isMoveWeatherCancelled(move); } + isMoveTerrainCancelled(move: Move) { + return this.terrain && this.terrain.isMoveTerrainCancelled(move); + } + getAttackTypeMultiplier(attackType: Type, grounded: boolean): number { let weatherMultiplier = 1; if (this.weather && !this.weather.isEffectSuppressed(this.scene)) diff --git a/src/phases.ts b/src/phases.ts index 54b74264aed..d29317941c5 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -26,7 +26,7 @@ import { BattlerTagType } from "./data/enums/battler-tag-type"; import { getPokemonMessage } from "./messages"; import { Starter } from "./ui/starter-select-ui-handler"; import { Gender } from "./data/gender"; -import { Weather, WeatherType, getRandomWeatherType, getWeatherDamageMessage, getWeatherLapseMessage } from "./data/weather"; +import { Weather, WeatherType, getRandomWeatherType, getTerrainBlockMessage, getWeatherDamageMessage, getWeatherLapseMessage } from "./data/weather"; import { TempBattleStat } from "./data/temp-battle-stat"; import { ArenaTagSide, ArenaTrapTag, MistTag, TrickRoomTag } from "./data/arena-tag"; import { ArenaTagType } from "./data/enums/arena-tag-type"; @@ -2040,13 +2040,18 @@ export class MovePhase extends BattlePhase { // Assume conditions affecting targets only apply to moves with a single target let success = this.move.getMove().applyConditions(this.pokemon, targets[0], this.move.getMove()); + let failedText = null; if (success && this.scene.arena.isMoveWeatherCancelled(this.move.getMove())) success = false; + else if (success && this.scene.arena.isMoveTerrainCancelled(this.move.getMove())) { + success = false; + failedText = getTerrainBlockMessage(targets[0], this.scene.arena.terrain.terrainType); + } if (success) this.scene.unshiftPhase(this.getEffectPhase()); else { this.pokemon.pushMoveHistory({ move: this.move.moveId, targets: this.targets, result: MoveResult.FAIL, virtual: this.move.virtual }); - this.showFailedText(); + this.showFailedText(failedText); } this.end(); @@ -2109,8 +2114,8 @@ export class MovePhase extends BattlePhase { this.scene.queueMessage(getPokemonMessage(this.pokemon, ` used\n${this.move.getName()}!`), 500); } - showFailedText(): void { - this.scene.queueMessage('But it failed!'); + showFailedText(failedText: string = null): void { + this.scene.queueMessage(failedText || 'But it failed!'); } end() {