-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.py
95 lines (75 loc) · 2.37 KB
/
levels.py
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
"""
Exp calculation for a given level and exp group
"""
import bisect
class EXPGroup:
def __init__(self, groupname):
functions = {'erratic': self.erratic,
'fast': self.fast,
'medfast': self.medfast,
'medslow': self.medslow,
'slow': self.slow,
'fluctuating': self.fluctuating
}
# build and cache a level table for this group
self._table = {i: functions[groupname](i) for i in range(1, 101)}
self._name = groupname
@property
def name(self):
return self._name
@property
def table(self):
return self._table
def get_exp(self, lvl: int) -> int:
return self.table[lvl]
def get_lvl(self, exp: int) -> int:
# get cached list of exp vals
lvls = list(self.table.values())
# insert our test exp value into this list
bisect.insort(lvls, exp)
# index the inserted value
point = lvls.index(exp)
return point
@staticmethod
def erratic(lvl):
if lvl < 50:
val = (lvl ** 3) * (100 - lvl) / 50
elif lvl < 68:
val = (lvl ** 3) * (150 - lvl) / 100
elif lvl < 98:
val = (lvl ** 3) * ((1911 - (10 * lvl)) / 3) / 500
else:
val = (lvl ** 3) * (160 - lvl) / 100
return int(val)
@staticmethod
def fast(lvl):
return int(4 * lvl ** 3 / 5)
@staticmethod
def medfast(lvl):
return int(lvl ** 3)
@staticmethod
def medslow(lvl):
return int((6 / 5) * lvl ** 3 - 15 * lvl ** 2 + 100 * lvl - 140)
@staticmethod
def slow(lvl):
return int(5 * lvl ** 3 / 4)
@staticmethod
def fluctuating(lvl):
if lvl < 15:
val = ((lvl ** 3) * (((lvl + 1) / 3) + 24)) / 50
elif lvl < 36:
val = (lvl ** 3) * (lvl + 14) / 50
else:
val = ((lvl ** 3) * ((lvl / 2) + 32)) / 50
return int(val)
if __name__ == '__main__':
grp = EXPGroup('fast')
print('1', grp.get_lvl(1))
print('75', grp.get_lvl(350214))
print('76', grp.get_lvl(352214))
print('100', grp.get_lvl(350000214))
print('0', grp.get_exp(1))
print('6', grp.get_exp(2))
print('563975', grp.get_exp(89))
print('776239', grp.get_exp(99))
print('800000', grp.get_exp(100))