Moved terrain messages to terrain.ts, made status failures use correct text

This commit is contained in:
Bertie690 2025-06-03 23:05:56 -04:00
parent dd2f475ded
commit 77f6befb70
7 changed files with 116 additions and 70 deletions

View File

@ -2856,6 +2856,11 @@ export default class BattleScene extends SceneBase {
promptDelay?: number | null,
defer?: boolean | null,
) {
// don't display empty strings
if (!message) {
return;
}
const phase = new MessagePhase(message, callbackDelay, prompt, promptDelay);
if (!defer) {
// adds to the end of PhaseQueuePrepend

View File

@ -4,6 +4,7 @@ import { PokemonType } from "#enums/pokemon-type";
import { ProtectAttr } from "./moves/move";
import type { BattlerIndex } from "#app/battle";
import i18next from "i18next";
import { getPokemonNameWithAffix } from "#app/messages";
export enum TerrainType {
NONE,
@ -97,3 +98,70 @@ export function getTerrainColor(terrainType: TerrainType): [number, number, numb
return [0, 0, 0];
}
/**
* Return the message associated with a terrain effect starting.
* @param terrainType - The {@linkcode TerrainType} starting.
* @returns A string containing the appropriate terrain start text.
*/
export function getTerrainStartMessage(terrainType: TerrainType): string {
switch (terrainType) {
case TerrainType.MISTY:
return i18next.t("terrain:mistyStartMessage");
case TerrainType.ELECTRIC:
return i18next.t("terrain:electricStartMessage");
case TerrainType.GRASSY:
return i18next.t("terrain:grassyStartMessage");
case TerrainType.PSYCHIC:
return i18next.t("terrain:psychicStartMessage");
default:
console.warn(`${terrainType} unexpectedly provided as terrain type to getTerrainStartMessage!`);
return "";
}
}
/**
* Return the message associated with a terrain effect ceasing to exist.
* @param terrainType - The {@linkcode TerrainType} being cleared.
* @returns A string containing the appropriate terrain clear text.
*/
export function getTerrainClearMessage(terrainType: TerrainType): string {
switch (terrainType) {
case TerrainType.MISTY:
return i18next.t("terrain:mistyClearMessage");
case TerrainType.ELECTRIC:
return i18next.t("terrain:electricClearMessage");
case TerrainType.GRASSY:
return i18next.t("terrain:grassyClearMessage");
case TerrainType.PSYCHIC:
return i18next.t("terrain:psychicClearMessage");
default:
console.warn(`${terrainType} unexpectedly provided as terrain type to getTerrainClearMessage!`);
return "";
}
}
/**
* Return the message associated with a terrain-induced move/effect blockage.
* @param pokemon - The {@linkcode Pokemon} being protected.
* @param terrainType - The {@linkcode TerrainType} in question
* @returns A string containing the appropriate terrain block text.
*/
export function getTerrainBlockMessage(pokemon: Pokemon, terrainType: TerrainType): string {
switch (terrainType) {
case TerrainType.MISTY:
return i18next.t("terrain:mistyBlockMessage", {
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
});
case TerrainType.ELECTRIC:
case TerrainType.GRASSY:
case TerrainType.PSYCHIC:
return i18next.t("terrain:defaultBlockMessage", {
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
terrainName: getTerrainName(terrainType),
});
default:
console.warn(`${terrainType} unexpectedly provided as terrain type to getTerrainBlockMessage!`);
return "";
}
}

View File

@ -7,7 +7,6 @@ import type Move from "./moves/move";
import { AttackMove } from "./moves/move";
import { randSeedInt } from "#app/utils/common";
import { SuppressWeatherEffectAbAttr } from "./abilities/ability";
import { TerrainType, getTerrainName } from "./terrain";
import i18next from "i18next";
import { globalScene } from "#app/global-scene";
import type { Arena } from "#app/field/arena";
@ -236,50 +235,6 @@ export function getWeatherBlockMessage(weatherType: WeatherType): string {
return i18next.t("weather:defaultEffectMessage");
}
export function getTerrainStartMessage(terrainType: TerrainType): string | null {
switch (terrainType) {
case TerrainType.MISTY:
return i18next.t("terrain:mistyStartMessage");
case TerrainType.ELECTRIC:
return i18next.t("terrain:electricStartMessage");
case TerrainType.GRASSY:
return i18next.t("terrain:grassyStartMessage");
case TerrainType.PSYCHIC:
return i18next.t("terrain:psychicStartMessage");
default:
console.warn("getTerrainStartMessage not defined. Using default null");
return null;
}
}
export function getTerrainClearMessage(terrainType: TerrainType): string | null {
switch (terrainType) {
case TerrainType.MISTY:
return i18next.t("terrain:mistyClearMessage");
case TerrainType.ELECTRIC:
return i18next.t("terrain:electricClearMessage");
case TerrainType.GRASSY:
return i18next.t("terrain:grassyClearMessage");
case TerrainType.PSYCHIC:
return i18next.t("terrain:psychicClearMessage");
default:
console.warn("getTerrainClearMessage not defined. Using default null");
return null;
}
}
export function getTerrainBlockMessage(pokemon: Pokemon, terrainType: TerrainType): string {
if (terrainType === TerrainType.MISTY) {
return i18next.t("terrain:mistyBlockMessage", {
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
});
}
return i18next.t("terrain:defaultBlockMessage", {
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
terrainName: getTerrainName(terrainType),
});
}
export interface WeatherPoolEntry {
weatherType: WeatherType;
weight: number;

View File

@ -5,8 +5,6 @@ import { randSeedInt, NumberHolder, isNullOrUndefined, type Constructor } from "
import type PokemonSpecies from "#app/data/pokemon-species";
import { getPokemonSpecies } from "#app/data/pokemon-species";
import {
getTerrainClearMessage,
getTerrainStartMessage,
getWeatherClearMessage,
getWeatherStartMessage,
getLegendaryWeatherContinuesMessage,
@ -18,7 +16,7 @@ import type Move from "#app/data/moves/move";
import type { ArenaTag } from "#app/data/arena-tag";
import { ArenaTagSide, ArenaTrapTag, getArenaTag } from "#app/data/arena-tag";
import type { BattlerIndex } from "#app/battle";
import { Terrain, TerrainType } from "#app/data/terrain";
import { Terrain, TerrainType, getTerrainClearMessage, getTerrainStartMessage } from "#app/data/terrain";
import {
applyAbAttrs,
applyPostTerrainChangeAbAttrs,
@ -433,9 +431,9 @@ export class Arena {
if (!ignoreAnim) {
globalScene.unshiftPhase(new CommonAnimPhase(undefined, undefined, CommonAnim.MISTY_TERRAIN + (terrain - 1)));
}
globalScene.queueMessage(getTerrainStartMessage(terrain)!); // TODO: is this bang correct?
globalScene.queueMessage(getTerrainStartMessage(terrain));
} else {
globalScene.queueMessage(getTerrainClearMessage(oldTerrainType)!); // TODO: is this bang correct?
globalScene.queueMessage(getTerrainClearMessage(oldTerrainType));
}
globalScene

View File

@ -257,6 +257,7 @@ import { MoveFlags } from "#enums/MoveFlags";
import { timedEventManager } from "#app/global-event-manager";
import { loadMoveAnimations } from "#app/sprites/pokemon-asset-loader";
import { ResetStatusPhase } from "#app/phases/reset-status-phase";
import { getTerrainBlockMessage } from "#app/data/terrain";
export enum LearnMoveSituation {
MISC,
@ -4612,16 +4613,33 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
);
}
queueImmuneMessage(quiet: boolean, effect?: StatusEffect): void {
if (!effect || quiet) {
/**
* Display an immunity message for a failed status application.
* @param quiet - Whether to suppress message and return early
* @param reason - The reason for the terrain blockage -
* can be "overlap" (already has same status), "other" (generic fail message)
* or a {@linkcode TerrainType} for terrain-based blockages.
*/
private queueImmuneMessage(quiet: boolean, reason: "overlap" | "other" | TerrainType = "other"): void {
if (quiet) {
return;
}
const message =
effect && this.status?.effect === effect
? getStatusEffectOverlapText(effect ?? StatusEffect.NONE, getPokemonNameWithAffix(this))
: i18next.t("abilityTriggers:moveImmunity", {
let message = "";
if (reason === "overlap" && this) {
// "XYZ is already XXX!"
message = getStatusEffectOverlapText(this.status?.effect ?? StatusEffect.NONE, getPokemonNameWithAffix(this));
} else if (typeof reason === "number") {
// "XYZ was protected by the XXX terrain!" /
// "XYZ surrounds itself with a protective mist!"
message = getTerrainBlockMessage(this, reason);
} else {
// "It doesn't affect XXX!"
message = i18next.t("abilityTriggers:moveImmunity", {
pokemonNameWithAffix: getPokemonNameWithAffix(this),
});
}
globalScene.queueMessage(message);
}
@ -4643,11 +4661,11 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
): boolean {
if (effect !== StatusEffect.FAINT) {
if (overrideStatus ? this.status?.effect === effect : this.status) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet, overrideStatus ? "overlap" : "other"); // having different status displays generic fail message
return false;
}
if (this.isGrounded() && !ignoreField && globalScene.arena.terrain?.terrainType === TerrainType.MISTY) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet, TerrainType.MISTY);
return false;
}
}
@ -4678,7 +4696,7 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
if (this.isOfType(PokemonType.POISON) || this.isOfType(PokemonType.STEEL)) {
if (poisonImmunity.includes(true)) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet);
return false;
}
}
@ -4686,13 +4704,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
}
case StatusEffect.PARALYSIS:
if (this.isOfType(PokemonType.ELECTRIC)) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet);
return false;
}
break;
case StatusEffect.SLEEP:
if (this.isGrounded() && globalScene.arena.terrain?.terrainType === TerrainType.ELECTRIC) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet, TerrainType.ELECTRIC);
return false;
}
break;
@ -4703,13 +4721,13 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
globalScene?.arena?.weather?.weatherType &&
[WeatherType.SUNNY, WeatherType.HARSH_SUN].includes(globalScene.arena.weather.weatherType))
) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet);
return false;
}
break;
case StatusEffect.BURN:
if (this.isOfType(PokemonType.FIRE)) {
this.queueImmuneMessage(quiet, effect);
this.queueImmuneMessage(quiet);
return false;
}
break;
@ -6702,7 +6720,6 @@ export class EnemyPokemon extends Pokemon {
return ret;
}
/**
* Show or hide the type effectiveness multiplier window
* Passing undefined will hide the window

View File

@ -43,7 +43,9 @@ import { WeatherType } from "#enums/weather-type";
* }
* ```
*/
const overrides = {} satisfies Partial<InstanceType<OverridesType>>;
const overrides = {
MOVESET_OVERRIDE: [Moves.WHIRLWIND, Moves.BATON_PASS, Moves.DRAGON_TAIL, Moves.CIRCLE_THROW]
} satisfies Partial<InstanceType<OverridesType>>;
/**
* If you need to add Overrides values for local testing do that inside {@linkcode overrides}

View File

@ -31,7 +31,7 @@ import { MoveFlags } from "#enums/MoveFlags";
import { SpeciesFormChangePreMoveTrigger } from "#app/data/pokemon-forms";
import { getStatusEffectActivationText, getStatusEffectHealText } from "#app/data/status-effect";
import { PokemonType } from "#enums/pokemon-type";
import { getTerrainBlockMessage, getWeatherBlockMessage } from "#app/data/weather";
import { getWeatherBlockMessage } from "#app/data/weather";
import { MoveUsedEvent } from "#app/events/battle-scene";
import type { PokemonMove } from "#app/field/pokemon";
import type Pokemon from "#app/field/pokemon";
@ -50,6 +50,7 @@ import { BattlerTagType } from "#enums/battler-tag-type";
import { Moves } from "#enums/moves";
import { StatusEffect } from "#enums/status-effect";
import i18next from "i18next";
import { getTerrainBlockMessage } from "#app/data/terrain";
export class MovePhase extends BattlePhase {
protected _pokemon: Pokemon;