deadhead-space-freight-tycoon/packages/sim/src/xp.ts

22 lines
932 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { GameConfig } from "@deadhead/content";
/** XP for one delivery, in whole points: base + per-million-km × distance + per-tier × tier. */
export function deliveryXp(distanceMillionKm: number, tier: number, config: GameConfig): number {
const { base, perMillionKm, perCargoTier } = config.xpPerDelivery;
return Math.round(base + perMillionKm * distanceMillionKm + perCargoTier * tier);
}
/** Pilot level: how many level thresholds the pilot's total XP has reached. */
export function pilotLevel(totalXp: number, config: GameConfig): number {
return config.pilotLevelXpThresholds.filter((threshold) => totalXp >= threshold).length;
}
/** Unspent skill points: levels × points per level minus points spent, never below 0. */
export function skillPointsAvailable(
level: number,
pointsSpent: number,
config: GameConfig,
): number {
return Math.max(0, level * config.skillPointsPerLevel - pointsSpent);
}