mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-01-16 05:51:56 +00:00
d052d444b6
* add type inference to getAttrs methods and refactor accordingly * Tests/infer types for get attrs methods (#1) * #1633: add spec/tests for coverage * move ability/move tests into /src/tests and rename to *.test.ts to match common naming patterns * use None in test cases to remove ambiguity * revert back to before test cases were merged --------- Co-authored-by: flx-sta <50131232+flx-sta@users.noreply.github.com>
84 lines
2.0 KiB
TypeScript
84 lines
2.0 KiB
TypeScript
import Pokemon from "../field/pokemon";
|
|
import Move from "./move";
|
|
import { Type } from "./type";
|
|
import * as Utils from "../utils";
|
|
import { IncrementMovePriorityAbAttr, applyAbAttrs } from "./ability";
|
|
import { ProtectAttr } from "./move";
|
|
import { BattlerIndex } from "#app/battle.js";
|
|
|
|
export enum TerrainType {
|
|
NONE,
|
|
MISTY,
|
|
ELECTRIC,
|
|
GRASSY,
|
|
PSYCHIC
|
|
}
|
|
|
|
export class Terrain {
|
|
public terrainType: TerrainType;
|
|
public turnsLeft: integer;
|
|
|
|
constructor(terrainType: TerrainType, turnsLeft?: integer) {
|
|
this.terrainType = terrainType;
|
|
this.turnsLeft = turnsLeft || 0;
|
|
}
|
|
|
|
lapse(): boolean {
|
|
if (this.turnsLeft) {
|
|
return !!--this.turnsLeft;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
getAttackTypeMultiplier(attackType: Type): number {
|
|
switch (this.terrainType) {
|
|
case TerrainType.ELECTRIC:
|
|
if (attackType === Type.ELECTRIC) {
|
|
return 1.3;
|
|
}
|
|
break;
|
|
case TerrainType.GRASSY:
|
|
if (attackType === Type.GRASS) {
|
|
return 1.3;
|
|
}
|
|
break;
|
|
case TerrainType.PSYCHIC:
|
|
if (attackType === Type.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)) {
|
|
const priority = new Utils.IntegerHolder(move.priority);
|
|
applyAbAttrs(IncrementMovePriorityAbAttr, user, null, move, priority);
|
|
return priority.value > 0 && user.getOpponents().filter(o => targets.includes(o.getBattlerIndex())).length > 0;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function getTerrainColor(terrainType: TerrainType): [ integer, integer, integer ] {
|
|
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 ];
|
|
}
|