Files
elysium/apps/web/src/utils/dailyChallenges.ts
T
hikari aaeece1a18 feat: add daily challenges system
Three PST-midnight-resetting challenges generated deterministically per
day from click, boss, quest, and prestige types. Progress tracked
server-side for bosses and prestige, client-side for clicks and quests.
Crystal rewards awarded on completion and preserved through prestige resets.
2026-03-06 22:22:18 -08:00

33 lines
1.2 KiB
TypeScript

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 };
};