File size: 9,661 Bytes
b8aecdd
 
 
 
 
 
 
88de31c
 
 
b8aecdd
5825182
88de31c
 
 
b8aecdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b76daae
88de31c
b76daae
88de31c
 
 
b8aecdd
88de31c
b76daae
88de31c
 
 
b76daae
 
 
 
 
 
 
 
 
5825182
b8aecdd
 
ef62e40
b8aecdd
 
 
 
 
 
 
ef62e40
b8aecdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88de31c
 
 
 
3ed500d
 
88de31c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef62e40
88de31c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef62e40
88de31c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b76daae
88de31c
 
 
 
 
 
 
 
 
 
 
 
 
b8aecdd
 
 
 
 
 
 
 
 
 
 
88de31c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b76daae
88de31c
 
 
b8aecdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88de31c
 
 
 
 
 
 
 
 
b8aecdd
 
 
88de31c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8aecdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88de31c
 
 
 
 
 
b8aecdd
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
import json
import os
from functools import cache

import requests
from tqdm import tqdm

from qt.constant import MAX_BASE_ATTR, MAX_MAGIC_ATTR, MAX_EMBED_ATTR, MAX_ENCHANT_ATTR
from qt.constant import ATTR_TYPE_MAP, ATTR_TYPE_TRANSLATE
from qt.constant import MAX_STONE_ATTR, STONE_ATTR, MAX_STONE_LEVEL
from qt.constant import EQUIPMENTS_DIR, ENCHANTS_DIR, STONES_DIR
from utils.parser import SUPPORT_SCHOOL

KINDS = set(sum([[school.kind, school.major] for school in SUPPORT_SCHOOL.values()], []))
SCHOOLS = set(["精简", "通用"] + [school.school for school in SUPPORT_SCHOOL.values()])

EQUIP_ATTR_MAP = {
    "Overcome": "破防",
    "Critical": "会心",
    "CriticalDamage": "会效",
    "Haste": "加速",
    "Surplus": "破招",
    "Strain": "无双"
}

POSITION_MAP = {
    "hat": 3,
    "jacket": 2,
    "belt": 6,
    "wrist": 10,
    "bottoms": 8,
    "shoes": 9,
    "necklace": 4,
    "pendant": 7,
    "ring": 5,
    "tertiary_weapon": 1,
    "primary_weapon": 0
}

SUFFIX_MAP = {
    3: 'armor',
    2: 'armor',
    6: 'armor',
    10: 'armor',
    8: 'armor',
    9: 'armor',
    4: 'trinket',
    7: 'trinket',
    5: 'trinket',
    1: 'weapon',
    0: 'weapon'
}
SPECIAL_ENCHANT_MAP = {
    3: {
        14350: [15436, 12],
        12800: [15436, 11],
        11500: [15436, 10],
        10600: [15436, 9]
    },
    2: {
        14350: [22151, 12],
        12800: [22151, 11],
        11500: [22151, 10],
        10600: [22151, 9]
    },
    6: {
        0: 22169
    },
    10: {
        0: 22166
    },
    9: {
        0: 33247
    }
}

equip_min_level = 12000
equip_params = {
    "client": "std",
    "pv_type": 1,
    "pz": 1,
    "page": 1,
    "per": 300,
    "min_level": 9000,
    "max_level": 17000
}

enchant_params = {
    "client": "std",
    "subtype": 1,
    "latest_enhance": 1
}


# @cache
def get_equips_list(position):
    position_id = POSITION_MAP[position]
    url = f"https://node.jx3box.com/equip/{SUFFIX_MAP[position_id]}"
    params = equip_params.copy()
    params['position'] = position_id
    equips = []
    res = requests.get(url, params=params).json()
    equips.extend(res['list'])
    while res['pages'] > params['page']:
        params['page'] += 1
        res = requests.get(url, params=params).json()
        equips.extend(res['list'])

    result = {get_equip_name(row): get_equip_detail(row) for row in reversed(equips) if
              row['SubType'] != "0" or row['DetailType'] != "9"}
    result = {k: v for k, v in result.items() if v['level'] >= equip_min_level or v['max_strength'] == 8}
    result = {k: v for k, v in result.items() if v['kind'] in KINDS}
    result = {k: v for k, v in result.items() if v['school'] in SCHOOLS}
    return result


def get_secondary_weapons():
    params = equip_params.copy()
    params['position'] = 0
    params['DetailType'] = 9

    url = f"https://node.jx3box.com/equip/weapon"
    equips = []
    res = requests.get(url, params=params).json()
    equips.extend(res['list'])
    while res['pages'] > params['page']:
        params['page'] += 1
        res = requests.get(url, params=params).json()
        equips.extend(res['list'])

    result = {get_equip_name(row): get_equip_detail(row) for row in reversed(equips)}
    result = {k: v for k, v in result.items() if v['level'] >= equip_min_level or v['max_strength'] == 8}
    result = {k: v for k, v in result.items() if v['kind'] in KINDS}
    result = {k: v for k, v in result.items() if v['school'] in SCHOOLS}
    return result


def get_equip_name(row):
    name = row['Name']
    if "无封" in name:
        name = f"{row['MagicKind']}{name}"
    attrs = " ".join([EQUIP_ATTR_MAP[attr] for attr in EQUIP_ATTR_MAP if attr in row['_Attrs']])
    level = row['Level']
    return f"{name} ({attrs}) {level}"


def get_equip_detail(row):
    base_attrs, magic_attrs, embed_attrs = {}, {}, {}
    set_id, set_attr, set_gain = "", {}, {}
    level = int(row['Level'])
    special_enchant = []
    gains = []
    for i in range(MAX_BASE_ATTR):
        if not (attr_type := row[f'Base{i + 1}Type']):
            break
        if attr_type not in ATTR_TYPE_MAP:
            continue
        base_attrs[ATTR_TYPE_MAP[attr_type]] = int(row[f'Base{i + 1}Max'])
    for i in range(MAX_MAGIC_ATTR):
        if not (attr := row[f'_Magic{i + 1}Type']):
            break
        attr = attr['attr']
        if attr[0] in ATTR_TYPE_MAP:
            magic_attrs[ATTR_TYPE_MAP[attr[0]]] = int(attr[1])
        elif attr[0] in ["atSetEquipmentRecipe", "atSkillEventHandler"]:
            gains.append(int(attr[1]))
        else:
            continue
    for i in range(MAX_EMBED_ATTR):
        if not (attr := row[f'_DiamondAttributeID{i + 1}']):
            break
        if attr[0] not in ATTR_TYPE_MAP:
            continue
        embed_attrs[ATTR_TYPE_MAP[attr[0]]] = int(attr[1])

    for k, v in SPECIAL_ENCHANT_MAP.get(row['SubType'], {}).items():
        if level > k:
            special_enchant = v
            break

    if row["SkillID"]:
        gains.append((int(row['SkillID']), int(row['SkillLevel'])))

    if set_id := row['_SetAttrbs']:
        set_id = set_id['UiID']
        for k, v in row['_SetData'].items():
            if not v:
                continue
            count = k.split("_")[0]
            attr = v['attr']
            if attr[0] in ATTR_TYPE_MAP:
                if count not in set_attr:
                    set_attr[count] = {}
                set_attr[count][ATTR_TYPE_MAP[attr[0]]] = int(attr[1])
            elif attr[0] in ["atSetEquipmentRecipe", "atSkillEventHandler"]:
                if count not in set_gain:
                    set_gain[count] = []
                set_gain[count].append(int(attr[1]))
    return {
        "id": row["ID"],
        "school": row['BelongSchool'],
        "kind": row['MagicKind'],
        "level": level,
        "max_strength": int(row['MaxStrengthLevel']),
        "base": base_attrs,
        "magic": magic_attrs,
        "embed": embed_attrs,
        "gains": gains,
        "special_enchant": special_enchant,
        "set_id": set_id,
        "set_attr": set_attr,
        "set_gain": set_gain
    }


@cache
def get_enchants_list(position):
    position_id = POSITION_MAP[position]
    url = f"https://node.jx3box.com/enchant/primary"
    params = enchant_params.copy()
    params['position'] = position_id
    res = requests.get(url, params=params)
    enchants = [e for e in sorted(res.json(), key=lambda x: x['Score'], reverse=True) if
                e['Attribute1ID'] in ATTR_TYPE_MAP]

    result = {get_enchant_name(row): get_enchant_detail(row) for row in enchants}

    return result


def get_weapon_enchants():
    return get_enchants_list("primary_weapon")


def get_enchant_name(row):
    if not row:
        return ""
    name = row['Name']
    attr = row['AttriName']
    return f"{name} {attr}"


def get_enchant_detail(row):
    attrs = {}
    for i in range(MAX_ENCHANT_ATTR):
        if not (attr_type := row[f'Attribute{i + 1}ID']):
            break
        if attr_type not in ATTR_TYPE_MAP:
            continue
        attrs[ATTR_TYPE_MAP[attr_type]] = int(row[f'Attribute{i + 1}Value1'])
    return {
        "id": row['ID'],
        "score": row['Score'],
        "attr": attrs
    }


def get_stones_list():
    url = "https://node.jx3box.com/enchant/stone"

    result = {}
    for level in tqdm(range(MAX_STONE_LEVEL)):
        level = level + 1
        stones = []
        params = {
            "client": "std",
            "level": level,
            "page": 1,
            "per": 100
        }
        res = requests.get(url, params=params).json()
        stones.extend(res['list'])
        while res['pages'] > params['page']:
            params['page'] += 1
            res = requests.get(url, params=params).json()
            stones.extend(res['list'])

        for row in stones:
            if detail := get_stone_detail(row):
                current = result
                for attr in detail['attr']:
                    if attr not in current:
                        current[attr] = {}
                    current = current[attr]
                current[level] = detail

    return result


def get_stone_name(row):
    name = row['Name']
    attrs = " ".join([ATTR_TYPE_TRANSLATE[ATTR_TYPE_MAP[attr]] for attr in row['_Attrs'] if attr in ATTR_TYPE_MAP])
    return f"{name} ({attrs})"


def get_stone_detail(row):
    attrs = {}
    for i in range(MAX_STONE_ATTR):
        if not (attr_type := row[f'Attribute{i + 1}ID']):
            break
        if attr_type not in STONE_ATTR:
            return
        attrs[ATTR_TYPE_MAP[attr_type]] = int(row[f'Attribute{i + 1}Value1'])

    return {
        "level": row['stone_level'],
        "attr": attrs
    }


if __name__ == '__main__':
    if not os.path.exists(EQUIPMENTS_DIR):
        os.makedirs(EQUIPMENTS_DIR)
    if not os.path.exists(ENCHANTS_DIR):
        os.makedirs(ENCHANTS_DIR)

    for pos in tqdm(POSITION_MAP):
        json.dump(
            get_equips_list(pos),
            open(os.path.join(EQUIPMENTS_DIR, pos), "w", encoding="utf-8"), ensure_ascii=False
        )
        json.dump(
            get_enchants_list(pos),
            open(os.path.join(ENCHANTS_DIR, pos), "w", encoding="utf-8"), ensure_ascii=False
        )
    json.dump(
        get_secondary_weapons(), open(os.path.join(EQUIPMENTS_DIR, "secondary_weapon"), "w", encoding="utf-8"),
        ensure_ascii=False)
    json.dump(
        get_weapon_enchants(), open(os.path.join(ENCHANTS_DIR, "secondary_weapon"), "w", encoding="utf-8")
    )
    json.dump(get_stones_list(), open(STONES_DIR, "w", encoding="utf-8"), ensure_ascii=False)