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:
@@ -14,6 +14,7 @@ import {
|
||||
saveGame,
|
||||
} from "../api/client.js";
|
||||
import { RESOURCE_CAP, applyTick, calculateClickPower } from "../engine/tick.js";
|
||||
import { updateChallengeProgress } from "../utils/dailyChallenges.js";
|
||||
import { formatNumber as formatNumberUtil } from "../utils/format.js";
|
||||
|
||||
|
||||
@@ -245,14 +246,28 @@ export const GameProvider = ({ children }: { children: React.ReactNode }): React
|
||||
if (!prev) return prev;
|
||||
const clickPower = calculateClickPower(prev);
|
||||
const newGold = Math.min(prev.resources.gold + clickPower, RESOURCE_CAP);
|
||||
|
||||
let updatedDailyChallenges = prev.dailyChallenges;
|
||||
let challengeCrystals = 0;
|
||||
if (updatedDailyChallenges) {
|
||||
const result = updateChallengeProgress(updatedDailyChallenges, "clicks", 1);
|
||||
updatedDailyChallenges = result.updatedChallenges;
|
||||
challengeCrystals = result.crystalsAwarded;
|
||||
}
|
||||
|
||||
return {
|
||||
...prev,
|
||||
resources: { ...prev.resources, gold: newGold },
|
||||
resources: {
|
||||
...prev.resources,
|
||||
gold: newGold,
|
||||
crystals: Math.min(prev.resources.crystals + challengeCrystals, RESOURCE_CAP),
|
||||
},
|
||||
player: {
|
||||
...prev.player,
|
||||
totalGoldEarned: prev.player.totalGoldEarned + clickPower,
|
||||
totalClicks: prev.player.totalClicks + 1,
|
||||
},
|
||||
dailyChallenges: updatedDailyChallenges,
|
||||
};
|
||||
});
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user