Skip to main content
The Milestone interface represents achievement-style goals that players can complete to earn rewards. Milestones track specific stat requirements and provide bonuses when achieved.

Interface definition

export interface Milestone {
  id: string;
  type: 'Strength' | 'Intelligence' | 'Endurance';
  requirement: string;
  reward: number;
  achieved: boolean;
  achievedAt?: Date;
  level: number;
}

Properties

id
string
required
Unique identifier for the milestone
type
'Strength' | 'Intelligence' | 'Endurance'
required
Which stat this milestone is associated with. Determines both the requirement type and the reward type.
requirement
string
required
Human-readable description of what must be accomplished to achieve this milestone (e.g., “Reach 100 Strength”)
reward
number
required
Numeric value of the reward granted when this milestone is achieved. The reward type matches the milestone type.
achieved
boolean
required
Whether this milestone has been completed by the player
achievedAt
Date
Timestamp when the milestone was achieved. Only present if achieved is true.
level
number
required
The tier or level of this milestone. Higher levels typically have higher requirements and rewards.

Usage examples

Creating a milestone

const strengthMilestone: Milestone = {
  id: 'strength_milestone_1',
  type: 'Strength',
  requirement: 'Reach 100 Strength',
  reward: 10,
  achieved: false,
  level: 1,
};

Checking milestone completion

function checkMilestone(
  milestone: Milestone,
  currentStat: number
): boolean {
  // Extract target value from requirement string
  const targetMatch = milestone.requirement.match(/\d+/);
  if (!targetMatch) return false;
  
  const targetValue = parseInt(targetMatch[0]);
  return currentStat >= targetValue;
}

// Check if player has met the requirement
const character = { baseStrength: 150 };
const isComplete = checkMilestone(strengthMilestone, character.baseStrength);
// true - player has 150 strength, milestone requires 100

Awarding a milestone

function awardMilestone(milestone: Milestone): Milestone {
  if (milestone.achieved) {
    return milestone; // Already awarded
  }
  
  return {
    ...milestone,
    achieved: true,
    achievedAt: new Date(),
  };
}

const completedMilestone = awardMilestone(strengthMilestone);
// { ...milestone, achieved: true, achievedAt: Date }

Filtering milestones by type

function getMilestonesByType(
  milestones: Milestone[],
  type: Milestone['type']
): Milestone[] {
  return milestones.filter((m) => m.type === type);
}

const strengthMilestones = getMilestonesByType(allMilestones, 'Strength');
const intelligenceMilestones = getMilestonesByType(allMilestones, 'Intelligence');

Getting total rewards earned

function getTotalRewards(
  milestones: Milestone[],
  type?: Milestone['type']
): number {
  return milestones
    .filter((m) => m.achieved && (!type || m.type === type))
    .reduce((total, m) => total + m.reward, 0);
}

// Get total strength rewards earned
const totalStrengthRewards = getTotalRewards(milestones, 'Strength');

// Get all rewards earned across all types
const allRewards = getTotalRewards(milestones);

Sorting milestones by progress

function sortMilestonesByProgress(
  milestones: Milestone[]
): Milestone[] {
  return [...milestones].sort((a, b) => {
    // Incomplete first
    if (a.achieved !== b.achieved) {
      return a.achieved ? 1 : -1;
    }
    // Then by level
    return a.level - b.level;
  });
}

Creating milestone tiers

const strengthMilestoneTiers: Milestone[] = [
  {
    id: 'strength_1',
    type: 'Strength',
    requirement: 'Reach 100 Strength',
    reward: 10,
    achieved: false,
    level: 1,
  },
  {
    id: 'strength_2',
    type: 'Strength',
    requirement: 'Reach 500 Strength',
    reward: 25,
    achieved: false,
    level: 2,
  },
  {
    id: 'strength_3',
    type: 'Strength',
    requirement: 'Reach 1000 Strength',
    reward: 50,
    achieved: false,
    level: 3,
  },
];
Milestones are persisted to localStorage through the MilestoneService. The service automatically saves milestone state whenever it changes.
The milestone system is designed to be extensible. While currently limited to stat-based milestones (Strength, Intelligence, Endurance), the structure supports adding new milestone types in the future.

Milestone types

The three milestone types correspond to character stats:
TypeRequirementReward Effect
StrengthReach X StrengthBonus strength points
IntelligenceReach X IntelligenceBonus intelligence points
EnduranceReach X EnduranceBonus endurance points
Milestone rewards are typically permanent bonuses that persist through prestige resets, making them valuable long-term progression goals.

Build docs developers (and LLMs) love