-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathkitg.js
1855 lines (1680 loc) · 131 KB
/
kitg.js
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
// These will allow quick selection of the buildings which consume energy
(function(s){var w,f={},o=window,l=console,m=Math,z='postMessage',x='HackTimer.js by turuslan: ',v='Initialisation failed',p=0,r='hasOwnProperty',y=[].slice,b=o.Worker;function d(){do{p=0x7FFFFFFF>p?p+1:0}while(f[r](p));return p}if(!/MSIE 10/i.test(navigator.userAgent)){try{s=o.URL.createObjectURL(new Blob(["var f={},p=postMessage,r='hasOwnProperty';onmessage=function(e){var d=e.data,i=d.i,t=d[r]('t')?d.t:0;switch(d.n){case'a':f[i]=setInterval(function(){p(i)},t);break;case'b':if(f[r](i)){clearInterval(f[i]);delete f[i]}break;case'c':f[i]=setTimeout(function(){p(i);if(f[r](i))delete f[i]},t);break;case'd':if(f[r](i)){clearTimeout(f[i]);delete f[i]}break}}"]))}catch(e){}}if(typeof(b)!=='undefined'){try{w=new b(s);o.setInterval=function(c,t){var i=d();f[i]={c:c,p:y.call(arguments,2)};w[z]({n:'a',i:i,t:t});return i};o.clearInterval=function(i){if(f[r](i))delete f[i],w[z]({n:'b',i:i})};o.setTimeout=function(c,t){var i=d();f[i]={c:c,p:y.call(arguments,2),t:!0};w[z]({n:'c',i:i,t:t});return i};o.clearTimeout=function(i){if(f[r](i))delete f[i],w[z]({n:'d',i:i})};w.onmessage=function(e){var i=e.data,c,n;if(f[r](i)){n=f[i];c=n.c;if(n[r]('t'))delete f[i]}if(typeof(c)=='string')try{c=new Function(c)}catch(k){l.log(x+'Error parsing callback code string: ',k)}if(typeof(c)=='function')c.apply(o,n.p)};w.onerror=function(e){l.log(e)};l.log(x+'Initialisation succeeded')}catch(e){l.log(x+v);l.error(e)}}else l.log(x+v+' - HTML5 Web Worker is not supported')})('HackTimerWorker.min.js');
var bldSmelter = gamePage.bld.buildingsData[15];
var bldBioLab = gamePage.bld.buildingsData[9];
var bldOilWell = gamePage.bld.buildingsData[20];
var bldFactory = gamePage.bld.buildingsData[22];
var bldCalciner = gamePage.bld.buildingsData[16];
var bldAccelerator = gamePage.bld.buildingsData[24];
var bldWarehouse = gamePage.bld.buildingsData[11];
var spcContChamber = gamePage.space.meta[5].meta[1];
var spcMoonBase = gamePage.space.meta[2].meta[1];
var spcEntangler = gamePage.space.meta[10].meta[0];
var spcSpaceStation = gamePage.space.meta[1].meta[2];
var spcLunarOutpost = gamePage.space.meta[2].meta[0];
var spcOrbitalArray = gamePage.space.meta[4].meta[1];
// These are the assorted variables
var proVar = gamePage.resPool.energyProd;
var conVar = gamePage.resPool.energyCons;
var FreeEnergy = 0;
var deadScript = "Script is dead";
var Iinc = 0;
var IincKAssign = 0;
var tick = 0;
var tick_inactive = 0;
var LeviTradeCnt = 0;
var embRefreshCnt = 0;
var postApocalypse_is_competed = true;
var GlobalMsg = {'craft':'','tech':'','relicStation':'','solarRevolution':'','ressourceRetrieval':'','chronosphere':'', 'science':''};
var science_labels = ['astronomy', 'theology', 'voidSpace', 'paradoxalKnowledge', 'navigation', 'architecture', 'physics', 'chemistry', 'archeology', 'electricity', 'biology'];
var sciencePriority = [null,[]]
var golden_Buildings = ["temple","tradepost"];
var switches = {"Energy Control":true, "Iron Will":false, "CollectResBReset":false}
var ActualTabs = Object.values(gamePage.tabs.filter(tab => tab.tabName != "Stats"));
var f = (a = 1, {x: c} ={ x: a / 10000}) => c;
function calc_sell_rate(res) {
let obj = {"name": res.name}
if (craftPriority[0].length > 0 && gamePage.bld.getPrices(craftPriority[0]).filter(rest => rest.name == res.name).length > 0 && gamePage.bld.getPrices(craftPriority[0]).filter(rest => rest.name == res.name)[0].val > gamePage.resPool.get(res.name).value){
obj.ratio = 0
}
else if (sciencePriority[0] != null && sciencePriority[1].filter(rest => rest.name == res.name).length > 0 && sciencePriority[1].filter(rest => rest.name == res.name)[0].val > gamePage.resPool.get(res.name).value){
obj.ratio = -1
}
else if ( gamePage.resPool.get(res.name).maxValue != 0) {
obj.ratio = gamePage.resPool.get(res.name).value / gamePage.resPool.get(res.name).maxValue * gamePage.resPool.get(res.name).value
}
else {
obj.ratio = 0.1 * gamePage.resPool.get(res.name).value
}
return obj;
}
var upgrades_craft = [
[gamePage.workshop.get("printingPress"),[["gear", 45*1.2]]],
[gamePage.workshop.get("fluidizedReactors"),[["alloy",200*1.2]]],
[gamePage.workshop.get("oxidation"),[["steel",5000*1.2]]],
[gamePage.workshop.get("miningDrill"),[["steel",750*1.2]]],
[gamePage.workshop.get("steelPlants"),[["gear",750*1.2]]],
[gamePage.workshop.get("rotaryKiln"),[["gear",500*1.2]]]
];
var policy_lst_all = [
"liberty", "authocracy", "communism",
"socialism", "diplomacy", "zebraRelationsAppeasement",
"knowledgeSharing", "stoicism", "mysticism",
"clearCutting", "fullIndustrialization", "militarizeSpace",
"necrocracy", "expansionism", "frugality", "siphoning", "spiderRelationsGeologists", "lizardRelationsDiplomats",
"sharkRelationsMerchants", "griffinRelationsMachinists", "dragonRelationsPhysicists", "nagaRelationsCultists"
];
var policy_lst_post_apocalypse = [
"liberty", "authocracy", "communism",
"socialism", "diplomacy", "zebraRelationsAppeasement",
"knowledgeSharing", "stoicism", "mysticism",
"environmentalism", "militarizeSpace",
"necrocracy", "expansionism", "frugality", "conservation", "siphoning"
];
var htmlMenuAddition = '<div id="farRightColumn" class="column">' +
'<a id="scriptOptions" onclick="selectOptions()"> | KGAutoPlay </a>' +
'<div id="optionSelect" style="display:none; margin-top:-235px; margin-left:-60px; width:200px" class="dialog help">' +
'<a href="#" onclick="clearOptionHelpDiv();" style="position: absolute; top: 10px; right: 15px;">close</a>' +
'<button id="killSwitch" onclick="clearInterval(clearScript()); gamePage.msg(deadScript);">Kill Switch</button> </br>' +
'<hr size=5>' +
'<button id="autoEnergy" style="color:black" onclick="autoSwitch(\'Energy Control\', \'autoEnergy\')"> Energy Control </button></br>' +
'<hr size=3>' +
'<button id="Collector" title = "Collect late game res(Tcrystal, Relic, Void) before reset." style="color:red" onclick="autoSwitch(\'CollectResBReset\', \'Collector\')"> CollectResBReset </button></br>' +
'<hr size=3>' +
'<button id="SellSpace" onclick="SellSpaceAndReset();">Sell Space and Reset</button> </br>' +
'<hr size=3>' +
'<button id="IronWill" style="color:red" onclick="autoSwitch(\'Iron Will\', \'IronWill\')"> IronWill </button></br>' +
'</div>' +
'</div>'
$("#footerLinks").append(htmlMenuAddition);
$(document.querySelector('#rightColumn > div.right-tab-header')).append("<a id='PriorityLabel' title = 'KGAutoPlay:\nLow priority for building construction and some technology.'></a>")
//$(document.querySelector("#midColumn")).append("<a id='PriorityLabel' title = 'KGAutoPlay: Low priority for building construction and some technology.'></a>")
function selectOptions() {
$("#optionSelect").toggle();
}
function clearOptionHelpDiv() {
$("#optionSelect").hide();
}
function clearScript() {
$("#farRightColumn").remove();
$("#PriorityLabel").remove();
$("#scriptOptions").remove();
clearInterval(runAllAutomation);
htmlMenuAddition = null;
}
function autoSwitch(varCheck, varName) {
if (!switches[varCheck]) {
switches[varCheck] = true;
gamePage.msg('Auto ' + varCheck + ' is now on');
document.getElementById(varName).style.color = 'black';
} else if (switches[varCheck]) {
switches[varCheck] = false;
gamePage.msg('Auto ' + varCheck + ' is now off');
document.getElementById(varName).style.color = 'red';
}
}
/* These are the functions which are controlled by the runAllAutomation timer */
// Auto Observe Astronomical Events
function autoObserve() {
var checkObserveBtn = document.getElementById("observeBtn");
if (typeof(checkObserveBtn) != 'undefined' && checkObserveBtn != null) {
document.getElementById('observeBtn').click();
}
}
//Auto praise the sun
function autoPraise(){
if (gamePage.religionTab.visible && !gamePage.challenges.isActive("atheism")) {
gamePage.tabs[5].update();
if (gamePage.religion.meta[1].meta[5].val == 1) {
if (gamePage.bld.getBuildingExt('mint').meta.val < 1 || gamePage.religion.getSolarRevolutionRatio() <= Math.max((gamePage.religion.transcendenceTier + 1) * 0.05, gamePage.getEffect("solarRevolutionLimit"))){
gamePage.religion.praise();
}
else if (gamePage.tabs[5].rUpgradeButtons.filter(res => res.model.resourceIsLimited == false && (!(res.model.name.includes('(complete)')))).length > 0){
var btn = gamePage.tabs[5].rUpgradeButtons.filter(res => res.model.resourceIsLimited == false && (!(res.model.name.includes('(complete)'))));
for (var rl = 0; rl < btn.length; rl++) {
if (btn[rl].model.enabled && btn[rl].model.visible) {
try {
btn[rl].controller.buyItem(btn[rl].model, {}, function(result) {
if (result) {
btn[rl].update();
gamePage.msg('Religion researched: ' + btn[rl].model.name);
}
});
} catch(err) {
console.log(err);
}
}
}
}
if (gamePage.resPool.get("faith").value >= gamePage.resPool.get("faith").maxValue*0.99){
if (gamePage.getEffect("voidResonance") > 0 && gamePage.religion.getRU("apocripha").on && gamePage.religion.getRU("transcendence").on && (gamePage.religion.faith / gamePage.religion.getApocryphaBonus()) > gamePage.resPool.get("faith").maxValue * Math.min(gamePage.religion.transcendenceTier, 10, Math.max(gamePage.religion.transcendenceTier * 0.05, gamePage.getEffect("solarRevolutionLimit")))){
gamePage.religion.resetFaith(1.01, false);
}
else if ( gamePage.religion.getRU("apocripha").on && gamePage.religion.getRU("transcendence").on && (gamePage.religion.faith / gamePage.religion.getApocryphaBonus()) > gamePage.resPool.get("faith").maxValue * Math.min(gamePage.religion.transcendenceTier, 10, Math.max(gamePage.religion.transcendenceTier * 0.05, gamePage.getEffect("solarRevolutionLimit")))){
gamePage.religion.resetFaith(1.01, false);
}
else {
gamePage.religion.praise();
}
}
if (gamePage.religion.getRU("transcendence").on){
var needNextLevel = gamePage.religion._getTranscendTotalPrice(gamePage.religion.transcendenceTier + 1) - gamePage.religion._getTranscendTotalPrice(gamePage.religion.transcendenceTier);
if (gamePage.religion.faithRatio > needNextLevel) {
gamePage.religion.faithRatio -= needNextLevel;
gamePage.religion.tcratio += needNextLevel;
gamePage.religion.transcendenceTier += 1;
self.game.msg($I("religion.transcend.msg.success", [gamePage.religion.transcendenceTier]));
}
}
} else if ((gamePage.resPool.get("faith").value >= gamePage.resPool.get("faith").maxValue*0.99) && gamePage.tabs[5].rUpgradeButtons.filter(res => res.model.resourceIsLimited == false && (!(res.model.name.includes('(complete)')))).length > 0){
var btn = gamePage.tabs[5].rUpgradeButtons.filter(res => res.model.resourceIsLimited == false && (!(res.model.name.includes('(complete)'))));
for (var rl = 0; rl < btn.length; rl++) {
if (btn[rl].model.enabled && btn[rl].model.visible) {
try {
btn[rl].controller.buyItem(btn[rl].model, {}, function(result) {
if (result) {
btn[rl].update();
gamePage.msg('Religion researched: ' + btn[rl].model.name);
}
});
} catch(err) {
console.log(err);
}
}
}
if (gamePage.resPool.get("faith").value >= gamePage.resPool.get("faith").maxValue*0.99){
gamePage.religion.praise();
}
} else if (gamePage.resPool.get("faith").value >= gamePage.resPool.get("faith").maxValue*0.99 || gamePage.tabs[5].rUpgradeButtons.filter(res => res.model.metadata.name == "solarRevolution")[0].model.visible == false){
gamePage.religion.praise();
}
if (!switches['CollectResBReset']) {
if (gamePage.science.get("cryptotheology").researched){
var btn = gamePage.tabs[5].ctPanel.children[0].children;
for (var cr = 0; cr < btn.length; cr++) {
if (btn[cr].model.enabled && btn[cr].model.visible) {
try {
btn[cr].controller.buyItem(btn[cr].model, {}, function(result) {
if (result) {
btn[cr].update();
gamePage.msg('Religion Cryptotheology researched: ' + btn[cr].model.name);
}
});
} catch(err) {
console.log(err);
}
}
}
}
}
if (gamePage.science.getPolicy("siphoning").researched && gamePage.religion.getPact("pactOfCleansing").unlocked && gamePage.getEffect("pactsAvailable") > 0 ){
if (gamePage.resPool.get("relic").value > 100 && gamePage.resPool.get("necrocorn").value > 10 && (gamePage.religion.getCorruptionPerTick() * (1 + gamePage.timeAccelerationRatio())) > 0.001 && gamePage.diplomacy.get("leviathans").energy >= gamePage.diplomacy.getMarkerCap()) {
var btn = gamePage.tabs[5].ptPanel.children[0].children.filter(res => res.model.metadata && res.model.metadata.unlocked && res.id == "pactOfCleansing" && res.model.enabled)
for (var cr = 0; cr < btn.length; cr++) {
if (btn[cr].model.enabled && btn[cr].model.visible) {
try {
btn[cr].controller.buyItem(btn[cr].model, {}, function(result) {
if (result) {
btn[cr].update();
gamePage.msg('Religion Pact accepted: ' + btn[cr].model.name);
}
});
} catch(err) {
console.log(err);
}
}
}
}
}
if (gamePage.religion.getPact("payDebt").unlocked && gamePage.resPool.get("necrocorn").value > gamePage.religion.getPact("payDebt").prices[0].val){
var btn = gamePage.tabs[5].ptPanel.children[0].children.filter(res => res.model.metadata && res.model.metadata.unlocked && res.id == "payDebt" && res.model.enabled)[0]
try {
btn.controller.buyItem(btn.model, {}, function(result) {
if (result) {
btn.update();
gamePage.msg('Religion : ' + btn.model.name);
}
});
} catch(err) {
console.log(err);
}
}
}
}
// Build buildings automatically
function autoBuild() {
var btn = gamePage.tabs[0].children.filter(res => res.model.metadata && res.model.metadata.unlocked && !res.model.resourceIsLimited && Object.keys(craftPriority[0]).length > 0 ? ((res.model.metadata.name == craftPriority[0]) || (NotPriority_blds.indexOf(res.model.metadata.name) > -1) || (res.model.prices.filter(ff2 => craftPriority[3].indexOf(ff2.name) != -1 ).length == 0 ) ) : res.model.metadata );
var solarRevolution_val = gamePage.religion.getRU('solarRevolution').val;
var mint_meta = gamePage.bld.getBuildingExt('mint').meta
for (var bl = 0; bl < btn.length; bl++) {
var btnModel = btn[bl].model;
var btnController = btn[bl].controller;
btnController.updateEnabled(btnModel);
if (btnModel.enabled) {
var btnMetadata = btnModel.metadata;
var btnPrices = btnModel.prices;
if (!switches['CollectResBReset'] || btnPrices.filter(res => res.name == 'relic' || res.name == 'timeCrystal' || res.name == 'void').length == 0) {
if ((golden_Buildings.includes(btnMetadata.name) && !gamePage.ironWill) || (gamePage.ironWill && mint_meta.val > 3 && golden_Buildings.includes(btnMetadata.name))) {
if ((solarRevolution_val == 1) || (btnMetadata.name == 'temple' && btnMetadata.val < 3) || (btnPrices.filter(res => res.name == 'gold')[0].val < (gamePage.resPool.get('gold').value - 500)) || (gamePage.resPool.get('gold').value == gamePage.resPool.get('gold').maxValue)) {
try {
btnController.buyItem(btnModel, {}, function(result) {
if (result) {
btn[bl].update();
gamePage.msg('Build: ' + btn[bl].model.name);
return;
}
});
} catch (err) {
console.log(err);
}
}
} else if (btnMetadata.name == "aiCore") {
if (btnMetadata.val < Math.floor(spcEntangler.val * 2.5)) {
try {
btnController.buyItem(btnModel, {}, function(result) {
if (result) {
btn[bl].update();
gamePage.msg('Build: ' + btn[bl].model.name);
return;
}
});
} catch (err) {
console.log(err);
}
}
} else if (btnMetadata.name == "field" && gamePage.challenges.isActive("postApocalypse") && gamePage.bld.getPollutionLevel() >= 5 && btnMetadata.val >= 95 - gamePage.time.getVSU("usedCryochambers").val - gamePage.bld.getPollutionLevel()) {
// Do nothing
} else if (btnMetadata.name == "field" && !gamePage.science.get('engineering').researched && gamePage.calendar.season >= 1 && btnPrices.filter(res => res.name == "catnip")[0].val * 3 > gamePage.resPool.get('catnip').value && gamePage.resPool.get('catnip').value < gamePage.resPool.get('catnip').maxValue * 0.9) {
// Do nothing
} else if (btnMetadata.name == "chronosphere") {
if ((gamePage.workshop.get("chronoforge").researched && gamePage.bld.getBuildingExt('chronosphere').meta.val >= 10 && ((gamePage.time.meta[0].meta[5].unlocked && gamePage.resPool.get("timeCrystal").value < gamePage.timeTab.cfPanel.children[0].children[6].model.prices.filter(res => res.name == "timeCrystal")[0].val * (gamePage.timeTab.cfPanel.children[0].children[6].model.metadata.val > 3 ? 0.9 : 0.05)) || !gamePage.science.get("paradoxalKnowledge").researched)) ||
(gamePage.bld.getBuildingExt('chronosphere').meta.val < 20 && gamePage.timeTab.visible && gamePage.resPool.get("timeCrystal").value - Chronosphere10SummPrices()["timeCrystal"] > 100 && gamePage.time.meta[0].meta[5].val > 0) ||
(gamePage.bld.getBuildingExt('chronosphere').meta.val < 10 && ((gamePage.resPool.get("unobtainium").value >= Chronosphere10SummPrices()["unobtainium"] && gamePage.resPool.get("timeCrystal").value >= Chronosphere10SummPrices()["timeCrystal"]) || gamePage.resPool.get("unobtainium").value >= gamePage.resPool.get("unobtainium").maxValue))) {
try {
btnController.buyItem(btnModel, {}, function(result) {
if (result) {
btn[bl].update();
gamePage.msg('Build: ' + btn[bl].model.name);
return;
}
});
} catch (err) {
console.log(err);
}
}
} else if (gamePage.ironWill) {
if (!btnMetadata.effects.maxKittens) {
if ((btnMetadata.name == "pasture" && !solarRevolution_val) ||
(!gamePage.workshop.get("goldOre").researched && btnPrices.filter(res => res.name == 'science').length > 0) ||
(gamePage.bld.getBuildingExt('workshop').meta.unlocked && gamePage.bld.getBuildingExt('workshop').meta.val == 0 && gamePage.bld.getBuildingExt('workshop').meta.name != btnMetadata.name && (btnPrices.filter(res => res.name == 'minerals' || res.name == 'slab').length > 0)) ||
(!gamePage.workshop.get("goldOre").researched && gamePage.workshop.get("goldOre").unlocked && gamePage.bld.getBuildingExt('workshop').meta.val > 0 && (btnPrices.filter(res => res.name == 'minerals' || res.name == 'slab').length > 0)) ||
((gamePage.bld.getBuildingExt('amphitheatre').meta.unlocked && gamePage.bld.getBuildingExt('amphitheatre').meta.val <= 10 && gamePage.bld.getBuildingExt('workshop').meta.val > 0 && gamePage.bld.getBuildingExt('amphitheatre').meta.name != btnMetadata.name) && btnPrices.filter(res => res.name == 'minerals' || res.name == 'slab').length > 0) ||
((solarRevolution_val == 0 && gamePage.bld.getBuildingExt('temple').meta.unlocked && gamePage.bld.getBuildingExt('temple').meta.val < 3 && gamePage.bld.getBuildingExt('amphitheatre').meta.val > 10 && gamePage.science.get('philosophy').researched && gamePage.bld.getBuildingExt('temple').meta.name != btnMetadata.name) && btnPrices.filter(res => res.name == 'slab').length > 0) ||
(((!gamePage.science.get('astronomy').researched && gamePage.science.get('astronomy').unlocked) || (!gamePage.science.get('philosophy').researched && gamePage.science.get('philosophy').unlocked) || (!gamePage.science.get('theology').researched && gamePage.science.get('theology').unlocked)) && btnPrices.filter(res => res.name == 'science').length > 0 && btnPrices.filter(res => res.name == 'science')[0].val > 1000)) {
// Do nothing
} else {
try {
btnController.buyItem(btnModel, {}, function(result) {
if (result) {
btn[bl].update();
gamePage.msg('Build: ' + btn[bl].model.name);
return;
}
});
} catch (err) {
console.log(err);
}
}
}
} else {
try {
btnController.buyItem(btnModel, {}, function(result) {
if (result) {
btn[bl].update();
gamePage.msg('Build: ' + btn[bl].model.name);
return;
}
});
} catch (err) {
console.log(err);
}
}
}
}
}
}
// Build space stuff automatically
function autoSpace() {
if (gamePage.spaceTab.visible) {
gamePage.tabs[6].update();
// Build space buildings
for (var z = 0; z < gamePage.tabs[6].planetPanels.length; z++) {
var spBuild = gamePage.tabs[6].planetPanels[z].children;
try {
for (var sp = 0 ;sp < spBuild.length; sp++) {
if (spBuild[sp].model.metadata.unlocked) {
if (!switches['CollectResBReset'] || spBuild[sp].model.prices.filter(res => res.name == 'relic' || res.name == 'timeCrystal' || res.name == 'void').length == 0) {
if (gamePage.workshop.get("relicStation").unlocked && !gamePage.workshop.get("relicStation").researched && spBuild[sp].model.prices.filter(res => res.name == 'antimatter').length > 0 && (!gamePage.challenges.isActive("energy") && gamePage.resPool.get("antimatter").value < gamePage.resPool.get("antimatter").maxValue )){
{}
}
else if (!gamePage.science.get('voidSpace').researched && ["hydroponics", "moonBase", "sunlifter", "cryostation", "heatsink"].includes(spBuild[sp].model.metadata.name) && (spBuild[sp].model.prices.filter(res => res.name == "eludium").length == 0 || spBuild[sp].model.prices.filter(res => res.name == "eludium")[0].val > 500) && gamePage.resPool.get("unobtainium").value < gamePage.resPool.get("unobtainium").maxValue * 0.5 ){
{}
}
else if ( ["moonBase"].includes(spBuild[sp].model.metadata.name) && gamePage.resPool.get("unobtainium").value < gamePage.resPool.get("unobtainium").maxValue * 0.5 && spBuild[sp].model.prices.filter(res => res.name == "unobtainium")[0].val > gamePage.resPool.get("eludium").value){
{}
}
else if ( spBuild[sp].model.metadata.name == "hydroponics" && spBuild[sp].model.prices.filter(res => res.name == "unobtainium")[0].val > gamePage.resPool.get("eludium").value){
{}
}
else if (gamePage.ironWill){
if(!spBuild[sp].model.metadata.effects.maxKittens){
spBuild[sp].controller.buyItem(spBuild[sp].model, {}, function(result) {
if (result) {
spBuild[sp].update();
gamePage.msg('Build in Space: ' + spBuild[sp].model.name);
return;
}
});
}
}else{
spBuild[sp].controller.buyItem(spBuild[sp].model, {}, function(result) {
if (result) {
spBuild[sp].update();
gamePage.msg('Build in Space: ' + spBuild[sp].model.name);
return;
}
});
}
}
}
}
} catch(err) {
console.log(err);
}
}
// Build space programs
var spcProg = gamePage.tabs[6].GCPanel.children;
for (var sp = 0; sp < spcProg.length; sp++) {
if (spcProg[sp].model.metadata.unlocked && spcProg[sp].model.on == 0) {
try {
spcProg[sp].controller.buyItem(spcProg[sp].model, {}, function(result) {
if (result) {
spcProg[sp].update();
gamePage.msg('Research Space program: ' + spcProg[sp].model.name );
return;
}
});
} catch(err) {
console.log(err);
}
}
}
}
}
// Trade automatically
function autoTrade() {
GlobalMsg["ressourceRetrieval"] = ''
if (gamePage.time.meta[0].meta[5].unlocked && gamePage.resPool.get("timeCrystal").value > gamePage.timeTab.cfPanel.children[0].children[6].model.prices.filter(res => res.name == "timeCrystal")[0].val * (gamePage.timeTab.cfPanel.children[0].children[6].model.metadata.val > 3 ? 0.9 : 0.05))
{
GlobalMsg["ressourceRetrieval"] = gamePage.timeTab.cfPanel.children[0].children[6].model.metadata.label + '(' + (gamePage.timeTab.cfPanel.children[0].children[6].model.metadata.val+1) + ') ' + Math.round((gamePage.resPool.get("timeCrystal").value / gamePage.timeTab.cfPanel.children[0].children[6].model.prices.filter(res => res.name == "timeCrystal")[0].val) * 100) + '%'
}
if (gamePage.bld.getBuildingExt('chronosphere').meta.val < 10 && gamePage.resPool.get("timeCrystal").value < (gamePage.bld.getBuildingExt('chronosphere').meta.val < 10 ? Chronosphere10SummPrices()["timeCrystal"] : 6)){
if (gamePage.diplomacy.get('leviathans').unlocked && gamePage.diplomacy.get('leviathans').duration != 0 && gamePage.resPool.get('unobtainium').value > 5000) {
gamePage.diplomacy.tradeMultiple(game.diplomacy.get("leviathans"),1);
}
}
if ((gamePage.resPool.get('titanium').value > 5000 || gamePage.bld.getBuildingExt('reactor').meta.val > 0 ) && gamePage.resPool.get('uranium').value < Math.min(gamePage.resPool.get('paragon').value,100) && gamePage.diplomacy.get('dragons').unlocked && gamePage.resPool.get('gold').value < gamePage.resPool.get('gold').maxValue * 0.95) {
gamePage.diplomacy.tradeAll(game.diplomacy.get("dragons"), 1);
}
let titRes = gamePage.resPool.get('titanium');
let ironRes = gamePage.resPool.get('iron');
let unoRes = gamePage.resPool.get('unobtainium');
let woodRes = gamePage.resPool.get('wood');
let mineralsRes = gamePage.resPool.get('minerals');
let goldResource = gamePage.resPool.get('gold');
let ivoryRes = gamePage.resPool.get('ivory');
let slabRes = gamePage.resPool.get('slab');
let uranRes = gamePage.resPool.get('uranium');
let scaffoldRes = gamePage.resPool.get('scaffold');
let coalRes = gamePage.resPool.get('coal');
let cultureRes = gamePage.resPool.get('culture');
if ((cultureRes.value >= 10000 || cultureRes.value >= cultureRes.maxValue) || gamePage.challenges.isActive("pacifism")) {
embRefreshCnt += 1;
if (embRefreshCnt >= 10){
gamePage.diplomacyTab.render();
embRefreshCnt = 0;
}
embassy_buttons = gamePage.diplomacyTab.racePanels.filter( emb => emb.race.unlocked && emb.embassyButton != null && !emb.embassyButton.model.resourceIsLimited)
if (embassy_buttons.length > 0) {
btn = embassy_buttons.sort(function(a, b) {return a.race.embassyLevel - b.race.embassyLevel;})[0]
btn.embassyButton.controller.buyItem(btn.embassyButton.model, {}, function(result) {
if (result) {
btn.embassyButton.update();
return;
}
});
}
}
if (gamePage.diplomacy.get('leviathans').unlocked && gamePage.diplomacy.get('leviathans').duration != 0) {
//blackcoin speculation
if (gamePage.science.get("blackchain").researched || gamePage.resPool.get("blackcoin").value > 0) {
if (gamePage.resPool.get("blackcoin").value > 0 && gamePage.calendar.cryptoPrice > 1090 ) {
gamePage.diplomacy.sellBcoin()
}
if (!switches['CollectResBReset'] && gamePage.resPool.get("relic").value > (1000 + gamePage.resPool.get("blackcoin").value * 1000) && gamePage.calendar.cryptoPrice < 1000 ) {
gamePage.diplomacy.buyBcoin()
}
}
}
if(((gamePage.religion.getRU('solarRevolution').val == 1 || ((gamePage.challenges.isActive("atheism") || gamePage.challenges.isActive("pacifism") ) && (gamePage.resPool.get('gold').value > 550 || gamePage.bld.getBuildingExt('mint').meta.val > 0 ) )) || (gamePage.resPool.get('gold').value == gamePage.resPool.get('gold').maxValue && gamePage.resPool.get('gold').maxValue < 500)) || (gamePage.ironWill)){
if ((goldResource.value > goldResource.maxValue * 0.95 || ((gamePage.bld.getBuildingExt('mint').meta.val > 0 && goldResource.value > (gamePage.bld.getBuildingExt('accelerator').meta.val < 1 ? 90 : Math.min(gamePage.bld.getBuildingExt('accelerator').meta.val * 1000, 10000))) || gamePage.religion.getRU("transcendence").on) || ((gamePage.challenges.isActive("atheism") || gamePage.challenges.isActive("pacifism")) && goldResource.value > 500) ) || (gamePage.ironWill && goldResource.value > (gamePage.religion.getRU('solarRevolution').val == 1 ? 15 : 600) ) || (gamePage.resPool.get('blueprint').value < 300 && gamePage.religion.getRU('solarRevolution').val == 1 && goldResource.value > 90)) {
if (gamePage.diplomacyTab.racePanels.length != gamePage.diplomacy.races.filter(race => race.unlocked).length) {
gamePage.diplomacyTab.render();
}
if (gamePage.diplomacy.get('leviathans').unlocked && gamePage.diplomacy.get('leviathans').duration != 0) {
if (unoRes.value > 5000 && gamePage.time.meta[0].meta[5].unlocked && gamePage.resPool.get("timeCrystal").value > gamePage.timeTab.cfPanel.children[0].children[6].model.prices.filter(res => res.name == "timeCrystal")[0].val * (gamePage.timeTab.cfPanel.children[0].children[6].model.metadata.val > 3 ? 0.9 : 0.05)){
gamePage.diplomacy.tradeAll(game.diplomacy.get("leviathans"));
}else if(unoRes.value > 5000 && ((gamePage.bld.getBuildingExt('chronosphere').meta.val >= 10 && gamePage.resPool.get("timeCrystal").value <= gamePage.resPool.get("eludium").value / 2 ) || switches['CollectResBReset'] )) {
gamePage.diplomacy.tradeMultiple(game.diplomacy.get("leviathans"),Math.min( gamePage.diplomacy.getMaxTradeAmt(game.diplomacy.get("leviathans")), Math.max(Math.floor(gamePage.resPool.get('unobtainium').value/5000),1)));
}
//Feed elders
if (gamePage.diplomacy.get("leviathans").energy < gamePage.diplomacy.getMarkerCap() && ((gamePage.resPool.get("necrocorn").value > (gamePage.diplomacy.get("leviathans").energy + 1)) || (gamePage.resPool.get("necrocorn").value >= 1 && (gamePage.religion.getCorruptionPerTick() * (1 + gamePage.timeAccelerationRatio())) > 0.001))){
gamePage.diplomacy.feedElders();
}
}
// name, buys, sells
let tradersAll = [
['zebras',
gamePage.diplomacy.get('zebras').buys,
[...gamePage.diplomacy.get('zebras').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('zebras'))), {"name": "titanium"}].map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
['griffins',
gamePage.diplomacy.get('griffins').buys,
gamePage.diplomacy.get('griffins').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('griffins'))).map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
['lizards',
gamePage.diplomacy.get('lizards').buys,
gamePage.diplomacy.get('lizards').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('lizards'))).map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
['sharks',
gamePage.diplomacy.get('sharks').buys,
gamePage.diplomacy.get('sharks').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('sharks'))).map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
['nagas',
gamePage.diplomacy.get('nagas').buys,
gamePage.diplomacy.get('nagas').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('nagas'))).map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
['spiders',
gamePage.diplomacy.get('spiders').buys,
gamePage.diplomacy.get('spiders').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('spiders'))).map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
['dragons',
gamePage.diplomacy.get('dragons').buys,
gamePage.diplomacy.get('dragons').sells.filter(sl => gamePage.diplomacy.isValidTrade(sl, gamePage.diplomacy.get('dragons'))).map(calc_sell_rate).sort(function(a, b) {return a.ratio - b.ratio;})
],
]
let trade = tradersAll.filter(tr => gamePage.diplomacy.get(tr[0]).unlocked && tr[1][0].val <= gamePage.resPool.get(tr[1][0].name).value && gamePage.resPool.get(tr[1][0].name).value >= (gamePage.resPool.get(tr[1][0].name).maxValue != 0 ? gamePage.resPool.get(tr[1][0].name).maxValue * 0.01 : 0)).sort(function(a, b) {return a[2][0].ratio - b[2][0].ratio;})[0]
if (trade) {
if (gamePage.ironWill) {
if (trade[0] == 'griffins' && gamePage.resPool.get(trade[1][0].name).value > gamePage.resPool.get(trade[1][0].name).maxValue * 0.8 ) {
gamePage.diplomacy.tradeMultiple(gamePage.diplomacy.get(trade[0]), Math.floor(gamePage.diplomacy.getMaxTradeAmt(gamePage.diplomacy.get(trade[0])) / 10));
}
else {
gamePage.diplomacy.tradeAll(gamePage.diplomacy.get(trade[0]));
}
}
else {
if (trade[0] == 'nagas' && gamePage.resPool.get('ivory').value < gamePage.resPool.get('slab').value ) {
// Do nothing
}
else {
gamePage.diplomacy.tradeAll(gamePage.diplomacy.get(trade[0]));
}
}
}
}
}
}
// Hunt automatically
function autoHunt() {
var tmpvalue = gamePage.resPool.get('furs').value
var catpower = gamePage.resPool.get('manpower');
if (!gamePage.challenges.isActive("pacifism") && (catpower.value > (catpower.maxValue * 0.9) || (tmpvalue/catpower.maxValue < 0.02))) {
gamePage.village.huntAll();
}
}
var resources = [
["catnip", "wood", 50],
["wood", "beam", 175],
["minerals", "slab", 250],
["iron", "plate", 125],
["oil", "kerosene", 7500],
["uranium", "thorium", 250],
["unobtainium", "eludium", 1000],
["furs", "parchment", 175]
];
var NotPriority_blds = ["temple","tradepost","aiCore","unicornPasture","chronosphere","mint","chapel","zebraOutpost","zebraWorkshop","zebraForge", "brewery", "accelerator", "ivoryTemple"];
var craftPriority = [[],[],0,[]]
var cntcrafts = 0
var reslist = {}
var reslist2 = []
var cnt = 0
function autoCraft2() {
var flag = true;
GlobalMsg['tech'] = ''
GlobalMsg['craft'] = ''
//finding priority bld for now
var resourcesAll = [
["beam", [["wood",175]],Math.min(gamePage.resPool.get("wood").value/175*(gamePage.getCraftRatio()+1),50000),true, true],
["slab", [["minerals",250]], Math.min(gamePage.resPool.get("minerals").value/250*(gamePage.getCraftRatio()+1),50000), gamePage.ironWill ? false : true, true],
["steel", [["iron",100],["coal",100]],Math.min(Math.max(Math.min(gamePage.resPool.get("iron").value/100*gamePage.getCraftRatio()+1,gamePage.resPool.get("coal").value/100*(gamePage.getCraftRatio()+1)),75),50000),true, true],
(gamePage.bld.getBuildingExt('reactor').meta.unlocked && !gamePage.resPool.isStorageLimited(gamePage.bld.getPrices('reactor'))) ?
["plate", [["iron",125]],gamePage.ironWill ? 15 : gamePage.resPool.get("plate").value < 200 ? 200 : (gamePage.resPool.get("titanium").value > 300 ? gamePage.bld.getPrices('reactor')[1].val : 200), false, true] :
["plate", [["iron",125]],gamePage.ironWill ? 15 : (gamePage.resPool.get("plate").value < 150 && gamePage.science.get("navigation").researched) ? 150 : Math.min(gamePage.resPool.get("iron").value/125*(gamePage.getCraftRatio()+1),50000),true, true],
["concrate", [["steel",25],["slab",2500]], gamePage.resPool.get("eludium").value > 125 ? gamePage.resPool.get("steel").value : 0, true, true],
["gear", [["steel",15]],25,true, true],
["alloy", [["steel",75],["titanium",10]], gamePage.resPool.get("eludium").value > 125 ? gamePage.resPool.get("steel").value : (gamePage.resPool.get("titanium").value < 20 ? 0 : Math.min(Math.max(Math.min(gamePage.resPool.get("steel").value/75*(gamePage.getCraftRatio()+1),gamePage.resPool.get("titanium").value/10*(gamePage.getCraftRatio()+1)), gamePage.workshop.get("geodesy").researched ? 50 : 0),1000)),false, true],
["eludium", [["unobtainium",1000],["alloy",2500]], gamePage.resPool.get("eludium").value < 125 ? 125 : (gamePage.bld.getBuildingExt('chronosphere').meta.val < 10 ? 125 : gamePage.resPool.get("eludium").value < 500 ? 500 : ((gamePage.resPool.get("unobtainium").value > gamePage.resPool.get("unobtainium").maxValue * 0.9 || gamePage.resPool.get("unobtainium").value >= Math.max(gamePage.resPool.get("eludium").value, (gamePage.resPool.get("timeCrystal").value > 1000000 ? gamePage.resPool.get("unobtainium").maxValue * 0.3 : (gamePage.resPool.get("eludium").value < 100000 ? 200000 : gamePage.resPool.get("unobtainium").maxValue * 0.1)))) ? gamePage.resPool.get("timeCrystal").value * 2 + 1 : 0)), false, true],
["scaffold", [["beam",50]],0,true, true],
["ship", [["scaffold",100],["plate",150],["starchart",25]],!gamePage.workshop.get("geodesy").researched ? 100 : (gamePage.resPool.get("starchart").value > 600 || gamePage.resPool.get("ship").value > 500) ? Math.min(gamePage.resPool.get("plate").value ,(100 + (gamePage.resPool.get("starchart").value - 500)/25)) :100 ,true, true],
["tanker", [["ship",200],["kerosene",gamePage.resPool.get('oil').maxValue * 2],["alloy",1250],["blueprint",5]],0,true, true],
["kerosene", [["oil",7500]],Math.min(gamePage.resPool.get("oil").value/7500*(gamePage.getCraftRatio()+1),50000),true, true],
["parchment", [["furs",175]],gamePage.resPool.get("starchart").value > 1 ? (gamePage.religion.getRU('solarRevolution').val == 1 ? gamePage.resPool.get("furs").value / 3 : 100) : 0,true, true],
["manuscript", [["parchment",25],["culture",400]], gamePage.ironWill ? (gamePage.resPool.get('culture').value > 1600 || gamePage.diplomacy.get('nagas').unlocked ? 50 : 0) : ((gamePage.religion.getRU('solarRevolution').val == 1 && gamePage.resPool.get('culture').value >= gamePage.resPool.get('culture').maxValue) ? gamePage.resPool.get("parchment").value / 3 : 200), true, gamePage.ironWill ? (gamePage.resPool.get('culture').value > 1600 || gamePage.diplomacy.get('nagas').unlocked ? true : false) : true],
["compedium", [["manuscript",50],["science",10000]],gamePage.ironWill ? (gamePage.science.get('astronomy').researched ? Math.min(gamePage.resPool.get("science").value/10000*(gamePage.getCraftRatio()+1),1500): 0) : (gamePage.religion.getRU('solarRevolution').val == 1 ? gamePage.resPool.get("manuscript").value / 3 : 110), true, gamePage.resPool.get("manuscript").value > 200 ? true : false],
["blueprint", [["compedium",25],["science",25000]],0,true, gamePage.resPool.get("compedium").value > 200 ? true : false],
["thorium", [["uranium",250]],Math.min(gamePage.resPool.get("uranium").value/250*(gamePage.getCraftRatio()+1),50000),true, true],
["megalith", [["slab",50],["beam",25],["plate",5]],0,true, gamePage.resPool.get("manuscript").value > 300 ? true : false],
["tMythril", [["bloodstone",5],["ivory",1000],["titanium",500]],5, true, (gamePage.ironWill && gamePage.resPool.get("tMythril").value < 5) ? true : false]
]
if (!gamePage.ironWill && (cntcrafts == 0 || cntcrafts > 200 || (Object.keys(craftPriority[0]).length > 0 && craftPriority[2] != gamePage.bld.getBuildingExt(craftPriority[0]).meta.val))) {
var Priority_blds = {
"hut" : gamePage.science.get('agriculture').researched ? (gamePage.bld.getBuildingExt('mine').meta.val > 0 ? 7 * ((gamePage.resPool.get("paragon").value > 200 || gamePage.village.getKittens() > 70) ? 1 : (!gamePage.challenges.anyChallengeActive() && gamePage.religion.getRU('solarRevolution').val == 1 && gamePage.resPool.get('paragon').value < 200) ? 10 : 2) : 5) : 1,
"logHouse" : 7 * ((gamePage.resPool.get("paragon").value > 200 || gamePage.village.getKittens() > 70) ? 1 : (!gamePage.challenges.anyChallengeActive() && gamePage.religion.getRU('solarRevolution').val == 1 && gamePage.resPool.get('paragon').value < 200) ? 10 : 2),
"mansion" : (gamePage.resPool.get("titanium").value > 300 && (gamePage.resPool.get("steel").value > 300 || gamePage.bld.getBuildingExt('mansion').meta.val > 10)) ? 1.5 : 0.00000001,
"steamworks" : (gamePage.challenges.isActive("pacifism") && gamePage.bld.getBuildingExt('steamworks').meta.val < 5) ? 50 : ((gamePage.bld.getBuildingExt('magneto').meta.val > 0) ? 2 : 0.00000001),
"magneto" : gamePage.bld.getBuildingExt('magneto').meta.val > 10 ? 2 : 0.00000001,
"factory" : (gamePage.resPool.get("titanium").value > 300 && gamePage.bld.getBuildingExt('magneto').meta.val > 10) ? 3 : 0.00000001,
"reactor" : gamePage.bld.getBuildingExt('magneto').meta.val > 10 ? 10 : 0.00000001,
"warehouse" : gamePage.bld.getBuildingExt('warehouse').meta.stage == 1 ? 0 : 0.0001,
"quarry" : gamePage.bld.getBuildingExt('quarry').meta.val < 5 ? 10 : 1.1,
"harbor" : (gamePage.bld.getBuildingExt('harbor').meta.val > 100 || (gamePage.resPool.get("ship").value > 0 && gamePage.resPool.get("plate").value > gamePage.bld.getPrices('harbor').filter(res => res.name == "plate")[0].val)) ? 1 : 0.0001,
"smelter" : gamePage.bld.getBuildingExt("amphitheatre").meta.val > 0 ? (gamePage.religion.getRU("solarRevolution").val == 0 ? ( (gamePage.resPool.get("gold").value < 500 && gamePage.bld.getBuildingExt("smelter").meta.on == gamePage.bld.getBuildingExt("smelter").meta.val) ? 100 : 5) : 5) : gamePage.challenges.isActive("pacifism") ? 100: 0.0001,
"observatory" : (!gamePage.challenges.isActive("blackSky") & gamePage.resPool.get("ship").value == 0 && gamePage.religion.getRU("solarRevolution").val == 1) ? 100 : (gamePage.resPool.get("ship").value == 0 && gamePage.bld.getBuildingExt('observatory').meta.val > 10 && gamePage.resPool.get("starchart").value >= 25) ? 0.00000001 : ((gamePage.religion.getRU("solarRevolution").val == 1 || gamePage.challenges.isActive("atheism")) ? 0.5 : 0.0001),
"oilWell" : (gamePage.bld.getBuildingExt('oilWell').meta.val == 0 && gamePage.resPool.get("coal").value > 0 ) ? 10 : (gamePage.resPool.get("oil").value < 500 ? 1 : 0.01),
"lumberMill" :gamePage.bld.getPrices("lumberMill").filter(res => res.name == "iron")[0].val + 150 <= gamePage.resPool.get("iron").value ? 1 : (gamePage.religion.getRU("solarRevolution").val == 1 ? 0.005 : 0.0001) * (gamePage.resPool.get("paragon").value > 200 ? 1 : 2),
"calciner" : ((gamePage.resPool.get("titanium").value > 0 && (gamePage.bld.getBuildingExt('calciner').meta.val > 10 || gamePage.resPool.get("oil").value > gamePage.bld.getPrices('calciner').filter(res => res.name == "oil")[0].val)) || gamePage.challenges.isActive("blackSky")) ? (gamePage.bld.getPrices('calciner').filter(res => res.name == "oil")[0].val < gamePage.resPool.get("oil").maxValue * 0.3 || (gamePage.resPool.get("kerosene").value > gamePage.resPool.get("oil").maxValue * 0.4 && gamePage.bld.getPrices('calciner').filter(res => res.name == "oil")[0].val < gamePage.resPool.get("kerosene").value )) ? (gamePage.bld.getBuildingExt('calciner').meta.val == 0 ? 10 : 1.1) : 0.00000001 : 0.00000001,
"biolab" : gamePage.bld.getBuildingExt('biolab').meta.val > 500 ? 1 : 0.0001,
"aqueduct" : gamePage.bld.getBuildingExt('aqueduct').meta.stage == 1 ? 0.01 : 0.1,
"amphitheatre" : (gamePage.bld.getBuildingExt('amphitheatre').meta.val == 0 && gamePage.resPool.get('parchment').value > 0) ? 7 : (gamePage.bld.getBuildingExt('amphitheatre').meta.stage == 0 && gamePage.resPool.get('parchment').value > 0) ? 3 : 0.00000001,
"ziggurat" : gamePage.bld.getBuildingExt('ziggurat').meta.val > 100 ? 1 : (gamePage.bld.getBuildingExt('ziggurat').meta.val < 20 && gamePage.bld.getPrices("ziggurat").filter(res => res.name == "blueprint")[0].val <= gamePage.resPool.get("blueprint").value && gamePage.science.get('theology').researched && gamePage.resPool.get("blueprint").value > 100 ) ? 0.1 : (gamePage.resPool.get("blueprint").value > 500 ? 0.01 : 0.00000001),
"mine": gamePage.bld.getBuildingExt('mine').meta.val > 0 ? 1 * (gamePage.resPool.get("paragon").value > 200 ? 1 : 2) : 10,
"workshop": gamePage.bld.getBuildingExt('workshop').meta.val > 0 ? 2 : 10,
"pasture": 0.0001,
"library": gamePage.bld.getBuildingExt('library').meta.val <= 10 ? 1 : 0.01,
"field" : (gamePage.challenges.isActive("postApocalypse") && gamePage.bld.getPollutionLevel() >= 5 || !gamePage.science.get('engineering').researched) ? 0 : 0.01
};
var allblds = gamePage.tabs[0].children.filter(res => res.model.metadata && res.model.metadata.unlocked && !res.model.resourceIsLimited)
var prior = [];
for (var prc = 0; prc < allblds.length; prc++) {
if (!gamePage.ironWill || (!allblds[prc].model.metadata.effects.maxKittens)) {
if (allblds[prc].model.metadata.name in Priority_blds && (allblds[prc].model.prices.filter(res => res.name == "blueprint").length > 0 ? (allblds[prc].model.metadata.val > 0 || gamePage.resPool.get("blueprint").value > allblds[prc].model.prices.filter(res => res.name == "blueprint")[0].val ) : true)) {
if (Priority_blds[allblds[prc].model.metadata.name] != 0){
prior[prior.length] = [Priority_blds[allblds[prc].model.metadata.name], allblds[prc].model.metadata.name, allblds[prc].model.prices]
}
}
else if ((allblds[prc].model.prices.filter(res => res.name == "blueprint").length > 0 ? (allblds[prc].model.metadata.val > 0 || gamePage.resPool.get("blueprint").value > allblds[prc].model.prices.filter(res => res.name == "blueprint")[0].val) : true) && NotPriority_blds.indexOf(allblds[prc].model.metadata.name) === -1) {
prior[prior.length] = [0.1, allblds[prc].model.metadata.name, allblds[prc].model.prices]
}
}
}
prior = prior.sort(function(a, b) {
return ( Object.keys(a[2]).reduce(function(c, d) {
var res_sum = 1
var res_sum_sub = 1
if (a[2][d].val > gamePage.resPool.get(a[2][d].name).value) {
res_sum = a[2][d].val - gamePage.resPool.get(a[2][d].name).value
for (var g = 0; g < resourcesAll.length; g++) {
if ( a[2][d].name == resourcesAll[g][0] ) {
res_sum = 1
differ = a[2][d].val - gamePage.resPool.get(a[2][d].name).value
for (var h = 0; h < resourcesAll[g][1].length;h++) {
for (var g2 = 0; g2 < resourcesAll.length; g2++) {
if ( resourcesAll[g][1][h][0] == resourcesAll[g2][0] ) {
res_sum_sub = 1
differ2 = (resourcesAll[g][1][h][1] * differ)/(gamePage.getCraftRatio()+1) - gamePage.resPool.get(resourcesAll[g2][0]).value
for (var h2 = 0; h2 < resourcesAll[g2][1].length;h2++) {
res_sum_sub += (resourcesAll[g2][1][h2][1] * differ2)/(gamePage.getCraftRatio()+1)
}
}
}
res_sum += Math.max((resourcesAll[g][1][h][1] * differ)/(gamePage.getCraftRatio()+1), res_sum_sub)
}
}
}
}
return c + res_sum } , 0)/a[0] - Object.keys(b[2]).reduce(function(c, d) {
var res_sum = 1
var res_sum_sub = 1
if (b[2][d].val > gamePage.resPool.get(b[2][d].name).value) {
res_sum = b[2][d].val - gamePage.resPool.get(b[2][d].name).value
for (var g = 0; g < resourcesAll.length; g++) {
if ( b[2][d].name == resourcesAll[g][0]) {
res_sum = 1
differ = b[2][d].val - gamePage.resPool.get(b[2][d].name).value
for (var h = 0; h < resourcesAll[g][1].length;h++) {
for (var g2 = 0; g2 < resourcesAll.length; g2++) {
if ( resourcesAll[g][1][h][0] == resourcesAll[g2][0] ) {
res_sum_sub = 1
differ2 = (resourcesAll[g][1][h][1] * differ)/(gamePage.getCraftRatio()+1) - gamePage.resPool.get(resourcesAll[g2][0]).value
for (var h2 = 0; h2 < resourcesAll[g2][1].length;h2++) {
res_sum_sub += (resourcesAll[g2][1][h2][1] * differ2)/(gamePage.getCraftRatio()+1)
}
}
}
res_sum += Math.max((resourcesAll[g][1][h][1] * differ)/(gamePage.getCraftRatio()+1), res_sum_sub)
}
}
}
}
return c + res_sum } ,0)/b[0]);
});
//priority bluildings
if (prior.length > 0) {
reslist = {}
reslist2 = []
bld_prior = prior[0]
if (prior.length > 4 && cntcrafts == 0 && ["logHouse", "hut"].includes(craftPriority[0])){
idxlastbld = prior.slice(0, 5).map(item => item[1]).indexOf(craftPriority[0])
if (idxlastbld != -1){
bld_prior = prior[idxlastbld]
}
}
for (var prc = 0; prc < bld_prior[2].length; prc++) {
reslist[bld_prior[2][prc].name] = bld_prior[2][prc].val
reslist2[reslist2.length] = bld_prior[2][prc].name
for (var g = 0; g < resourcesAll.length; g++) {
if (bld_prior[2][prc].name == resourcesAll[g][0]) {
for (var h = 0; h < resourcesAll[g][1].length;h++) {
if (isNaN(reslist[resourcesAll[g][1][h][0]])) {
let tmpval = (resourcesAll[g][1][h][1] * (bld_prior[2][prc].val - gamePage.resPool.get(bld_prior[2][prc].name).value ) - gamePage.resPool.get(resourcesAll[g][1][h][0]).value)/(gamePage.getCraftRatio()+1)
reslist[resourcesAll[g][1][h][0]] = tmpval < 0 ? 1 : Math.max(tmpval, gamePage.resPool.get(resourcesAll[g][1][h][0]).value)
}
else {
let tmpval = Math.max(reslist[resourcesAll[g][1][h][0]], (resourcesAll[g][1][h][1] * (bld_prior[2][prc].val - gamePage.resPool.get(bld_prior[2][prc].name).value ) - gamePage.resPool.get(resourcesAll[g][1][h][0]).value)/(gamePage.getCraftRatio()+1))
reslist[resourcesAll[g][1][h][0]] = tmpval < 0 ? 1 : Math.max(tmpval, gamePage.resPool.get(resourcesAll[g][1][h][0]).value)
}
reslist2[reslist2.length] = resourcesAll[g][1][h][0]
}
}
}
}
craftPriority = [bld_prior[1], bld_prior[2], gamePage.bld.getBuildingExt(bld_prior[1]).meta.val, reslist2]
}
cntcrafts = 0
}
if (Object.keys(craftPriority[0]).length > 0) {
cntcrafts+=1
GlobalMsg['craft'] = gamePage.bld.getBuildingExt(craftPriority[0])._metaCache.label + ' (' + (gamePage.bld.getBuildingExt(craftPriority[0]).meta.val+1) + ')' + ': ' + (201 - cntcrafts)
}
if (cntcrafts > 200) {
cntcrafts = 0
}
if (gamePage.science.get("construction").researched && gamePage.tabs[3].visible ) {
for (var g = 0; g < resourcesAll.length; g++) {
if (resourcesAll[g][0] in reslist) {
if (Math.max(resourcesAll[g][2], gamePage.resPool.get(resourcesAll[g][0]).value) < reslist[resourcesAll[g][0]]){
resourcesAll[g][2] = reslist[resourcesAll[g][0]]
resourcesAll[g][4] = true
}
resourcesAll[g][3] = false
}else{
for (var z = 0; z < resourcesAll[g][1].length; z++) {
if (resourcesAll[g][1][z][0] in reslist && (gamePage.resPool.get((resourcesAll[g][1][z][0]).maxValue > 0 && gamePage.resPool.get(resourcesAll[g][1][z][0]).value < gamePage.resPool.get(resourcesAll[g][1][z][0]).maxValue) || gamePage.resPool.get(resourcesAll[g][1][z][0]).value < reslist[resourcesAll[g][1][z][0]] * 2) && !["plate", "ship", "eludium", "alloy"].includes(resourcesAll[g][0])) {
resourcesAll[g][3] = false
resourcesAll[g][4] = false
}
}
}
}
//priority upgrades
if (gamePage.resPool.get('ship').value > 0) {
for (var pru = 0; pru < upgrades_craft.length; pru++) {
if (upgrades_craft[pru][0].researched ) {
upgrades_craft.splice(pru,1);
break;
}
if (upgrades_craft[pru][0].unlocked ){
for (var j = 0; j < upgrades_craft[pru][1].length; j++) {
if (gamePage.resPool.get(upgrades_craft[pru][1][j][0]).value >= upgrades_craft[pru][1][j][1]*1.2){
continue;
}
for (var g = 0; g < resourcesAll.length; g++) {
if (resourcesAll[g][0] == upgrades_craft[pru][1][j][0]) {
if (Math.max(resourcesAll[g][2], gamePage.resPool.get(resourcesAll[g][0]).value) < upgrades_craft[pru][1][j][1]){
resourcesAll[g][2] = upgrades_craft[pru][1][j][1]
resourcesAll[g][4] = true
}
resourcesAll[g][3] = false
}
}
let respack = resourcesAll.filter(res => res[0] == upgrades_craft[pru][1][j][0])[0][1]
reslist = []
for (var g = 0; g < respack.length; g++) {
reslist[reslist.length] = respack[g][0]
}
for (var g = 0; g < resourcesAll.length; g++) {
for (var b = 0; b < resourcesAll[g][1].length; b++) {
if ( (resourcesAll[g][0] != upgrades_craft[pru][1][j][0] && reslist.indexOf(resourcesAll[g][1][b][0]) > 0) || resourcesAll[g][1][b][0] == upgrades_craft[pru][1][j][0]) {
if (gamePage.resPool.get(upgrades_craft[pru][1][j][0]).value < upgrades_craft[pru][1][j][1] ) {
resourcesAll[g][4] = false
}
}
}
}
}
if (Object.keys(craftPriority[0]).length > 0) {
GlobalMsg['tech'] = upgrades_craft[pru][0].label
}
break;
}
}
}
var resourcesAllF = resourcesAll.filter(res => res[4] && gamePage.workshop.getCraft(res[0]).unlocked ).sort(function(a, b) {
return (gamePage.resPool.get(a[0]).value - gamePage.resPool.get(b[0]).value);
});
for (var crf = 0; crf < resourcesAllF.length; crf++) {
var curResTarget = gamePage.resPool.get(resourcesAllF[crf][0]);
if (gamePage.workshop.getCraft(resourcesAllF[crf][0]).unlocked && resourcesAllF[crf][4]) {
flag = true;
cnt = 0;
if (curResTarget.value <= resourcesAllF[crf][2]) {
if (gamePage.resPool.get(resourcesAllF[crf][1][0][0]).value >= resourcesAllF[crf][1][0][1]) {
if (gamePage.ironWill && resourcesAllF[crf][0] == "slab" && gamePage.bld.getBuildingExt("mint").meta.val == 0 ) {
for (var x = 0; x < resourcesAllF[crf][1].length; x++) {
cnt = Math.min(cnt != 0 ? cnt : Math.floor((gamePage.resPool.get(resourcesAllF[crf][1][x][0]).value / resourcesAllF[crf][1][x][1])/10),Math.floor((gamePage.resPool.get(resourcesAllF[crf][1][x][0]).value / resourcesAllF[crf][1][x][1])/10), Math.floor(resourcesAllF[crf][2]) - curResTarget.value) + 1;
}
}
else {
for (var x = 0; x < resourcesAllF[crf][1].length; x++) {
if (cnt == 0){
cnt = Math.floor((gamePage.resPool.get(resourcesAllF[crf][1][x][0]).value / resourcesAllF[crf][1][x][1]))
}
cnt = Math.min(cnt, Math.floor((gamePage.resPool.get(resourcesAllF[crf][1][x][0]).value / resourcesAllF[crf][1][x][1])))
}
}
}
}
else{
for (var x = 0; x < resourcesAllF[crf][1].length; x++) {
tmpvalue = gamePage.resPool.get(resourcesAllF[crf][1][x][0]).value
tmpvalueMax = gamePage.resPool.get(resourcesAllF[crf][1][x][0]).maxValue
if ((tmpvalue < resourcesAllF[crf][1][x][1]) || (tmpvalueMax == 0 && curResTarget.value*2 > tmpvalue)) {
flag = false;
}
else if (tmpvalueMax != 0 && (((gamePage.resPool.get('paragon').value < 100 && !(gamePage.religion.getRU('solarRevolution').val == 1) ) && Object.keys(craftPriority[0]).length > 0 && resourcesAllF[crf][1].filter(ff2 => craftPriority[3].indexOf(ff2[0]) != -1 ).length != 0 ) || (curResTarget.value < tmpvalue && tmpvalue/tmpvalueMax < 0.3) || (curResTarget.value >= tmpvalue && tmpvalue/tmpvalueMax <= 1))) {
flag = false;
}
if (flag && ((cnt > (tmpvalue / resourcesAllF[crf][1][x][1])) || (cnt == 0))) {
cnt = cnt == 0 ? 1 : cnt
if (resourcesAllF[crf][0] == "eludium") {
if (gamePage.resPool.get("unobtainium").value > gamePage.resPool.get("unobtainium").maxValue * 0.9){
cnt = Math.ceil(tmpvalue / resourcesAllF[crf][1][x][1]/2);
}
else{
cnt = 0;
}
}
}
}
}
if (flag == true && cnt > 0) {
if (resourcesAllF[crf][0] == "ship") {
if (gamePage.resPool.get("ship").value < 100 || (gamePage.resPool.get("ship").value < 5000 && gamePage.workshop.get("geodesy").researched) || gamePage.resPool.get("starchart").value > 1500){
gamePage.craft(resourcesAllF[crf][0], cnt);
}
}
else if (resourcesAllF[crf][0] == "kerosene") {
if (gamePage.resPool.get("oil").value >= gamePage.resPool.get("oil").maxValue * 0.9 || (gamePage.resPool.get("kerosene").value < 50000 && gamePage.resPool.get("oil").value > 1000000)){
gamePage.craft(resourcesAllF[crf][0], cnt);
}
}
else {
gamePage.craft(resourcesAllF[crf][0], cnt);
}
}
}
}
for (var crft = 0; crft < resources.length; crft++) {
var curRes = gamePage.resPool.get(resources[crft][0]);
var resourcePerTick = gamePage.getResourcePerTick(resources[crft][0], 0);
var resourcePerCraft = Math.max(Math.min((resourcePerTick * 5),curRes.value), 1);
var resourcePerCraftTrade = Math.max(Math.min((resourcePerTick * 100),curRes.value), 1);
if (Object.keys(craftPriority[0]).length > 0 && craftPriority[3].indexOf(resources[crft][0]) != -1 ) {
if (curRes.maxValue > 0 && curRes.value >= curRes.maxValue && gamePage.workshop.getCraft(resources[crft][1]).unlocked) {
gamePage.craft(resources[crft][1], Math.floor((resourcePerCraftTrade / resources[crft][2])));
}
else if (curRes.maxValue == 0 && curRes.value > gamePage.resPool.get(resources[crft][1]).value && gamePage.workshop.getCraft(resources[crft][1]).unlocked) {
gamePage.craft(resources[crft][1], Math.floor((resourcePerCraftTrade / resources[crft][2])));
}
}
else if (curRes.maxValue > 0 && curRes.value > (curRes.maxValue - resourcePerCraft) && gamePage.workshop.getCraft(resources[crft][1]).unlocked) {
gamePage.craft(resources[crft][1], Math.floor((resourcePerCraftTrade / resources[crft][2])));
}
else if (curRes.maxValue == 0 && curRes.value > gamePage.resPool.get(resources[crft][1]).value && gamePage.workshop.getCraft(resources[crft][1]).unlocked) {
gamePage.craft(resources[crft][1], Math.floor((resourcePerCraftTrade / resources[crft][2])));
}
}
}
// }
}
// Auto Research
function autoResearch() {
if (gamePage.tabs[2].visible) {
gamePage.tabs[2].update();
GlobalMsg['science'] = ''
if (science_labels.length > 0){
for (var sc = 0; sc < science_labels.length; sc++) {
if (gamePage.science.get(science_labels[sc]).unlocked && !gamePage.science.get(science_labels[sc]).researched){
GlobalMsg['science'] = gamePage.science.get(science_labels[sc]).label
sciencePriority = [gamePage.science.get(science_labels[sc]).label, gamePage.science.get(science_labels[sc]).prices]
break;
} else if (gamePage.science.get(science_labels[sc]).researched){
science_labels.splice(sc, 1);
sciencePriority = [null,[]];
break;
}
}
}
var btn = gamePage.tabs[2].buttons.filter(res => res.model.metadata.unlocked && res.model.enabled && !res.model.metadata.researched);
for (var rsc = 0; rsc < btn.length; rsc++) {
if ((gamePage.ironWill && !['astronomy','theology'].includes(btn[rsc].model.metadata.name)) && ((!gamePage.science.get('astronomy').researched && gamePage.science.get('astronomy').unlocked ) || (!gamePage.science.get('theology').researched && gamePage.science.get('theology').unlocked)))
{}
else{
try {
btn[rsc].controller.buyItem(btn[rsc].model, {}, function(result) {
if (result) {
btn[rsc].update();
gamePage.msg('Researched: ' + btn[rsc].model.name );
return;
}
});
} catch(err) {
console.log(err);
}
}
}
//policy
if (gamePage.religion.getRU('solarRevolution').val == 1 || gamePage.resPool.get("culture").value >= 2000){
var policy_lst = !gamePage.challenges.isActive("postApocalypse") ? policy_lst_all : policy_lst_post_apocalypse
var policy_btns = gamePage.tabs[2].policyPanel.children.filter(res => res.model.metadata.unlocked && res.model.enabled && !res.model.metadata.researched)
for (var rsc = 0; rsc < policy_btns.length; rsc++) {
if (policy_lst.includes(policy_btns[rsc].id)){
try {
pr_no_confirm = gamePage.opts.noConfirm;
gamePage.opts.noConfirm = true;
policy_btns[rsc].controller.buyItem(policy_btns[rsc].model, {}, function(result) {