-
Notifications
You must be signed in to change notification settings - Fork 121
/
DataCenter.py
1281 lines (1196 loc) · 47.8 KB
/
DataCenter.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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import base64
import datetime
import gzip
import json
import os
import pickle
import time
from collections import defaultdict
from io import BytesIO
from typing import Optional, TYPE_CHECKING
from difflib import get_close_matches
from rich.table import Table as RTable
from core.constant import USER_DEFAULT_DICT as UDD, MAX_MAP
from core.usercentre import AutomatorRecorder
from core.utils import get_time_str, WowSearch
if TYPE_CHECKING:
from pcrdata.pcrdata import PCRData
from core.utils import WowSearch
import rich.box as rbox
import openpyxl
from core.richutils import RText, ROrderGrid, ROneTable, RValue, RComment, RLRProgress
JSNameWow: Optional[WowSearch] = None
ZBNameWow: Optional[WowSearch] = None
def refresh_track_max(v):
global data
if "track_max" in v and v["track_max"] is True:
A, B = data.get_max_track()
if B == 3:
track_zb = [False, True, False, True, False, True]
elif B == 4:
track_zb = [False, True, False, True, True, True]
elif B == 5:
track_zb = [False, True, True, True, True, True]
else:
raise ValueError(f"Max track is {A}-{B}???")
v["track_zb"] = track_zb
v["track_rank"] = A
v["track"] = f"{A}.{B}"
def LoadPCRData() -> "PCRData":
global data, JSNameWow, ZBNameWow
if not os.path.isdir("pcrdata"):
os.makedirs("pcrdata")
if not os.path.exists("pcrdata/data.dat"):
return None
try:
with open("pcrdata/data.dat", "rb") as db_file:
data = pickle.load(db_file)
try:
JSNameWow = WowSearch(data.C_ID)
JSNameWow.parse()
except Exception as e:
print("角色搜索模块加载失败!", e)
JSNameWow = None
try:
ZBNameWow = WowSearch(data.EQU_ID)
ZBNameWow.parse()
except Exception as e:
print("角色搜索模块加载失败!", e)
ZBNameWow = None
return data
except Exception as e:
print("读取数据发生错误!", e)
return None
def UpdateData():
global data
if not os.path.isdir("pcrdata"):
os.makedirs("pcrdata")
try:
import pcrdata.pcrdata as pcrdata
pcrdata.update()
data = pcrdata.PCRData()
pickle.dump(data, open("pcrdata/data.dat", "wb"))
return data
except Exception as e:
print("更新数据发生错误:", e)
return None
last_account = ""
AR: Optional[AutomatorRecorder] = None
def GetLastAccount():
global last_account, AR
if not os.path.exists("bind_account.txt"):
last_account = ""
AR = None
return
with open("bind_account.txt", "r", encoding="utf-8") as f:
lines = f.readlines()
if len(lines) > 0:
last_account = lines[0]
AR = AutomatorRecorder(last_account)
def UnBind():
global last_account, AR
last_account = ""
AR = None
with open("bind_account.txt", "w", encoding="utf-8") as f:
f.write("")
def BindAccount(account):
global last_account, AR
if account != "":
last_account = account
AR = AutomatorRecorder(account)
with open("bind_account.txt", "w", encoding="utf-8") as f:
f.write(account)
print("account绑定成功:", account)
def MH_ZB(name, args):
t = float(get_arg(args, "t", "0.6"))
lst = list(data.EQU_ID.keys())
words = get_close_matches(name, lst, 1, t)
print("阈值:", t, "模糊查询结果:", words)
def ZB_KC_FIX():
# 修复装备库存
global AR
kc = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
bad_k = []
for k in kc:
if k not in data.EQU_ID:
bad_k += [k]
if len(bad_k) == 0:
print("装备库存无需修复。")
return
print("检测到有", len(bad_k), "个条目需要修复:")
print("装备 库存 修复 ----------------------")
print("接下来每行会输出一个名称不符的条目,并给出它的最近更新时间。")
print("请输入它的正确名称,则该条目将会被替换为此名称。")
print("若存在较新条目已经存在该名称,则此项会被舍弃。")
print("若存在较旧条目已经存在该名称,此项将替换之。")
print("输入 0 表示舍弃该项。")
print("您可以在/ocrfix文件夹中找到出错的条目的截图以便于识别。")
print("您可以手动把错误截图的文件名改为正确的名称,则下次再次识别出错时会自动修复。")
total = len(bad_k)
for ind, k in enumerate(bad_k):
while True:
v = kc[k]
num, tim, bz = v
print("[", ind + 1, "/", total, "] 上次更新:", get_time_str(tim), "数量", num, "备注", bz)
new_k = input(f"{k} -> ")
if new_k == "0":
del kc[k]
AR.set("zhuangbei_kucun", kc)
break
elif new_k not in data.EQU_ID:
print("该名称不存在!")
elif new_k in kc:
if kc[new_k][1] > tim:
print("存在较新记录,此项作废。")
else:
print("存在较旧记录,此项替换。")
kc[new_k] = kc.pop(k)
AR.set("zhuangbei_kucun", kc)
break
else:
kc[new_k] = kc.pop(k)
AR.set("zhuangbei_kucun", kc)
break
print("修复已完成!")
def JS_FIX():
# 修复角色信息
global AR
kc = AR.get("juese_info", UDD["juese_info"])
bad_k = []
for k in kc:
if k not in data.C_ID:
bad_k += [k]
if len(bad_k) == 0:
print("角色名称无需修复。")
return
print("检测到有", len(bad_k), "个条目需要修复:")
print("角色 修复 ---------------------------")
print("接下来每行会输出一个名称不符的条目,并给出它的最近更新时间。")
print("请输入它的正确名称,则该条目将会被替换为此名称。")
print("若存在较新条目已经存在该名称,则此项会被舍弃。")
print("若存在较旧条目已经存在该名称,此项将替换之。")
print("输入 0 表示舍弃该项。")
print("您可以在/ocrfix文件夹中找到出错的条目的截图以便于识别。")
print("您可以手动把错误截图的文件名改为正确的名称,则下次再次识别出错时会自动修复。")
total = len(bad_k)
for ind, k in enumerate(bad_k):
while True:
v = kc[k]
print("[", ind + 1, "/", total, "] 上次更新:", get_time_str(v['last_update']))
new_k = input(f"{k} -> ")
if new_k == "0":
del kc[k]
AR.set("juese_info", kc)
break
elif new_k not in data.C_ID:
print("该名称不存在!")
elif new_k in kc:
if kc[new_k]['last_update'] > v['last_update']:
print("存在较新记录,此项作废。")
else:
print("存在较旧记录,此项替换。")
kc[new_k] = kc.pop(k)
AR.set("juese_info", kc)
break
else:
kc[new_k] = kc.pop(k)
AR.set("juese_info", kc)
break
print("修复已完成!")
def ToLibrary():
# 角色
from functools import reduce
List1 = []
js = AR.get("juese_info", UDD["juese_info"])
for j, v in js.items():
if j not in data.C_ID:
continue
cur = {}
# e: equip 000000
cur['e'] = reduce(lambda x, y: x + str(int(y)), v['zb'], "")
# p: Rank
cur['p'] = int(v["rank"])
# r: Star
cur['r'] = int(v["star"])
# u: id
cur['u'] = hex(data.C_ID[j] // 100)[2:]
# t: track
cur['t'] = v.get("track", False)
# q: special
cur['q'] = v.get("special", "")
List1 += [cur]
List2 = []
# zb
zb = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
for z, v in zb.items():
if z not in data.EQU_ID:
continue
cur = {}
# c: num
num, _, _ = v
cur['c'] = str(num)
# e: id
cur['e'] = hex(data.EQU_ID[z])[2:]
# a: hide
cur['a'] = '1'
List2 += [cur]
print("CODE------------------------------")
print(base64.b64encode(gzip.compress(bytes(json.dumps([List1, List2]), encoding='utf-8'))).decode("utf-8"))
print("----------------------------------")
print("https://pcredivewiki.tw/Armory")
def FromLibrary(all=False):
code = input("请粘贴Code: ")
output = json.load(BytesIO(gzip.decompress(base64.b64decode(code))))
js_info = output[0]
zb_info = output[1]
# js
js = AR.get("juese_info", UDD["juese_info"])
for cur in js_info:
uid = int(cur['u'], 16) * 100 + 1
key = data.ID_C[uid]
js.setdefault(key, {})
if all:
equ = [i == '1' for i in cur['e']]
rank = cur['p']
star = cur['r']
js[key]['zb'] = equ
js[key]['rank'] = rank
js[key]['star'] = star
track = cur['t']
if track.isnumeric() and float(track) > 30:
print("出现奇怪现象:你的", key, "的Track是不是", track, "?")
js[key]['track'] = track
if track not in ["false", "true", False, True]:
if '.' in track:
A, B = track.split(".")
A = int(A)
B = int(B)
ZBLABLE = {
3: [False, True, False, True, False, True],
4: [False, True, False, True, True, True],
5: [False, True, True, True, True, True]
}
js[key]['track_rank'] = A
js[key]['track_zb'] = ZBLABLE[B]
else:
A = int(track)
js[key]["track_rank"] = A
js[key]["track_zb"] = [True] * 6
elif track in ['false', False]:
if "track_rank" in js[key]:
del js[key]["track_rank"]
if "track_zb" in js[key]:
del js[key]["track_zb"]
special = cur['q']
js[key]['special'] = special
AR.set("juese_info", js)
# zb
zb = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
if all:
for cur in zb_info:
eid = int(cur['e'], 16)
if eid in data.ID_EQU:
key = data.ID_EQU[eid]
else:
continue
comment = "From Lib"
update_time = time.time()
try:
num = int(cur['c'])
except:
num = int(cur['c'], 16)
print("出现奇妙的现象:你的装备", data.ID_EQU[eid], "数量是不是", num, '个?')
zb[key] = (num, update_time, comment)
AR.set("zhuangbei_kucun", zb)
def SearchJSName(name: str) -> int:
global JSNameWow
if name.isnumeric():
n = int(name)
if n in data.ID_C:
return n
elif n * 100 + 1 in data.ID_C:
return n * 100 + 1
elif (n // 100) * 100 + 1 in data.ID_C:
return (n // 100) * 100 + 1
else:
return -1
if name in data.C_ID:
return data.C_ID[name]
else:
if JSNameWow is None:
return -1
else:
name = JSNameWow.get_all_by_tree(name)
if len(name) == 0:
return -1
elif name[0] in data.C_ID:
return data.C_ID[name[0]]
else:
return -1
def JS_SHOW(name):
ID = SearchJSName(name)
if ID == -1:
print("找不到该角色!")
return
obj = AR.get("juese_info", UDD["juese_info"])
name = data.ID_C[ID]
print("角色信息:", name, " 角色ID:", ID // 100)
if name in obj:
v = obj[name]
refresh_track_max(v)
if 'star' in v:
print("星:", *['★'] * v['star'])
if 'dengji' in v:
print("等级:", v['dengji'])
CELL = {}
# (0,0) - (0,1)
CELL[(0, 0)] = 'R'
if 'rank' in v:
CELL[(0, 1)] = str(v['rank'])
else:
CELL[(0, 1)] = "?"
# (1,0) - (3,1)
if 'zb' not in v:
for i in range(6):
CELL[(1 + i // 2, i % 2)] = "?"
else:
for i in range(6):
CELL[(1 + i // 2, i % 2)] = '■' if v['zb'][i] else '□'
CELL[(1, 2)] = "-->"
# (0,3) - (3,4)
if 'track_rank' in v and 'track_zb' in v:
flag = True
CELL[(0, 3)] = 'R'
if "track_max" in v and v["track_max"] is True:
CELL[(0, 4)] = str(v['track_rank']) + " (MAX)"
else:
CELL[(0, 4)] = str(v['track_rank'])
for i in range(6):
CELL[(1 + i // 2, i % 2 + 3)] = '■' if v['track_zb'][i] else '□'
else:
flag = False
if flag:
max_c = 4
else:
max_c = 1
max_r = 3
for r in range(max_r + 1):
for c in range(max_c + 1):
if (r, c) in CELL:
print(CELL[(r, c)], end='\t')
else:
print(end='\t')
print()
if 'haogan' in v:
print("好感:", v['haogan'])
if 'special' in v:
print("专武:", v["special"])
else:
print("你并没有这个角色!")
def ParseZBStr(zb_str):
for z in zb_str:
assert z in ['0', '1'], "装备字符串一定为0或1!"
assert len(zb_str) == 6
return [z == '1' for z in zb_str]
def JS_TRACK(name, rank=0, zb_str="", track_str=None):
# rank=-1: 不跟踪
# track_str is not None
ID = SearchJSName(name)
if ID == -1:
print("找不到该角色!")
return
name = data.ID_C[ID]
obj = AR.get("juese_info", UDD["juese_info"])
if name not in obj:
print("你并没有获得这个角色。")
return
if rank == -1:
obj[name]["track_max"] = False
obj[name]["track"] = False
if "track_rank" in obj[name]:
del obj[name]["track_rank"]
if "track_zb" in obj[name]:
del obj[name]["track_zb"]
AR.set("juese_info", obj)
JS_SHOW(name)
return
if track_str == "max":
obj[name]["track_max"] = True
refresh_track_max(obj[name])
else:
obj[name]["track_max"] = False
if track_str is not None:
if '.' not in track_str:
A = int(track_str)
rank = A
zb_str = "111111"
else:
A, B = track_str.split('.')
A = int(A)
B = int(B)
rank = A
if B == 3:
zb_str = '010101'
elif B == 4:
zb_str = '010111'
elif B == 5:
zb_str = '011111'
elif B == 6:
zb_str = '111111'
track_str = track_str.rstrip(".6")
elif B == 0:
zb_str = '000000'
track_str = track_str.rstrip(".0")
else:
raise Exception("错误的lib_track_str!")
obj[name]["track"] = track_str
obj[name]["track_rank"] = int(rank)
obj[name]["track_zb"] = ParseZBStr(zb_str)
AR.set("juese_info", obj)
JS_SHOW(name)
def has_arg(args, key):
for k in args:
if k == key:
return True
return False
def get_arg(args, key, default):
for k in args:
if k.startswith(key):
return k[k.find("=") + 1:]
return default
def JS_TRACKINFO():
from rich import print
obj = AR.get("juese_info", UDD["juese_info"])
zb = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
store = {}
for k, v in zb.items():
num, _, _ = v
if k in data.EQU_ID:
store[data.EQU_ID[k]] = num
table = RTable(title="练度追踪", caption="*当前可满:以目前的库存最高能满装Rank。\n"
"*下一RANK:要在下一RANK上满装还需要的碎片。", caption_justify="left")
table.add_column("角色", justify='center')
table.add_column("进度", justify='center')
table.add_column("当前可满", justify='center')
table.add_column("下一RANK", justify='center')
for k, v in obj.items():
refresh_track_max(v)
if not ('track_rank' in v and 'track_zb' in v and 'zb' in v and 'rank' in v):
continue
if k not in data.C_ID:
continue
cid = data.C_ID[k]
need_equip_before = data.calc_rankup_equip(cid, v['rank'], [False] * 6, v['track_rank'], v['track_zb'])
if need_equip_before == "FUCK":
print(f"找不到 {k}(ID:{data.C_ID[k]}) 的装备数据,这也太抽象了吧!暂时跳过吧……")
continue
before_store = data.calc_equips_decompose(need_equip_before)
need_equip_after = data.calc_rankup_equip(cid, v['rank'], v['zb'], v['track_rank'], v['track_zb'])
after_store = data.calc_equips_decompose(need_equip_after, store=store)
before_sum = sum(before_store.values())
after_sum = sum(after_store.values())
if before_sum == 0:
continue
if v['track_rank'] == v['rank']:
fg = True
for t1, t2 in zip(v['track_zb'], v['zb']):
if t1 and (not t2):
fg = False
break
if fg:
continue
cur_rank = v['rank']
cur_after_sum = 0
while cur_rank <= v['track_rank']:
cur_zb = [True] * 6 if cur_rank < v['track_rank'] else v['track_zb']
cur_need = data.calc_rankup_equip(cid, v['rank'], v['zb'], cur_rank, cur_zb)
cur_after = data.calc_equips_decompose(cur_need, store=store)
cur_after_sum = sum(cur_after.values())
if cur_after_sum > 0:
break
cur_rank += 1
R = []
R += [k]
OG = ROrderGrid(2)
OG.add(RLRProgress(before_sum - after_sum, before_sum, RValue("R%2d" % v['rank']),
RValue("R%2d" % v['track_rank']), width=20, percent=False))
OG.add(RComment(''.join(['O' if p else '_' for p in v['track_zb']])))
OG.finish()
R += [OG]
cur_rank -= 1
R += ["Rank " + str(cur_rank)]
R += ["x" + str(cur_after_sum)]
table.add_row(*R)
print(table)
def JS_SET(name, item, value):
ID = SearchJSName(name)
if ID == -1:
print("找不到该角色!")
return
name = data.ID_C[ID]
obj = AR.get("juese_info", UDD["juese_info"])
if name not in obj:
print("你并没有获得这个角色。")
return
obj[name][item] = value
obj[name]["last_update"] = time.time()
AR.set("juese_info", obj)
JS_SHOW(name)
def JS_NEW(name):
ID = SearchJSName(name)
if ID == -1:
print("找不到该角色!")
return
name = data.ID_C[ID]
obj = AR.get("juese_info", UDD["juese_info"])
if name in obj:
print("你已经获得了该角色!")
return
obj[name] = {
"dengji": 1,
"rank": 1,
"haogan": 1,
"zb": [False] * 6,
"star": 1,
"last_update": time.time(),
}
AR.set("juese_info", obj)
JS_SHOW(name)
def JS_DEL(name):
ID = SearchJSName(name)
if ID == -1:
print("找不到该角色!")
return
name = data.ID_C[ID]
obj = AR.get("juese_info", UDD["juese_info"])
if name not in obj:
print("你并没有该角色!")
return
del obj[name]
AR.set("juese_info", obj)
def ZB_ST_LACK(args):
from rich import print
need_equip = {}
juese = AR.get("juese_info", UDD["juese_info"])
for k, v in juese.items():
if k in data.C_ID and "track_rank" in v and "track_zb" in v \
and "rank" in v and "zb" in v:
refresh_track_max(v)
ne = data.calc_rankup_equip(data.C_ID[k], v["rank"], v["zb"], v["track_rank"], v["track_zb"])
if ne == "FUCK":
print(f"找不到 {k}(ID:{data.C_ID[k]}) 的装备数据,这也太抽象了吧!暂时跳过吧……")
continue
data.dict_plus(need_equip, ne, False)
if has_arg(args, "--item"):
lack = need_equip
else:
if not has_arg(args, "--no-store"):
store = {}
zb = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
for k, v in zb.items():
num, _, _ = v
if k in data.EQU_ID:
store[data.EQU_ID[k]] = num
store = data.calc_equips_decompose(store)
# print("STORE:")
# for k,v in store.items():
# print(data.get_name(k),":",v)
need_equip = data.calc_equips_decompose(need_equip)
# print("NEED_EQUIP:")
# for k,v in need_equip.items():
# print(data.get_name(k),":",v)
lack = data.calc_equips_decompose(need_equip, store)
else:
lack = data.calc_equips_decompose(need_equip)
show = defaultdict(list)
for equ in lack:
show[data.EInfo[equ]['plevel']] += [equ]
LABEL = {
1: '铁',
2: '铜',
3: '银',
4: '金',
5: '紫',
6: '红',
7: '绿',
}
min_rare = int(get_arg(args, "--min-rare", "0"))
max_rare = int(get_arg(args, "--max-rare", "7"))
max_tu = get_arg(args, "--max-tu", None)
if max_tu is not None:
max_tu = int(max_tu)
normal = data.make_normal_map_prob(max_tu)
for k in sorted(show, reverse=True):
if k < min_rare or k > max_rare:
continue
table = RTable(title="稀有度:" + LABEL[k], show_lines=True, box=rbox.HEAVY_EDGE)
table.add_column("装备", justify="center")
table.add_column("缺失", justify="center")
if has_arg(args, "--normal"):
table.add_column("刷取区域", justify="center")
for equ in show[k]:
row = [data.ID_EQU[equ], f"x{lack[equ]}"]
if has_arg(args, "--normal"):
if equ not in normal:
row += ['']
else:
RR = ROrderGrid(8)
lst = normal[equ]
for prob, (A, B) in lst:
RR.add(ROneTable(f"{A}-{B}", f"{prob}%"))
RR.finish()
row += [RR]
table.add_row(*row)
print(table)
def ZB_ST_ADVICE(args, verbose=True):
from rich import print
max_tu = get_arg(args, "--max-tu", None)
if max_tu is not None:
max_tu = int(max_tu)
else:
max_tu = MAX_MAP
min_rare = int(get_arg(args, "--min-rare", "0"))
max_rare = int(get_arg(args, "--max-rare", "7"))
num_w = float(get_arg(args, "--num-w", "0.1"))
need_equip = {}
js_need = {}
zb_js = {}
juese = AR.get("juese_info", UDD["juese_info"])
for k, v in juese.items():
if k in data.C_ID and "track_rank" in v and "track_zb" in v \
and "rank" in v and "zb" in v:
refresh_track_max(v)
ne = data.calc_rankup_equip(data.C_ID[k], v["rank"], v["zb"], v["track_rank"], v["track_zb"])
if ne == "FUCK":
print(f"找不到 {k}(ID:{data.C_ID[k]}) 的装备数据,这也太抽象了吧!暂时跳过吧……")
continue
# for n in list(ne.keys()):
# lv = data.EInfo[n]['plevel']
# if lv < min_rare or lv > max_rare:
# ne.pop(n)
ne2 = data.calc_equips_decompose(ne)
for n in ne2:
js_need.setdefault(k, {})
js_need[k].setdefault(n, 0)
js_need[k][n] += ne2[n]
zb_js.setdefault(n, {})
zb_js[n].setdefault(k, 0)
zb_js[n][k] += ne2[n]
data.dict_plus(need_equip, ne, False)
store = {}
if not has_arg(args, "--no-store"):
zb = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
for k, v in zb.items():
num, _, _ = v
if k in data.EQU_ID:
store[data.EQU_ID[k]] = num
store = data.calc_equips_decompose(store)
need_equip = data.calc_equips_decompose(need_equip)
lack = data.calc_equips_decompose(need_equip, store)
else:
lack = data.calc_equips_decompose(need_equip)
# Do Rare Filter
new_lack = {}
for k, v in lack.items():
plevel = data.EInfo[k]["plevel"]
if min_rare <= plevel <= max_rare:
new_lack[k] = v
lack = new_lack
prob_map = data.make_normal_map_prob(max_tu)
map_js = {}
for k, v in zb_js.items():
if k not in prob_map:
continue
m = prob_map[k]
for _, (A, B) in m:
mid = f"{A}-{B}"
map_js.setdefault(mid, {})
data.dict_plus(map_js[mid], v, False)
out_map = None
try:
out_map, result_int = data.make_map_advice(lack, prob_map, num_w)
except Exception as e:
print(e)
if num_w > 0:
print("可能是混合整数搜索失败!你可能需要安装cvxopt依赖")
out_map, result_int = data.make_map_advice(lack, prob_map, 0)
mul = int(get_arg(args, "--n", "1"))
if mul > 1:
result_int = 0
keys = list(out_map.keys())
for i in keys:
out_map[i] = int(round(out_map[i] / mul))
if out_map[i] == 0:
out_map.pop(i)
continue
result_int += out_map[i]
out_sorted = sorted(out_map, reverse=True, key=lambda x: out_map[x])
if not verbose:
return out_sorted, out_map
table = RTable(title="刷取建议",
caption=RText("倍率:") + RValue("【", mul, "】") + RText(' 总次数:') + RValue(int(result_int)),
box=rbox.HEAVY_EDGE, show_lines=True)
js_flag = has_arg(args, "--js")
zb_flag = has_arg(args, "--zb")
store_flag = has_arg(args, "--no-store")
table.add_column("图号", justify="center")
table.add_column("次数", justify="center")
if js_flag or zb_flag:
table.add_column("详细信息", justify="center")
for out in out_sorted:
row = []
row += [out]
row += [f"x{out_map[out]}"]
if zb_flag:
RR = ROrderGrid(4)
A, B = out.split('-')
A = int(A)
B = int(B)
rew = data.calc_normal_reward(A, B)
for r in rew:
if r["rid"] in lack:
col = []
col += [data.ID_EQU[r['rid']]]
col += [RValue(f"x{lack[r['rid']]}")]
if not store_flag:
col[-1] += f"\t库存:{store.get(r['rid'], 0)}"
col += ["----------"]
sss = []
if js_flag:
sss += []
cur = zb_js[r['rid']]
for nam in sorted(cur, reverse=True, key=lambda x: cur[x]):
sss += ["%s x%d" % (nam, cur[nam])]
col += ['\n'.join(sss)]
ROT = ROneTable(*col)
RR.add(ROT)
RR.finish()
row += [RR]
elif js_flag:
cur = map_js[out]
cur_sort = sorted(cur, reverse=True, key=lambda x: cur[x])
sss = []
for p in cur_sort:
sss += ["%s x%d" % (p, cur[p])]
row += ["\n".join(sss)]
table.add_row(*row)
print(table)
def XLS_OUTPUT():
global last_account, AR
wb = openpyxl.load_workbook("pcrdata/sample_xlsx.xlsx")
os.makedirs("xls", exist_ok=True)
dest_filename = f"xls/{last_account}.xlsx"
ws1 = wb.worksheets[0]
juese = AR.get("juese_info", UDD["juese_info"])
data = LoadPCRData()
for nam, info in juese.items():
refresh_track_max(info)
row = []
if nam not in data.C_ID:
_id = -1
print("存在未知角色:", nam, "你可能需要进行js fix!")
else:
_id = data.get_id(nam)
position = data.get_position(_id)
distance = data.CInfo[_id]["search_area_width"]
row.append(data.get_id(nam)) # ID
row.append(nam) # Name
if "track_rank" in info and "track_zb" in info:
_track_zb = info["track_zb"]
_track_rank = info["track_rank"]
zb_str = "".join([str(int(z)) for z in _track_zb])
if zb_str == "010101":
track = f"{_track_rank}.3"
elif zb_str == "010111":
track = f"{_track_rank}.4"
elif zb_str == "011111":
track = f"{_track_rank}.5"
elif zb_str == "111111":
track = f"{_track_rank}"
else:
track = ""
if "track_max" in info and info["track_max"] == "max":
row.append("max")
else:
row.append(track)
else:
row.append("")
if position == "front":
row.append("前卫")
elif position == "middle":
row.append("中卫")
else:
row.append("后卫")
row.append(distance)
row.append(info['dengji'])
row.append(info['haogan'])
row.append(info['star'])
row.append(info['rank'])
for zb in info['zb']:
row.append(int(zb))
if "track_rank" in info:
row.append(info["track_rank"])
else:
row.append("")
if "track_zb" in info:
for zb in info["track_zb"]:
row.append(int(zb))
else:
for _ in range(6):
row.append("")
row.append(datetime.datetime.fromtimestamp(info["last_update"]).strftime("%Y/%m/%d %H:%M:%S"))
ws1.append(row)
ws2 = wb.worksheets[1]
kc = AR.get("zhuangbei_kucun", UDD["zhuangbei_kucun"])
for nam, info in kc.items():
if nam in data.EQU_ID:
_id = data.get_id(nam)
else:
_id = -1
print("存在未知装备:", nam, "你可能需要进行zb kc fix!")
row = []
row.append(_id)
row.append(nam)
row.append(info[0]) # num
row.append(datetime.datetime.fromtimestamp(info[1]).strftime("%Y/%m/%d %H:%M:%S"))
row.append(info[2]) # 备注
ws2.append(row)
wb.save(dest_filename)
wb.close()
print("已经保存到:", dest_filename, "中!")
def XLS_INPUT(_all=False):
global last_account, AR
dest_filename = f"xls/{last_account}.xlsx"
print("正在读取:", dest_filename)
wb = openpyxl.load_workbook(dest_filename)
ws1 = wb.worksheets[0]
juese = AR.get("juese_info", UDD["juese_info"])
data = LoadPCRData()
for r in range(3, ws1.max_row + 1):
_id = int(ws1.cell(r, 1).value)
_nam = str(ws1.cell(r, 2).value)
_track_str = ws1.cell(r, 3).value
_lv = int(ws1.cell(r, 6).value)
_haogan = int(ws1.cell(r, 7).value)
_star = int(ws1.cell(r, 8).value)
_rank = int(ws1.cell(r, 9).value)
_zb = [ws1.cell(r, x).value for x in [10, 11, 12, 13, 14, 15]]
_track_rank = ws1.cell(r, 16).value
_track_zb = [ws1.cell(r, x).value for x in [17, 18, 19, 20, 21, 22]]
# Check Name
if _nam not in data.C_ID:
print("读取到名称", _nam, "不在数据库中,跳过该条目!")
continue
if _nam not in juese:
print("角色", _nam, "不在你的数据中,添加该角色!")
juese[_nam] = {
"dengji": 1,
"rank": 1,
"haogan": 1,
"zb": [False] * 6,
"star": 1,
"last_update": time.time(),
}
info = juese[_nam]
# Add Track
if _track_str is not None:
_track_str = str(_track_str)
if _track_str == "max":
info["track_max"] = True
refresh_track_max(info)
else:
info["track_max"] = False
if _track_str == "false":
info["track"] = False
if "track_rank" in info: del info["track_rank"]
if "track_zb" in info: del info["track_zb"]
else:
if '.' not in _track_str:
A = int(_track_str)
rank = A
zb_str = "111111"
else:
A, B = _track_str.split('.')
A = int(A)
B = int(B)
rank = A
if B == 3:
zb_str = '010101'
elif B == 4:
zb_str = '010111'
elif B == 5:
zb_str = '011111'
elif B == 6:
zb_str = '111111'
_track_str = _track_str.rstrip(".6")
else:
raise Exception(f"错误的一键追踪指令:{_track_str}!")
info["track"] = _track_str
info["track_rank"] = rank
info["track_zb"] = ParseZBStr(zb_str)
else: