-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeNest_map.js
More file actions
116 lines (93 loc) · 2.9 KB
/
Copy pathcodeNest_map.js
File metadata and controls
116 lines (93 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
let xp_required = 100;
let ALL_levels = 100;
let increase = []
let level = []
let level_xp = []
fetch('/api/convert/xp/to/LV')
.then(response => response.json())
.then(xp => {
for (let lv = 1; lv <= ALL_levels; lv++) {
if (lv >= 1 && lv <= 10) {
increase.push(0.21); // 21%
level.push(lv);
}
else if (lv > 10 && lv <= 20) {
// 12%
increase.push(0.12);
level.push(lv);
} else if (lv > 20 && lv <= 30) {
// 10%
increase.push(0.10);
level.push(lv);
}
else if (lv > 30 && lv <= 80) {
// 5%
increase.push(0.05);
level.push(lv);
} else if (lv > 80 && lv <= 100) {
increase.push(0.025);
level.push(lv); // 2.5%
}
}
let lev_xp = [];
lev_xp.push(xp_required)
for (let i =1; i < ALL_levels; i++) {
xp_required = xp_required * (1 + increase[i]);
lev_xp.push(Math.floor(xp_required));
}
console.log(lev_xp)
console.log(level)
let userLV = 1;
let current_xp = 0
let next_xp =lev_xp[0];
let i = 0
while (xp > lev_xp[i]) {
console.log('--->'+i)
userLV = level[i]+1
current_xp = lev_xp[i]
next_xp = lev_xp[i+1]
i++
}
console.log(userLV)
fetch('/api/user/lv', {
method: 'POST',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({ userLV })
})
let user_distance = xp - current_xp
let xp_distance = next_xp - current_xp
let avreg = 0;
if (xp_distance > 0) {
avreg = user_distance / xp_distance;
} else {
avreg = 1;
}
console.log('user xp its ' + xp);
console.log('curent xp its ' + current_xp);
console.log('next xp its ' + next_xp);
console.log('user_distance = ' + user_distance)
console.log('xp_distance = ' + xp_distance)
//progress circle
var bar = new ProgressBar.Circle(progress_bar, {
strokeWidth: 4,
easing: 'easeInOut',
duration: 1400,
color: 'Green',
trailColor: '#eee',
trailWidth: 6,
svgStyle: {
height: '100%',
width: '100%'
}
});
bar.animate(avreg);
document.getElementById('grade').innerHTML = userLV
})
var level_user_div = document.getElementById('level');
fetch('/api/user/LV/show')
.then(response => response.json())
.then(LV_show =>{
level_user_div.innerHTML = 'lv '+LV_show;
})