File size: 2,449 Bytes
f0b1638
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from typing import Dict

from base.buff import Buff
from base.skill import Skill
from utils.lua import parse


class Parser:
    records: dict
    status: dict

    start_time: list
    end_time: list

    info_flag: bool
    fight_flag: bool

    school: int

    def __init__(self, skills: Dict[str, Skill], buffs: Dict[str, Buff]):
        self.skills = skills
        self.buffs = buffs

    def reset(self):
        self.info_flag = True
        self.fight_flag = False

        self.records = {}
        self.status = {}

        self.start_time = []
        self.end_time = []

    def parse_info(self, detail):
        if isinstance(detail, list):
            self.info_flag = False

    def parse_time(self, detail, timestamp):
        if detail[1]:
            self.start_time.append(int(timestamp))
            self.records[self.start_time[-1]] = {}
            self.fight_flag = True
        else:
            self.end_time.append(int(timestamp))
            self.fight_flag = False

    def parse_buff(self, detail):
        buff_id, buff_stack, buff_level = detail[4], detail[5], detail[8]
        if buff_id not in self.buffs:
            return
        if not buff_stack:
            self.status.pop((buff_id, buff_level))
        else:
            self.status[(buff_id, buff_level)] = buff_stack

    def parse_skill(self, detail, timestamp):
        skill = detail[4], detail[5]
        if skill[0] not in self.skills:
            return

        current_record = self.records[self.start_time[-1]]
        if skill not in current_record:
            current_record[skill] = {}
        status = tuple(
            (buff_id, buff_level, buff_stack) for (buff_id, buff_level), buff_stack in self.status.items()
        )
        if status not in current_record[skill]:
            current_record[skill][status] = []
        current_record[skill][status].append(int(timestamp) - self.start_time[-1])

    def __call__(self, file_name):
        self.reset()

        for line in open(file_name):
            row = line.split("\t")
            if row[4] == "4" and self.info_flag:
                self.parse_info(parse(row[-1]))
            elif row[4] == "5":
                self.parse_time(parse(row[-1]), row[3])
            elif row[4] == "13":
                self.parse_buff(parse(row[-1]))
            elif row[4] == "21" and self.fight_flag:
                self.parse_skill(parse(row[-1]), row[3])

        return self.records