habits.andr33v.ru/server/utils/village.ts

63 lines
1.6 KiB
TypeScript

// server/utils/village.ts
export type VillageObjectKind =
| 'HOUSE'
| 'FIELD'
| 'LUMBERJACK'
| 'QUARRY'
| 'WELL'
| 'ROAD'
| 'FENCE';
export type CropKind = 'BLUEBERRIES' | 'CORN';
// --- Game Economy & Rules ---
export const VILLAGE_GRID_SIZE = { width: 15, height: 15 };
export const ITEM_COSTS: Partial<Record<VillageObjectKind, number>> = {
HOUSE: 50,
FIELD: 15,
ROAD: 5,
FENCE: 10,
};
export const OBSTACLE_CLEAR_COST: Record<string, number> = {
ROCK: 20,
BUSH: 5,
MUSHROOM: 10,
DEFAULT: 15, // Fallback cost for untyped obstacles
};
export const PLANTING_COST = 2; // A small, flat cost for seeds
export const MOVE_COST = 1; // Cost to move any player-built item
// --- Crop Timings (in milliseconds) ---
export const CROP_GROWTH_TIME: Record<CropKind, number> = {
BLUEBERRIES: 60 * 60 * 1000, // 1 hour
CORN: 4 * 60 * 60 * 1000, // 4 hours
};
// --- Rewards ---
export const CROP_HARVEST_REWARD: Record<CropKind, { exp: number, coins: number }> = {
BLUEBERRIES: { exp: 5, coins: 0 },
CORN: { exp: 10, coins: 1 },
};
/**
* Checks if a crop is grown based on when it was planted.
* @param plantedAt The ISO string or Date object when the crop was planted.
* @param cropType The type of crop.
* @returns True if the crop has finished growing.
*/
export function isCropGrown(plantedAt: Date | null, cropType: CropKind | null): boolean {
if (!plantedAt || !cropType) {
return false;
}
const growthTime = CROP_GROWTH_TIME[cropType];
if (growthTime === undefined) {
return false;
}
return (Date.now() - new Date(plantedAt).getTime()) > growthTime;
}