Skip to content

Commit 39d7ab3

Browse files
committed
Add XP multiplier based on task due date
1 parent bf23cf3 commit 39d7ab3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/store/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export default createStore({
44
state: {
55
todos: [] as any[],
66
user: {
7-
level: 0,
8-
xp: 0,
9-
progress: 0,
7+
level: 0 as number,
8+
xp: 0 as number,
9+
progress: 0 as number,
1010
},
1111
},
1212
getters: {
@@ -20,7 +20,16 @@ export default createStore({
2020
const task = state.todos.find(
2121
(todo: { newId: number }) => todo.newId === payload
2222
);
23-
const xp = Math.max(task.difficulty * task.priority, 1); //get at least 1 xp when the task is completed
23+
const daysToDue: number =
24+
(Number(new Date(task.dueDate + " 23:59:59.999")) -
25+
Number(new Date().setHours(23, 59, 59, 999))) /
26+
(1000 * 24 * 60 * 60); //calculate number of days until the task is due
27+
const dateMultiplier: number =
28+
daysToDue < 0 ? 0.5 : 1 + 1 / (daysToDue + 1); //if task is overdue, xp multiplier is half the amount, else xp multiplier bonus increases when task gets closer to due date
29+
const xp: number = Math.max(
30+
Math.floor(task.difficulty * task.priority * dateMultiplier),
31+
1
32+
); //get at least 1 xp when the task is completed
2433
state.user.xp += xp;
2534
state.user.level = Math.floor(Math.pow(state.user.xp, 1 / 3 + 5e-16)); //calculate level based on how many xp
2635
state.user.progress =

0 commit comments

Comments
 (0)