import type { DailyChallengeState, DailyChallengeType } from "@elysium/types"; /** * Increments progress for daily challenges matching the given type. * Returns the updated challenge state and any crystals awarded for newly-completed challenges. * * Note: challenge generation and daily resets are handled server-side only. * This utility is purely for client-side progress tracking. */ export const updateChallengeProgress = ( challengeState: DailyChallengeState, type: DailyChallengeType, amount: number, ): { updatedChallenges: DailyChallengeState; crystalsAwarded: number } => { let crystalsAwarded = 0; const updatedChallenges: DailyChallengeState = { ...challengeState, challenges: challengeState.challenges.map((challenge) => { if (challenge.type !== type || challenge.completed) return challenge; const newProgress = Math.min(challenge.progress + amount, challenge.target); const nowCompleted = newProgress >= challenge.target; if (nowCompleted) crystalsAwarded += challenge.rewardCrystals; return { ...challenge, progress: newProgress, completed: nowCompleted }; }), }; return { updatedChallenges, crystalsAwarded }; };