Skip to content

Commit 7504e72

Browse files
committed
Add task repetition multiplier based on task repetition occurance and task repetition frequency
1 parent 39d7ab3 commit 7504e72

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/store/index.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,54 @@ export default createStore({
2626
(1000 * 24 * 60 * 60); //calculate number of days until the task is due
2727
const dateMultiplier: number =
2828
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+
let repeatMultiplier: number; //calculate task repetition multiplier based on task repetition occurance and task repetition frequency
30+
if (task.repeatFrequency == 1) {
31+
//if task repetition is daily
32+
if (task.repeatOften < 7) {
33+
//7 days is 1 week
34+
repeatMultiplier = 1 + (task.repeatOften - 1) / (7 - 1); //1x xp multiplier for daily tasks (1 day) to 2x xp multiplier for weekly tasks (7 days)
35+
} else if (task.repeatOften < 30) {
36+
//approximately 30 days is 1 month
37+
repeatMultiplier = 2 + (task.repeatOften - 7) / (30 - 7); //2x xp multiplier for weekly tasks (7 days) to 3x xp multiplier for monthly tasks (approximately 30 days)
38+
} else if (task.repeatOften < 365) {
39+
//approximately 365 days is 1 year
40+
repeatMultiplier = 3 + (task.repeatOften - 30) / (365 - 30); //3x xp multiplier for monthly tasks (approximately 30 days) to 4x xp multiplier for yearly tasks (approximately 365 days)
41+
} else {
42+
repeatMultiplier = 5 - 365 / task.repeatOften; //4x xp multiplier for yearly tasks (approximately 365 days) to 5x xp multiplier for one-time tasks
43+
}
44+
} else if (task.repeatFrequency == 2) {
45+
//if task repetition is weekly
46+
if (task.repeatOften < 4) {
47+
//approximately 4 weeks is 1 month
48+
repeatMultiplier = 2 + (task.repeatOften - 1) / (4 - 1); //2x xp multiplier for weekly tasks (1 week) to 3x xp multiplier for monthly tasks (approximately 4 weeks)
49+
} else if (task.repeatOften < 52) {
50+
//approximately 52 weeks is 1 year
51+
repeatMultiplier = 3 + (task.repeatOften - 4) / (52 - 4); //3x xp multiplier for monthly tasks (approximately 4 weeks) to 4x xp multiplier for yearly tasks (approximately 52 weeks)
52+
} else {
53+
repeatMultiplier = 5 - 52 / task.repeatOften; //4x xp multiplier for yearly tasks (approximately 52 weeks) to 5x xp multiplier for one-time tasks
54+
}
55+
} else if (task.repeatFrequency == 3) {
56+
//if task repetition is monthly
57+
if (task.repeatOften < 12) {
58+
//12 months is 1 year
59+
repeatMultiplier = 3 + (task.repeatOften - 1) / (12 - 1); //3x xp multiplier for monthly tasks (1 month) to 4x xp multiplier for yearly tasks (12 months)
60+
} else {
61+
repeatMultiplier = 5 - 12 / task.repeatOften; //4x xp multiplier for yearly tasks (12 months) to 5x xp multiplier for one-time tasks
62+
}
63+
} else if (task.repeatFrequency == 4) {
64+
//if task repetition is yearly
65+
repeatMultiplier = 5 - 1 / task.repeatOften; //4x xp multiplier for yearly tasks (1 year) to 5x xp multiplier for one-time tasks
66+
} else {
67+
//if task repetition is one-time
68+
repeatMultiplier = 5; //get 5x xp multiplier for one-time tasks
69+
}
2970
const xp: number = Math.max(
30-
Math.floor(task.difficulty * task.priority * dateMultiplier),
71+
Math.floor(
72+
task.difficulty * task.priority * dateMultiplier * repeatMultiplier
73+
),
3174
1
3275
); //get at least 1 xp when the task is completed
33-
state.user.xp += xp;
76+
state.user.xp += xp; //get amount of xp earned based on task difficulty, task priority, task due date and task repetition
3477
state.user.level = Math.floor(Math.pow(state.user.xp, 1 / 3 + 5e-16)); //calculate level based on how many xp
3578
state.user.progress =
3679
((state.user.xp - Math.pow(state.user.level, 3)) /

0 commit comments

Comments
 (0)