-
Notifications
You must be signed in to change notification settings - Fork 1
/
levels.py
368 lines (334 loc) · 6.52 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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/usr/bin/python
# -*- coding: utf-8 -*-
from utils import (
Client,
ClientConfig,
MyFileHandler,
MyFormatter,
MyStreamHandler,
Path,
Settings,
Sg,
box,
ceil,
chunks,
compare,
copy,
datetime,
excepthook,
floor,
format_time,
get_font_name,
get_menu_pixels,
get_rotation,
get_text,
global_settings,
hdlr,
importlib,
json,
load_font,
log,
logger,
logging,
my_emit,
os,
requests,
rfh,
set_text,
sys,
timedelta,
)
level_bbox = (975, 143, 1060, 198)
font_color = (254, 254, 254)
single_digit_diff = 21
second_digit_diff = 43
bar_bbox = (1082, 148, 1656, 149)
bar_colors = ((158, 158, 177), (128, 128, 153), (30, 60, 126))
rewards_bar_bbox = (786, 331, 1365, 332)
rewards_bar_colors = ((35, 120), (190, 255), (40, 165))
locked_pixel = (1163, 875)
locked_color = (110, 200, 211)
first_digit_dict = {
"1": (
(10, 17),
(15, 45),
(17, 4),
(20, 15),
(27, 45),
(29, 4),
(19, 32),
),
"2": (
(5, 11),
(6, 5),
(9, 3),
(30, 4),
(34, 45),
(36, 12),
),
"3": (
(3, 37),
(7, 10),
(8, 3),
(9, 23),
(33, 6),
(36, 34),
),
"4": (
(2, 25),
(2, 34),
(19, 45),
(30, 45),
(32, 3),
(37, 27),
),
"5": (
(4, 37),
(5, 26),
(7, 4),
(23, 20),
(34, 4),
(36, 32),
),
"6": (
(2, 28),
(3, 37),
(16, 3),
(25, 46),
(29, 3),
(37, 27),
),
"7": (
(4, 3),
(4, 11),
(5, 45),
(19, 45),
(36, 3),
(36, 12),
),
"8": (
(2, 38),
(5, 12),
(19, 27),
(20, 3),
(36, 11),
(37, 35),
),
"9": (
(10, 45),
(15, 3),
(15, 30),
(19, 23),
(22, 28),
(24, 45),
),
"0": (
(1, 30),
(9, 6),
(15, 13),
(23, 46),
(24, 34),
(37, 17),
),
}
second_digit_dict = dict(
(key, tuple((x + second_digit_diff, y) for (x, y) in value))
for (key, value) in first_digit_dict.items()
)
single_digit_dict = dict(
(key, tuple((x + single_digit_diff, y) for (x, y) in value))
for (key, value) in first_digit_dict.items()
)
level_hundred_conditions = (
(0, 9),
(0, 15),
(10, 42),
(11, 8),
(27, 14),
(49, 39),
(62, 37),
(84, 9),
(84, 40),
)
levels_xp = [ # infinite xp if lvl 0 (undefined)
# infinite xp if lvl 100 (max lvl)
0,
210,
368,
455,
542,
628,
737,
867,
997,
1127,
1278,
1430,
1582,
1733,
1907,
2080,
2253,
2427,
2622,
2817,
3012,
3207,
3402,
3618,
3813,
4030,
4247,
4463,
4680,
4918,
5135,
5373,
5612,
5850,
6088,
6372,
6565,
6803,
7063,
7302,
7562,
7800,
8060,
8320,
8580,
8840,
9122,
9382,
9642,
9923,
10183,
10465,
10747,
11007,
11288,
11570,
11852,
12113,
12415,
12718,
13000,
13282,
13585,
13867,
14170,
14473,
14755,
15058,
15362,
15665,
15968,
16272,
16575,
16878,
17182,
17507,
17810,
18113,
18438,
18742,
19067,
19370,
19695,
20020,
20323,
20648,
20973,
21298,
21623,
21948,
22273,
22598,
22923,
23270,
23595,
23920,
24267,
24592,
24917,
25263,
float("inf"),
]
gold_levels = list(range(7, 20, 2)) + list(range(21, 101))
def get_duration_xp(duration):
return int(40.91 * duration)
def get_duration_gold(duration):
return 10 * duration
class LevelNotDetected(Exception):
pass
class LevelDefiner:
def __init__(self, brawlhalla):
self.brawlhalla = brawlhalla
def _get_single_digit_level(self, image):
return int(self.get_single_digit(image))
def _get_double_digit_level(self, image):
return int(self.get_first_digit(image) + self.get_second_digit(image))
@staticmethod
def _get_level_hundred(image):
if all(image.getpixel(pos) == font_color for pos in level_hundred_conditions):
return 100
raise TypeError
def get_level(self):
screenshot = self.brawlhalla.make_screenshot()
level = screenshot.crop(level_bbox)
for f in [
self._get_single_digit_level,
self._get_double_digit_level,
self._get_level_hundred,
]:
try:
# noinspection PyArgumentList
return f(level)
except TypeError:
pass
logger.error("level_error")
raise LevelNotDetected
def get_percentage(self):
count = -3
screenshot = self.brawlhalla.make_screenshot()
bar = screenshot.crop(bar_bbox)
for i in range(bar.width):
if bar.getpixel((i, 0)) in bar_colors:
break
count += 1
perc = count / bar.width
return perc
def get_reward_percentage(self):
count = 1
screenshot = self.brawlhalla.make_screenshot()
bar = screenshot.crop(rewards_bar_bbox)
for i in range(bar.width):
pixel = bar.getpixel((i, 0))
if all(
rewards_bar_colors[i][1] > pixel[i] > rewards_bar_colors[i][0]
for i in range(len(pixel))
):
count += 1
perc = count / bar.width
return perc
def get_xp(self, level, reward=False):
if level == 100:
return 0
return int(
((self.get_reward_percentage() if reward else self.get_percentage()))
* levels_xp[level]
)
def get_unlocked(self):
screenshot = self.brawlhalla.make_screenshot()
return screenshot.getpixel(locked_pixel) != locked_color
@staticmethod
def get_digit(conditions, image):
for digit in conditions:
if all(image.getpixel(pos) == font_color for pos in conditions[digit]):
return digit
def get_first_digit(self, image):
return self.get_digit(first_digit_dict, image)
def get_second_digit(self, image):
return self.get_digit(second_digit_dict, image)
def get_single_digit(self, image):
return self.get_digit(single_digit_dict, image)