/
main.go
1793 lines (1636 loc) · 46.2 KB
/
main.go
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
package main
import (
"bufio"
"bytes"
"compress/gzip"
"compress/zlib"
"encoding/base64"
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math"
"math/rand"
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
)
var referencesim = "https://gcsim.app/viewer/share/BGznqjs62S9w8qxpxPu7w" //link to the gcsim that gives rotation, er reqs and optimization priority. actually no er reqs unless user wants, instead, let them use their er and set infinite energy.
//var chars = make([]Character, 4);
var artifarmtime = 126 //how long it should simulate farming artis, set as number of artifacts farmed. 20 resin ~= 1.07 artifacts.
var artifarmsims = 30 //default: -1, which will be 100000/artifarmtime. set it to something else if desired. nvm 30 is fine lol
var domains []string
var simspertest = 100000 //iterations to run gcsim at when testing dps gain from upgrades.
var godatafile = "GOdata.txt" //filename of the GO data that will be used for weapons, current artifacts, and optimization settings besides ER. When go adds ability to optimize for x*output1 + y*output2, the reference sim will be used to determine optimization target.
var good string
var domstring = ""
var optiorder = []string{"ph0", "ph1", "ph2", "ph3"} //the order in which to optimize the characters
var manualOverride = []string{"", "", "", ""}
var optifor = []string{"", "", "", ""} //chars to not optimize artis for
var team = []string{"", "", "", ""}
var dbconfig = ""
var mode6 = 6
var mode85 = false
var optiall = false
var justgenartis = false
var artisonly = false
func main() {
flag.IntVar(&simspertest, "i", 10000, "sim iterations per test")
flag.IntVar(&artifarmsims, "a", 30, "how many artifact trials to do")
flag.IntVar(&artifarmtime, "ft", 126, "how many artifacts to farm")
flag.BoolVar(&optiall, "all", false, "reoptimize artifacts on all characters")
flag.IntVar(&mode6, "tlmin", 6, "bring talents to a certain level")
flag.BoolVar(&mode85, "85", false, "level chars to 85 before 90")
flag.BoolVar(&justgenartis, "artigen", false, "just generate artifact jsons")
flag.BoolVar(&artisonly, "onlyartis", false, "only test artifacts")
teamc := ""
flag.StringVar(&teamc, "team", "", "the team to test")
flag.StringVar(&referencesim, "url", "", "your simulation")
flag.StringVar(&domstring, "d", "", "domains to farm")
//flag.StringVar(&manualOverride, "mo", "", "override which artis to sim the result sims with, used when changing sets")
//var na = ""
//flag.StringVar(&na, "na", "", "chars to skip optimizing for")
flag.Parse()
//noartis = strings.Split(na, ",")
team = strings.Split(teamc, ",")
good2, err2 := os.ReadFile(godatafile)
good = string(good2)
if team[0] != "" {
dbconfig = makeConfig()
it := "iteration=" + strconv.Itoa(simspertest)
dbconfig = reIter.ReplaceAllString(dbconfig, it)
dbconfig = reWorkers.ReplaceAllString(dbconfig, "workers=30")
}
if artifarmsims == -1 {
artifarmsims = 10000 / artifarmtime
}
if domstring == "" {
//refsimdomains
domains = []string{""}
} else {
//domains = strings.Split(domstring, ",")
//processdomstring()
}
time.Now().UnixNano()
rand.Seed(42)
err := run()
if err != nil || err2 != nil {
fmt.Printf("Error encountered, ending script: %+v\n", err2)
}
fmt.Print("\ntesting complete (press enter to exit)")
bufio.NewReader(os.Stdin).ReadBytes('\n')
}
type DBData struct {
Config string `json:"config"`
DPS float64 `json:"dps"`
ViewerKey string `json:"viewer_key"`
}
func makeConfig() string {
return personalizeConfig(getConfig())
}
func getConfig() string {
//fetch from: https://viewer.gcsim.workers.dev/gcsimdb
var data []DBData
getJson("https://viewer.gcsim.workers.dev/gcsimdb", &data)
for _, v := range data {
match := true
for _, c := range team {
if !strings.Contains(v.Config, c) {
match = false
break
}
}
if match {
return v.Config
}
}
fmt.Printf("no gcsim db entry found for %v", team)
return ""
}
func personalizeConfig(config string) string {
if justgenartis {
return config
}
lines := strings.Split(config, "\n")
for i := range lines { //remove all set and stats lines
if strings.Contains(lines[i], "char lvl") || strings.Contains(lines[i], "add set") {
lines[i] = ""
} else if strings.Contains(lines[i], "add weapon") || strings.Contains(lines[i], "add stats") {
lines[i] = ""
}
}
lines = append(lines, "energy every interval=69,420 amount=100;")
for i := range team {
charinfo := good[strings.Index(good, "key\":\""+GOchars[getCharID(team[i])]):]
charinfo = charinfo[strings.Index(charinfo, "level")+1:]
lvl := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")]
//0 20 1 40 2 50 3 60 4 70 5 80 6 90
charinfo = charinfo[strings.Index(charinfo, "ascension")+1:]
maxlvl, _ := strconv.Atoi(charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")])
maxlvl = maxlvl*10 + 30
if maxlvl == 30 {
maxlvl = 20
}
charinfo = charinfo[strings.Index(charinfo, "talent")+1:]
charinfo = charinfo[strings.Index(charinfo, "auto")+1:]
aa := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")]
charinfo = charinfo[strings.Index(charinfo, "skill")+1:]
e := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")]
charinfo = charinfo[strings.Index(charinfo, "burst")+1:]
q := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, "}")]
charinfo = charinfo[strings.Index(charinfo, "constellation")+1:]
c := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")]
for j := range lines { //we do this so that the characters are declared in the right order, otherwise sim orders them based on action list which messes things up
if lines[j] == "" {
lines[j] = team[i] + " char lvl=" + lvl + "/" + strconv.Itoa(maxlvl) + " cons=" + c + " talent=" + aa + "," + e + "," + q + ";"
break
}
}
artisets := []string{"", "", "", "", ""}
ascount := []int{0, 0, 0, 0, 0}
ttlsubs := newsubs()
for j := 0; j < 5; j++ {
charinfo = charinfo[strings.Index(charinfo, "location\":\""+GOchars[getCharID(team[i])])-250:]
if !strings.Contains(charinfo[250:], "weapons") { //strings.Index(charinfo, ",")-1 < 0 {
break //this means no more artis found
}
//fmt.Printf("%v\n", charinfo[:300])
charinfo = charinfo[strings.Index(charinfo, "setKey")+1:]
set := charinfo[strings.Index(charinfo, ":")+2 : strings.Index(charinfo, ",")-1]
for k, s := range artisets {
if s == set {
ascount[k]++
break
} else if s == "" {
artisets[k] = set
ascount[k]++
break
}
}
//this basically assumes mainstats for lvl 20 atm
charinfo = charinfo[strings.Index(charinfo, "mainStatKey")+1:]
msk := charinfo[strings.Index(charinfo, ":")+2 : strings.Index(charinfo, ",")-1]
ttlsubs[getStatID(msk)] += msv[getStatID(msk)]
for k := 0; k < 4; k++ {
charinfo = charinfo[strings.Index(charinfo, "key")+1:]
ssk := charinfo[strings.Index(charinfo, ":")+2 : strings.Index(charinfo, ",")-1]
if ssk == "" {
continue
}
charinfo = charinfo[strings.Index(charinfo, "value")+1:]
ssv := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, "}")]
ssvf64, _ := strconv.ParseFloat(ssv, 64)
ttlsubs[getStatID(ssk)] += ssvf64 / float64(ispct[getStatID(ssk)])
}
charinfo = charinfo[strings.Index(charinfo, "lock")+1:]
}
lines = append(lines, team[i]+" add stats "+torolls(ttlsubs)+";")
for j := range ascount {
if ascount[j] >= 2 {
additional := ""
if artisets[j] == "HuskOfOpulentDreams" {
additional = " +params=[stacks=4]"
}
count := "2"
if ascount[j] >= 4 {
count = "4"
}
lines = append(lines, team[i]+" add set=\""+strings.ToLower(artisets[j])+"\" count="+count+additional+";")
}
}
//purposely avoid filtering to only the weapon section here, so that it errors if theres another arti with this location
charinfo = charinfo[strings.Index(charinfo, "location\":\""+GOchars[getCharID(team[i])])-100:]
charinfo = charinfo[strings.Index(charinfo, "key")+1:]
wep := charinfo[strings.Index(charinfo, ":")+2 : strings.Index(charinfo, ",")-1]
charinfo = charinfo[strings.Index(charinfo, "level")+1:]
lvl = charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")]
//0 20 1 40 2 50 3 60 4 70 5 80 6 90
charinfo = charinfo[strings.Index(charinfo, "ascension")+1:]
maxlvl, _ = strconv.Atoi(charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")])
maxlvl = maxlvl*10 + 30
if maxlvl == 30 {
maxlvl = 20
}
charinfo = charinfo[strings.Index(charinfo, "refinement")+1:]
r := charinfo[strings.Index(charinfo, ":")+1 : strings.Index(charinfo, ",")]
additional := ""
if wep == "SerpentSpine" {
additional = " +params=[stacks=5]"
}
lines = append(lines, team[i]+" add weapon=\""+strings.ToLower(wep)+"\" refine="+r+" lvl="+lvl+"/"+strconv.Itoa(maxlvl)+additional+";")
}
return strings.Join(lines, "\n")
}
var myClient = &http.Client{Timeout: 10 * time.Second}
func getJson(url string, target interface{}) error {
r, err := myClient.Get(url)
if err != nil {
return err
}
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(target)
}
func run() error {
if true {
//download nightly cmd line build
//https://github.com/genshinsim/gcsim/releases/download/nightly/gcsim.exe
//err := download("./gcsim.exe", "https://github.com/genshinsim/gcsim/releases/download/nightly/gcsim.exe")
err := download("./gcsim.exe", "https://github.com/genshinsim/gcsim/releases/latest/download/gcsim.exe")
if err != nil {
return errors.Wrap(err, "")
}
}
if referencesim == "" && dbconfig == "" {
return errors.New("please input either your team with -team or your simulation with -url!")
}
//make a tmp folder if it doesn't exist
if _, err := os.Stat("./tmp"); !os.IsNotExist(err) {
//fmt.Println("tmp folder already exists, deleting...")
// path/to/whatever exists
os.RemoveAll("./tmp/")
}
os.Mkdir("./tmp", 0755)
var data jsondata
if dbconfig == "" {
data = readURL(referencesim)
} else {
data = runSim(dbconfig)
}
fmt.Println("running tests...")
//get baseline result
baseline := runTest(test{"baseline", []int{0}}, data.Config, data)
fmt.Print("\n")
printResult(baseline, baseline)
//generate necessary tests
tests := getTests(data)
//run and print the tests (simultaneously, so that users can see data gradually coming in)
for _, t := range tests {
printResult(runTest(t, data.Config, data), baseline)
}
return nil
}
func processdomstring() { //this is ugly
domains = strings.Split(domstring, ",")
for i := range domains {
if strings.Contains(domains[i], "(") {
doartisfor := domains[i][strings.Index(domains[i], "(")+1 : len(domains[i])-1]
domains[i] = domains[i][:strings.Index(domains[i], "(")]
settings := ""
if strings.Contains(doartisfor, "|") {
settings = doartisfor[strings.Index(doartisfor, "|")+1:]
doartisfor = doartisfor[:strings.Index(doartisfor, "|")]
}
manualOverride[i] = settings
optifor[i] = doartisfor
}
if optiall {
optifor[i] = optiorder[i]
}
}
}
func getTests(data jsondata) (tt []test) { //in future, auto skip tests of talents that are not used in the config
tests := make([]test, 0)
for i, c := range data.Characters { //should split this into functions
//add level tests
newlevel := (c.Level/10 + 1) * 10
if newlevel < 40 && newlevel != 20 {
newlevel += 10
}
newmax := newlevel + 10
if newmax < 40 {
newmax = 40 //could just do this with math.max, but it require floats for some reason
}
if newlevel >= 90 {
newlevel = 90
if mode85 && c.Level < 85 {
newlevel = 85
}
}
//fmt.Printf("%v", c)
if c.Level < 90 && c.Level != c.MaxLvl { //levelup test
tests = append(tests, test{"level", []int{i, newlevel, c.MaxLvl}})
} else if c.Level < 90 { //levelup and ascension test
newmax -= 10
tests = append(tests, test{"level", []int{i, newlevel, newmax}})
newlevel -= 10
if newlevel == 75 {
newlevel += 5
}
}
if c.MaxLvl < 90 { //ascension test
tests = append(tests, test{"level", []int{i, newlevel, newmax}})
}
//add talent tests
talents := []int{c.Talents.Attack, c.Talents.Skill, c.Talents.Burst}
for j, t := range talents {
if t == 10 {
continue
}
//talent maxlevel reqs: 2 50, 3/4 60, 5/6 70, 7/8 80, 9/10 90
lvlneed := 10*(t/2) + 50
if c.MaxLvl < lvlneed { //talent test that requires ascension
tests = append(tests, test{"talent", []int{i, j, t + 1, 1, newmax - 10, newmax}})
} else if c.MaxLvl >= 70 && t < mode6 && mode6 != 0 { //new: upgrade talents below 6 to 6 if possible, because 1->2 is too small to accurately say anything
tests = append(tests, test{"talent", []int{i, j, mode6, 0, -2, -2}})
} else { //talent test without ascension
tests = append(tests, test{"talent", []int{i, j, t + 1, 0, -2, -2}})
}
}
//add weapon tests
newlevel = (c.Weapon.Level/10 + 1) * 10
if newlevel < 40 && newlevel != 20 {
newlevel += 10
}
newmax = newlevel + 10
if newmax < 40 {
newmax = 40 //could just do this with math.max, but it require floats for some reason
}
if newlevel > 90 {
newlevel = 90
}
if c.Weapon.Level < 90 && c.Weapon.Level != c.Weapon.MaxLvl { //levelup test
tests = append(tests, test{"weapon", []int{i, rarity(c.Weapon.Name), newlevel, c.Weapon.MaxLvl}})
} else if c.Weapon.Level < 90 { //levelup and ascension test
newmax -= 10
tests = append(tests, test{"weapon", []int{i, rarity(c.Weapon.Name), newlevel, newmax}})
newlevel -= 10
if newlevel == 30 {
newlevel -= 10
}
}
if c.Weapon.MaxLvl < 90 { //ascension test
tests = append(tests, test{"weapon", []int{i, rarity(c.Weapon.Name), newlevel, newmax}})
}
//add artifact test
//tests = append(tests, test{"artifact", []int{i}})
}
//if only artis, remove all the tests above
if artisonly {
tests = make([]test, 0)
}
//artifact tests
makeOptiOrder(data) //generate the order in which to optimize the chars
processdomstring()
if domains[0] == "" { //if the user didnt specify, farm the sim domains
//todo
} else {
for i, d := range domains {
tests = append(tests, test{"artifact", []int{domainid(d), i}})
}
}
return tests
}
func makeOptiOrder(data jsondata) { //sort the chars by dps in refsim to determine optimization order
dps := []float64{-1.0, -1.0, -1.0, -1.0}
for i := range data.CharDPS { //sort the dps's... right now using dps vs primary target, should use their ttl dps
for j := range dps {
if data.CharDPS[i].DPS1.Mean > dps[j] {
for k := 3; k > j; k-- {
dps[k] = dps[k-1]
}
dps[j] = data.CharDPS[i].DPS1.Mean
break
}
}
}
for i, c := range data.Characters { //now sort the names accordingly. could probably do both at once with better code
for j := range dps {
if data.CharDPS[i].DPS1.Mean == dps[j] {
optiorder[j] = c.Name
}
}
}
}
func domainid(dom string) int { //returns the internal id for an artifact's domain
id := -1
for i, a := range artiabbrs {
if dom == a {
id = i
}
}
if id == -1 {
fmt.Printf("no domain found for %v", dom)
return -1
}
id = (id / 2) * 2 //if it's odd, subtract one
return id
}
func rarity(wep string) int {
jsn, err := os.ReadFile("./wep/" + wep + ".json")
if err != nil {
fmt.Println(err)
}
data := wepjson{}
err = json.Unmarshal(jsn, &data)
if err != nil {
fmt.Println(err)
}
data.Rarity, err = strconv.Atoi(data.Raritys)
if data.Rarity < 3 {
data.Rarity = 3
}
return data.Rarity
}
func printResult(res, base result) {
info := res.info + ":"
dps := "DPS: " + fmt.Sprintf("%.0f", res.DPS)
if res.resin == -1 {
fmt.Printf("%-40v%-30v\n", info, dps)
return
}
dps += " (+" + fmt.Sprintf("%.0f", res.DPS-base.DPS) + ")"
resin := "Resin: " + fmt.Sprintf("%.0f", res.resin)
dpsresin := "DPS/Resin: " + fmt.Sprintf("%.2f", math.Max((res.DPS-base.DPS)/res.resin, 0.0))
fmt.Printf("%-40v%-30v%-30v%-24v\n", info, dps, resin, dpsresin)
}
func download(path string, url string) error {
//remove if exists
if _, err := os.Stat(path); !os.IsNotExist(err) {
fmt.Printf("%v already exists, deleting...\n", path)
// path/to/whatever exists
os.RemoveAll(path)
}
fmt.Printf("Downloading: %v\n", url)
// Get the data
resp, err := http.Get(url)
if err != nil {
return errors.Wrap(err, "")
}
defer resp.Body.Close()
// Create the file
out, err := os.Create(path)
if err != nil {
return errors.Wrap(err, "")
}
defer out.Close()
// Write the body to file
_, err = io.Copy(out, resp.Body)
return errors.Wrap(err, "")
}
type TalentDetail struct {
Attack int `json:"attack"`
Skill int `json:"skill"`
Burst int `json:"burst"`
}
type jsondata struct {
Config string `json:"config_file"`
Characters []struct {
Name string `json:"name"`
Level int `json:"level"`
MaxLvl int `json:"max_level"`
Cons int `json:"cons"`
Weapon struct {
Name string `json:"name"`
Refine int `json:"refine"`
Level int `json:"level"`
MaxLvl int `json:"max_level"`
} `json:"weapon"`
Stats []float64 `json:"stats"`
Talents TalentDetail `json:"talents"`
} `json:"char_details"`
DPSraw FloatResult `json:"dps"`
NumTarget int `json:"target_count"`
CharDPS []struct {
DPS1 FloatResult `json:"1"`
DPS2 FloatResult `json:"2"`
DPS3 FloatResult `json:"3"`
} `json:"damage_by_char_by_targets"`
DPS float64
}
type FloatResult struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
Mean float64 `json:"mean"`
SD float64 `json:"sd"`
}
type wepjson struct {
Raritys string `json:"rarity"`
Rarity int
}
type result struct {
info string
DPS float64
resin float64
}
type test struct {
typ string
params []int
}
const PurpleBookXP = 20000
var reIter = regexp.MustCompile(`iteration=(\d+)`)
var reWorkers = regexp.MustCompile(`workers=(\d+)`)
type blah struct {
Data string `json:"data"`
}
func readURL(url string) (data2 jsondata) {
spaceClient := http.Client{
Timeout: time.Second * 2, // Timeout after 2 seconds
}
urlreal := "https://viewer.gcsim.workers.dev/" + url[strings.LastIndex(url, "/"):]
req, err := http.NewRequest(http.MethodGet, urlreal, nil)
if err != nil {
log.Fatal(err)
}
res, getErr := spaceClient.Do(req)
if getErr != nil {
log.Fatal(getErr)
}
if res.Body != nil {
defer res.Body.Close()
}
body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
log.Fatal(readErr)
}
idk := blah{}
data := jsondata{}
err = json.Unmarshal(body, &idk)
b64z := idk.Data
z, err4 := base64.StdEncoding.DecodeString(b64z)
if err4 != nil {
fmt.Println(err4)
return
}
r, err2 := zlib.NewReader(bytes.NewReader(z))
if err2 != nil {
r, err2 = gzip.NewReader(bytes.NewReader(z))
if err2 != nil {
fmt.Println(err2)
return
}
}
resul, err3 := ioutil.ReadAll(r)
if err3 != nil {
fmt.Println(err3)
return
}
err = json.Unmarshal(resul, &data)
data.DPS = data.DPSraw.Mean
if err != nil {
fmt.Println(err)
return
}
//fix the iterations
it := "iteration=" + strconv.Itoa(simspertest)
data.Config = reIter.ReplaceAllString(data.Config, it)
data.Config = reWorkers.ReplaceAllString(data.Config, "workers=30")
return data
}
func runTest(t test, config string, baseline jsondata) (res result) {
var simdata jsondata
switch t.typ {
case "baseline":
simdata = runSim(config)
case "level":
simdata = runSim(runLevelTest(t, config))
case "talent":
//fmt.Printf("%vt%v", t, config)
simdata = runSim(runTalentTest(t, config))
case "weapon":
simdata = runSim(runWeaponTest(t, config))
case "artifact":
simdata = runSim(runArtifactTest(t, config))
default:
fmt.Printf("invalid test type %v??", t.typ)
}
return generateResult(t, simdata, baseline)
}
func generateResult(t test, sd jsondata, base jsondata) (res2 result) {
return result{desc(t, sd), sd.DPS, resin(t, base)}
}
func desc(t test, sd jsondata) (dsc string) {
switch t.typ {
case "baseline":
return "current"
case "level":
return sd.Characters[t.params[0]].Name + " to " + strconv.Itoa(t.params[1]) + "/" + strconv.Itoa(t.params[2])
case "talent":
talent := "aa"
if t.params[1] == 1 {
talent = "e"
} else if t.params[1] == 2 {
talent = "q"
}
ascension := ""
if t.params[3] == 1 {
ascension = " (requires ascension)"
}
return sd.Characters[t.params[0]].Name + " " + talent + " to " + strconv.Itoa(t.params[2]) + ascension
case "weapon":
if sd.Characters[t.params[0]].Weapon.Name == "thrillingtalesofdragonslayers" { //ttds is too long and breaks the formatting, so we need a (ugly) manual override :derpfei:
return sd.Characters[t.params[0]].Name + "'s ttds to " + strconv.Itoa(t.params[2]) + "/" + strconv.Itoa(t.params[3])
}
return sd.Characters[t.params[0]].Name + "'s " + sd.Characters[t.params[0]].Weapon.Name + " to " + strconv.Itoa(t.params[2]) + "/" + strconv.Itoa(t.params[3])
case "artifact":
//return sd.Characters[t.params[0]].Name + " artifacts"
return "farm " + artiabbrs[t.params[0]] + " domain for " + fmt.Sprintf("%.1f", float64(artifarmtime)/(9.0*1.07)) + " days"
default:
fmt.Printf("invalid test type %v??", t.typ)
}
return ""
}
var talentmora = []int{125, 175, 250, 300, 375, 1200, 2600, 4500, 7000}
var talentbks = []int{3, 6, 12, 18, 27, 36, 54, 108, 144}
type materials struct {
mora int
books float64 //measured in purple books
bossmats int //for example, hoarfrost core. Currently we assume gemstones aren't important/worth counting resin for because of azoth dust, but in the future we could have options instead of assumptions.
talentbooks int //measured in teachings
weaponmats int //measured in the lowest level
artifacts int
}
var wpmats = [][]int{{2, 2 * 3, 4 * 3, 2 * 9, 4 * 9, 3 * 27}, {3, 3 * 3, 6 * 3, 3 * 9, 6 * 9, 4 * 27}, {5, 5 * 3, 9 * 3, 5 * 9, 9 * 9, 6 * 27}}
var wpmora = [][]int{{5, 10, 15, 20, 25, 30}, {5, 15, 20, 30, 35, 45}, {10, 20, 30, 45, 55, 65}}
func resin(t test, sd jsondata) (rsn float64) {
mats := materials{0, 0.0, 0, 0, 0, 0}
switch t.typ {
case "baseline":
return -1
case "level":
mats.books += xptolvl(sd.Characters[t.params[0]].Level-1, t.params[1]-1) / PurpleBookXP
mats.mora = int(math.Floor(mats.books/5.0)) * PurpleBookXP
if t.params[2] != sd.Characters[t.params[0]].MaxLvl { //if we ascended
mats.mora += 20000 * (t.params[2] - 30) / 10
mats.bossmats += int(math.Floor((float64(t.params[2])-30.0)/10.0*(float64(t.params[2])-30.0)/10.0/2.0)) + int(math.Max(0, float64(t.params[2])-80.0)/5.0)
}
case "talent":
if t.params[2] == mode6 && t.params[3] == 0 { //this whole function is ugly, but this part especially. functionality first tho
talents := []int{sd.Characters[t.params[0]].Talents.Attack, sd.Characters[t.params[0]].Talents.Skill, sd.Characters[t.params[0]].Talents.Burst}
for i := talents[t.params[1]] + 1; i <= mode6; i++ {
mats.mora += talentmora[i-2] * 100
mats.talentbooks += talentbks[i-2]
}
} else {
mats.mora += talentmora[t.params[2]-2] * 100
mats.talentbooks += talentbks[t.params[2]-2]
if t.params[3] == 1 {
mats.books += xptolvl(sd.Characters[t.params[0]].Level-1, t.params[4]-1) / PurpleBookXP
mats.mora += int(math.Floor(mats.books/5.0)) * PurpleBookXP
mats.mora += 20000 * (t.params[5] - 30) / 10
mats.bossmats += int(math.Floor((float64(t.params[5])-30.0)/10.0*(float64(t.params[5])-30.0)/10.0/2.0)) + int(math.Max(0, float64(t.params[5])-80.0)/5.0)
}
}
case "weapon":
mats.mora += (wpexp[t.params[1]-3][t.params[2]-1] - wpexp[t.params[1]-3][sd.Characters[t.params[0]].Weapon.Level-1]) / 10
if t.params[3] != sd.Characters[t.params[0]].Weapon.MaxLvl { //if we ascended
mats.weaponmats += wpmats[t.params[1]-3][(t.params[3]-30)/10-1]
mats.mora += wpmora[t.params[1]-3][(t.params[3]-30)/10-1]
}
case "artifact":
mats.artifacts += artifarmtime
default:
fmt.Printf("invalid test type %v??", t.typ)
}
return resinformats(mats)
}
func xptolvl(l1 int, l2 int) (xp float64) {
return float64(crexp[l2] - crexp[l1])
}
var resinrates = []float64{ //1 resin = x of this
60000 / 20, //mora
122500.0 / PurpleBookXP / 20.0, //xp books
255.0 / 4000.0, //bossmats
(2.2 + 1.97*3.0 + 0.23*9.0) / 20.0, //talent books
(2.2 + 2.4*3.0 + 0.64*9.0 + 0.07*27.0) / 20.0, //weapon mats
107.0 / 2000.0, //artifacts
}
func resinformats(mats materials) (rsn float64) {
resin := float64(mats.mora) / resinrates[0]
resin += mats.books / resinrates[1]
resin += float64(mats.bossmats) / resinrates[2]
resin += float64(mats.talentbooks) / resinrates[3]
resin += float64(mats.weaponmats) / resinrates[4]
resin += float64(mats.artifacts) / resinrates[5]
return resin
}
//these 3 test functions below should probably go in a diff file
func runLevelTest(t test, config string) (c string) { //params for level test: 0: charid 1: new level 2: new max level
lines := strings.Split(config, "\n")
count := 0
curline := -1
//fmt.Printf("\n\n%v", config)
for count <= t.params[0] {
curline++
if strings.Contains(lines[curline], "char lvl") {
count++
}
}
newline := lines[curline][0 : strings.Index(lines[curline], "lvl")+4]
newline += strconv.Itoa(t.params[1]) + "/" + strconv.Itoa(t.params[2])
newline += lines[curline][strings.Index(lines[curline], " cons"):]
lines[curline] = newline
return strings.Join(lines, "\n")
}
func runTalentTest(t test, config string) (c string) { //params for talent test: 0: charid 1: talent id (aa/e/q) 2: new level 3: requires ascension (0 or 1) 4: new level (if needed) 5: new max level (if needed)
cfg := config
if t.params[3] == 1 { //increase the level if upgrading the talent requires ascension
cfg = runLevelTest(test{"thisshouldntmatter", []int{t.params[0], t.params[4], t.params[5]}}, config)
}
lines := strings.Split(cfg, "\n")
count := 0
curline := -1
for count <= t.params[0] {
curline++
if strings.Contains(lines[curline], "char lvl") {
count++
}
}
//10 makes this really annoying because it's two chars instead of one
start := strings.Index(lines[curline], "talent=") + 6
end := strings.Index(lines[curline], ",")
if t.params[1] >= 1 { // upgrading e talent
start = end
end = start + strings.Index(lines[curline][start+1:], ",") + 1
}
if t.params[1] == 2 { //upgrading q talent
start = end
end = strings.Index(lines[curline], ";")
}
newline := lines[curline][:start+1]
newline += strconv.Itoa(t.params[2])
newline += lines[curline][end:]
lines[curline] = newline
return strings.Join(lines, "\n")
}
func runWeaponTest(t test, config string) (c string) { //params for weapon test: 0: charid 1: weapon *s 2: new level 3: new max level
lines := strings.Split(config, "\n")
count := 0
curline := -1
for count <= t.params[0] {
curline++
if strings.Contains(lines[curline], "refine=") {
count++
}
}
newline := lines[curline][0 : strings.Index(lines[curline], "lvl")+4]
newline += strconv.Itoa(t.params[2]) + "/" + strconv.Itoa(t.params[3]) + ";"
lines[curline] = newline
return strings.Join(lines, "\n")
}
type subrolls struct {
Atk float64
AtkP float64
HP float64
HPP float64
Def float64
DefP float64
EM float64
ER float64
CR float64
CD float64
}
func runArtifactTest(t test, config string) (c string) { //params for artifact test: 0: domainid, 1: position in domain q
lines := strings.Split(config, "\n")
for i := range lines { //remove all set and stats lines
if strings.Contains(lines[i], "add stats") { //|| strings.Contains(l, "add set") {
skip := true //this is really ugly. it's to skip deleting stat lines of chars we wont be optimizing, but it should probably be cleaner lol
if strings.Contains(optifor[t.params[1]], lines[i][:strings.Index(lines[i], " ")-1]) || optifor[t.params[1]] == "" {
skip = false
}
if skip {
continue
}
lines[i] = ""
} else if strings.Contains(lines[i], "add set") {
if strings.Contains(manualOverride[t.params[1]], lines[i][:strings.Index(lines[i], " ")-1]) {
lines[i] = ""
}
}
}
farmJSONs(t.params[0])
for i := range optiorder {
skip := true //this is really ugly. it's to skip deleting stat lines of chars we wont be optimizing, but it should probably be cleaner lol
if strings.Contains(optifor[t.params[1]], optiorder[i]) || optifor[t.params[1]] == "" {
skip = false
}
if skip {
continue
}
lines = append(lines, makeNewLines(i, t.params[1]))
}
return strings.Join(lines, "\n")
}
func makeNewLines(c, d int) string {
runAutoGO(c)
return parseAGresults(c, d)
}
func runAutoGO(c int) {
makeTemplate(c)
cmd := exec.Command("cmd", "/C", "npm run start")
//cmd := exec.Command("npm run start")
cmd.Dir = "./AutoGO"
err := cmd.Run()
//fmt.Printf("%v", out)
if err != nil {
fmt.Printf("%v", err)
}
//bufio.NewReader(os.Stdin).ReadBytes('\n') //wait for the user to signify autogo is done by pressing enter
}
func makeTemplate(c int) {
//exec.Command("node AutoGO/src/createTemplate.js " + GOchars[getCharID(optiorder[c])] + " tmpl").Output()
cmd := exec.Command("cmd", "/C", "node src/createTemplate.js "+GOchars[getCharID(optiorder[c])]+" tmpl good/gojson0.json")
//cmd := exec.Command("npm run start")
cmd.Dir = "./AutoGO"
err := cmd.Run()
//fmt.Printf("%v", out)
if err != nil {
fmt.Printf("%v", err)
}
}
func getCharID(name string) int {
for i, c := range simChars {
if c == name {
return simCharsID[i]
}
}
fmt.Printf("%v not found in list of sim characters", name)
return -1
}
type AGresult struct {
User string `json:"user"`
Data string `json:"data"`
}
func parseAGresults(c, d int) string {
jsonData, err := os.ReadFile("./AutoGO/output/tmpl.json")
if err != nil {
fmt.Printf("%v", err)
}
var results []AGresult
err = json.Unmarshal([]byte(jsonData), &results)
if err != nil {
fmt.Printf("%v", err)
}
avgsubs := newsubs()
for i := range results { //ttl up all the arti sim iters
newsubs := getAGsubs(results[i].Data, results[i].User)
//fmt.Printf("\n%v", newsubs)
avgsubs = addsubs(avgsubs, newsubs)
//deleteArtis(results[i].User, newsubs) //delete the artis chosen so that they're not selected again for another char
}
for i := range avgsubs { //complete the average
avgsubs[i] /= float64(len(results))
avgsubs[i] /= float64(ispct[i])
}
newlines := ""
//we really should count how many arti sims use each set bonus combo, and run sims for each of them (numsims = numregularsims(10000 usually) * % of trials that had this set bonus combo), then avg results..
//but for now... manual overrides when switching sets
if strings.Contains(manualOverride[d], optiorder[c]) {