Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 14x 6x 8x 16x 5x 11x 11x 16x 12x 5x 7x | /**
* Type guard functions for combat system
* Provides runtime type checking for better type safety
*/
import { PlayerArchetype, VitalPointCategory, VitalPointSeverity } from "../../types/common";
import { VitalPoint } from "../vitalpoint/types";
/**
* Type guard to check if a value is a valid PlayerArchetype
* @param value - Value to check
* @returns True if value is a valid PlayerArchetype
*/
export function isValidArchetype(value: unknown): value is PlayerArchetype {
if (typeof value !== "string") {
return false;
}
return Object.values(PlayerArchetype).includes(value as PlayerArchetype);
}
/**
* Type guard to check if a value is a valid VitalPoint
* @param value - Value to check
* @returns True if value is a valid VitalPoint
*/
export function isVitalPoint(value: unknown): value is VitalPoint {
if (!value || typeof value !== "object") {
return false;
}
const obj = value as Record<string, unknown>;
// Validate position structure
const hasValidPosition =
obj.position !== undefined &&
typeof obj.position === "object" &&
obj.position !== null &&
typeof (obj.position as Record<string, unknown>).x === "number" &&
typeof (obj.position as Record<string, unknown>).y === "number";
return (
typeof obj.id === "string" &&
typeof obj.category === "string" &&
Object.values(VitalPointCategory).includes(obj.category as VitalPointCategory) &&
typeof obj.severity === "string" &&
Object.values(VitalPointSeverity).includes(obj.severity as VitalPointSeverity) &&
hasValidPosition &&
Array.isArray(obj.effects) &&
typeof obj.names === "object" &&
obj.names !== null &&
typeof obj.description === "object" &&
obj.description !== null &&
typeof obj.targetingDifficulty === "number" &&
Array.isArray(obj.effectiveStances)
);
}
/**
* Type guard to check if a value is a valid VitalPointCategory
* @param value - Value to check
* @returns True if value is a valid VitalPointCategory
*/
export function isVitalPointCategory(value: unknown): value is VitalPointCategory {
if (typeof value !== "string") {
return false;
}
return Object.values(VitalPointCategory).includes(value as VitalPointCategory);
}
|