-
Notifications
You must be signed in to change notification settings - Fork 9
/
logs_units_guid.py
462 lines (391 loc) · 14.6 KB
/
logs_units_guid.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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
from collections import defaultdict
import logs_pet_bullshit
from c_player_classes import CLASS_FROM_HTML, SPELL_BOOK
from h_debug import Loggers, running_time
from h_other import sort_dict_by_value
LOGGER_REPORTS = Loggers.reports
CLASSES = list(CLASS_FROM_HTML)
_prefix = [
"Bat", "Blight", "Bone", "Brain", "Carrion", "Casket", "Corpse", "Crypt", "Dirt", "Earth", "Eye", "Grave", "Gravel", "Hammer",
"Limb", "Marrow", "Pebble", "Plague", "Rat", "Rib", "Root", "Rot", "Skull", "Spine", "Stone", "Tomb", "Worm"]
_suffix = [
"basher", "breaker", "catcher", "chewer", "chomp", "cruncher", "drinker", "feeder", "flayer", "gnaw", "gobbler", "grinder",
"keeper", "leaper", "masher", "muncher", "ravager", "rawler", "ripper", "rumbler", "slicer", "stalker", "stealer", "thief"]
GHOUL_NAMES = {f"{x}{y}" for x in _prefix for y in _suffix}
TEMP_DK_PETS = {
"005E8F", # Army of the Dead Ghoul
"00660D", # Risen Ghoul
"007616", # Risen Ally
}
NIL_GUID = "0x0000000000000000"
FLAG_SKIP = {"PARTY_KILL", "UNIT_DIED"}
FLAG_PET_AGGRO = {"SWING_DAMAGE", "SPELL_DAMAGE"}
FLAG_IGNORE_PLAYER_CLASS = {
"SPELL_AURA_REMOVED",
"ENCHANT_APPLIED",
}
NAMES_SKIP = {"nil", "Unknown"}
PET_FILTER_SPELLS = {
"43771", # Well Fed (Spiced Mammoth Treats)
"65247", # Well Fed (Kibler's Bits)
# from dk
"48743", # Death Pact
"51328", # Corpse Explosion
"63560", # Ghoul Frenzy
# from warlock
"25228", # Soul Link
"23720", # Blessing of the Black Book
"32553", # Life Tap
"32554", # Mana Feed - Drain Mana
"32752", # Summoning Disorientation
"54181", # Fel Synergy
"54607", # Soul Leech Mana
"59092", # Dark Pact
"70840", # Devious Minds
"755", # Health Funnel 1
"3698", # Health Funnel 2
"3699", # Health Funnel 3
"3700", # Health Funnel 4
"11693", # Health Funnel 5
"11694", # Health Funnel 6
"11695", # Health Funnel 7
"27259", # Health Funnel 8
"47856", # Health Funnel 9
"16569", # Health Funnel
"40671", # Health Funnel
"60829", # Health Funnel
# from pet
"35696", # Demonic Knowledge
"47283", # Empowered Imp
"7812", # Sacrifice 1
"19438", # Sacrifice 2
"19440", # Sacrifice 3
"19441", # Sacrifice 4
"19442", # Sacrifice 5
"19443", # Sacrifice 6
"27273", # Sacrifice 7
"47985", # Sacrifice 8
"47986", # Sacrifice 9
# Imp
"23759", # Master Demonologist
"23826", # Master Demonologist
"23827", # Master Demonologist
"23828", # Master Demonologist
"23829", # Master Demonologist
# Voidwalker
"23760", # Master Demonologist
"23841", # Master Demonologist
"23842", # Master Demonologist
"23843", # Master Demonologist
"23844", # Master Demonologist
# Succubus
"23761", # Master Demonologist
"23833", # Master Demonologist
"23834", # Master Demonologist
"23835", # Master Demonologist
"23836", # Master Demonologist
# Felhunter
"23762", # Master Demonologist
"23837", # Master Demonologist
"23838", # Master Demonologist
"23839", # Master Demonologist
"23840", # Master Demonologist
# Felguard
"35702", # Master Demonologist
"35703", # Master Demonologist
"35704", # Master Demonologist
"35705", # Master Demonologist
"35706", # Master Demonologist
# from hunter
"1002", # Eyes of the Beast
"1539", # Feed Pet
"19574", # Bestial Wrath
"19577", # Intimidation
"34952", # Go for the Throat 1
"34953", # Go for the Throat 2
"61669", # Aspect of the Beast
"68130", # Greatness (4T9)
"70728", # Exploit Weakness
"136", # Mend Pet 1
"3111", # Mend Pet 2
"3661", # Mend Pet 3
"3662", # Mend Pet 4
"13542", # Mend Pet 5
"13543", # Mend Pet 6
"13544", # Mend Pet 7
"27046", # Mend Pet 8
"48989", # Mend Pet 9
"48990", # Mend Pet 10
"33976", # Mend Pet
# from pet
"53434", # Call of the Wild
"57475", # Kindred Spirits
"53412", # Invigoration
"53517", # Roar of Recovery
"70893", # Culling the Herd
"19579", # Spirit Bond 1
"24529", # Spirit Bond 2
"24604", # Furious Howl 1
"64491", # Furious Howl 2
"64492", # Furious Howl 3
"64493", # Furious Howl 4
"64494", # Furious Howl 5
"64495", # Furious Howl 6
}
BOSS_PETS = {
"008F0B": "008F04", # Bone Spike
"009738": "008F04", # Bone Spike
"009737": "008F04", # Bone Spike
# "0008F4": "008F04", # Coldflame
# "00954E": "008FF7", # Vengeful Shade
# "009765": "008EF5", # Defile
"009513": "009443", # Swarming Shadows
# "008809": "0087DC", # Nether Portal
# "0087FD": "0087DC", # Infernal Volcano
"009EE9": "009BB7", # Living Inferno
"009EEB": "009BB7", # Living Ember
"008170": "008208", # Guardian of Yogg-Saron
"00823F": "00820D", # XS-013 Scrapbot
"008242": "00820D", # XE-321 Boombot
"008240": "00820D", # XM-024 Pummeller
# "0xF1300084D4000832": "00820D", # Life Spark
# "0xF1300084D1000833": "00820D", # Void Zone
"00826B": "00808A", # Writhing Lasher'
"0085E3": "00808A", # Ward of Life'
}
def is_player(guid):
return guid[:3] == "0x0"
def is_perma_pet(guid):
return guid[:5] == "0xF14"
def pet_group_by_id(pets_raw):
d: defaultdict[str, set[str]] = defaultdict(set)
for guid in pets_raw:
if is_perma_pet(guid):
d[guid[6:-6]].add(guid)
return d
def new_unit(name: str, master_name: str, master_guid: str):
return {
'name': name,
'master_name': master_name,
'master_guid': master_guid
}
def add_missing_pets(everything: dict[str, str], pets_perma: dict[str, dict[str, str]], pets_perma_all: set[str]):
def get_name(guid_id):
for guid in everything:
if guid[6:-6] == guid_id:
return everything[guid]['name']
def get_owner(pet_guids):
owners = defaultdict(int)
for pet_guid in pet_guids:
if pet_guid not in pets_perma:
continue
owner_guid = pets_perma[pet_guid].get('master_guid')
if owner_guid:
owners[owner_guid] += 1
if None in owners:
del owners[None]
if owners:
owners = sort_dict_by_value(owners)
return list(owners)[0]
missing_owner = []
pets_perma_all_groupped = pet_group_by_id(pets_perma_all)
for guid_id, pet_guids in pets_perma_all_groupped.items():
master_guid = get_owner(pet_guids)
if not master_guid:
missing_owner.append(guid_id)
continue
if master_guid not in everything:
continue
master_name = everything[master_guid]['name']
pet_name = get_name(guid_id)
_pet = new_unit(pet_name, master_name, master_guid)
for pet_guid in pet_guids:
everything[pet_guid] = _pet
pets_perma[pet_guid] = _pet
return missing_owner
@running_time
def logs_parser(logs: list[str]): # sourcery no-metrics
everything: dict[str, dict[str, str]] = {}
pets_perma: dict[str, dict[str, str]] = {}
temp_pets: dict[str, dict[str, str]] = {}
pets_perma_all: set[str] = set()
_ignored_pet_names = set()
other_perma_pets: dict[str, dict[str, set[str]]] = defaultdict(lambda: defaultdict(set))
players = {}
players_classes = {}
players_skip = set()
for line in logs:
_, flag, sGUID, sName, tGUID, tName, *other = line.split(',', 8)
if sName == 'Unknown' or tName in NAMES_SKIP:
continue
if sGUID not in everything:
everything[sGUID] = {'name': sName}
elif tGUID not in everything:
everything[tGUID] = {'name': tName}
try:
spell_id = other[0]
except IndexError:
continue
if sGUID not in players_skip:
if not is_player(sGUID):
players_skip.add(sGUID)
elif spell_id in SPELL_BOOK and flag not in FLAG_IGNORE_PLAYER_CLASS:
players[sGUID] = sName
class_i = SPELL_BOOK[spell_id]
players_classes[sGUID] = CLASSES[class_i]
players_skip.add(sGUID)
# LOGGER_REPORTS.info(f" NEW CLASS | {sName:12} | {line}")
if spell_id == "47468": # Claw
# if sGUID[6:-6] not in TEMP_DK_PETS:
if sGUID[:5] == "0xF14":
other_perma_pets["Ghoul"][sGUID].add(tGUID)
if sName in _ignored_pet_names:
pass
elif sName not in GHOUL_NAMES:
_ignored_pet_names.add(sName)
LOGGER_REPORTS.debug(f"sName not in GHOUL_NAMES {sName}")
elif spell_id == "54053": # Shadow Bite
if sGUID[:5] == "0xF14" and tGUID[:4] == "0xF1":
other_perma_pets["Felhunter"][sGUID].add(tGUID)
elif spell_id == "72898": # Waterbolt
if sGUID[:5] == "0xF14" and tGUID[:4] == "0xF1":
other_perma_pets["Water Elemental"][sGUID].add(tGUID)
elif flag == "SPELL_SUMMON":
if tGUID[6:-6] in BOSS_PETS:
continue
if is_perma_pet(tGUID):
pets_perma[tGUID] = new_unit(tName, sName, sGUID)
pets_perma_all.add(tGUID)
elif sGUID != tGUID:
temp_pets[tGUID] = new_unit(tName, sName, sGUID)
elif spell_id in PET_FILTER_SPELLS:
if sGUID == tGUID:
if is_perma_pet(sGUID):
pets_perma_all.add(sGUID)
elif is_player(sGUID):
pet_info = new_unit(tName, sName, sGUID)
if is_perma_pet(tGUID):
pets_perma[tGUID] = pet_info
pets_perma_all.add(tGUID)
else:
temp_pets[tGUID] = pet_info
elif is_player(tGUID):
pet_info = new_unit(sName, tName, tGUID)
if is_perma_pet(sGUID):
pets_perma[sGUID] = pet_info
pets_perma_all.add(sGUID)
else:
temp_pets[sGUID] = pet_info
elif spell_id == "34650": # Mana Leech
temp_pets[sGUID] = new_unit("Shadowfiend", tName, tGUID)
elif is_perma_pet(sGUID) and flag in FLAG_PET_AGGRO:
pets_perma_all.add(sGUID)
everything |= temp_pets
for guid, name in players.items():
everything[guid] = {'name': name}
missing_owner = add_missing_pets(everything, pets_perma, pets_perma_all)
return {
"everything": everything,
"players": dict(sorted(players.items())),
"classes": dict(sorted(players_classes.items())),
"pets_perma": pets_perma,
"other_perma_pets": other_perma_pets,
"missing_owner": missing_owner,
}
def convert_nested_masters(data: dict[str, dict[str, str]]):
for unit_info in data.values():
if 'master_guid' not in unit_info:
continue
master_info = data.get(unit_info['master_guid'])
if not master_info:
continue
master_master_guid = master_info.get('master_guid')
if not master_master_guid:
continue
unit_info['master_guid'] = master_master_guid
unit_info['master_name'] = data[master_master_guid]['name']
@running_time
def get_water_elementals(logs_slice: list[str]):
WATER_ELEMENTAL_ID = "00946A"
WATER_ELEMENTAL_SUMMON_ID = "31687"
WATER_ELEMENTAL_SUMMON_ID_STR = f",{WATER_ELEMENTAL_SUMMON_ID},"
water_elementals = {}
last_water_elemental = None
lines_from_last_summon = 0
for line in logs_slice:
if WATER_ELEMENTAL_SUMMON_ID_STR in line:
_, _, source_guid, source_name, _, _, spell_id, _ = line.split(',', 7)
if spell_id == WATER_ELEMENTAL_SUMMON_ID:
last_water_elemental = new_unit("Water Elemental", source_name, source_guid)
lines_from_last_summon = 0
continue
if last_water_elemental is None:
continue
if WATER_ELEMENTAL_ID not in line:
lines_from_last_summon += 1
if lines_from_last_summon > 200:
LOGGER_REPORTS.debug(f"Water Elemental | {last_water_elemental['master_name']:12} >>> not found")
last_water_elemental = None
continue
_, _, source_guid, _, target_guid, _ = line.split(',', 5)
if source_guid[6:-6] == WATER_ELEMENTAL_ID:
elemental_guid = source_guid
elif target_guid[6:-6] == WATER_ELEMENTAL_ID:
elemental_guid = target_guid
else:
continue
if elemental_guid in water_elementals:
continue
LOGGER_REPORTS.debug(f"Water Elemental | {last_water_elemental['master_name']:12} >>> {elemental_guid}")
water_elementals[elemental_guid] = last_water_elemental
last_water_elemental = None
lines_from_last_summon = 0
return water_elementals
def get_mutated_aboms(logs_slice: list[str]):
MUTATED_ABOMINATION_ID = "00958D"
MUTATED_TRANSFORMATION_ID = "70308"
MUTATED_TRANSFORMATION_ID_STR = f",{MUTATED_TRANSFORMATION_ID},"
mutated_aboms = {}
last_abom_unit_data = None
lines_from_last_summon = 0
for line in logs_slice:
if MUTATED_TRANSFORMATION_ID_STR in line:
_, _, source_guid, source_name, _, _, spell_id, _ = line.split(',', 7)
if spell_id == MUTATED_TRANSFORMATION_ID:
last_abom_unit_data = new_unit("Mutated Abomination", source_name, source_guid)
lines_from_last_summon = 0
continue
if last_abom_unit_data is None:
continue
if MUTATED_ABOMINATION_ID not in line:
lines_from_last_summon += 1
if lines_from_last_summon > 200:
LOGGER_REPORTS.debug(f"Mutated Abomination | {last_abom_unit_data['master_name']:12} >>> not found")
last_abom_unit_data = None
continue
_, _, source_guid, _, target_guid, _ = line.split(',', 5)
if source_guid != target_guid:
continue
if source_guid[6:-6] != MUTATED_ABOMINATION_ID:
continue
LOGGER_REPORTS.debug(f"Mutated Abomination | {last_abom_unit_data['master_name']:12} >>> {source_guid}")
mutated_aboms[source_guid] = last_abom_unit_data
last_abom_unit_data = None
lines_from_last_summon = 0
return mutated_aboms
@running_time
def get_mutated_aboms_wrap(logs: list[str], encounter_data: list[int, int]):
mutated_aboms = {}
for s, f in encounter_data:
mutated_aboms |= get_mutated_aboms(logs[s:f])
return mutated_aboms
@running_time
def guids_main(logs, enc_data):
parsed = logs_parser(logs)
parsed["everything"] |= get_water_elementals(logs)
if "Professor Putricide" in enc_data:
pp_segments = enc_data["Professor Putricide"]
parsed["everything"] |= get_mutated_aboms_wrap(logs, pp_segments)
logs_pet_bullshit.find_pet_owners(logs, enc_data, parsed)
convert_nested_masters(parsed["everything"])
return parsed