forked from ariffb25/stikerinbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevelling.js
50 lines (50 loc) · 1.46 KB
/
levelling.js
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
module.exports = {
/**
* Growth rate
* `2.576652002695681`
*/
growth: Math.pow(Math.PI / Math.E, 1.618) * Math.E * .75,
/**
* get XP range at specified level
* @param {Number} level
* @param {Number} multiplier
*/
xpRange(level, multiplier = global.multiplier || 1) {
if (level < 0) throw new TypeError('level cannot be negative value')
level = Math.floor(level)
let min = level === 0 ? 0 : Math.round(Math.pow(level, this.growth) * multiplier) + 1
let max = Math.round(Math.pow(++level, this.growth) * multiplier)
return {
min,
max,
xp: max - min
}
},
/**
* get level by xp
* @param {Number} xp
* @param {Number} multiplier
*/
findLevel(xp, multiplier = global.multiplier || 1) {
if (xp === Infinity) return Infinity
if (isNaN(xp)) return NaN
if (xp <= 0) return -1
let level = 0
do level++
while (this.xpRange(level, multiplier).min <= xp)
return --level
},
/**
* is able to level up?
* @param {Number} level
* @param {Number} xp
* @param {Number} multiplier
*/
canLevelUp(level, xp, multiplier = global.multiplier || 1) {
if (level < 0) return false
if (xp === Infinity) return true
if (isNaN(xp)) return false
if (xp <= 0) return false
return level < this.findLevel(xp, multiplier)
}
}