-
Notifications
You must be signed in to change notification settings - Fork 2
/
sneak_dungeon.py
198 lines (155 loc) · 4.55 KB
/
sneak_dungeon.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
import json
from urllib.parse import parse_qsl
try:
import padcrypt
except ImportError:
print("Warning: Don't know how to decrypt sneak_dungeon.")
# Need to get:
#- card_db
#- non-monster types (e.g. gold)
#-
__all__ = [
'SneakData',
]
class SneakData:
""" Holds wave data.
"""
def __init__(self, waves):
"""
"""
'''
Waves are structured as:
* waves[floor] = wave
* wave[i] = spawn
* spawn = [??, enemy_id, enemy_lv, drop_id, drop_lv, plusses]
- All ints.
'''
'''
goal:
sdata = SneakData(...)
sdata
.coins: int
.xp: int
.drops
# who really cares about chests?
# well, they matter for dropcount.
wave = sdata[floor]
spawn = wave.spawns[i]
spawn.name
spawn.lv
drop = wave.drop
if drop is not None:
sdata.coins
waves.
'''
floors = self.floors = []
for wave in waves:
wave
# incomplete
@classmethod
def from_encrypted(cls, ciphertext):
"""
"""
assert cls == SneakData, "Not ready for subclassing"
return cls.from_decrypted(padcrypt.decodePadDungeon(ciphertext))
@classmethod
def from_decrypted(cls, plaintext):
""" Create from plaintext.
"""
assert cls == SneakData, "Not ready for subclassing"
waves = _query2wavelist(plaintext)
return cls(waves)
def encrypted(self):
raise NotImplementedError("Haha no you cheater.")
def yaml(self):
"""
"""
''' Goal:
dungeon_name:
Drops:
- Rank XP
- Coins
- Mon (Lv)
- Mon (Lv)
Floors:
- drop: Mon (lv)
enemies:
- Mon (lv)
- Mon (lv)
- Mon (lv)
- drop: Mon (lv)
enemies:
- Mon (lv)
- Mon (lv)
- Mon (lv)
'''
def html(self):
"""
"""
''' Goal:
dungeon_name:
- drop: Mon (lv) | None
enemies:
- id. mon_name (lv)
- id. mon_name (lv)
- drop: Mon (lv)
enemies:
- id. mon_name (lv)
- id. mon_name (lv)
'''
class Spawn:
# Needs card_data for:
#- Name
#- XP
#-
# Needs bonus info for non-monster drops.
def __init__(self, raw):
self._unk, self.mon_id, self.lv, self.drop, self.dropvar, self.plusses = raw
def display(self, card_db):
"""Given a source of card info, display this spawn.
"""
mon = card_db[self.mon_id]
mon_s = f"{mon.name} @ lv{self.lv}"
if self.drop == 0:
return mon_s
elif self.drop < 9900:
drop = card_db[self.drop]
drop_lv = self.dropvar
drop_s = f"{drop.name} @ {drop_lv}"
elif self.drop == 9900:
drop_s = f"{self.dropvar} coins"
else:
drop_s = f"(other) @ {self.dropvar}"
return f"{mon_s}: {drop_s}"
def parse_uriparams(uri_params):
"""Decodes URI params and returns a dict.
URI params are `<name>=<val>` pairs, delimited by '&'.
"""
return dict(s.split('=', 1) for s in uri_params.split('&'))
def parse_uriparams(uri_params):
"""Decodes URI params and returns a dict.
URI params are `<name>=<val>` pairs, delimited by '&'.
"""
return dict(parse_qsl(uri_params))
def _j2wavelist(s):
"""
Input: JSON string or dict.
Output: wave list.
"""
if isinstance(s, str):
e = json.loads(s)['e']
else:
e = s['e']
plaintext = padcrypt.decodePadDungeon(e)
return _query2wavelist(plaintext)
def _query2wavelist(plaintext):
"""Handles the deciphered text.
Like 'waves={WAVELIST}&dh={DH}&rs={RS}'
"""
# raw_waves = parse_uriparams(plaintext)['waves']
raw_waves = plaintext.split('&')[0].split('=')[1]
wave_arr = json.loads(raw_waves.replace('"w":', ''))
# # Or use eval.
# assert not set(raw_waves) - set(digits + ',[]'), 'Unexpected characters.'
# wave_arr = eval(raw_waves)
return wave_arr