pokerogue/src/data/terrain.ts
Sirz Benjie 48e911e03c
[Refactor] Remove circular deps 3 (#5959)
* Move game-mode to its own file

Reduces circular imports to 325

* Move battler-index to own file

Reduces circular deps to 314

* Move trainer-variant to own file

Reduces circ deps to 313

* Move enums in pokemon to their own file

* Move arena-tag-type to its own file

* Move pokemon-moves to its own file

* Move command to own file

* Move learnMoveType to own file

* Move form change item to own file

* Move battlerTagLapseType to own file

* Move anim enums to own shared file

* Move enums out of challenges

* Move species form change triggers to own file

Reduces circ imports to 291

* Update test importing pokemon move

* Replace move attribute imports with string names

* Untangle circular deps from game data

* Fix missing string call in switch summon phase

* Apply kev's suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

* Ensure ChargeMove's is method calls super

* Use InstanceType for proper narrowing

* Apply kev's suggestions from code review

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>

---------

Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-06-09 16:24:13 -07:00

99 lines
2.4 KiB
TypeScript

import type Pokemon from "../field/pokemon";
import type Move from "./moves/move";
import { PokemonType } from "#enums/pokemon-type";
import type { BattlerIndex } from "#enums/battler-index";
import i18next from "i18next";
export enum TerrainType {
NONE,
MISTY,
ELECTRIC,
GRASSY,
PSYCHIC,
}
export class Terrain {
public terrainType: TerrainType;
public turnsLeft: number;
constructor(terrainType: TerrainType, turnsLeft?: number) {
this.terrainType = terrainType;
this.turnsLeft = turnsLeft || 0;
}
lapse(): boolean {
if (this.turnsLeft) {
return !!--this.turnsLeft;
}
return true;
}
getAttackTypeMultiplier(attackType: PokemonType): number {
switch (this.terrainType) {
case TerrainType.ELECTRIC:
if (attackType === PokemonType.ELECTRIC) {
return 1.3;
}
break;
case TerrainType.GRASSY:
if (attackType === PokemonType.GRASS) {
return 1.3;
}
break;
case TerrainType.PSYCHIC:
if (attackType === PokemonType.PSYCHIC) {
return 1.3;
}
break;
}
return 1;
}
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())
);
}
}
return false;
}
}
export function getTerrainName(terrainType: TerrainType): string {
switch (terrainType) {
case TerrainType.MISTY:
return i18next.t("terrain:misty");
case TerrainType.ELECTRIC:
return i18next.t("terrain:electric");
case TerrainType.GRASSY:
return i18next.t("terrain:grassy");
case TerrainType.PSYCHIC:
return i18next.t("terrain:psychic");
}
return "";
}
export function getTerrainColor(terrainType: TerrainType): [number, number, number] {
switch (terrainType) {
case TerrainType.MISTY:
return [232, 136, 200];
case TerrainType.ELECTRIC:
return [248, 248, 120];
case TerrainType.GRASSY:
return [120, 200, 80];
case TerrainType.PSYCHIC:
return [160, 64, 160];
}
return [0, 0, 0];
}