-
Notifications
You must be signed in to change notification settings - Fork 54
/
auto_get_res_new.py
746 lines (655 loc) · 30.7 KB
/
auto_get_res_new.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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
import json
import lzma
import os
import pickle
import re
from datetime import datetime
import cv2
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from skimage.feature import hog
from sklearn.neighbors import KNeighborsClassifier
from arknights_mower.utils.image import loadimg, thres2
class Arknights数据处理器:
def __init__(self):
self.当前时间戳 = datetime.now().timestamp()
self.物品表 = self.加载json(
"./ArknightsGameResource/gamedata/excel/item_table.json"
)
self.干员表 = self.加载json(
"./ArknightsGameResource/gamedata/excel/character_table.json"
)
self.抽卡表 = self.加载json(
"./ArknightsGameResource/gamedata/excel/gacha_table.json"
)
self.关卡表 = self.加载json(
"./ArknightsGameResource/gamedata/excel/stage_table.json"
)
self.活动表 = self.加载json(
"./ArknightsGameResource/gamedata/excel/activity_table.json"
)
self.基建表 = self.加载json(
"./ArknightsGameResource/gamedata/excel/building_data.json"
)
self.游戏变量 = self.加载json(
"./ArknightsGameResource/gamedata/excel/gamedata_const.json"
)
self.装仓库物品的字典 = {"NORMAL": [], "CONSUME": [], "MATERIAL": []}
self.常驻关卡 = self.加载json("arknights_mower/data/stage_data.json")
self.所有buff = []
self.限定十连 = self.抽卡表["limitTenGachaItem"]
self.联动十连 = self.抽卡表["linkageTenGachaItem"]
self.普通十连 = self.抽卡表["normalGachaItem"]
self.所有卡池 = self.限定十连 + self.联动十连 + self.普通十连
def 加载json(self, file_path):
with open(file_path, "r", encoding="utf-8") as f:
return json.load(f)
def 添加物品(self):
def 检查图标代码匹配(目标图标代码, 物品类型):
匹配结果 = False
for 池子限时物品 in self.所有卡池:
if (
池子限时物品["itemId"] == 目标图标代码
and self.当前时间戳 > 池子限时物品["endTime"]
):
匹配结果 = True
break
分割部分 = 目标图标代码.split("_")
if len(分割部分) == 2 and 分割部分[0].endswith("recruitment10"):
匹配结果 = True
if len(分割部分) == 6 and int(分割部分[5]) < 2023:
匹配结果 = True
if len(分割部分) == 3 and 目标图标代码.startswith("uni"):
匹配结果 = True
if len(分割部分) == 3 and 目标图标代码.startswith("voucher_full"):
匹配结果 = True
if 目标图标代码 == "ap_supply_lt_60":
匹配结果 = True
抽卡 = self.抽卡表.get("gachaPoolClient", [])
for 卡池 in 抽卡:
if 卡池["LMTGSID"] == 目标图标代码 and self.当前时间戳 > int(
卡池["endTime"]
):
匹配结果 = True
return 匹配结果
self.物品_名称对 = {}
if not os.path.exists("./ui/public/depot/EXP.webp"):
png_image = Image.open("./ArknightsGameResource/item/EXP_PLAYER.png")
png_image.save("./ui/public/depot/EXP.webp", "WEBP")
for 物品代码, 物品数据 in self.物品表["items"].items():
中文名称 = 物品数据.get("name", "")
图标代码 = 物品数据.get("iconId", "")
排序代码 = 物品数据.get("sortId", "")
分类类型 = 物品数据.get("classifyType", "")
物品类型 = 物品数据.get("itemType", "")
源文件路径 = f"./ArknightsGameResource/item/{图标代码}.png"
排除开关 = False
排除开关 = 检查图标代码匹配(图标代码, 物品类型)
if 分类类型 != "NONE" and 排序代码 > 0 and not 排除开关:
if os.path.exists(源文件路径):
目标文件路径 = f"./ui/public/depot/{中文名称}.webp"
self.装仓库物品的字典[分类类型].append([目标文件路径, 源文件路径])
if not os.path.exists(目标文件路径):
png_image = Image.open(源文件路径)
png_image.save(目标文件路径, "WEBP")
templist = [物品代码, 图标代码, 中文名称, 分类类型, 排序代码]
self.物品_名称对[物品代码] = templist
self.物品_名称对[中文名称] = templist
print(f"复制 {源文件路径} 到 {目标文件路径}")
else:
print(f"可以复制,但是未找到: {源文件路径}")
with open(
"./arknights_mower/data/key_mapping.json", "w", encoding="utf8"
) as json_file:
json.dump(self.物品_名称对, json_file, ensure_ascii=False, indent=4)
print()
def 添加干员(self):
干员_名称列表 = []
干员_职业列表 = {}
for 干员代码, 干员数据 in self.干员表.items():
if not 干员数据["itemObtainApproach"]:
continue
干员名 = 干员数据["name"]
干员_名称列表.append(干员名)
干员_职业列表[干员名] = 干员数据["profession"]
干员头像路径 = f"./ArknightsGameResource/avatar/{干员代码}.png"
目标路径 = f"./ui/public/avatar/{干员数据['name']}.webp"
print(f"{干员名}: {干员代码}")
try:
png_image = Image.open(干员头像路径)
png_image.save(目标路径, "WEBP")
except Exception as ex:
print("头像读取失败")
print(ex)
干员_名称列表.sort(key=len)
with open(
"./arknights_mower/data/agent_profession.json", "w", encoding="utf-8"
) as f:
json.dump(干员_职业列表, f, ensure_ascii=False)
with open("./arknights_mower/data/agent.json", "w", encoding="utf-8") as f:
json.dump(干员_名称列表, f, ensure_ascii=False)
print()
def 读取卡池(self):
抽卡 = self.抽卡表.get("gachaPoolClient", [])
卡池类型映射 = {
"SINGLE": "单人池",
"LIMITED": "限定池",
"NORM": "普通池",
"CLASSIC": "中坚池",
"CLASSIC_ATTAIN": "跨年中坚池",
"LINKAGE": "联动池",
"ATTAIN": "跨年池",
"FESCLASSIC": "中坚甄选",
}
for 项 in 抽卡:
卡池名称 = 项.get("gachaPoolName")
开始时间戳 = 项.get("openTime")
结束时间戳 = 项.get("endTime")
卡池类型代码 = 项.get("gachaPoolId")
卡池出人 = 项.get("dynMeta")
if self.当前时间戳 < 结束时间戳:
卡池类型 = 卡池类型映射.get(卡池类型代码.split("_")[0], 卡池类型代码)
if 卡池类型代码.split("_")[1] == "ATTAIN":
卡池类型 = "跨年中坚池"
if 卡池名称 == "适合多种场合的强力干员":
卡池名称 = 卡池类型
开始时间 = datetime.fromtimestamp(开始时间戳)
结束时间 = datetime.fromtimestamp(结束时间戳 + 1)
print("卡池名称:", 卡池名称)
print("卡池类型:", 卡池类型)
if 卡池类型 == "中坚池":
print(
卡池出人["main6RarityCharId"],
卡池出人["sub6RarityCharId"],
卡池出人["rare5CharList"],
)
if self.当前时间戳 > 开始时间戳:
print("正在进行")
print("卡池结束时间:", 结束时间)
else:
print("卡池开始时间:", 开始时间)
print("卡池结束时间:", 结束时间)
print(卡池类型代码)
print()
def 读取活动关卡(self):
关卡 = self.关卡表["stageValidInfo"]
还未结束的非常驻关卡 = {
键: 值
for 键, 值 in 关卡.items()
if 值["endTs"] != -1 and 值["endTs"] > self.当前时间戳
}
还未结束的非常驻关卡 = dict(sorted(还未结束的非常驻关卡.items()))
for 键, _ in 还未结束的非常驻关卡.items():
关卡代码 = self.关卡表["stages"][键]["code"]
if 键.endswith("#f#"):
关卡代码 += " 突袭"
关卡名称 = self.关卡表["stages"][键]["name"]
关卡结束时间戳 = 还未结束的非常驻关卡[键]["endTs"]
# 关卡结束时间 = datetime.fromtimestamp(还未结束的非常驻关卡[键]["endTs"] + 1)
关卡掉落表 = self.关卡表["stages"][键]["stageDropInfo"][
"displayDetailRewards"
]
关卡掉落 = {}
突袭首次掉落 = [
self.物品表.get("items", {}).get(item["id"], {}).get("name", item["id"])
for item in 关卡掉落表
if item["dropType"] == 1
]
常规掉落 = [
self.物品表.get("items", {}).get(item["id"], {}).get("name", item["id"])
for item in 关卡掉落表
if item["dropType"] == 2
]
特殊掉落 = [
self.物品表.get("items", {}).get(item["id"], {}).get("name", item["id"])
for item in 关卡掉落表
if item["dropType"] == 3
]
额外物资 = [
self.物品表.get("items", {}).get(item["id"], {}).get("name", item["id"])
for item in 关卡掉落表
if item["dropType"] == 4
]
首次掉落 = [
self.物品表.get("items", {}).get(item["id"], {}).get("name", item["id"])
for item in 关卡掉落表
if item["dropType"] == 8
]
关卡掉落 = {
"突袭首次掉落": 突袭首次掉落,
"常规掉落": 常规掉落,
"首次掉落": 首次掉落,
"特殊掉落": 特殊掉落,
"额外物资": 额外物资,
}
self.常驻关卡.append(
{
"id": 关卡代码,
"name": 关卡名称,
"drop": 关卡掉落,
"end": 关卡结束时间戳,
"周一": 1,
"周二": 1,
"周三": 1,
"周四": 1,
"周五": 1,
"周六": 1,
"周日": 1,
}
)
unkey = 0
for item in self.常驻关卡:
item["key"] = unkey
unkey += 1
with open(
"./ui/src/pages/stage_data/event_data.json", "w", encoding="utf-8"
) as f:
json.dump(self.常驻关卡, f, ensure_ascii=False, indent=2)
def load_recruit_data(self):
recruit_data = {}
recruit_result_data = {
4: [],
3: [],
2: [],
1: [],
-1: [],
}
# for 干员代码, 干员数据 in self.干员表.items():
# print(干员代码,干员数据)
recruit_list = self.抽卡表["recruitDetail"].replace("\\n<@rc.eml>", "")
recruit_list = recruit_list.replace("\\n", "")
recruit_list = recruit_list.replace("\r", "")
recruit_list = recruit_list.replace("★", "")
recruit_list = recruit_list.replace("<@rc.eml>", "")
recruit_list = recruit_list.replace("</>", "")
recruit_list = recruit_list.replace("/", "")
recruit_list = recruit_list.replace(" ", "\n")
recruit_list = recruit_list.replace("--------------------", "")
recruit_list = recruit_list.replace("<@rc.title>公开招募说明", "")
recruit_list = recruit_list.replace("<@rc.em>※稀有职业需求招募说明※", "")
recruit_list = recruit_list.replace(
"<@rc.em>当职业需求包含高级资深干员,且招募时限为9小时时,招募必得6星干员",
"",
)
recruit_list = recruit_list.replace(
"<@rc.em>当职业需求包含资深干员同时不包含高级资深干员,且招募时限为9小时,则该次招募必得5星干员",
"",
)
recruit_list = recruit_list.replace("<@rc.subtitle>※全部可能出现的干员※", "")
recruit_list = recruit_list.replace("绿色高亮的不可寻访干员,可以在此招募", "")
recruit_list = recruit_list.split("\n")
profession = {
"MEDIC": "医疗干员",
"WARRIOR": "近卫干员",
"SPECIAL": "特种干员",
"SNIPER": "狙击干员",
"CASTER": "术师干员",
"TANK": "重装干员",
"SUPPORT": "辅助干员",
"PIONEER": "先锋干员",
}
for 干员代码, 干员数据 in self.干员表.items():
干员名 = 干员数据["name"]
if 干员数据["profession"] not in profession:
continue
if 干员名 in recruit_list:
tag = 干员数据["tagList"]
# 数据中稀有度从0-5
干员数据["rarity"] = 干员数据["rarity"] + 1
if len(干员名) <= 4:
recruit_result_data[len(干员名)].append(干员代码)
else:
recruit_result_data[-1].append(干员代码)
if 干员数据["rarity"] == 5:
tag.append("资深干员")
elif 干员数据["rarity"] == 6:
tag.append("高级资深干员")
if 干员数据["position"] == "MELEE":
tag.append("近战位")
elif 干员数据["position"] == "RANGED":
tag.append("远程位")
tag.append(profession[干员数据["profession"]])
recruit_data[干员代码] = {
"name": 干员名,
"stars": 干员数据["rarity"],
"tags": 干员数据["tagList"],
}
print(
"{} stars:{} tags:{}".format(
干员名, 干员数据["rarity"], 干员数据["tagList"]
)
)
print("载入公招干员数据{}个".format(len(recruit_data)))
with open("./arknights_mower/data/recruit.json", "w", encoding="utf-8") as f:
json.dump(recruit_data, f, ensure_ascii=False, indent=4)
with open(
"./arknights_mower/data/recruit_result.json", "w", encoding="utf-8"
) as f:
json.dump(recruit_result_data, f, ensure_ascii=False, indent=4)
def load_recruit_template(self):
# !/usr/bin/env python3
template = {}
with open("./arknights_mower/data/recruit.json", "r", encoding="utf-8") as f:
recruit_operators = json.load(f)
font = ImageFont.truetype("FZDYSK.TTF", 120)
print(len(recruit_operators))
for operator in recruit_operators:
im = Image.new(mode="RGBA", size=(1920, 1080))
draw = ImageDraw.Draw(im)
draw.text((0, 0), recruit_operators[operator]["name"], font=font)
im = im.crop(im.getbbox())
im = cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2GRAY)
template[operator] = im
with lzma.open("arknights_mower/models/recruit_result.pkl", "wb") as f:
pickle.dump(template, f)
def load_recruit_tag(self):
with open("./arknights_mower/data/recruit.json", "r", encoding="utf-8") as f:
recruit_agent = json.load(f)
font = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", 30
)
recruit_tag = ["资深干员", "高级资深干员"]
recruit_tag_template = {}
for x in recruit_agent.values():
recruit_tag += x["tags"]
recruit_tag = list(set(recruit_tag))
for tag in recruit_tag:
im = Image.new(mode="RGBA", color=(49, 49, 49), size=(215, 70))
W, H = im.size
draw = ImageDraw.Draw(im)
_, _, w, h = draw.textbbox((0, 0), tag, font=font)
draw.text(((W - w) / 2, (H - h) / 2 - 5), tag, font=font)
recruit_tag_template[tag] = cv2.cvtColor(
np.array(im.crop(im.getbbox())), cv2.COLOR_RGB2BGR
)
with lzma.open("./arknights_mower/models/recruit.pkl", "wb") as f:
pickle.dump(recruit_tag_template, f)
def load_recruit_resource(self):
self.load_recruit_data()
self.load_recruit_template()
self.load_recruit_tag()
def 训练仓库的knn模型(self, 模板文件夹, 模型保存路径):
def 提取特征点(模板):
模板 = 模板[40:173, 40:173]
hog_features = hog(
模板,
orientations=18,
pixels_per_cell=(8, 8),
cells_per_block=(2, 2),
block_norm="L2-Hys",
transform_sqrt=True,
channel_axis=2,
)
return hog_features
def 加载图片特征点_标签(模板类型):
特征点列表 = []
标签列表 = []
for [目标文件路径, 源文件路径] in self.装仓库物品的字典[模板类型]:
模板 = cv2.imread(源文件路径)
模板 = cv2.resize(模板, (213, 213))
特征点 = 提取特征点(模板)
特征点列表.append(特征点)
标签列表.append(self.物品_名称对[目标文件路径[18:-5]][2])
return 特征点列表, 标签列表
def 训练knn模型(images, labels):
knn_classifier = KNeighborsClassifier(
weights="distance", n_neighbors=1, n_jobs=-1
)
knn_classifier.fit(images, labels)
return knn_classifier
def 保存knn模型(classifier, filename):
with lzma.open(filename, "wb") as f:
pickle.dump(classifier, f)
模板特征点, 模板标签 = 加载图片特征点_标签(模板文件夹)
knn模型 = 训练knn模型(模板特征点, 模板标签)
保存knn模型(knn模型, 模型保存路径)
def 批量训练并保存扫仓库模型(self):
self.训练仓库的knn模型("NORMAL", "./arknights_mower/models/NORMAL.pkl")
self.训练仓库的knn模型("CONSUME", "./arknights_mower/models/CONSUME.pkl")
# self.训练仓库的knn模型("MATERIAL", "./arknights_mower/models/MATERIAL.pkl")
def 训练在房间内的干员名的模型(self):
font = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", 37
)
data = {}
kernel = np.ones((12, 12), np.uint8)
with open("./arknights_mower/data/agent.json", "r", encoding="utf-8") as f:
agent_list = json.load(f)
for operator in sorted(agent_list, key=lambda x: len(x), reverse=True):
img = Image.new(mode="L", size=(400, 100))
draw = ImageDraw.Draw(img)
draw.text((50, 20), operator, fill=(255,), font=font)
img = np.array(img, dtype=np.uint8)
img = thres2(img, 200)
dilation = cv2.dilate(img, kernel, iterations=1)
contours, _ = cv2.findContours(
dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE
)
rect = map(lambda c: cv2.boundingRect(c), contours)
x, y, w, h = sorted(rect, key=lambda c: c[0])[0]
img = img[y : y + h, x : x + w]
tpl = np.zeros((46, 265), dtype=np.uint8)
tpl[: img.shape[0], : img.shape[1]] = img
# cv2.imwrite(f"/home/zhao/Desktop/data/{operator}.png", tpl)
data[operator] = tpl
with lzma.open("arknights_mower/models/operator_room.model", "wb") as f:
pickle.dump(data, f)
def 训练选中的干员名的模型(self):
font31 = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", 31
)
font30 = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", 30
)
font25 = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", 25
)
font27 = ImageFont.truetype(
"arknights_mower/fonts/SourceHanSansCN-Medium.otf", 27
)
data = {}
kernel = np.ones((10, 10), np.uint8)
with open("./arknights_mower/data/agent.json", "r", encoding="utf-8") as f:
agent_list = json.load(f)
for idx, operator in enumerate(agent_list):
font = font31
if not operator[0].encode().isalpha():
if len(operator) == 7:
if "·" in operator:
# 维娜·维多利亚 识别的临时解决办法
font = font27
else:
font = font25
elif len(operator) == 6:
font = font30
img = Image.new(mode="L", size=(400, 100))
draw = ImageDraw.Draw(img)
if "·" in operator:
x, y = 50, 20
char_index = {
i: False for i, char in enumerate(operator) if char == "·"
}
for i, char in enumerate(operator):
if i in char_index and not char_index[i]:
x -= 8
char_index[i] = True
if i + 1 not in char_index and char == "·":
char_index[i + 1] = False
draw.text((x, y), char, fill=(255,), font=font) # 绘制每个字符
char_width, char_height = font.getbbox(char)[
2:4
] # getbbox 返回 (x1, y1, x2, y2)
x += char_width
else:
draw.text((50, 20), operator, fill=(255,), font=font)
img = np.array(img, dtype=np.uint8)
img = thres2(img, 140)
dilation = cv2.dilate(img, kernel, iterations=1)
contours, _ = cv2.findContours(
dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE
)
rect = map(lambda c: cv2.boundingRect(c), contours)
x, y, w, h = sorted(rect, key=lambda c: c[0])[0]
img = img[y : y + h, x : x + w]
tpl = np.zeros((42, 200), dtype=np.uint8)
tpl[: img.shape[0], : img.shape[1]] = img
# cv2.imwrite(f"/home/zhao/Desktop/data/{operator}.png", tpl)
data[operator] = tpl
with lzma.open("arknights_mower/models/operator_select.model", "wb") as f:
pickle.dump(data, f)
def auto_fight_avatar(self):
avatar_mapping = {} # char_285_medic2 -> Lancet-2
for name, data in self.干员表.items():
avatar_mapping[name] = data["name"]
avatar = {} # Lancet-2 -> List[avatar image]
avatar_path = "./ArknightsGameResource/avatar"
for i in os.listdir(avatar_path):
# i: char_285_medic2.png
for j, k in avatar_mapping.items():
# j: char_285_medic2
# k: Lancet-2
if i.startswith(j):
img = loadimg(os.path.join(avatar_path, i), True)
img = cv2.resize(img, None, None, 0.5, 0.5)
if k not in avatar:
avatar[k] = []
avatar[k].append(img)
break
with lzma.open("./arknights_mower/models/avatar.pkl", "wb") as f:
pickle.dump(avatar, f)
def 获得干员基建描述(self):
buff描述 = self.基建表["buffs"]
buff_table = {}
for buff名称, 相关buff in buff描述.items():
buff_table[buff名称] = [
相关buff["buffName"],
相关buff["description"],
相关buff["roomType"],
相关buff["buffCategory"],
相关buff["skillIcon"],
相关buff["buffColor"],
相关buff["textColor"],
]
干员技能列表 = []
name_key = 0
for 角色id, 相关buff in self.基建表["chars"].items():
干员技能字典 = {
"key": 0,
"name": "",
"span": 0,
"child_skill": [],
}
干员技能字典["name"] = self.干员表[角色id]["name"]
skill_key = 0
name_key += 1
干员技能字典["key"] = name_key
for item in 相关buff["buffChar"]:
skill_level = 0
if item["buffData"] != []:
for item2 in item["buffData"]:
干员技能详情 = {}
干员技能详情["skill_key"] = skill_key
干员技能详情["skill_level"] = skill_level
skill_level += 1
干员技能详情["phase_level"] = (
f'精{item2["cond"]["phase"]} {item2["cond"]["level"]}级'
)
干员技能详情["skillname"] = buff_table[item2["buffId"]][0]
text = buff_table[item2["buffId"]][1]
pattern = r"<\$(.*?)>"
matches = re.findall(pattern, text)
ex_string = []
干员技能详情["buffer"] = False
干员技能详情["buffer_des"] = []
if matches:
干员技能详情["buffer"] = True
ex_string = list(
set([match.replace(".", "_") for match in matches])
)
ex_string.sort()
干员技能详情["buffer_des"] = ex_string
self.所有buff.extend(ex_string)
干员技能详情["des"] = text
干员技能详情["roomType"] = roomType[
buff_table[item2["buffId"]][2]
]
干员技能详情["buffCategory"] = buff_table[item2["buffId"]][3]
干员技能详情["skillIcon"] = buff_table[item2["buffId"]][4]
干员技能详情["buffColor"] = buff_table[item2["buffId"]][5]
干员技能详情["textColor"] = buff_table[item2["buffId"]][6]
干员技能字典["child_skill"].append(干员技能详情)
干员技能详情 = []
干员技能字典["span"] = len(干员技能字典["child_skill"])
skill_key += 1
干员技能列表.append(干员技能字典.copy())
干员技能列表 = sorted(干员技能列表, key=lambda x: (-x["key"]))
# print(干员技能列表)
with open(
"./ui/src/pages/basement_skill/skill.json", "w", encoding="utf-8"
) as f:
json.dump(干员技能列表, f, ensure_ascii=False, indent=2)
def buff转换(self):
buff_table = {}
pattern = r"<\$(.*?)>"
for item in self.游戏变量["termDescriptionDict"]:
matches = re.findall(
pattern, self.游戏变量["termDescriptionDict"][item]["description"]
)
matches = [match.replace(".", "_") for match in matches]
dict1 = self.游戏变量["termDescriptionDict"][item]
dict1["buffer"] = []
if item.startswith("cc") and matches:
dict1["buffer"] = matches
buff_table[item.replace(".", "_")] = dict1
with open(
"./ui/src/pages/basement_skill/buffer.json", "w", encoding="utf-8"
) as f:
json.dump(buff_table, f, ensure_ascii=False, indent=2)
def 添加基建技能图标(self):
# 源目录和目标目录
source_dir = "./ArknightsGameResource/building_skill"
destination_dir = "./ui/public/building_skill"
# 创建目标目录(如果不存在)
os.makedirs(destination_dir, exist_ok=True)
# 遍历源目录中的所有文件
for root, dirs, files in os.walk(source_dir):
for file in files:
if file.endswith(".png"):
src_file_path = os.path.join(root, file)
# 修改文件扩展名为 .webp
dest_file_name = os.path.splitext(file)[0] + ".webp"
dest_file_path = os.path.join(destination_dir, dest_file_name)
if not os.path.exists(dest_file_path):
with Image.open(src_file_path) as img:
img.save(dest_file_path, "webp")
print(f"转换: {src_file_path} 到 {dest_file_path}")
else:
print(f"跳过: {dest_file_path} 已存在")
roomType = {
"POWER": "发电站",
"DORMITORY": "宿舍",
"MANUFACTURE": "制造站",
"MEETING": "会客室",
"WORKSHOP": "加工站",
"TRADING": "贸易站",
"HIRE": "人力办公室",
"TRAINING": "训练室",
"CONTROL": "中枢",
}
数据处理器 = Arknights数据处理器()
数据处理器.添加物品() # 显示在仓库里的物品
数据处理器.添加干员()
数据处理器.读取卡池()
数据处理器.读取活动关卡()
# 和 数据处理器.添加物品() 有联动 , 添加物品提供了分类的图片位置
数据处理器.批量训练并保存扫仓库模型()
print("批量训练并保存扫仓库模型,完成")
数据处理器.训练在房间内的干员名的模型()
print("训练在房间内的干员名的模型,完成")
数据处理器.训练选中的干员名的模型()
print("训练选中的干员名的模型,完成")
数据处理器.auto_fight_avatar()
数据处理器.获得干员基建描述()
数据处理器.buff转换() # 所有buff描述,包括其他buff
数据处理器.添加基建技能图标()
数据处理器.load_recruit_resource()