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

48 lines
1.9 KiB
TypeScript

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;
/** Ships bought from the Market, not received in the deal (CR-013). */
marketShipsBought: number;
/** Pilots hired (the avatar excluded). */
pilotsHired: number;
/** Resolved Priority contract deliveries, by any pilot (CR-013). */
priorityDeliveries: 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 "market-ships-bought":
return progress.marketShipsBought >= condition.count;
case "priority-deliveries":
return progress.priorityDeliveries >= 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);
}