-
Notifications
You must be signed in to change notification settings - Fork 42
/
skill.lua
1136 lines (1063 loc) · 42.4 KB
/
skill.lua
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
fetchSkillIcon = function()
toast("正在检查更新基建图标...")
if disable_hotupdate then return end
local url = update_source .. '/skill.zip'
-- log("url", url)
-- if beta_mode then url = url .. '.beta' end
local md5url = url .. '.md5'
local path = getWorkPath() .. '/skill.zip'
local extract_path = getWorkPath() .. '/skill'
local md5path = path .. '.md5'
if downloadFile(md5url, md5path) == -1 then
toast("下载基建图标校验数据失败")
ssleep(3)
return
end
local f = io.open(md5path, 'r')
local expectmd5 = f:read() or '1'
f:close()
if expectmd5 == loadConfig("skill_md5", "2") then
toast("已经是最新版基建图标")
return
end
if downloadFile(url, path) == -1 then
toast("下载最新基建图标失败")
ssleep(3)
return
end
if fileMD5(path) ~= expectmd5 then
toast("基建图标校验失败")
ssleep(3)
return
end
unZip(path, extract_path)
saveConfig("skill_md5", expectmd5)
return restartScript()
end
discover = still_wrapper(function(operators, pngdata, pageid, mood_only)
-- 异步滑动
-- local delay = swipo(false, true)
-- local start_time = time()
-- local w, h, color = getScreenPixel(table.unpack(point.第一干员卡片范围))
local prewhite = 0
-- TODO 是这个导致卡片没识别到吗
local y = scale(383)
local corner = {}
for x = scale(600), scale(1590) do
if cmpColor(x, y, 'FFFFFF', default_findcolor_confidence) == 1 then
prewhite = prewhite + 1
elseif prewhite > scale(5) and
cmpColor(x, y, '898989', default_findcolor_confidence) == 1 then
prewhite = 0
table.insert(corner, x)
end
end
log(113, #corner)
local card = {}
if #corner == 0 then
log("基建换班找不到卡片")
return
end
local prex = -math.huge
for _, x in pairs(corner) do
if x - prex > scale(207) then
prex = x
table.insert(card, { x, scale(379) })
table.insert(card, { x, scale(801) })
end
end
-- card = table.slice(card, 4, 4)
-- log(114, card)
local empty1_num = 0
for idx, v in pairs(card) do
-- 技能判断
local icon1 = {
v[1] + scale(7), v[2] + scale(18), v[1] + scale(60), v[2] + scale(70),
}
local icon2 = {
v[1] + scale(70), v[2] + scale(18), v[1] + scale(123), v[2] + scale(70),
}
-- log(147, icon1)
local png = ''
local png2 = ''
if not mood_only then
png = 'empty1'
png =
findBuildingSkill(icon1[1], icon1[2], icon1[3], icon1[4], pngdata) or
png
-- 已到结尾,返回
if png == 'empty1' then
empty1_num = empty1_num + 1
-- 第一页有可能有多个
if pageid > 1 or pageid == 1 and empty1_num > 3 then
log("page end", icon1, idx, v)
return true
end
end
png2 = 'empty2'
operator = skillpng2operator[png]
if #operator == 1 then
else
png2 =
findBuildingSkill(icon2[1], icon2[2], icon2[3], icon2[4], pngdata) or
png2
if png2 ~= 'empty2' and not disable_log then
operator2 = skillpng2operator[png2]
operator = table.intersect(operator, operator2)
end
end
end
-- 心情判断
local mood = 0
-- log(v[1])
local mood1 = { v[1] + scale(49), v[2] + scale(93) }
-- log(mood1)
for i = 24, 1, -1 do
local moodi = { mood1[1] + scale((i - 1) * 5.3478), mood1[2] }
-- log(moodi, getColor(moodi[1], moodi[2]))
-- if getColor(moodi[1], moodi[2]) == 'FFFFFF' then
if cmpColor(moodi[1], moodi[2], 'FFFFFF', 0.4) == 1 then
mood = i
break
end
end
log(129, idx, operator, mood)
-- 异格将心情设为负值
local yg1 = { v[1] + scale(7), v[2] - scale(219) }
local yg2 = { v[1] + scale(7), v[2] - scale(205) }
local yg3 = { v[1] + scale(15), v[2] - scale(264) }
-- "1276|801|898989,1291|537|272727"
log("yg1", yg1)
log("yg2", yg2)
log("yg3", yg3)
yg1 = getPixelColor(yg1[1], yg1[2])
yg2 = getPixelColor(yg2[1], yg2[2])
yg3 = getPixelColor(yg3[1], yg3[2])
log("yg1", yg1)
log("yg2", yg2)
log("yg3", yg3)
if math.abs(colorDiff(yg1, yg2)) < 36 and table.any(ygStaitonColor,
function(color)
return math.abs(colorDiff(yg1, color)) < 36
end) and (math.abs(colorDiff(yg3, "ff003030")) < 75) then
-- ffffbb22
log("异格干员")
mood = -mood
if mood == 0 then mood = -1 end
end
-- exit()
table.insert(operators, { png, png2, mood, icon1, pageid })
end
-- sleep(max(0, delay - (time() - start_time)))
log(217, operators)
-- exit()
end)
-- 贸易站干员选择
-- operator: 列表,每个元素包含两个技能图标
-- dormitoryCapacity: 宿舍可容纳人数
-- dormitoryLevelSum: 宿舍等级之和
-- goldStationNum: 赤金生产线数
-- 返回效率最高的index
tradingStationOperatorBest = function(operator, dormitoryCapacity,
dormitoryLevelSum, goldStationNum,
goodType, level)
log("194,goldStationNum,dormitoryCapacity,dormitoryLevelSum", 194,
goldStationNum, dormitoryCapacity, dormitoryLevelSum)
-- 参考 https://prts.wiki/w/罗德岛基建
local maxStorage, maxOperator
maxOperator = level
if level == 1 then
maxStorage = 6
elseif level == 2 then
maxStorage = 8
else
maxStorage = 10
end
-- 输入index组合,计算平均加成,与groundtruth差距:
-- 1. 只考虑8小时平均收益,非实际换班间隔
-- 2. 12心情以下干员不考虑,也忽略心情消耗
-- 3. 忽略 ?? 效果
local base, storage, all, gold, extra, only_need
local score = function(icons)
base = 0
storage = 0 -- 容量
extra = 0 -- 额外加成
gold = goldStationNum
all = {}
only_need = {}
-- 应用独立技能效果
for _, icon in pairs(table.flatten(icons)) do
all[icon] = (all[icon] or 0) + 1
-- log(266, icon, goodType, base)
if icon == 'bskill_tra_spd3' then
base = base + 0.35
elseif icon == 'bskill_tra_spd&formula1' then
base = base + 0.3 + 0.04 -- 近似两种产物
elseif icon == 'bskill_tra_spd&meet1' then
base = base + 0.4 -- 近似满级会客厅
elseif icon == 'bskill_tra_spd&cost' then
base = base + 0.3
elseif icon == 'bskill_tra_spd&limit7' then
base = base + 0.3
storage = storage + 1
elseif icon == 'bskill_tra_spd&limit6' then
base = base + 0.25
storage = storage + 1
elseif icon == 'bskill_tra_spd&limit5' then
base = base + 0.20
storage = storage + 4
elseif icon == 'bskill_tra_spd&limit4' then
base = base + 0.15
storage = storage + 4
elseif icon == 'bskill_tra_spd&limit3' then
base = base + 0.15
storage = storage + 2
elseif icon == 'bskill_tra_spd&limit2' then
base = base + 0.1
storage = storage + 4
elseif icon == 'bskill_tra_spd&limit1' then
base = base + 0.1
storage = storage + 2
elseif icon == 'bskill_tra_spd2' then
base = base + 0.3
elseif icon == 'bskill_tra_spd1' then
base = base + 0.2
elseif icon == "bskill_tra_par&per1" then -- 赫德雷 伊内丝和W加成不考虑
base = base + 0.25
elseif icon == "bskill_tra_par&per2" then
base = base + 0.30
elseif icon == "bskill_tra_spd&limit_down1" then -- 锏
base = base + 0.20
storage = storage - 2
elseif icon == "bskill_tra_spd&limit_down2" then
base = base + 0.25
storage = storage - 6
elseif icon == "bskill_tra_limit2spd" then
base = base + math.floor(storage / 5) * 0.25
elseif icon == "bskill_trade_ord_spd_variable" then -- 琳琅诗怀雅
base = base + storage * 0.04
elseif icon == 'bskill_tra_flow_gc2' then
base = base + 0.05
gold = gold + (gold // 2) * 2
elseif icon == 'bskill_tra_flow_gc1' then
base = base + 0.05
gold = gold + (gold // 4) * 2
elseif icon == 'bskill_tra_spd&dorm2' then
base = base + 0.02 * dormitoryLevelSum
elseif icon == 'bskill_tra_spd&dorm1' then
base = base + 0.01 * dormitoryLevelSum
elseif icon == 'bskill_tra_bd_n2' then
-- 忽略其他站人间烟火
base = base + 0.01 * dormitoryCapacity
elseif icon == 'bskill_tra_limit&cost"' then
storage = storage + 5
elseif icon == 'bskill_tra_wt&cost2' and goodType == '贵金属' then
-- 认为裁缝B单独用效果极小
base = base + 0.02
elseif icon == 'bskill_tra_wt&cost1' and goodType == '贵金属' then
-- 认为裁缝B单独用效果极小
base = base + 0.01
elseif all['bskill_tra_long2'] and goodType == '贵金属' then
-- 认为投资B单独用效果极小
base = base + 0.02
elseif all['bskill_tra_long1'] and goodType == '贵金属' then
-- 认为投资A单独用效果极小
base = base + 0.01
end
end
-- 应用全局性技能
-- 火哨
if all["bskill_tra_share1"] then base = base + (level - 1) * 0.15 end
-- 拉狗徳狗
local texas = all['bskill_tra_texas1'] or all['bskill_tra_texas2']
if all['bskill_tra_Lappland1'] then
if texas then
storage = storage + 2
base = base + 0.65
end
elseif all['bskill_tra_Lappland2'] then
if texas then
storage = storage + 4
base = base + 0.65
end
end
-- 雪雉
if all['bskill_tra_spd_variable22'] then
base = base + min(0.35, base // 0.05 * 0.05) *
all['bskill_tra_spd_variable22']
end
-- 图耶
if all['bskill_tra_flow_gs2'] then
base = base + 0.05 + (gold // 2) * 0.15 * all['bskill_tra_flow_gs2']
end
if all['bskill_tra_flow_gs1'] then
base = base + 0.05 + (gold // 4) * 0.15 * all['bskill_tra_flow_gs1']
end
-- 鸿雪
if all['bskill_tra_flow_gs'] then
base = base + 0.00 + (gold // 1) * 0.05 * all['bskill_tra_flow_gs']
end
-- 孑
if all['bskill_tra_limit_count'] then
-- 孑精1
base = base + max(1, (maxStorage + storage - base // 0.1)) * 0.04
elseif all['bskill_tra_limit_diff'] then
-- https://ngabbs.com/read.php?tid=26013244&rand=499
-- 孑0 / 德拉ii =112% (1天3换(18/6) 、只在换班时收单)
-- 孑0 近似
base = base + (maxStorage + storage) * 0.04 / (level + 1.12) * 4.034
end
-- 巫恋
if all['bskill_tra_vodfox'] and goodType == '贵金属' then
if maxOperator == 1 then
base = 0
elseif maxOperator == 2 then
base = 0.45 + 0.01
else
-- 参考 https://bbs.nga.cn/read.php?tid=25965441&rand=365
-- 即使柏喙/卡夫卡等价白板,也倾向于选,因为其他地方也不怎么用
if all['bskill_tra_wt&cost2'] and all['bskill_tra_long2'] then
only_need = {
'bskill_tra_vodfox', 'bskill_tra_wt&cost2', 'bskill_tra_long2',
}
base = 1.7192
elseif all['bskill_tra_wt&cost2'] and all['bskill_tra_long1'] then
only_need = {
'bskill_tra_vodfox', 'bskill_tra_wt&cost2', 'bskill_tra_long1',
}
base = 1.3205
elseif all['bskill_tra_wt&cost2'] then
only_need = { 'bskill_tra_vodfox', 'bskill_tra_wt&cost2' }
base = 0.9218
elseif all['bskill_tra_long2'] then
only_need = {
'bskill_tra_vodfox', 'bskill_tra_long2', 'bskill_tra_wt&cost1',
}
base = 1.4734 + 0.001 * all['bskill_tra_wt&cost1']
elseif all['bskill_tra_long1'] then
only_need = {
'bskill_tra_vodfox', 'bskill_tra_long1', 'bskill_tra_wt&cost1',
}
base = 1.1927 + 0.001 * all['bskill_tra_wt&cost1']
else
only_need = { 'bskill_tra_vodfox', 'bskill_tra_wt&cost1' }
base = 0.9120 + 0.001 * all['bskill_tra_wt&cost1']
end
end
end
-- 但书,禁用巫恋
if not all['bskill_tra_vodfox'] and goodType == "贵金属" then
if all['bskill_tra_against'] then base = (1 + base) * 1.276 - 1 end
if all['bskill_tra_against2'] then base = (1 + base) * 1.556 - 1 end
end
-- 禁用尤里卡
if all['bskill_tra_spd&wt1'] then base = -1 end
return base, only_need
end
-- 过滤心情小于阈值的干员
local minAllowedMood = shift_min_mood
if disable_shift_mood then minAllowedMood = -1 end
operator = table.filter(operator,
function(x) return x[3] >= minAllowedMood end)
-- 移除心情
operatorIcon = map(function(x) return { x[1], x[2] } end, operator)
-- 遍历全部组合
local best = {}
local best_score = -1
local best_only_need = {}
log(354, #operator, maxOperator)
for _, c in pairs(table.combination(range(1, #operator), maxOperator)) do
local s, only_need = score(table.index(operatorIcon, c))
-- log(401, table.index(operator, c), s)
if s > best_score then
best = c
best_score = s
best_only_need = only_need
end
end
best = table.index(operator, best)
-- 特殊处理,只需要部分干员
if #best_only_need > 0 then
best = table.filter(best, function(v)
return #table.intersect(best_only_need, { v[1], v[2] }) > 0
end)
end
return best, best_score
end
testManufacturingStationOperatorBest = function()
local operator = {
{ 'bskill_man_exp3', 'bskill_man_exp1', 12 }, { 'bskill_man_exp2', '', 12 },
{ '', 'bskill_man_spd_variable31', 12 }, { 'bskill_man_spd2', '', 12 },
{ '', 'bskill_man_spd&limit&cost2', 12 },
{ '', 'bskill_man_spd&limit&cost4', 12 },
}
local tradingStationNum = 3
local powerStationNum = 3
local goodType = "作战记录"
local level = 3
local best, best_score
best, best_score = manufacturingStationOperatorBest(operator,
tradingStationNum,
powerStationNum, 0,
goodType, level)
log(best, best_score)
end
-- 制造站干员选择
-- operator: 列表,每个元素包含两个技能图标与心情
-- tradingStationNum: 贸易站数量
-- powerStationNum: 发电站数量
-- totalStationLevel: 等级总量
-- type: 制造物类别
-- level: 制造站等级
-- 返回效率最高的index
manufacturingStationOperatorBest = function(operator, tradingStationNum,
powerStationNum, totalStationLevel,
goodType, level)
-- 参考 https://prts.wiki/w/罗德岛基建/制造站
local maxStorage, maxOperator
maxOperator = level
if level == 1 then
maxStorage = 24
elseif level == 2 then
maxStorage = 36
else
maxStorage = 54
end
log("401,goodType", goodType, operator[1])
-- log("maxStorage", maxStorage)
-- log("maxOperator", maxOperator)
-- 输入index组合,计算平均加成,与groundtruth差距:
-- 1. 只考虑8小时平均收益,非实际换班间隔
-- 2. 12心情以下干员不考虑,也忽略心情消耗
-- 3. 忽略 迷迭香所有技能 效果
-- 4. 忽略 意识协议 效果(标准化技能识别不支持)
-- 5. 忽略 我寻思能行 效果(发电站技能加成)
local base, disable_moon_effect, storage, storages, standard, all, station,
station_only, only_need, robot
local score = function(icons)
base = 0
robot = 0 -- 工程机器人
storage = {} -- 容量效果
standard = 0 -- 标准化技能数量
station = 0 -- 根据设施加成
station_only = false -- 是否只根据设施加成
all = {}
only_need = {}
-- log(icons)
-- log(table.flatten(icons))
-- 应用独立技能效果
for idx, icon in pairs(table.flatten(icons)) do
operatoridx = (idx + 1) // 2
all[icon] = (all[icon] or 0) + 1
-- log(266, icon, goodType, base)
if icon == 'bskill_man_limit&cost5' then
storage[operatoridx] = (storage[operatoridx] or 0) + 10
elseif icon == 'bskill_man_exp3' then
if goodType == '作战记录' then base = base + 0.35 end
-- log(272, base)
elseif icon == 'bskill_man_exp2' then
if goodType == '作战记录' then base = base + 0.30 end
elseif icon == 'bskill_man_exp1' then
if goodType == '作战记录' then base = base + 0.25 end
elseif icon == 'bskill_man_gold2' then
if goodType == '贵金属' then base = base + 0.35 end
elseif icon == 'bskill_man_gold1' then
if goodType == '贵金属' then base = base + 0.30 end
elseif icon == 'bskill_man_spd&trade' then
-- 清流,使用贸易站数量
if goodType == '贵金属' then
-- base = base + 0.20 * tradingStationNum
station = station + 0.20 * tradingStationNum
end
elseif icon == 'bskill_man_spd_bd_n1' then
-- 迷迭香不考虑
elseif icon == 'bskill_man_spd_bd1' then
-- 迷迭香不考虑
elseif icon == 'bskill_man_spd_bd2' then
-- 迷迭香不考虑
elseif icon == "bskill_man_gold&blacksteel" then
-- 排除杏仁
elseif icon == 'bskill_man_spd3' then
base = base + 0.30
elseif icon == 'bskill_man_spd2' then
base = base + 0.25
elseif icon == 'bskill_man_limit&cost3' then
storage[operatoridx] = (storage[operatoridx] or 0) + 16
-- table.insert(storage, 16)
elseif icon == 'bskill_man_spd&limit&cost3' then
base = base + 0.25
storage[operatoridx] = (storage[operatoridx] or 0) - 12
-- table.insert(storage, -12)
elseif icon == 'bskill_man_spd_add1' then
-- 8小时平均收益 ((0.2+0.24)/2*5+0.25*3)/8
base = base + 0.23125
elseif icon == 'bskill_man_spd_add2' then
-- 8小时平均收益 ((0.15+0.23)/2*5+0.25*3)/8
base = base + 0.2125
elseif icon == 'bskill_man_spd1' then
base = base + 0.15
elseif icon == 'bskill_man_spd&limit3' then
base = base + 0.1
storage[operatoridx] = (storage[operatoridx] or 0) + 10
-- table.insert(storage, 10)
elseif icon == 'bskill_man_spd&limit1' then
base = base + 0.1
-- table.insert(storage, 6)
storage[operatoridx] = (storage[operatoridx] or 0) + 6
elseif icon == 'bskill_man_spd&limit&cost2' then
base = base - 0.05
-- table.insert(storage, 19)
storage[operatoridx] = (storage[operatoridx] or 0) + 19
elseif icon == 'bskill_man_spd&limit&cost1' then
base = base - 0.05
-- table.insert(storage, 16)
storage[operatoridx] = (storage[operatoridx] or 0) + 16
elseif icon == 'bskill_man_spd&limit&cost4' then
base = base - 0.2
-- table.insert(storage, 17)
storage[operatoridx] = (storage[operatoridx] or 0) + 17
elseif icon == 'bskill_man_exp&limit2' then
if goodType == '作战记录' then
-- table.insert(storage, 15)
storage[operatoridx] = (storage[operatoridx] or 0) + 15
end
elseif icon == 'bskill_man_exp&limit1' then
if goodType == '作战记录' then
-- table.insert(storage, 12)
storage[operatoridx] = (storage[operatoridx] or 0) + 12
end
elseif icon == 'bskill_man_limit&cost2' then
-- table.insert(storage, 10)
storage[operatoridx] = (storage[operatoridx] or 0) + 10
elseif icon == 'bskill_man_limit&cost1' then
-- table.insert(storage, 8)
storage[operatoridx] = (storage[operatoridx] or 0) + 8
elseif icon == 'bskill_man_exp&cost' then
-- Vlog 心情消耗不考虑
elseif icon == 'bskill_man_originium2' then
if goodType == '源石' then base = base + 0.35 end
elseif icon == 'bskill_man_originium1' then
if goodType == '源石' then base = base + 0.3 end
elseif icon == 'bskill_man_constrLv' then
robot = min(64, robot + totalStationLevel)
elseif icon == 'empty' then
log('empty')
end
end
-- 应用全局性技能
-- 至简
if all["bskill_man_spd_bd3"] then base = base + (robot // 16) * 0.05 end
if all["bskill_man_spd_bd4"] then base = base + (robot // 8) * 0.05 end
if all['bskill_man_spd_variable31'] then
-- 泡泡
for _, s in pairs(storage) do
if s > 0 and s <= 16 then
base = base + s * 0.01 * all['bskill_man_spd_variable31']
elseif s > 16 then
base = base + s * 0.03 * all['bskill_man_spd_variable31']
end
end
elseif all['bskill_man_spd_variable11'] then
-- 红云
base = base + max(table.sum(storage), 0) * 0.02 *
all['bskill_man_spd_variable11']
end
if all['bskill_man_spd_variable21'] then
-- 槐虎
base = base + min(0.4, base // 0.05 * 0.05) *
all['bskill_man_spd_variable21']
end
-- 发电站数
if all['bskill_man_spd&power3'] then
station_only = true
station = station + 0.15 * powerStationNum * all['bskill_man_spd&power3']
table.extend(only_need, { 'bskill_man_spd&power3' })
end
if all['bskill_man_spd&power2'] then
station_only = true
station = station + 0.1 * powerStationNum * all['bskill_man_spd&power2']
table.extend(only_need, { 'bskill_man_spd&power2' })
end
if all['bskill_man_spd&power1'] then
station_only = true
station = station + 0.05 * powerStationNum * all['bskill_man_spd&power1']
table.extend(only_need, { 'bskill_man_spd&power1' })
end
if all['bskill_man_skill_spd'] then
-- 水月,标准化技能数量
base = base + standard * 0.05 * all['bskill_man_skill_spd']
-- base = base + 0
-- 目前水月还是选0.25
end
-- 禁止过小容量
if maxStorage + table.sum(storage) < 20 then base = -1 end
-- 禁止多次减容量
if table.sum(storage) < -15 then base = -1 end
if station_only then
base = station
table.extend(only_need, { 'bskill_man_spd&trade' })
else
base = base + station
end
return base, only_need
end
-- 过滤心情小于阈值的干员
local minAllowedMood = shift_min_mood
if disable_shift_mood then minAllowedMood = -1 end
operator = table.filter(operator,
function(x) return x[3] >= minAllowedMood end)
-- 移除心情
operatorIcon = map(function(x) return { x[1], x[2] } end, operator)
-- 遍历全部组合
local best = {}
local best_score = -1
local best_only_need = {}
for _, c in pairs(table.combination(range(1, #operator), maxOperator)) do
local s, only_need = score(table.index(operatorIcon, c))
if s > best_score then
best = c
best_score = s
best_only_need = only_need
end
-- log(401, c, s)
-- if table.equal(c, {1, 2, 3}) then exit() end
end
best = table.index(operator, best)
-- 特殊处理,白板干员用白板
if #best_only_need > 0 then
best = table.filter(best, function(v)
return #table.intersect(best_only_need, { v[1], v[2] }) > 0
end)
end
return best, best_score
end
stationIconMask = {}
stationIconCenterMask = {}
w, h = 36, 36
for i = 1, h do
for j = 1, w do
if true then
table.insert(stationIconMask, { i, j })
-- log(613,i,j)
end
if ((i - 18.5) ^ 2 + (j - 18.5) ^ 2) < 17 ^ 2 then
table.insert(stationIconCenterMask, { i, j })
end
end
end
-- exit()
findBuildingSkill = function(x1, y1, x2, y2, pngdata)
local s = ''
local w, h, color = getScreenPixel(x1, y1, x2, y2)
local i, j, b, g, r
local data = {}
for _, m in pairs(stationIconMask) do
i, j = m[1], m[2]
-- b, g, r = colorToRGB(color[(i - 1) * w + j])
b, g, r = colorToRGB(color[scale((i - 1) / 720 * 1080) * w +
scale(j / 720 * 1080)])
table.extend(data, { r, g, b })
if nil then
r = string.format('%X', r):padStart(2, '0')
g = string.format('%X', g):padStart(2, '0')
b = string.format('%X', b):padStart(2, '0')
s = s .. i .. '|' .. j .. '|' .. r .. g .. b .. ','
end
end
-- log(s)
-- exit()
--
local best_score = 100
-- local threshold = 100
local best = nil
local score = 0
local scoreBase = 0
local pointScore = 0
-- local flatPoint = 0
local abs = math.abs
local flatScoreTable = {}
local flatScore = 0
for i = 1, #stationIconMask - 36 do
flatScore = abs(data[i * 3 - 2] - data[(i + 1) * 3 - 2]) +
abs(data[i * 3 - 1] - data[(i + 1) * 3 - 1]) +
abs(data[i * 3] - data[(i + 1) * 3]) +
abs(data[i * 3 - 2] - data[(i + 36) * 3 - 2]) +
abs(data[i * 3 - 1] - data[(i + 36) * 3 - 1]) +
abs(data[i * 3] - data[(i + 36) * 3])
table.insert(flatScoreTable, 1 / (1 + flatScore))
scoreBase = scoreBase + flatScoreTable[#flatScoreTable]
end
-- local tmp = ''
for k, v in pairs(pngdata) do
-- tmp = ''
score = 0
for i = 1, #stationIconMask do
pointScore = abs(data[i * 3 - 2] - v[i * 3 - 2]) +
abs(data[i * 3 - 1] - v[i * 3 - 1]) +
abs(data[i * 3] - v[i * 3])
score = score + pointScore * flatScoreTable[i]
-- if i % 36 == 1 then tmp = tmp .. '\n' end
-- if pointScore > 200 then
-- tmp = tmp .. '1'
-- else
-- tmp = tmp .. ' '
-- end
if score / scoreBase > best_score then break end
end
score = score / scoreBase
-- if k == 'bskill_tra_long1' then log(662, score, tmp) end
-- if k == 'bskill_tra_flow_gc1' then log(663, score, tmp) end
-- if k == 'bskill_tra_flow_gc1' then log(663, score, tmp) end
-- if k == 'bskill_tra_spd_variable22' then log(662, score, tmp) end
-- if k == 'bskill_tra_spd&wt1' then log(663, score, tmp) end
--
-- if k == 'bskill_tra_texas1' then log(662, score, tmp) end
-- if k == 'bskill_tra_Lappland2' then log(663, score, tmp) end
-- if k == 'bskill_meet_spd3' then log(663, score, tmp) end
-- if k == 'bskill_meet_spd2' then log(662, score, tmp) end
-- if k == 'bskill_man_spd2' then log(663, score, tmp) end
-- if k == 'bskill_man_exp2' then log(662, score, tmp) end
-- if k == 'bskill_ctrl_t_spd' then log('t', score, tmp) end
-- if k == 'bskill_ctrl_c_spd' then log('c', score, tmp) end
-- exit()
if best_score > score then
best_score = score
best = k
end
end
-- log(2208, best_score, best, x1, y1, x2, y2)
-- exit()
return best
end
initPngdata = function()
if skillpng2operator then return end
-- 读取数据
local f = io.open(getWorkPath() .. '/skill/skillicon2operator.json', 'r')
skillpng2operator = f:read()
f:close()
local status
status, skillpng2operator = pcall(JsonDecode, skillpng2operator)
if not status then stop("基建图标数据异常", 'cur') end
-- 扩充精英化等级
for k, v in pairs(skillpng2operator) do
local extra = {}
for _, o in pairs(v) do
if o:endsWith('1') then table.insert(extra, o:sub(1, #o - 1) .. '2') end
if o:endsWith('0') then
table.insert(extra, o:sub(1, #o - 1) .. '1')
table.insert(extra, o:sub(1, #o - 1) .. '2')
end
end
table.extend(v, extra)
end
-- 第一技能缺失,无需再考虑
skillpng2operator['empty1'] = {}
-- 第二技能缺失,所有干员
skillpng2operator['empty2'] = table.remove_duplicate(table.flatten(
skillpng2operator))
-- 读取图标
manufacturingPngdata = {}
tradingPngdata = {}
meetingPngdata = {}
controlPngdata = {}
officePngdata = {}
stationType2pngData = {
制造站 = manufacturingPngdata,
贸易站 = tradingPngdata,
会客厅 = meetingPngdata,
控制中枢 = controlPngdata,
办公室 = officePngdata,
}
local s = ''
for v, _ in pairs(skillpng2operator) do
local pngdata
if v:startsWith("bskill_man") then
pngdata = manufacturingPngdata
elseif v:startsWith("bskill_tra_") then
pngdata = tradingPngdata
elseif v:startsWith("bskill_meet") then
pngdata = meetingPngdata
elseif v:startsWith("bskill_ctrl") then
pngdata = controlPngdata
elseif v:startsWith("bskill_hire") then
pngdata = officePngdata
else
pngdata = {}
end
local _, _, color = getImage(getWorkPath() .. '/skill/' .. v .. '.png')
-- if v=='empty1' then
-- print(color)
-- end
pngdata[v] = {}
for _, m in pairs(stationIconMask) do
i, j = m[1], m[2]
b, g, r = colorToRGB(color[(w - i - 1) * w + j])
table.extend(pngdata[v], { r, g, b })
if nil and v == 'bskill_man_exp2' then
-- if v == 'bskill_ws_evolve2' then
r = string.format('%X', r):padStart(2, '0')
g = string.format('%X', g):padStart(2, '0')
b = string.format('%X', b):padStart(2, '0')
s = s .. i .. '|' .. j .. '|' .. r .. g .. b .. ','
end
end
end
if not manufacturingPngdata['bskill_man_exp2'] then
toast("基建图标数据异常")
ssleep(5)
end
if not tradingPngdata['bskill_tra_spd&wt1'] then
toast("基建图标数据异常")
ssleep(5)
end
end
-- 是否是贸易站,商品类别
chooseOperator = function(stationType, goodType, stationLevel,
tradingStationNum, powerStationNum, dormitoryCapacity,
dormitoryLevelSum, goldStationNum, totalStationLevel)
log("stationType", stationType)
log("goodType", goodType)
log("stationLevel", stationLevel)
log("tradingStationNum", tradingStationNum)
log("powerStationNum", powerStationNum)
log("dormitoryCapacity", dormitoryCapacity)
log("dormitoryLevelSum", dormitoryLevelSum)
log("goldStationNum", goldStationNum)
log("totalStationLevel", totalStationLevel)
-- exit()
local start_time = time()
initPngdata()
-- 至少等一秒
sleep(max(0, 1000 - (time() - start_time)))
-- exit()
-- ==> 滑动获取所有技能
local maxSwipTimes = 10
local operator = {}
for i = 1, maxSwipTimes do
-- if discover(operator,
-- (not trading) and manufacturingPngdata or tradingPngdata, i) then
-- log(stationType, #stationType2pngData[stationType])
if discover(operator, stationType2pngData[stationType], i) then break end
-- exit()
-- 三次重试
local state = sample("干员第一个")
for j = 1, 3 do
log("842尝试翻页", j)
if findOne("正在提交反馈至神经") then
disappear("正在提交反馈至神经", network_timeout)
ssleep(.5)
end
swipo()
if not findOne(state) then break end
end
end
swipo(true, true)
start_time = time()
-- log(671, operator)
-- exit()
-- TODO 滑动时就可以开始计算
-- 计算最优技能
local best, best_score
if stationType == "制造站" then
best, best_score = manufacturingStationOperatorBest(operator,
tradingStationNum,
powerStationNum,
totalStationLevel,
goodType, stationLevel)
elseif stationType == "贸易站" then
best, best_score = tradingStationOperatorBest(operator, dormitoryCapacity,
dormitoryLevelSum,
goldStationNum, goodType,
stationLevel)
elseif stationType == "会客厅" then
best, best_score = meetingStationOperatorBest(operator)
elseif stationType == "办公室" then
best, best_score = officeStationOperatorBest(operator)
elseif stationType == "控制中枢" then
best, best_score = controlStationOperatorBest(operator)
end
sleep(max(0, 500 - (time() - start_time)))
tap("清空选择")
-- 按页数排序
table.sort(best, function(a, b) return a[5] < b[5] end)
-- 选择干员
operator = best
log(692, operator, best_score)
local pageid = 1
for i = 1, #operator do
log(i, operator[i])
while operator[i][5] > pageid do
local state = sample("干员第一个")
for j = 1, 3 do
log("844尝试翻页", j)
if findOne("正在提交反馈至神经") then
disappear("正在提交反馈至神经", network_timeout)
ssleep(.5)
end
swipo()
if not findOne(state) then break end
end
pageid = pageid + 1
end
local p = operator[i][4]
tap({ p[1] + scale(106), p[2] })
sleep(50)
end
swipo(true, true)
-- exit()
end
-- 会客厅干员选择:先选+25%,剩下按鹰序
-- 返回效率最高的index
meetingStationOperatorBest = function(operator)
-- 过滤心情小于阈值的干员
local minAllowedMood = shift_min_mood
if disable_shift_mood then minAllowedMood = -1 end
operator = table.filter(operator,
function(x) return x[3] >= minAllowedMood end)
local best = {}
local best_score = -1
local remain = {}
for _, o in pairs(operator) do
if table.includes({ o[1], o[2] }, 'bskill_meet_spdOwned1') then
-- 禁用尤里卡
elseif o[1] == "bskill_meet_spd&cost" or o[2] == "bskill_meet_spd&cost" then
table.insert(best, 1, o)
elseif o[1] == "bskill_meet_spdNotOwned2" or o[2] ==
"bskill_meet_spdNotOwned2" then
-- 晓歌有人评测过吗
table.insert(best, 1, o)
elseif o[1] == "bskill_meet_exchange" or o[2] == "bskill_meet_exchange" then
table.insert(best, 1, o) -- 跃跃
elseif o[1] == "bskill_meet_spd3" or o[2] == "bskill_meet_spd3" then
table.insert(best, o)
else