-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
2106 lines (1941 loc) · 79 KB
/
main.py
File metadata and controls
2106 lines (1941 loc) · 79 KB
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 configparser
import sys
import datetime
import os
import json
import shutil
import time
from settings import settings
import splitter
import hashlib
# Var init with default value
c_profileid = 0
c_profilemaxid = 0
legmin = settings.default_leg_min
legmax = settings.default_leg_max
t19min = settings.default_equip_t19_min
t19max = settings.default_equip_t19_max
t20min = settings.default_equip_t20_min
t20max = settings.default_equip_t20_max
t21min = settings.default_equip_t21_min
t21max = settings.default_equip_t21_max
outputFileName = settings.default_outputFileName
# txt, because standard-user cannot be trusted
inputFileName = settings.default_inputFileName
logFileName = settings.logFileName
errorFileName = settings.errorFileName
# quiet_mode for faster output; console is very slow
b_quiet = settings.b_quiet
i_generatedProfiles = 0
b_simcraft_enabled = settings.default_sim_enabled
s_stage = ""
iterations_firstpart = settings.default_iterations_stage1
iterations_secondpart = settings.default_iterations_stage2
iterations_thirdpart = settings.default_iterations_stage3
target_error_secondpart = settings.default_target_error_stage2
target_error_thirdpart = settings.default_target_error_stage3
gemspermutation = False
gem_ids = {}
gem_ids["150haste"] = "130220"
gem_ids["200haste"] = "151583"
gem_ids["haste"] = "151583" # always contains maximum quality
gem_ids["150crit"] = "130219"
gem_ids["200crit"] = "151580"
gem_ids["crit"] = "151580" # always contains maximum quality
gem_ids["150vers"] = "130221"
gem_ids["200vers"] = "151585"
gem_ids["vers"] = "151585" # always contains maximum quality
gem_ids["150mast"] = "130222"
gem_ids["200mast"] = "151584"
gem_ids["mast"] = "151584" # always contains maximum quality
gem_ids["200str"] = "130246"
gem_ids["str"] = "130246"
gem_ids["200agi"] = "130247"
gem_ids["agi"] = "130247"
gem_ids["200int"] = "130248"
gem_ids["int"] = "130248"
# Error handle
def printLog(stringToPrint):
if not b_quiet:
# should this console-output be here at all? outputting to file AND console could be handled separately
# e.g. via simple debug-toggle (if b_debug: print(...))
print(stringToPrint)
today = datetime.date.today()
logFile.write(str(today) + ":" + stringToPrint + "\n")
# Add legendary to the right tab
def addToTab(x):
stringToAdd = "L,id=" + x[1] + (",bonus_id=" + x[2] if x[2] != "" else "") + (
",enchant_id=" + x[3] if x[3] != "" else "") + (",gem_id=" + x[4] if x[4] != "" else "")
if x[0] == 'head':
l_head.append(stringToAdd)
elif x[0] == 'neck':
l_neck.append(stringToAdd)
elif x[0] == 'shoulders':
l_shoulders.append(stringToAdd)
elif x[0] == 'back':
l_back.append(stringToAdd)
elif x[0] == 'chest':
l_chest.append(stringToAdd)
elif x[0] == 'wrist':
l_wrists.append(stringToAdd)
elif x[0] == 'hands':
l_hands.append(stringToAdd)
elif x[0] == 'waist':
l_waist.append(stringToAdd)
elif x[0] == 'legs':
l_legs.append(stringToAdd)
elif x[0] == 'feet':
l_feet.append(stringToAdd)
elif x[0] == 'finger1':
l_finger1.append(stringToAdd)
elif x[0] == 'finger2':
l_finger2.append(stringToAdd)
elif x[0] == 'trinket1':
l_trinket1.append(stringToAdd)
elif x[0] == 'trinket2':
l_trinket2.append(stringToAdd)
# Manage legendary with command line
def handlePermutation(elements):
for element in elements:
pieces = element.split('|')
addToTab(pieces)
def handleGems(gems):
allowed_gems = ["crit", "vers", "haste", "mast", "int", "str", "agi"]
global splitted_gems
if gems:
splitted_gems = gems.split(",")
for i in range(len(splitted_gems)):
if splitted_gems[i] not in allowed_gems:
printLog("Unknown gem to sim, please check your input: " + str(splitted_gems[i]))
print("Unknown gem to sim, please check your input: " + str(splitted_gems[i]))
sys.exit(1)
# Check if permutation is valid
def checkUsability():
# namingdata contains info for the profile-name
global namingData
namingData = {}
temp_t19 = 0
temp_t20 = 0
temp_t21 = 0
for i in range(len(l_gear)):
if l_gear[i][0:3] == "T19":
temp_t19 = temp_t19 + 1
if l_gear[i][0:3] == "T20":
temp_t20 = temp_t20 + 1
if l_gear[i][0:3] == "T21":
temp_t21 = temp_t21 + 1
if temp_t19 < int(t19min):
return " " + str(temp_t19) + ": too few T19-items (" + str(t19min) + " asked)"
if temp_t20 < int(t20min):
return " " + str(temp_t20) + ": too few T20-items (" + str(t20min) + " asked)"
if temp_t21 < int(t21min):
return " " + str(temp_t21) + ": too few T21-items (" + str(t21min) + " asked)"
if temp_t19 > int(t19max):
return " " + str(temp_t19) + ": too much T19-items (" + str(t19max) + " asked)"
if temp_t20 > int(t20max):
return " " + str(temp_t20) + ": too much T20-items (" + str(t20max) + " asked)"
if temp_t21 > int(t21max):
return " " + str(temp_t21) + ": too much T21-items (" + str(t21max) + " asked)"
if l_gear[10] == l_gear[11]:
return " Same ring"
if l_gear[12] == l_gear[13]:
return " Same trinket"
nbLeg = 0
for a in range(len(l_gear)):
if l_gear[a][0] == "L":
nbLeg = nbLeg + 1
if nbLeg < legmin:
return str(nbLeg) + " leg (" + str(legmin) + " asked)"
if nbLeg > legmax:
return str(nbLeg) + " leg (" + str(legmax) + " asked)"
# check if amanthuls-trinket is the 3rd trinket; otherwise its an invalid profile
# because 3 other legs have been equipped
if nbLeg == 3:
if not getIdFromItem(l_gear[12]) == "154172" and not getIdFromItem(l_gear[13]) == "154172":
return " 3 legs equipped, but no Amanthul-Trinket found"
# check gems
# int, str, agi should be only equipped once:
nUniqueGems = 0
for a in range(len(l_gear)):
gems = getGemsFromItem(l_gear[a])
if "130246" in gems or "130247" in gems or "130248" in gems:
nUniqueGems += 1
if nUniqueGems > 1:
return str(nUniqueGems) + " too many unique gems (str, agi, int)"
# if a valid profile was detected, fill namingData; otherwise its pointless
if nbLeg == 0:
namingData['Leg0'] = ""
namingData["Leg1"] = ""
elif nbLeg == 1:
for a in range(len(l_gear)):
if l_gear[a][0] == "L":
namingData['Leg0'] = getIdFromItem(l_gear[a][0])
elif nbLeg == 2:
for a in range(len(l_gear)):
if l_gear[a][0] == "L":
if namingData.get('Leg0') != None:
namingData['Leg1'] = getIdFromItem(l_gear[a])
else:
namingData['Leg0'] = getIdFromItem(l_gear[a])
elif nbLeg == 3:
for a in range(len(l_gear)):
if l_gear[a][0] == "L":
if namingData.get('Leg0') == None:
namingData['Leg0'] = getIdFromItem(l_gear[a])
else:
if namingData.get('Leg1') != None:
namingData['Leg1'] = getIdFromItem(l_gear[a])
else:
namingData['Leg2'] = getIdFromItem(l_gear[a])
namingData["T19"] = temp_t19
namingData["T20"] = temp_t20
namingData["T21"] = temp_t21
if getIdFromItem(l_gear[10]) == getIdFromItem(l_gear[11]):
return F"Ring1: {l_gear[10]} same as Ring2: {l_gear[11]}"
if getIdFromItem(l_gear[12]) == getIdFromItem(l_gear[13]):
return F"Trinket1: {l_gear[12]} same as Trinket2: {l_gear[13]}"
return ""
def getIdFromItem(item):
splits = item.split(",")
for s in splits:
if s.startswith("id="):
return s[3:]
# Print a simc profile
def scpout(oh):
global c_profileid
global i_generatedProfiles
result = checkUsability()
digits = len(str(c_profilemaxid))
mask = '00000000000000000000000000000000000'
maskedProfileID = (mask + str(c_profileid))[-digits:]
# output status every 5000 permutations, user should get at least a minor progress shown; also does not slow down
# computation very much
if int(maskedProfileID) % 5000 == 0:
print("Processed: " + str(maskedProfileID) + "/" + str(c_profilemaxid) + " (" + str(
round(100 * float(int(maskedProfileID) / int(c_profilemaxid)), 1)) + "%)")
if int(maskedProfileID) == c_profilemaxid:
print("Processed: " + str(maskedProfileID) + "/" + str(c_profilemaxid) + " (" + str(
round(100 * float(int(maskedProfileID) / int(c_profilemaxid)), 1)) + "%)")
if result != "":
printLog("Profile:" + str(maskedProfileID) + "/" + str(c_profilemaxid) + ' Warning, not printed:' + result)
else:
if not b_quiet:
print("Profile:" + str(maskedProfileID) + "/" + str(c_profilemaxid))
outputFile.write(c_class + "=" + getStringForProfile() + maskedProfileID + "\n")
outputFile.write("specialization=" + c_spec + "\n")
outputFile.write("race=" + c_race + "\n")
outputFile.write("level=" + c_level + "\n")
outputFile.write("role=" + c_role + "\n")
outputFile.write("position=" + c_position + "\n")
outputFile.write("talents=" + c_talents + "\n")
outputFile.write("artifact=" + c_artifact + "\n")
if c_crucible != "":
outputFile.write("crucible=" + c_crucible + "\n")
if c_potion != "":
outputFile.write("potion=" + c_potion + "\n")
if c_flask != "":
outputFile.write("flask=" + c_flask + "\n")
if c_food != "":
outputFile.write("food=" + c_food + "\n")
if c_augmentation != "":
outputFile.write("augmentation=" + c_augmentation + "\n")
if c_other != "":
outputFile.write(c_other + "\n")
if l_gear[0][0] == "L":
outputFile.write("head=" + l_gear[0][1:] + "\n")
elif (l_gear[0][0:3] == "T19" or l_gear[0][0:3] == "T20"):
outputFile.write("head=" + l_gear[0][3:] + "\n")
else:
outputFile.write("head=" + l_gear[0] + "\n")
outputFile.write("neck=" + (l_gear[1] if l_gear[1][0] != "L" else l_gear[1][1:]) + "\n")
if l_gear[2][0] == "L":
outputFile.write("shoulders=" + l_gear[2][1:] + "\n")
elif (l_gear[2][0:3] == "T19" or l_gear[2][0:3] == "T20"):
outputFile.write("shoulders=" + l_gear[2][3:] + "\n")
else:
outputFile.write("shoulders=" + l_gear[2] + "\n")
if l_gear[3][0] == "L":
outputFile.write("back=" + l_gear[3][1:] + "\n")
elif (l_gear[3][0:3] == "T19" or l_gear[3][0:3] == "T20"):
outputFile.write("back=" + l_gear[3][3:] + "\n")
else:
outputFile.write("back=" + l_gear[3] + "\n")
if l_gear[4][0] == "L":
outputFile.write("chest=" + l_gear[4][1:] + "\n")
elif (l_gear[4][0:3] == "T19" or l_gear[4][0:3] == "T20"):
outputFile.write("chest=" + l_gear[4][3:] + "\n")
else:
outputFile.write("chest=" + l_gear[4] + "\n")
outputFile.write("wrists=" + (l_gear[5] if l_gear[5][0] != "L" else l_gear[5][1:]) + "\n")
if l_gear[6][0] == "L":
outputFile.write("hands=" + l_gear[6][1:] + "\n")
elif (l_gear[6][0:3] == "T19" or l_gear[6][0:3] == "T20"):
outputFile.write("hands=" + l_gear[6][3:] + "\n")
else:
outputFile.write("hands=" + l_gear[6] + "\n")
outputFile.write("waist=" + (l_gear[7] if l_gear[7][0] != "L" else l_gear[7][1:]) + "\n")
if l_gear[8][0] == "L":
outputFile.write("legs=" + l_gear[8][1:] + "\n")
elif (l_gear[8][0:3] == "T19" or l_gear[8][0:3] == "T20"):
outputFile.write("legs=" + l_gear[8][3:] + "\n")
else:
outputFile.write("legs=" + l_gear[8] + "\n")
outputFile.write("feet=" + (l_gear[9] if l_gear[9][0] != "L" else l_gear[9][1:]) + "\n")
outputFile.write("finger1=" + (l_gear[10] if l_gear[10][0] != "L" else l_gear[10][1:]) + "\n")
outputFile.write("finger2=" + (l_gear[11] if l_gear[11][0] != "L" else l_gear[11][1:]) + "\n")
outputFile.write("trinket1=" + (l_gear[12] if l_gear[12][0] != "L" else l_gear[12][1:]) + "\n")
outputFile.write("trinket2=" + (l_gear[13] if l_gear[13][0] != "L" else l_gear[13][1:]) + "\n")
outputFile.write("main_hand=" + l_gear[14] + "\n")
if oh == 1:
outputFile.write("off_hand=" + l_gear[15] + "\n\n")
else:
outputFile.write("\n")
i_generatedProfiles += 1
c_profileid += 1
return ()
# Print a simc profile
def scpoutprofileset(oh):
global c_profileid
global i_generatedProfiles
result = checkUsability()
digits = len(str(c_profilemaxid))
mask = '00000000000000000000000000000000000'
maskedProfileID = (mask + str(c_profileid))[-digits:]
# output status every 5000 permutations, user should get at least a minor progress shown; also does not slow down
# computation very much
if int(maskedProfileID) % 5000 == 0:
print("Processed: " + str(maskedProfileID) + "/" + str(c_profilemaxid) + " (" + str(
round(100 * float(int(maskedProfileID) / int(c_profilemaxid)), 1)) + "%)")
if int(maskedProfileID) == c_profilemaxid:
print("Processed: " + str(maskedProfileID) + "/" + str(c_profilemaxid) + " (" + str(
round(100 * float(int(maskedProfileID) / int(c_profilemaxid)), 1)) + "%)")
if result != "":
printLog("Profile:" + str(maskedProfileID) + "/" + str(c_profilemaxid) + ' Warning, not printed:' + result)
else:
if not b_quiet:
print("Profile:" + str(maskedProfileID) + "/" + str(c_profilemaxid))
# generate first profile
if i_generatedProfiles == 0:
outputFile.write(c_class + "=" + getStringForProfile() + maskedProfileID + "\n")
outputFile.write("specialization=" + c_spec + "\n")
outputFile.write("race=" + c_race + "\n")
outputFile.write("level=" + c_level + "\n")
outputFile.write("role=" + c_role + "\n")
outputFile.write("position=" + c_position + "\n")
outputFile.write("talents=" + c_talents + "\n")
outputFile.write("artifact=" + c_artifact + "\n")
if c_crucible != "":
outputFile.write("crucible=" + c_crucible + "\n")
if c_potion != "":
outputFile.write("potion=" + c_potion + "\n")
if c_flask != "":
outputFile.write("flask=" + c_flask + "\n")
if c_food != "":
outputFile.write("food=" + c_food + "\n")
if c_augmentation != "":
outputFile.write("augmentation=" + c_augmentation + "\n")
if c_other != "":
outputFile.write(c_other + "\n")
if l_gear[0][0] == "L":
outputFile.write("head=" + l_gear[0][1:] + "\n")
elif (l_gear[0][0:3] == "T19" or l_gear[0][0:3] == "T20" or l_gear[0][0:3] == "T21"):
outputFile.write("head=" + l_gear[0][3:] + "\n")
else:
outputFile.write("head=" + l_gear[0] + "\n")
outputFile.write("neck=" + (l_gear[1] if l_gear[1][0] != "L" else l_gear[1][1:]) + "\n")
if l_gear[2][0] == "L":
outputFile.write("shoulders=" + l_gear[2][1:] + "\n")
elif (l_gear[2][0:3] == "T19" or l_gear[2][0:3] == "T20" or l_gear[2][0:3] == "T21"):
outputFile.write("shoulders=" + l_gear[2][3:] + "\n")
else:
outputFile.write("shoulders=" + l_gear[2] + "\n")
if l_gear[3][0] == "L":
outputFile.write("back=" + l_gear[3][1:] + "\n")
elif (l_gear[3][0:3] == "T19" or l_gear[3][0:3] == "T20" or l_gear[3][0:3] == "T21"):
outputFile.write("back=" + l_gear[3][3:] + "\n")
else:
outputFile.write("back=" + l_gear[3] + "\n")
if l_gear[4][0] == "L":
outputFile.write("chest=" + l_gear[4][1:] + "\n")
elif (l_gear[4][0:3] == "T19" or l_gear[4][0:3] == "T20" or l_gear[4][0:3] == "T21"):
outputFile.write("chest=" + l_gear[4][3:] + "\n")
else:
outputFile.write("chest=" + l_gear[4] + "\n")
outputFile.write("wrists=" + (l_gear[5] if l_gear[5][0] != "L" else l_gear[5][1:]) + "\n")
if l_gear[6][0] == "L":
outputFile.write("hands=" + l_gear[6][1:] + "\n")
elif (l_gear[6][0:3] == "T19" or l_gear[6][0:3] == "T20" or l_gear[6][0:3] == "T21"):
outputFile.write("hands=" + l_gear[6][3:] + "\n")
else:
outputFile.write("hands=" + l_gear[6] + "\n")
outputFile.write("waist=" + (l_gear[7] if l_gear[7][0] != "L" else l_gear[7][1:]) + "\n")
if l_gear[8][0] == "L":
outputFile.write("legs=" + l_gear[8][1:] + "\n")
elif (l_gear[8][0:3] == "T19" or l_gear[8][0:3] == "T20" or l_gear[8][0:3] == "T21"):
outputFile.write("legs=" + l_gear[8][3:] + "\n")
else:
outputFile.write("legs=" + l_gear[8] + "\n")
outputFile.write("feet=" + (l_gear[9] if l_gear[9][0] != "L" else l_gear[9][1:]) + "\n")
outputFile.write("finger1=" + (l_gear[10] if l_gear[10][0] != "L" else l_gear[10][1:]) + "\n")
outputFile.write("finger2=" + (l_gear[11] if l_gear[11][0] != "L" else l_gear[11][1:]) + "\n")
outputFile.write("trinket1=" + (l_gear[12] if l_gear[12][0] != "L" else l_gear[12][1:]) + "\n")
outputFile.write("trinket2=" + (l_gear[13] if l_gear[13][0] != "L" else l_gear[13][1:]) + "\n")
outputFile.write("main_hand=" + l_gear[14] + "\n")
if oh == 1:
outputFile.write("off_hand=" + l_gear[15] + "\n\n")
else:
outputFile.write("\n")
i_generatedProfiles += 1
# all other profiles
else:
pset_prefix = "profileset.\"" + c_profilename + "_" + maskedProfileID + "\"+="
outputFile.write("talents=" + c_talents + "\n")
if c_other != "":
outputFile.write(pset_prefix + c_other + "\n")
if l_gear[0][0] == "L":
outputFile.write(pset_prefix + "head=" + l_gear[0][1:] + "\n")
elif (l_gear[0][0:3] == "T19" or l_gear[8][0:3] == "T20" or l_gear[8][0:3] == "T21"):
outputFile.write(pset_prefix + "head=" + l_gear[0][3:] + "\n")
else:
outputFile.write(pset_prefix + "head=" + l_gear[0] + "\n")
outputFile.write(pset_prefix + "neck=" + (l_gear[1] if l_gear[1][0] != "L" else l_gear[1][1:]) + "\n")
if l_gear[2][0] == "L":
outputFile.write(pset_prefix + "shoulders=" + l_gear[2][1:] + "\n")
elif (l_gear[2][0:3] == "T19" or l_gear[2][0:3] == "T20" or l_gear[2][0:3] == "T21"):
outputFile.write(pset_prefix + "shoulders=" + l_gear[2][3:] + "\n")
else:
outputFile.write(pset_prefix + "shoulders=" + l_gear[2] + "\n")
if l_gear[3][0] == "L":
outputFile.write(pset_prefix + "back=" + l_gear[3][1:] + "\n")
elif (l_gear[3][0:3] == "T19" or l_gear[3][0:3] == "T20" or l_gear[3][0:3] == "T21"):
outputFile.write(pset_prefix + "back=" + l_gear[3][3:] + "\n")
else:
outputFile.write(pset_prefix + "back=" + l_gear[3] + "\n")
if l_gear[4][0] == "L":
outputFile.write(pset_prefix + "chest=" + l_gear[4][1:] + "\n")
elif (l_gear[4][0:3] == "T19" or l_gear[4][0:3] == "T20" or l_gear[4][0:3] == "T21"):
outputFile.write(pset_prefix + "chest=" + l_gear[4][3:] + "\n")
else:
outputFile.write(pset_prefix + "chest=" + l_gear[4] + "\n")
outputFile.write(pset_prefix + "wrists=" + (l_gear[5] if l_gear[5][0] != "L" else l_gear[5][1:]) + "\n")
if l_gear[6][0] == "L":
outputFile.write(pset_prefix + "hands=" + l_gear[6][1:] + "\n")
elif (l_gear[6][0:3] == "T19" or l_gear[6][0:3] == "T20" or l_gear[6][0:3] == "T21"):
outputFile.write(pset_prefix + "hands=" + l_gear[6][3:] + "\n")
else:
outputFile.write(pset_prefix + "hands=" + l_gear[6] + "\n")
outputFile.write(pset_prefix + "waist=" + (l_gear[7] if l_gear[7][0] != "L" else l_gear[7][1:]) + "\n")
if l_gear[8][0] == "L":
outputFile.write(pset_prefix + "legs=" + l_gear[8][1:] + "\n")
elif (l_gear[8][0:3] == "T19" or l_gear[8][0:3] == "T20" or l_gear[8][0:3] == "T21"):
outputFile.write(pset_prefix + "legs=" + l_gear[8][3:] + "\n")
else:
outputFile.write(pset_prefix + "legs=" + l_gear[8] + "\n")
outputFile.write(pset_prefix + "feet=" + (l_gear[9] if l_gear[9][0] != "L" else l_gear[9][1:]) + "\n")
outputFile.write(pset_prefix + "finger1=" + (l_gear[10] if l_gear[10][0] != "L" else l_gear[10][1:]) + "\n")
outputFile.write(pset_prefix + "finger2=" + (l_gear[11] if l_gear[11][0] != "L" else l_gear[11][1:]) + "\n")
outputFile.write(
pset_prefix + "trinket1=" + (l_gear[12] if l_gear[12][0] != "L" else l_gear[12][1:]) + "\n")
outputFile.write(
pset_prefix + "trinket2=" + (l_gear[13] if l_gear[13][0] != "L" else l_gear[13][1:]) + "\n")
outputFile.write(pset_prefix + "main_hand=" + l_gear[14] + "\n")
if oh == 1:
outputFile.write(pset_prefix + "off_hand=" + l_gear[15] + "\n\n")
else:
outputFile.write("\n")
i_generatedProfiles += 1
c_profileid += 1
return ()
# Manage command line parameters
# todo: include logic to split into smaller/larger files (default 50)
def handleCommandLine():
global inputFileName
global outputFileName
global legmin
global legmax
global b_quiet
global b_simcraft_enabled
global s_stage
global restart
global gemspermutation
# parameter-list, so they are "protected" if user enters wrong commandline
set_parameters = set()
set_parameters.add("-i")
set_parameters.add("-o")
set_parameters.add("-l")
set_parameters.add("-quiet")
set_parameters.add("-sim")
set_parameters.add("-gems")
for a in range(1, len(sys.argv)):
if sys.argv[a] == "-i":
inputFileName = sys.argv[a + 1]
if inputFileName not in set_parameters:
if os.path.isfile(inputFileName):
printLog("Input file changed to " + inputFileName)
else:
print("Error: Input file does not exist")
sys.exit(1)
else:
print("Error: No or invalid input file declared: " + inputFileName)
sys.exit(1)
if sys.argv[a] == "-o":
outputFileName = sys.argv[a + 1]
if outputFileName not in set_parameters:
printLog("Output file changed to " + outputFileName)
# if os.path.isfile(outputFileName):
# print("Error: Output file already exists")
# sys.exit(1)
else:
print("Error: No or invalid output file declared: " + outputFileName)
sys.exit(1)
if sys.argv[a] == "-l":
elements = sys.argv[a + 1].split(',')
# produces an error if <-l "" 2:2> was entered, what is the correct syntax?
# i handle this in settings.py
if elements:
handlePermutation(elements)
# number of leg
if sys.argv[a + 2][0] != "-":
legNb = sys.argv[a + 2].split(':')
legmin = int(legNb[0])
legmax = int(legNb[1])
printLog("Set legendary to " + str(legmin) + "/" + str(legmax))
if sys.argv[a] == "-quiet":
printLog("Quiet-Mode enabled")
b_quiet = 1
# if option -sim exists in commandline incl. stage1,2,3, it overwrites all values of settings.py
if sys.argv[a] == "-sim":
# check path of simc.exe
if not os.path.exists(settings.simc_path):
printLog("Error: Wrong path to simc.exe: " + str(settings.simc_path))
print("Error: Wrong path to simc.exe: " + str(settings.simc_path))
sys.exit(1)
else:
printLog("Path to simc.exe valid, proceeding...")
print("SimCraft-Mode enabled")
printLog("SimCraft-Mode enabled")
b_simcraft_enabled = True
# optional parameter to skip steps and continue at a certain point without deleting intermediate files:
# usage main.py -i ... -o ... -sim [stage1|stage2|stage3]
# staging is equivalent to the 3 iteration processes:
# - 1: mass processing with few iterations (default)
# - 2: picking best n and process these
# - 3: picking top n out of these
# it is essentially used to skip the most time consuming part, stage 1
# to test alterations and different outputs, e.g. using same gear within different scenarios
# (standard might be patchwerk, but what happens with this gear- and talentchoice in a helterskelter-szenario?)
if sys.argv[a + 1] != s_stage:
restart = True
else:
restart = False
s_stage = sys.argv[a + 1]
if s_stage in set_parameters:
printLog("Wrong parameter for -sim: " + str(s_stage))
print("Wrong parameter for ""-sim"" option: " + str(s_stage))
sys.exit(1)
if not s_stage:
printLog("Missing parameter for -sim: " + s_stage)
print("Missing parameter for ""-sim"" option: " + str(s_stage))
sys.exit(1)
if s_stage != "stage1" and s_stage != "stage2" and s_stage != "stage3":
printLog("Wrong Parameter for Stage: " + str(s_stage))
sys.exit(1)
if sys.argv[a] == "-gems":
gems = sys.argv[a + 1]
if gems not in set_parameters:
gemspermutation = True
handleGems(gems)
# returns target_error, iterations, elapsed_time_seconds for a given class_spec
def get_data(class_spec):
result = []
f = open(os.path.join(os.getcwd(), settings.analyzer_path, settings.analyzer_filename), "r")
file = json.load(f)
for variant in file[0]:
for p in variant["playerdata"]:
if p["specialization"] == class_spec:
for s in range(len(p["specdata"])):
item = (
variant["target_error"], p["specdata"][s]["iterations"],
p["specdata"][s]["elapsed_time_seconds"])
result.append(item)
return result
def cleanup():
printLog("Cleaning up")
if not os.path.exists(os.path.join(os.getcwd(), settings.result_subfolder)):
printLog("Result-subfolder does not exist: " + str(settings.result_subfolder) + ", creating it")
os.makedirs(settings.result_subfolder)
if os.path.exists(os.path.join(os.getcwd(), settings.subdir3)):
for root, dirs, files in os.walk(os.path.join(os.getcwd(), settings.subdir3)):
for file in files:
if file.endswith(".html"):
printLog("Moving file: " + str(file))
shutil.move(os.path.join(os.getcwd(), settings.subdir3, file),
os.path.join(os.getcwd(), settings.result_subfolder, file))
if os.path.exists(os.path.join(os.getcwd(), settings.subdir1)):
if settings.delete_temp_default or input(
"Do you want to remove subfolder: " + settings.subdir1 + "? (Press y to confirm): ") == "y":
printLog("Removing: " + settings.subdir1)
shutil.rmtree(settings.subdir1)
if os.path.exists(os.path.join(os.getcwd(), settings.subdir2)):
if settings.delete_temp_default or input(
"Do you want to remove subfolder: " + settings.subdir2 + "? (Press y to confirm): ") == "y":
shutil.rmtree(settings.subdir2)
printLog("Removing: " + settings.subdir2)
if os.path.exists(os.path.join(os.getcwd(), settings.subdir3)):
if settings.delete_temp_default or input(
"Do you want to remove subfolder: " + settings.subdir3 + "? (Press y to confirm): ") == "y":
shutil.rmtree(settings.subdir3)
printLog("Removing: " + settings.subdir3)
def validateSettings():
# validate amount of legendaries
if legmin > legmax or legmax > 3 or legmin > 3 or legmin < 0 or legmax < 0:
printLog("Error: Legmin: " + str(legmin) + ", Legmax: " + str(
legmax) + ". Please check settings.py for these parameters!")
sys.exit(0)
# validate tier-set
if (int(t19min) + int(t20min) + int(
t21min) > 6) or t19min < 0 or t19min > 6 or t20min < 0 or t20min > 6 or t21min < 0 or t21min > 6 or t19max < 0 or t19max > 6 or t20max < 0 or t20max > 6 or t21max < 0 or t21max > 6 or t19min > t19max or t20min > t20max or t21min > t21max:
printLog("Error: Wrong Tier-Set-Combination: T19: " + str(t19min) + "/" + str(t19max) + ", T20: " + str(
t20min) + "/" + str(t20max) + ", T21: " + str(t21min) + "/" + str(
t21max) + ". Please check settings.py for these parameters!")
sys.exit(0)
# use a "safe mode", overwriting the values
if settings.simc_safe_mode:
printLog("Using Safe Mode")
settings.simc_threads = 1
if b_simcraft_enabled:
if os.name == "nt":
if not settings.simc_path.endswith("simc.exe"):
printLog("simc.exe wrong or missing in settings.py path-variable, please edit it")
sys.exit(0)
if os.path.exists(os.path.join(os.getcwd(), settings.analyzer_path, settings.analyzer_filename)):
printLog("Analyzer-file found")
else:
printLog("Analyzer-file not found, make sure you have a complete AutoSimc-Package")
sys.exit(1)
if settings.default_error_rate_multiplier <= 0:
printLog("Wrong default_error_rate_multiplier: " + str(settings.default_error_rate_multiplier))
def generate_checksum_of_permutations():
hash_md5 = hashlib.sha3_256()
with open(settings.default_outputFileName, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
print(str(hash_md5.hexdigest()))
def get_Possible_Gem_Combinations(numberOfGems):
printLog("Creating Gem Combinations")
printLog("Number of Gems: " + str(numberOfGems))
l_gems = []
# 1 gem
if numberOfGems == 1:
for r in splitted_gems:
l_gems.append(gem_ids.get(r))
# 2 gems
if numberOfGems == 2:
for r in splitted_gems:
for s in splitted_gems:
if r < s:
l_gems.append(gem_ids.get(r) + "/" + gem_ids.get(s))
else:
l_gems.append(gem_ids.get(s) + "/" + gem_ids.get(r))
if numberOfGems == 3:
for r in splitted_gems:
for s in splitted_gems:
for t in splitted_gems:
p = [r, s, t]
p.sort()
l_gems.append(gem_ids.get(p[0]) + "/" + gem_ids.get(p[1]) + "/" + gem_ids.get(p[2]))
return l_gems
def getGemsFromItem(item):
a = item.split(",")
gems = []
for i in range(len(a)):
# look for gem_id-string in items
if a[i].startswith("gem_id"):
b, c = a[i].split("=")
gems = c.split("/")
# up to 3 possible gems
return gems
# gearlist contains a list of items, as in l_head
def permutateGemsInSlotGearList(slot_gearlist, slot):
printLog("Permutating slot_gearlist: " + str(slot_gearlist))
for item in slot_gearlist:
printLog(str(item))
a = item.split(",")
gems = []
for i in range(len(a)):
# look for gem_id-string in items
if a[i].startswith("gem_id"):
b, c = a[i].split("=")
gems = c.split("/")
# up to 3 possible gems
new_gems = get_Possible_Gem_Combinations(len(gems))
printLog("New Gems: " + str(new_gems))
new_item = ""
for n in range(len(a)):
if not str(a[n]).startswith("gem") and not a[n] == "":
new_item += "," + str(a[n])
while new_gems:
ins = new_item + ",gem_id=" + new_gems.pop()
if slot == 1:
if ins not in l_head:
l_head.insert(0, ins)
if slot == 2:
if ins not in l_neck:
l_neck.insert(0, ins)
if slot == 3:
if ins not in l_shoulders:
l_shoulders.insert(0, ins)
if slot == 4:
if ins not in l_chest:
l_chest.insert(0, ins)
if slot == 5:
if ins not in l_wrists:
l_wrists.insert(0, ins)
if slot == 6:
if ins not in l_hands:
l_hands.insert(0, ins)
if slot == 7:
if ins not in l_waist:
l_waist.insert(0, ins)
if slot == 8:
if ins not in l_legs:
l_legs.insert(0, ins)
if slot == 9:
if ins not in l_feet:
l_feet.insert(0, ins)
if slot == 10:
if ins not in l_finger1:
l_finger1.insert(0, ins)
if slot == 11:
if ins not in l_finger2:
l_finger2.insert(0, ins)
if slot == 12:
if ins not in l_trinket1:
l_trinket1.insert(0, ins)
if slot == 13:
if ins not in l_trinket2:
l_trinket2.insert(0, ins)
# look for gems-string in items
# todo implement
if a[i].startswith("gems"):
print(str(a[i]))
# add gems to the lists
# current template
## gems=150crit_150crit_150crit (not implemented yet)
## shoulder=,id=146666,bonus_id=3459/3530,gem_id=130220/130220/130220
def permutateGems():
printLog("Permutating Gems")
permutateGemsInSlotGearList(l_head, 1)
permutateGemsInSlotGearList(l_neck, 2)
permutateGemsInSlotGearList(l_shoulders, 3)
permutateGemsInSlotGearList(l_chest, 4)
permutateGemsInSlotGearList(l_wrists, 5)
permutateGemsInSlotGearList(l_hands, 6)
permutateGemsInSlotGearList(l_waist, 7)
permutateGemsInSlotGearList(l_legs, 8)
permutateGemsInSlotGearList(l_feet, 9)
permutateGemsInSlotGearList(l_finger1, 10)
permutateGemsInSlotGearList(l_finger2, 11)
permutateGemsInSlotGearList(l_trinket1, 12)
permutateGemsInSlotGearList(l_trinket2, 13)
# todo: add checks for missing headers, prio low
def permutate():
# Read input.txt to init vars
config = configparser.ConfigParser()
config.read(inputFileName, encoding='utf-8-sig')
profile = config['Profile']
gear = config['Gear']
# Read input.txt
# Profile
global c_profilename
c_profilename = profile['profilename']
global c_profileid
c_profileid = int(profile['profileid'])
global c_class
c_class = profile['class']
global c_race
c_race = profile['race']
global c_level
c_level = profile['level']
global c_spec
c_spec = profile['spec']
global c_role
c_role = profile['role']
global c_position
c_position = profile['position']
global c_talents
c_talents = profile['talents']
global c_artifact
c_artifact = profile['artifact']
global c_crucible
if config.has_option('Profile', 'crucible'):
c_crucible = profile['crucible']
else:
c_crucible = ""
global c_potion
if config.has_option('Profile', 'potion'):
c_potion = profile['potion']
else:
c_potion = ""
global c_flask
if config.has_option('Profile', 'flask'):
c_flask = profile['flask']
else:
c_flask = ""
global c_food
if config.has_option('Profile', 'food'):
c_food = profile['food']
else:
c_food = ""
global c_augmentation
if config.has_option('Profile', 'augmentation'):
c_augmentation = profile['augmentation']
else:
c_augmentation = ""
global c_other
c_other = profile['other']
# Gear
c_head = gear['head']
c_neck = gear['neck']
if config.has_option('Gear', 'shoulders'):
c_shoulders = gear['shoulders']
else:
c_shoulders = gear['shoulder']
c_back = gear['back']
c_chest = gear['chest']
if config.has_option('Gear', 'wrists'):
c_wrists = gear['wrists']
else:
c_wrists = gear['wrist']
c_hands = gear['hands']
c_waist = gear['waist']
c_legs = gear['legs']
c_feet = gear['feet']
c_finger1 = gear['finger1']
c_finger2 = gear['finger2']
c_trinket1 = gear['trinket1']
c_trinket2 = gear['trinket2']
c_main_hand = gear['main_hand']
if config.has_option('Gear', 'off_hand'):
c_off_hand = gear['off_hand']
else:
c_off_hand = ""
# Split vars to lists
global l_head
l_head = c_head.split('|')
global l_neck
l_neck = c_neck.split('|')
global l_shoulders
l_shoulders = c_shoulders.split('|')
global l_back
l_back = c_back.split('|')
global l_chest
l_chest = c_chest.split('|')
global l_wrists
l_wrists = c_wrists.split('|')
global l_hands
l_hands = c_hands.split('|')
global l_waist
l_waist = c_waist.split('|')
global l_legs
l_legs = c_legs.split('|')
global l_feet
l_feet = c_feet.split('|')
global l_finger1
l_finger1 = c_finger1.split('|')
global l_finger2
l_finger2 = c_finger2.split('|')
global l_trinket1
l_trinket1 = c_trinket1.split('|')
global l_trinket2
l_trinket2 = c_trinket2.split('|')
global l_main_hand
l_main_hand = c_main_hand.split('|')
global l_off_hand
l_off_hand = c_off_hand.split('|')
global l_talents
l_talents = c_talents.split('|')
# permutate talents
temp_talents = []
if settings.enable_talent_permutation:
for t in l_talents:
for a in range(1, 4):
for b in range(1, 4):
for c in range(1, 4):
for d in range(1, 4):
for e in range(1, 4):
for f in range(1, 4):
for g in range(1, 4):
temp_talent = ""
if settings.permutate_row1:
temp_talent = str(a)
else:
temp_talent = str(t[0])
if settings.permutate_row2:
temp_talent += str(b)
else:
temp_talent += str(t[1])
if settings.permutate_row3:
temp_talent += str(c)
else:
temp_talent += str(t[2])
if settings.permutate_row4:
temp_talent += str(d)
else:
temp_talent += str(t[3])
if settings.permutate_row5:
temp_talent += str(e)
else:
temp_talent += str(t[4])
if settings.permutate_row6:
temp_talent += str(f)
else:
temp_talent += str(t[5])
if settings.permutate_row7:
temp_talent += str(g)
else:
temp_talent += str(t[6])
if temp_talent not in temp_talents:
temp_talents.append(temp_talent)
for t in temp_talents:
if t not in l_talents:
l_talents.append(t)
# add gem-permutations
if gemspermutation:
permutateGems()
# better handle rings and trinket-combinations
# should now be deterministic, previous versions generated a random order and numbering
for a in l_finger2:
if l_finger1.count(a) == 0:
l_finger1.append(a)
for b in l_trinket2:
if l_trinket1.count(b) == 0: