-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlimited_bonus_data.py
272 lines (216 loc) · 5.95 KB
/
limited_bonus_data.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# Parsing bonus data.
action = 'download_limited_bonus_data'
ver = 'pver'
datanum = 39
jsonkey = 'bonuses'
from datetime import datetime as DT
import json
from util import ojson_load, ojson_loads
from padutil import ghtime
import dungeon_data
from dataclass import DataClass
"""
TODO:
- Find a way to set dungeon_data.
- Must do it in a way that doesn't depend on a global.
?- Or don't set it in init. Pass it in when printing.
"""
#dummy
# dungeons = {}
# keys: 'sebiadm'
# s: start
# e: end
# b: bonus type
# 2: coins * 10000
# 3: drop * 10000
# 5: stamina * 10000
# 6: special dungeon
# 8: PEM
# 9: REM
# 10: PEM cost? (skip)
# 11: xp bonus chance * 10000
# 12: (old:) absolute +egg rate?? * 10000
# 14: GF announcement?
# 16: (new:) relative +egg rate?? * 10000
# 17: skillup bonus
# 21: tournament over?
# 22: tournament?
# i: unknown
## TODO:
# - Identify urgents. (They last for an hour.)
# - Up to three hours now.
# - The dungeons are tagged as "Limited", so there's a flag SOMEWHERE.
# - Rather than start-end times, have time categories.
# - Categories:
# - Urgent (1 hour).
# - Day.
# - Week.
# - Biweek.
# ? Two-week?
# - Halfmonth.
# - E.g. coin dungeons and MP shop.
# -
# ^- Or have times.
# - Hour.
# - Day.
# ^^- Or have columns per unit.
# - Hour.
# - Day.
# - Week.
# -
# -
# -! The bonus data depends on group. (E.g. urgents.)
# -
# -
def ghmult(x):
mult = x/10000
if int(mult) == mult:
mult = int(mult)
return '%sx' % mult
def ghchance(x):
assert x % 100 == 0
return '%d%%' % (x//100)
class Bonus:
# Lists special handlers for each type.
types = {
1: {'b':'exp*', 'a':ghmult},
2: {'b':'coin*', 'a':ghmult},
3: {'b':'drop*', 'a':ghmult},
5: {'b':'stam*', 'a':ghmult},
11: {'b':'great*', 'a':ghmult},
12: {'b':'plus%', 'a':ghchance},
16: {'b':'plus*', 'a':ghmult},
17: {'b':'skill*', 'a':ghmult},
6: {'b':'dung'}, # special/co-op dungeon list
10: {'b':'pem$', 'a':int},
# 8: {'b':'rem?', },
# 9: {'b':'pem?', },
8: {'b':'pem?', }, # Or "current"?
9: {'b':'rem?', }, # Or "next"?
14: {'b':'gf_?', },
15: {'b':'present?', },
21: {'b':'tourn', }, # "tourney is over, results pending"?
22: {'b':'annc', },
23: {'b':'meta?', }, # metadata?
25: {'b':'drop%?', },
36: {'b':'mxp*', 'a':ghmult},
37: {'b':'dskill*', 'a':ghmult},
}
keys = 'sebiadfm'
#f: floor
'iadfm'
keynames = {
'i': 'i',
'a': 'amt',
'd': 'dung',
'f': 'floor',
'm': 'msg',
}
def __init__(self, raw):
if not set(raw) <= set(Bonus.keys):
raise ValueError('Unexpected keys: ' + str(set(raw) - set(Bonus.keys)))
self.s = ghtime(raw['s'])
self.e = ghtime(raw['e'])
# if 'd' in raw:
# # self.d = dungeons[int(raw['d'])]
# self.d = dungeons.get(int(raw['d']), 'd:%s'%raw['d'])
self.d = raw.get('d')
if 'm' in raw:
self.m = 'm'.replace('\n', r'\n')
b = raw['b']
others = 'iadfm'
self.b = b
if b in Bonus.types:
typ = Bonus.types[b]
self.type = typ['b']
else:
self.b = b
typ = {}
self.type = 'UNK_%d' % b
for k, key in self.keynames.items():
if k in raw:
if k in typ:
setattr(self, key, typ[k](raw[k]))
else:
setattr(self, key, raw[k])
self.raw = raw
def __repr__(self):
d = dict(self.raw)
d.pop('b')
d.pop('s')
d.pop('e')
return 'Bonuses(%r, %r)' % (self.type, d)
#? Should each bonus have a different class?
#############
# 2020 code
#############
#? Should I make it an enum?
b_codes = {
1: 'xp',
2: 'coins',
3: 'drop',
5: 'stamina',
6: 'specialdungeon',
}
def current_dungeons(bonuses, dungeons):
"""Parse out the current dungeons.
"""
if isinstance(bonuses, str):
bonuses = ojson_loads(bonuses)['bonuses']
bdungs = [
dungeons[b['d']] for b in bonuses
if b['b'] == 6
]
return bdungs
def current_skillup_dungeons(bonuses, dungeons):
"""Parse out the current skillup dungeons.
"""
if isinstance(bonuses, str):
bonuses = ojson_loads(bonuses)['bonuses']
bdungs = [
dungeons.get(b['d'], b['d']) for b in bonuses
if b['b'] == 25 and b.get('a', 0) == 0
]
return bdungs
#############
# [2020] Loads.
#############
def load(fpath=None):
"""Load the JSON from given folder or file path.
"""
if fpath is None:
import datafiles
fpath = datafiles.root
raise NotImplementedError("Oops, didn't put bonus data into datafiles folder.")
if os.path.isdir(fpath):
fpath = os.path.join(fpath, action+'.json')
j = ojson_load(fpath)
return loadjson(j)
#TODO: Cache it based on filepath.
#! Check modified time.
def loads(s):
j = ojson_loads(s)
return loadjson(j)
def loadjson(j):
"""Load from JSON dict.
"""
raws = j['bonuses']
v = j.get('v', 1) # version
if v != 2:
warnings.warn("Bonus JSON has unknown version %s." % (v))
bonuses = readbonuses2(raws)
return bonuses
def readbonuses2(raws):
return Bonuses(raws)
#############
# [2020] Trying this again??
#############
class Bonuses:
def __init__(self, jlist):
self.bonuses = list(map(Bonus, jlist))
def specials(self, dungeonDB):
return [
dungeonDB[b.d]
for b in self.bonuses
if b.b == 6 #special
]