generated from nhcarrigan/template
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.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user