import type { GoalCondition, OnboardingGoal } from "@deadhead/content"; /** The facts about a player that onboarding goals are checked against. */ export interface GoalProgress { /** Contracts delivered by the player's own ships (tutorial runs excluded). */ ownShipDeliveries: number; /** Skill points spent across all pilots. */ skillPointsSpent: number; shipsOwned: number; /** Pilots hired (the avatar excluded). */ pilotsHired: number; /** Resolved contract deliveries (not deadheads) flown by the veteran (CR-010). */ veteranContracts: number; /** Locations discovered beyond the ones that start discovered. */ locationsDiscovered: number; dealAccepted: boolean; loanBalance: number; } export function isGoalConditionMet(condition: GoalCondition, progress: GoalProgress): boolean { switch (condition.kind) { case "own-ship-deliveries": return progress.ownShipDeliveries >= condition.count; case "skill-points-spent": return progress.skillPointsSpent >= condition.count; case "ships-owned": return progress.shipsOwned >= condition.count; case "pilots-hired": return progress.pilotsHired >= condition.count; case "veteran-contracts": return progress.veteranContracts >= condition.count; case "locations-discovered": return progress.locationsDiscovered >= condition.count; case "loan-paid-off": // Only a loan that was taken can be paid off. return progress.dealAccepted && progress.loanBalance <= 0; } } /** Ids of the goals whose conditions are met, in the goals' order (decision 0.5.34). */ export function completedGoals(goals: readonly OnboardingGoal[], progress: GoalProgress): string[] { return goals.filter((goal) => isGoalConditionMet(goal.condition, progress)).map((g) => g.id); }