generated from nhcarrigan/template
feat: support runestone rewards in achievement system (#190)
- Add runestones field to AchievementReward type - Update tick engine to accumulate and apply runestone rewards when achievements unlock, alongside the existing crystal rewards
This commit is contained in:
+19
-14
@@ -11,7 +11,6 @@
|
|||||||
/* eslint-disable max-lines -- Engine file necessarily exceeds line limit */
|
/* eslint-disable max-lines -- Engine file necessarily exceeds line limit */
|
||||||
/* eslint-disable import/group-exports -- Exports appear alongside their definitions for readability */
|
/* eslint-disable import/group-exports -- Exports appear alongside their definitions for readability */
|
||||||
/* eslint-disable import/exports-last -- Exports appear alongside their definitions for readability */
|
/* eslint-disable import/exports-last -- Exports appear alongside their definitions for readability */
|
||||||
/* eslint-disable unicorn/no-array-reduce -- reduce is the most readable approach for multiplier chains */
|
|
||||||
/* eslint-disable max-nested-callbacks -- Tick engine requires nested array operations for game logic */
|
/* eslint-disable max-nested-callbacks -- Tick engine requires nested array operations for game logic */
|
||||||
import {
|
import {
|
||||||
type Achievement,
|
type Achievement,
|
||||||
@@ -818,24 +817,30 @@ export const applyTick = (
|
|||||||
zones: updatedZones,
|
zones: updatedZones,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check achievements and apply crystal rewards for newly unlocked ones
|
// Check achievements and apply crystal and runestone rewards for newly unlocked ones
|
||||||
const updatedAchievements = checkAchievements(partialState);
|
const updatedAchievements = checkAchievements(partialState);
|
||||||
const crystalsFromAchievements = updatedAchievements.reduce(
|
let crystalsFromAchievements = 0;
|
||||||
(sum, achievement, index) => {
|
let runestonesFromAchievements = 0;
|
||||||
const wasLocked = state.achievements[index]?.unlockedAt === null;
|
for (const [ index, achievement ] of updatedAchievements.entries()) {
|
||||||
const isNowUnlocked = achievement.unlockedAt !== null;
|
const wasLocked = state.achievements[index]?.unlockedAt === null;
|
||||||
if (wasLocked && isNowUnlocked) {
|
const isNowUnlocked = achievement.unlockedAt !== null;
|
||||||
return sum + (achievement.reward?.crystals ?? 0);
|
if (wasLocked && isNowUnlocked) {
|
||||||
}
|
crystalsFromAchievements
|
||||||
return sum;
|
= crystalsFromAchievements + (achievement.reward?.crystals ?? 0);
|
||||||
},
|
runestonesFromAchievements
|
||||||
0,
|
= runestonesFromAchievements + (achievement.reward?.runestones ?? 0);
|
||||||
);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...partialState,
|
...partialState,
|
||||||
achievements: updatedAchievements,
|
achievements: updatedAchievements,
|
||||||
resources: {
|
prestige: {
|
||||||
|
...partialState.prestige,
|
||||||
|
runestones:
|
||||||
|
partialState.prestige.runestones + runestonesFromAchievements,
|
||||||
|
},
|
||||||
|
resources: {
|
||||||
...partialState.resources,
|
...partialState.resources,
|
||||||
crystals: capResource(
|
crystals: capResource(
|
||||||
partialState.resources.crystals + crystalsFromAchievements,
|
partialState.resources.crystals + crystalsFromAchievements,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ interface AchievementCondition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface AchievementReward {
|
interface AchievementReward {
|
||||||
crystals?: number;
|
crystals?: number;
|
||||||
|
runestones?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Achievement {
|
interface Achievement {
|
||||||
|
|||||||
Reference in New Issue
Block a user