-
Notifications
You must be signed in to change notification settings - Fork 9
/
logs_valk_grabs.py
322 lines (286 loc) · 9.77 KB
/
logs_valk_grabs.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
from collections import defaultdict
import logs_base
from h_debug import running_time
from h_other import sort_dict_by_value
mobs = {"008EF5", "009342", "008F5D"}
REMORSELESS_WINTER_TRANSITION_1 = {"68981", "74271", "74270", "74272"}
REMORSELESS_WINTER_TRANSITION_2 = {"72259", "74274", "74273", "74275"}
REMORSELESS_WINTER = REMORSELESS_WINTER_TRANSITION_1 | REMORSELESS_WINTER_TRANSITION_2
FLAGS = ['SPELL_CAST_START', "SWING_DAMAGE", "RANGE_DAMAGE", "SPELL_CAST_SUCCESS", "ENVIRONMENTAL_DAMAGE"]
# 8/28 00:21:30.020 ENVIRONMENTAL_DAMAGE,0x0000000000000000,nil,0x80000000,0x070000000070C7FA,"Lomphidon",0x514,FALLING,626,0,1,0,0,0,nil,nil,nil
@running_time
def find_tanks(logs_slice: list[str]):
dmg_taken = defaultdict(int)
for line in logs_slice:
if ',SWING_' not in line:
continue
line = line.split(',', 5)
if line[2][6:-6] in mobs:
dmg_taken[line[4]] += 1
dmg_taken = sort_dict_by_value(dmg_taken)
return set(list(dmg_taken)[:2])
@running_time
def get_valks_summon_time(logs_slice: list[str]):
valks: dict[str, int] = {}
for line in logs_slice:
if '_SUMMON' in line and ",0xF150008F01" in line:
guid = line.split(',', 5)[4]
valks[guid] = logs_slice.index(line)
return valks
@running_time
def get_valks_first_cast(logs_slice: list[str]):
valks: dict[str, int] = {}
for line in logs_slice:
if '_START' not in line:
continue
guid = line.split(',', 3)[2]
if guid[6:-6] == "008F01" and guid not in valks:
valks[guid] = logs_slice.index(line)
return valks
@running_time
def get_valk_phase(logs_slice: list[str]):
start = None
end = None
for line in logs_slice:
# if line[-5:] != ",BUFF":
# continue
if '0008EF5' not in line:
continue
try:
_line = line.split(',', 7)
if _line[6] not in REMORSELESS_WINTER:
continue
if _line[6] in REMORSELESS_WINTER_TRANSITION_1:
if _line[1] == "SPELL_AURA_REMOVED":
start = logs_slice.index(line)
elif _line[1] == "SPELL_AURA_APPLIED":
end = logs_slice.index(line)
return start, end
except IndexError:
pass
return start, end
def get_valk_waves(logs_slice_t2):
valks_summon = get_valks_summon_time(logs_slice_t2)
print(valks_summon)
valks_cast = get_valks_first_cast(logs_slice_t2)
print(valks_cast)
valks = list(valks_summon)
valks = [valks[x:x+3] for x in range(0, len(valks), 3)]
print(valks)
VALK_WAVES = [
(
valks_summon[wave[-1]],
min(valks_cast.get(x, -1) for x in wave)
)
for wave in valks
]
last_valk_wave_end = VALK_WAVES[-1][1]
if last_valk_wave_end == -1:
del VALK_WAVES[-1]
return VALK_WAVES
def get_casts(logs_slice: list[str]):
casts = defaultdict(int)
for line in logs_slice:
_, flag, guid, _ = line.split(',', 3)
if flag in FLAGS:
casts[guid] += 1
return sort_dict_by_value(casts)
@running_time
def get_casters(logs_slice: list[str]):
print(len(logs_slice))
casters: list[str] = []
for line in logs_slice:
_, flag, guid, _ = line.split(',', 3)
if flag in FLAGS and guid not in casters:
casters.append(guid)
return casters
def convert_to_uptime(a):
return [
x if x < 0 else x*1000//max(a)/10
for x in a
]
def get_players_alive_after_waves(valk_waves, logs_slice):
AFTER_WAVES: list[set[str]] = []
for x, y in zip(valk_waves, valk_waves[1:]):
ws, wf = x[1], y[0]
ws = wf - (wf-ws) // 4
_slice = logs_slice[ws:wf]
c = get_casters(_slice)
AFTER_WAVES.append(c)
_slice = logs_slice[y[1]:]
c = get_casters(_slice)
AFTER_WAVES.append(c)
return AFTER_WAVES
def get_players_alive_after_waves(valk_waves, logs_slice):
AFTER_WAVES: list[set[str]] = []
for x, y in zip(valk_waves, valk_waves[1:]):
_slice = logs_slice[x[1]:y[0]]
c = get_casters(_slice)
AFTER_WAVES.append(c)
_slice = logs_slice[y[1]:]
c = get_casters(_slice)
AFTER_WAVES.append(c)
return AFTER_WAVES
def get_players_alive_after_waves(valk_waves, logs_slice):
AFTER_WAVES: list[set[str]] = []
for x, y in zip(valk_waves, valk_waves[1:]):
ws, wf = x[1], y[0]
wf = ws + (wf-ws) // 4
_slice = logs_slice[ws:wf]
c = get_casters(_slice)
AFTER_WAVES.append(c)
_slice = logs_slice[y[1]:]
c = get_casters(_slice)
AFTER_WAVES.append(c)
return AFTER_WAVES
@running_time
def get_env_deaths(logs_slice: list[str]):
dropped: set[str] = set()
for line in logs_slice:
if "FALLING" not in line:
continue
guid = line.split(',', 5)[4]
dropped.add(guid)
return dropped
def get_players_deaths_after_waves(valk_waves, logs_slice):
AFTER_WAVES: list[set[str]] = []
for x, y in zip(valk_waves, valk_waves[1:]):
ws, wf = x[1], y[0]
wf = ws + (wf-ws) // 2
_slice = logs_slice[ws:wf]
c = get_env_deaths(_slice)
AFTER_WAVES.append(c)
ws, wf = y[1], len(logs_slice)
wf = ws + (wf-ws) // 2
_slice = logs_slice[ws:wf]
c = get_env_deaths(_slice)
AFTER_WAVES.append(c)
return AFTER_WAVES
def get_grabs(data: dict[str, list], i: int):
new_data = {k: v[i] for k, v in data.items() if v[i] != -1}
new_data = sort_dict_by_value(new_data)
valks = 3
if len(new_data) < 11:
valks = 1
return set(list(new_data)[-valks:])
def present_players(logs_slice):
players = set()
for line in logs_slice:
if "0x0" not in line:
continue
players.add(line.split(',', 5)[4])
return
@running_time
def main(logs_slice: list[str], players: dict[str, str]):
t2s, t2f = get_valk_phase(logs_slice)
if t2s is None:
return
logs_slice_t2 = logs_slice[t2s:t2f]
VALK_WAVES = get_valk_waves(logs_slice_t2)
if len(VALK_WAVES) < 2:
return
AFTER_WAVES = get_players_alive_after_waves(VALK_WAVES, logs_slice_t2)
AFTER_WAVES_DROPS = get_players_deaths_after_waves(VALK_WAVES, logs_slice_t2)
TANKS = find_tanks(logs_slice[:t2s])
# print(TANKS)
# _players = set(players) - TANKS
players_present = get_casters(logs_slice[t2s:t2s+VALK_WAVES[0][0]])
players_present = set(players_present) & set(players) - TANKS
# players_present = set()
# for d in AFTER_WAVES:
# players_present.update(set(d) & _players)
# players_present = {x for x in players_present if x in players and x not in TANKS}
print(players_present)
GRABS = defaultdict(list)
for (ws, wf), _casts, _drops in zip(VALK_WAVES, AFTER_WAVES, AFTER_WAVES_DROPS):
CASTS = get_casts(logs_slice_t2[ws:wf])
print(_drops)
for pguid in players_present:
pname = players[pguid]
if pguid in _drops:
print(pname, 'was dropped')
v = -2
elif pguid in CASTS:
v = CASTS[pguid]
elif pguid not in _casts:
print(pname, 'is dead')
v = -1
else:
v = 0
GRABS[pname].append(v)
print(GRABS)
GRABS = {k: convert_to_uptime(v) for k,v in GRABS.items()}
waves_len = len(list(GRABS.values())[0])
return [
get_grabs(GRABS, x)
for x in range(waves_len)
]
class ValkGrabs(logs_base.THE_LOGS):
@logs_base.cache_wrap
def grabs_info(self, s, f):
logs_slice = self.LOGS[s:f]
players = self.get_players_guids()
return main(logs_slice, players)
def valk_info_all(self, segments):
grabs_total = defaultdict(int)
all_grabs = []
for s, f in segments:
grabs = self.grabs_info(s, f)
if grabs is None:
continue
all_grabs.extend(grabs)
for g in grabs:
for p in g:
grabs_total[p] += 1
waves = list(range(1, len(all_grabs)+1))
grabs_total = dict(sorted(grabs_total.items()))
grabs_total = sort_dict_by_value(grabs_total)
return {
"ALL_GRABS": all_grabs,
"GRABS_TOTAL": grabs_total,
"WAVES": waves,
}
GRABS = {
"22-08-27--20-19--Deydraenna--Icecrown": [
{"Parsifai", "Kikepatrol", "Kardiokill"},
{"Bdsmka", "Skvig", "Kardiokill"},
{"Kikepatrol", "Wopka", "Legendarnox"},
],
"22-08-26--21-03--Nomadra--Lordaeron": [
{"Dlt", "Wakemeup", "Stanicenemy"},
{"Nolfein", "Etnica", "Dotq"},
{"Risli", "Stanicenemy", "Arthemiis"},
],
"22-08-18--20-31--Meownya--Lordaeron": [
{"Narzisse", "Quarthon", "Yarel"},
{"Zibra", "Cocainomado", "Whiterplanet"},
{"Zibra", "Ahcelf", "Dim"},
{"Zibra", "Quarthon", "Dim"},
],
"22-08-25--20-20--Jebber--Lordaeron": [
{"Sana", "Luw", "Jengo"},
{"Syella", "Sharpshady", "Matan"},
{"Sharpshady", "Lockver", "Dodgypsy"},
],
"22-08-18--20-00--Lockver--Lordaeron": [
{"Orkleczyc", "Sharpshady", "Murmaider"},
{"Orkleczyc", "Tmsdk", "Pingpong"},
{"Sharpshady", "Jengo", "Murmaider"},
{"Orkleczyc", "Triwoll", "Alpinae"},
],
}
def __test(name, attempt=-2):
report = logs_main.THE_LOGS(name)
enc_data = report.get_enc_data()
S, F = enc_data["The Lich King"][attempt]
logs_slice = report.get_logs(S, F)
players = report.get_players_guids()
data = main(logs_slice, players)
print(data)
for x, y in zip(data, GRABS[name]):
print(x == y)
if __name__ == "__main__":
import logs_main
# for x in GRABS:
# __test(x)
__test(list(GRABS)[-1])