forked from WG-SpaceCoder/AutoTrimps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoTrimps.js
1264 lines (1144 loc) · 60.8 KB
/
AutoTrimps.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
// ==UserScript==
// @name AutoTrimps
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author zininzinin, spindrjr
// @include *trimps.github.io*
// @grant none
// ==/UserScript==
(function() {
"use strict";
//Variables//
var runInterval = 200; //How often to loop through logic
var enableDebug = true; //Spam console?
var startAllSelected = false;
var avoidFast = false; //switch to heap when encountering a fast enemy?
var ManualGather = 'metal';
//List Variables//
var jobList = [{
name: 'Explorer',
max: -1,
ratio: 10
}, {
name: 'Trainer',
max: -1,
ratio: 99
}, {
name: 'Miner',
max: -1,
ratio: 10
}, {
name: 'Farmer',
max: -1,
ratio: 10
}, {
name: 'Lumberjack',
max: -1,
ratio: 10
}, {
name: 'Scientist',
max: -1,
ratio: 1
}];
var equipmentList = {
'Dagger': {
Upgrade: 'Dagadder',
Stat: 'attack',
Resource: 'metal',
Equip: true
},
'Mace': {
Upgrade: 'Megamace',
Stat: 'attack',
Resource: 'metal',
Equip: true
},
'Polearm': {
Upgrade: 'Polierarm',
Stat: 'attack',
Resource: 'metal',
Equip: true
},
'Battleaxe': {
Upgrade: 'Axeidic',
Stat: 'attack',
Resource: 'metal',
Equip: true
},
'Greatsword': {
Upgrade: 'Greatersword',
Stat: 'attack',
Resource: 'metal',
Equip: true
},
'Boots': {
Upgrade: 'Bootboost',
Stat: 'health',
Resource: 'metal',
Equip: true
},
'Helmet': {
Upgrade: 'Hellishmet',
Stat: 'health',
Resource: 'metal',
Equip: true
},
'Pants': {
Upgrade: 'Pantastic',
Stat: 'health',
Resource: 'metal',
Equip: true
},
'Shoulderguards': {
Upgrade: 'Smoldershoulder',
Stat: 'health',
Resource: 'metal',
Equip: true
},
'Breastplate': {
Upgrade: 'Bestplate',
Stat: 'health',
Resource: 'metal',
Equip: true
},
'Arbalest': {
Upgrade: 'Harmbalest',
Stat: 'attack',
Resource: 'metal',
Equip: true
},
'Gambeson': {
Upgrade: 'GambesOP',
Stat: 'health',
Resource: 'metal',
Equip: true
},
'Shield': {
Upgrade: 'Supershield',
Stat: 'health',
Resource: 'wood',
Equip: true
},
'Gym': {
Upgrade: 'Gymystic',
Stat: 'block',
Resource: 'wood',
Equip: false
}
};
var upgradeList = ['Coordination', 'Speedminer', 'Speedlumber', 'Speedfarming', 'Speedscience', 'Megaminer', 'Megalumber', 'Megafarming', 'Megascience', 'Efficiency', 'Potency', 'TrainTacular', 'Miners', 'Scientists', 'Trainers', 'Explorers', 'Blockmaster', 'Battle', 'Bloodlust', 'Bounty', 'Egg', 'Anger', 'Formations', 'Dominance', 'Barrier', 'UberHut', 'UberHouse', 'UberMansion', 'UberHotel', 'UberResort', 'Trapstorm'];
var buildingList = ['Hut', 'House', 'Gym', 'Mansion', 'Hotel', 'Resort', 'Gateway', 'Collector', 'Warpstation', 'Tribute', 'Nursery']; //NOTE THAT I REMOVED WORMHOLE TEMPORARILY UNTILL I FIGURE OUT WHAT TO DO WITH IT
// setInterval(printGame, runInterval);
//Page Changes//
document.getElementById("buyHere").innerHTML += '<div id="autoContainer" style="display: block; font-size: 12px;"> <div id="autoTitleDiv" class="titleDiv"> <div class="row"> <div class="col-xs-4"><span id="autoTitleSpan" class="titleSpan">Automation</span> </div> </div> </div> <br> <div class="autoBox" id="autoHere"> </div> <table style="text-align: left; vertical-align: top; width: 90%;" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="vertical-align: top;"> Loops <br> <input id="chkBuyStorage" title="Will buy storage when resource is almost full" type="checkbox">Buy Storage <br> <input id="chkManualStorage" title="Will automatically gather resources and trap trimps" type="checkbox">Manual Gather <br> <input id="chkBuyJobs" title="Buys jobs based on ratios configured" type="checkbox">Buy Jobs <br> <input id="chkBuyBuilding" title="Will buy non storage buildings as soon as they are available" type="checkbox">Buy Buildings <br> <input id="chkBuyUpgrades" title="autobuy non eqipment Upgrades" type="checkbox">Buy Upgrades <br> <input id="chkAutoStance" title="automate setting stance" type="checkbox">Auto Stance</td> <td style="vertical-align: top;"> Equipment <br> <input id="chkBuyEquipH" title="Will buy the most efficient armor available" type="checkbox">Buy Armor <br> <input id="chkBuyPrestigeH" title="Will buy the most efficient armor upgrade available" type="checkbox">Buy Armor Upgrades <br> <input id="chkBuyEquipA" title="Will buy the most efficient weapon available" type="checkbox">Buy Weapons <br> <input id="chkBuyPrestigeA" title="Will buy the most efficient weapon upgrade available" type="checkbox">Buy Weapon Upgrades <br><br> Misc Settings <br> <input id="chkTrapTrimps" title="automate trapping trimps" type="checkbox">Trap Trimps<br><input id="geneticistTargetBreedTime" title="Breed time in seconds to shoot for using geneticists" style="width: 20%;color: #000000;font-size: 12px;" value="5"> Geneticist Timer<br></td> </tr> <tr> <td style="vertical-align: middle; text-align: left;"> <br>Max Buildings to build <br> <input id="maxHut" style="width: 20%;color: #000000;font-size: 12px;" value="100"> Hut <br> <input id="maxHouse" style="width: 20%;color: #000000;font-size: 12px;" value="100"> House <br> <input id="maxMansion" style="width: 20%;color: #000000;font-size: 12px;" value="100"> Mansion <br> <input id="maxHotel" style="width: 20%;color: #000000;font-size: 12px;" value="100"> Hotel <br> <input id="maxResort" style="width: 20%;color: #000000;font-size: 12px;" value="100"> Resort <br> <input id="maxGateway" style="width: 20%;color: #000000;font-size: 12px;" value="100"> Gateway <br> <input id="maxCollector" style="width: 20%;color: #000000;font-size: 12px;" value="100"> Collector <br> <input id="maxWarpstation" style="width: 20%;color: #000000;font-size: 12px;" value="-1"> Warpstation <br> <input id="maxGym" style="width: 20%;color: #000000;font-size: 12px;" value="-1"> Gym <br> <input id="maxTribute" style="width: 20%;color: #000000;font-size: 12px;" value="-1"> Tribute <br> <input id="maxNursery" style="width: 20%;color: #000000;font-size: 12px;" value="-1"> Nursery <br> <br> </td> <td style="text-align: left; vertical-align: top;"> <br>Maps <br> <input id="chkAutoUniqueMap" title="Auto run unique maps" type="checkbox"> Auto run unique maps <br> <input id="chkAutoProgressMap" title="Runs maps when cannot defeat current level" type="checkbox">Auto map when stuck <br> <input id="maxHitsTillStuck" style="width: 10%; color: #000000;" value="10"> Max hits to kill enemy before stuck<br><br>Ratios  Max<br><input id="FarmerRatio" style="width: 10%; color: #000000;" value="10"><input id="FarmerMax" style="width: 10%; color: #000000;" value="-1"> Farmer<br><input id="LumberjackRatio" style="width: 10%; color: #000000;" value="10"><input id="LumberjackMax" style="width: 10%; color: #000000;" value="-1"> Lumberjack<br><input id="MinerRatio" style="width: 10%; color: #000000;" value="10"><input id="MinerMax" style="width: 10%; color: #000000;" value="-1"> Miner<br><input id="ScientistRatio" style="width: 10%; color: #000000;" value="10"><input id="ScientistMax" style="width: 10%; color: #000000;" value="-1"> Scientist<br><input id="TrainerRatio" style="width: 10%; color: #000000;" value="10"><input id="TrainerMax" style="width: 10%; color: #000000;" value="-1"> Trainer<br><input id="ExplorerRatio" style="width: 10%; color: #000000;" value="10"><input id="ExplorerMax" style="width: 10%; color: #000000;" value="-1"> Explorer</td> </tr> </tbody> </table></div>';
var temp = document.getElementById("autoContainer").innerHTML.split('input id="');
temp.splice(0, 1);
var pageSettings = [];
for (var i in temp) {
pageSettings.push(temp[i].substring(0, temp[i].indexOf('"')));
}
//Set all the saved variables
for (var index in pageSettings) {
var setting = pageSettings[index];
if (localStorage.getItem(setting) != null) {
// debug(setting + ' is of type ' + document.getElementById(setting).type);
var local = localStorage.getItem(setting);
if (document.getElementById(setting).type == 'checkbox') {
local = (local == 'true');
if (document.getElementById(setting).checked != local) {
// debug('FIRST Setting ' + setting + ' to ' + local + ' from ' + document.getElementById(setting).checked);
document.getElementById(setting).checked = local;
// debug(setting + ' is set to ' + document.getElementById(setting).checked);
}
} else {
if (document.getElementById(setting).value != localStorage.getItem(setting)) {
// debug('FIRST Setting ' + setting + ' to ' + localStorage.getItem(setting));
document.getElementById(setting).value = localStorage.getItem(setting);
// debug(setting + ' is set to ' + document.getElementById(setting).value);
}
}
}
}
function saveSettings() {
// debug('Saved');
for (var index in pageSettings) {
var setting = pageSettings[index];
// debug('Setting is ' +setting);
if (document.getElementById(setting).type == 'checkbox') {
localStorage.setItem(setting, document.getElementById(setting).checked);
} else {
localStorage.setItem(setting, document.getElementById(setting).value);
}
}
}
function AutoBuyStorage() {
return document.getElementById("chkBuyStorage").checked;
}
function AutoManualLabor() {
return document.getElementById("chkManualStorage").checked;
}
function autoBuyJobs() {
return document.getElementById("chkBuyJobs").checked;
}
function AutoBuyBuilding() {
return document.getElementById("chkBuyBuilding").checked;
}
function AutoBuyEquipH() {
return document.getElementById("chkBuyEquipH").checked;
}
function AutoBuyPrestigeH() {
return document.getElementById("chkBuyPrestigeH").checked;
}
function AutoBuyEquipA() {
return document.getElementById("chkBuyEquipA").checked;
}
function AutoBuyPrestigeA() {
return document.getElementById("chkBuyPrestigeA").checked;
}
function AutoBuyUpgrades() {
return document.getElementById("chkBuyUpgrades").checked;
}
function AutoUniqueMap() {
return document.getElementById("chkAutoUniqueMap").checked;
}
function AutoProgressMap() {
return document.getElementById("chkAutoProgressMap").checked;
}
function maxHitsTillStuck() {
return document.getElementById("maxHitsTillStuck").value;
}
function trapTrimps() {
return document.getElementById("chkTrapTrimps").checked;
}
function autoStanceChecked() {
return document.getElementById("chkAutoStance").checked;
}
function getTargetBreedTime() {
return document.getElementById("geneticistTargetBreedTime").value;
}
//I honestly have no idea why I have to do this >.>
document.getElementById("wood").style.opacity = "1";
document.getElementById("science").style.opacity = "1";
document.getElementById("jobsTab").style.opacity = "1";
document.getElementById("upgradesTab").style.opacity = "1";
document.getElementById("equipmentTab").style.opacity = "1";
document.getElementById("buyTabsUl").innerHTML += '<li role="presentation" id="autoTab" onclick="filterTabs(\'auto\')" class="buyTab"><a id="autoA" href="#">Automation</a></li>';
window.mapsClicked();
window.mapsClicked();
window.mapsClicked();
//Functions//
function debug(message) {
if (enableDebug)
console.log(message);
}
function clickButton(id) {
debug('Trying to click button: ' + id);
if (document.getElementById(id).style.visibility != 'hidden') {
document.getElementById(id).click();
setTimeout(function() {}, 10);
return true;
} else {
debug('Cannot click button: ' + id);
return false;
}
}
function buyJob(jobTitle, amount, fire) {
//debug('Hiring ' + amount + ' ' + jobTitle);
if (amount == undefined || (!canAffordJob(jobTitle, amount) && !fire)){
amount = 1;
}
if(!canAffordJob(jobTitle, amount)) return;
var oldAmount = window.game.global.buyAmt;
var oldFire = window.game.global.firing;
window.game.global.firing = fire == true ? true : false;
window.game.global.buyAmt = amount;
window.buyJob(jobTitle);
window.game.global.buyAmt = oldAmount;
window.game.global.firing = oldFire;
window.tooltip('hide');
}
//adjust geneticists to reach desired breed timer
function manageGenes() {
var fWorkers = Math.ceil(window.game.resources.trimps.realMax() / 2) - window.game.resources.trimps.employed;
//if we need to hire geneticists
if (getTargetBreedTime() >= 0 && getTargetBreedTime() > getBreedTime() && !window.game.jobs.Geneticist.locked) {
//if there's no free worker spots, fire a scientist
if (fWorkers < 1 && window.canAffordJob('Geneticist', false, fWorkers)) {
buyJob('Scientist', 1, true);
fWorkers = Math.ceil(window.game.resources.trimps.realMax() / 2) - window.game.resources.trimps.employed;
}
//hire a geneticist
buyJob('Geneticist');
}
//if we need to fire geneticists
if (getTargetBreedTime() >= 0 && getTargetBreedTime() < getBreedTime() && !window.game.jobs.Geneticist.locked) {
buyJob('Geneticist', 1, true);
}
}
function jobMax(jobName) {
return document.getElementById(jobName + 'Max').value;
}
function jobRatio(jobName) {
return document.getElementById(jobName + 'Ratio').value;
}
function determineJobWant(j) {
var jobName = jobList[j].name;
var max = jobMax(jobName);
var ratio = jobRatio(jobName);
if (!window.game.jobs[jobName].locked) {
if (!canAffordJob(jobName, 1)) {
return 0;
} else if (max >= 0) {
if (max <= window.game.jobs[jobName].owned) {
return 0;
} else {
return 1 / Math.min(max, window.game.jobs[jobName].owned / ratio);
}
} else {
return 1 / (window.game.jobs[jobName].owned / ratio);
}
// debug('Job: ' +jobList[jobIndex].name+ '. Want: ' +jobList[j].want);
}
return 0;
}
function getBreedTime() {
var trimps = window.game.resources.trimps;
var breeding = trimps.owned - trimps.employed;
var trimpsMax = trimps.realMax();
var potencyMod = trimps.potency;
if (window.game.global.brokenPlanet) breeding /= 10;
//Pheromones
potencyMod += (potencyMod * window.game.portal.Pheromones.level * window.game.portal.Pheromones.modifier);
if (window.game.jobs.Geneticist.owned > 0) potencyMod *= Math.pow(.98, window.game.jobs.Geneticist.owned);
if (window.game.unlocks.quickTrimps) potencyMod *= 2;
breeding = breeding * potencyMod;
updatePs(breeding, true);
var timeRemaining = log10((trimpsMax - trimps.employed) / (trimps.owned - trimps.employed)) / log10(1 + (potencyMod / 10));
if (!window.game.global.brokenPlanet) timeRemaining /= 10;
timeRemaining = Math.floor(timeRemaining) + " Secs";
var fullBreed = 0;
if (window.game.options.menu.showFullBreed.enabled) {
var adjustedMax = (window.game.portal.Coordinated.level) ? window.game.portal.Coordinated.currentSend : trimps.maxSoldiers;
var totalTime = log10((trimpsMax - trimps.employed) / ((trimpsMax - adjustedMax) - trimps.employed)) / log10(1 + (potencyMod / 10));
if (!window.game.global.brokenPlanet) totalTime /= 10;
fullBreed = Math.floor(totalTime) + " Secs";
timeRemaining += " / " + fullBreed;
}
// debug('Time to breed is ' +Math.floor(totalTime));
return Math.floor(totalTime);
}
function canPurchaseWorkers() {
for (var j in jobList) {
if (window.canAffordJob(jobList[j].name, false, 1)) {
return true;
}
}
return false;
}
function freeWorkers() {
if (!canPurchaseWorkers() || Math.floor(window.game.resources.trimps.owned - window.game.resources.trimps.employed) === 0) return 0;
return Math.ceil(window.game.resources.trimps.realMax() / 2) - window.game.resources.trimps.employed;
}
function canAffordJob(jobName, amount) {
var workspaces = Math.ceil(game.resources.trimps.realMax() / 2) - game.resources.trimps.employed;
if (workspaces <= 0) return false;
if (!window.canAffordJob(jobName, false, workspaces)) return false;
if (freeWorkers() === 0) return false;
if (amount == undefined) amount = 1;
for (var costItem in window.game.jobs[jobName].cost) {
// debug('Checking cost for ' +costItem+ ' and ' +jobName+ ': ' + window.checkJobItem(jobName, false, costItem, null, 1));
if (!window.checkJobItem(jobName, false, costItem, null, amount)) return false;
}
return true;
}
function buyJobs() {
if (autoBuyJobs()) { //don't buy jobs if total trimps has dropped below 80%, to prevent dropping to 0 breeding during large population cap purchase (gigastation)
if ((window.game.resources.trimps.employed === 0 && window.game.resources.trimps.realMax() != window.game.resources.trimps.owned) || window.game.resources.trimps.owned / window.game.resources.trimps.realMax() < .8) {
return;
}
// debug('AutoBuyJobs = ' + autoBuyJobs());
var i = 0;
var amountToBuy = Math.ceil(freeWorkers() * 0.001);
while (freeWorkers() > 0 && i < 100) {
i++;
// debug('Job loop');
var greatestWant = 0;
var jobToHire = '';
for (var j in jobList) {
// debug('Job: ' +jobList[j].name+ '. Is unlocked? ' +window.game.jobs[jobList[j].name].locked);
var want = determineJobWant(j);
// debug('Job: ' +jobList[j].name+ '. Want: ' +want);
if (want > greatestWant) {
greatestWant = want;
jobToHire = jobList[j].name;
}
}
if (jobToHire === '') {
// debug('No job to hire :(');
} else {
//debug ('entering buy. jobtohire:' + jobToHire);
//why does this instantly break the game?!
/* if (amountToBuy > jobMax(jobToHire) && jobMax(jobToHire) > 0) {
debug('buy over max amt:' + amountToBuy +'jobmax:' + jobMax(jobToHire) + 'for job:' +jobToHire);
amountToBuy = jobMax(jobToHire);
}*/
// debug('owned ' + window.game.resources.trimps.owned + ' employed ' + window.game.resources.trimps.employed + ' amountToBuy ' + amountToBuy);
if (Math.floor(window.game.resources.trimps.owned - window.game.resources.trimps.employed) - amountToBuy <= 2) return;
var oldAmount = window.game.global.buyAmt;
if (jobMax(jobToHire) > 0) {
buyJob(jobToHire, Math.min(jobMax(jobToHire)-window.game.jobs[jobToHire].owned, amountToBuy), false);
} else {
buyJob(jobToHire, amountToBuy, false);
}
}
}
}
}
function buildingAtMax(buildingName) {
var buildingMax = document.getElementById('max' + buildingName).value;
if (buildingMax < 0) return false;
return buildingMax <= window.game.buildings[buildingName].owned;
}
function buyBuildings() {
if (AutoBuyBuilding() && window.game.global.buildingsQueue.length < 5) {
var oldAmount = window.game.global.buyAmt;
window.game.global.buyAmt = 1;
for (var buildingIndex in buildingList) {
var building = buildingList[buildingIndex];
// debug('Checking building ' +building+ ' buildingMax ' +document.getElementById('max' + building).value);
if (window.canAffordBuilding(building, false) && !window.game.buildings[building].locked && !buildingAtMax(building)) {
// debug('Attempting to build: ' + building);
window.buyBuilding(building);
window.tooltip('hide');
}
}
window.game.global.buyAmt = oldAmount;
}
}
function evaluateEfficiency(equipName) {
var equip = equipmentList[equipName];
var gameResource = equip.Equip ? window.game.equipment[equipName] : window.game.buildings[equipName];
if (equipName == 'Shield') {
if (gameResource.blockNow) {
equip.Stat = 'block';
} else {
equip.Stat = 'health';
}
}
var Eff = Effect(gameResource, equip);
var Cos = Cost(gameResource, equip);
var Res = Eff / Cos;
var Status = 'white';
var Wall = false;
//white - Upgrade is not available
//yellow - Upgrade is not affordable
//orange - Upgrade is affordable, but will lower stats
//red - Yes, do it now!
if (!window.game.upgrades[equip.Upgrade].locked) {
//Evaluating upgrade!
var CanAfford = window.canAffordTwoLevel(window.game.upgrades[equip.Upgrade]);
if (equip.Equip) {
var NextEff = PrestigeValue(equip.Upgrade);
var NextCost = getNextPrestigeCost(equip.Upgrade) * Math.pow(1 - window.game.portal.Artisanistry.modifier, window.game.portal.Artisanistry.level);
Wall = NextEff / NextCost > Res;
}
if (!CanAfford) {
Status = 'yellow';
} else {
if (!equip.Equip) {
//Gymystic is always cool, fuck shield - lol
Status = 'red';
} else {
var CurrEff = gameResource.level * Eff;
var NeedLevel = Math.ceil(CurrEff / NextEff);
var Ratio = gameResource.cost[equip.Resource][1];
var NeedResource = NextCost * (Math.pow(Ratio, NeedLevel) - 1) / (Ratio - 1);
if (window.game.resources[equip.Resource].owned > NeedResource) {
Status = 'red';
} else {
Status = 'orange';
}
}
}
}
return {
Stat: equip.Stat,
Factor: Res,
Status: Status,
Wall: Wall
};
}
function Effect(gameResource, equip) {
if (equip.Equip) {
return gameResource[equip.Stat + 'Calculated'];
} else {
//That be Gym
var oldBlock = gameResource.increase.by * gameResource.owned;
var Mod = game.upgrades.Gymystic.done ? (game.upgrades.Gymystic.modifier + (0.01 * (game.upgrades.Gymystic.done - 1))) : 1;
var newBlock = gameResource.increase.by * (gameResource.owned + 1) * Mod;
return newBlock - oldBlock;
}
}
function Cost(gameResource, equip) {
var price = parseFloat(getBuildingItemPrice(gameResource, equip.Resource, equip.Equip));
if (equip.Equip) price = Math.ceil(price * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
return price;
}
function PrestigeValue(what) {
var name = window.game.upgrades[what].prestiges;
var equipment = window.game.equipment[name];
var stat;
if (equipment.blockNow) stat = "block";
else stat = (typeof equipment.health !== 'undefined') ? "health" : "attack";
var toReturn = Math.round(equipment[stat] * Math.pow(1.19, ((equipment.prestige) * game.global.prestige[stat]) + 1));
return toReturn;
}
function buyEquipment() {
var Best = {
'healthwood': {
Factor: 0,
Name: '',
Wall: false,
Status: 'white'
},
'healthmetal': {
Factor: 0,
Name: '',
Wall: false,
Status: 'white'
},
'attackmetal': {
Factor: 0,
Name: '',
Wall: false,
Status: 'white'
},
'blockwood': {
Factor: 0,
Name: '',
Wall: false,
Status: 'white'
}
};
for (var equipName in equipmentList) {
var equip = equipmentList[equipName];
// debug('Equip: ' + equip + ' EquipIndex ' + equipName);
var gameResource = equip.Equip ? window.game.equipment[equipName] : window.game.buildings[equipName];
// debug('Game Resource: ' + gameResource);
if (!gameResource.locked) {
document.getElementById(equipName).style.color = 'white';
var evaluation = evaluateEfficiency(equipName);
// debug(equipName + ' evaluation ' + evaluation.Status);
var BKey = equip.Stat + equip.Resource;
// debug(equipName + ' bkey ' + BKey);
if (Best[BKey].Factor == 0 || Best[BKey].Factor < evaluation.Factor) {
Best[BKey].Factor = evaluation.Factor;
Best[BKey].Name = equipName;
Best[BKey].Wall = evaluation.Wall;
Best[BKey].Status = evaluation.Status;
}
document.getElementById(equipName).style.borderColor = evaluation.Status;
if (evaluation.Status != 'white' && evaluation.Status != 'yellow') {
document.getElementById(equip.Upgrade).style.color = evaluation.Status;
}
if (evaluation.Status == 'yellow') {
document.getElementById(equip.Upgrade).style.color = 'white';
}
if (evaluation.Wall) {
document.getElementById(equipName).style.color = 'yellow';
}
if (
evaluation.Status == 'red' &&
(
(
AutoBuyPrestigeA() &&
equipmentList[equipName].Stat == 'attack'
) ||
(
AutoBuyPrestigeH() &&
(
equipmentList[equipName].Stat == 'health' ||
equipmentList[equipName].Stat == 'block'
)
)
)
) {
var upgrade = equipmentList[equipName].Upgrade;
debug('Upgrading ' + upgrade);
window.buyUpgrade(upgrade);
// window.tooltip('hide');
}
}
}
for (var stat in Best) {
if (Best[stat].Name != '') {
var DaThing = equipmentList[Best[stat].Name];
document.getElementById(Best[stat].Name).style.color = Best[stat].Wall ? 'orange' : 'red';
if ((AutoBuyEquipA() && DaThing.Stat == 'attack') || (AutoBuyEquipH() && (DaThing.Stat == 'health' || DaThing.Stat == 'block'))) {
if (DaThing.Equip && !Best[stat].Wall && window.canAffordBuilding(Best[stat].Name, null, null, true)) {
debug('Leveling equipment ' + Best[stat].Name);
window.buyEquipment(Best[stat].Name);
window.tooltip('hide');
}
}
}
}
}
//add way to buy scientists upgrade before bloodlust and miners?
function buyUpgrades() {
for (var upgrade in upgradeList) {
upgrade = upgradeList[upgrade];
var gameUpgrade = window.game.upgrades[upgrade];
if (AutoBuyUpgrades() && gameUpgrade.allowed > gameUpgrade.done && window.canAffordTwoLevel(upgrade) /*&& !window.jobs.Scientist.locked*/ ) {
window.buyUpgrade(upgrade);
// window.tooltip('hide');
document.getElementById("upgradesAlert").innerHTML = '';
}
}
}
//spams buys of storage in early game but oh well. Just get rid of console spam
function buyStorage() {
if (AutoBuyStorage()) {
var packMod = 1 + window.game.portal.Packrat.level * window.game.portal.Packrat.modifier;
var Bs = {
'Barn': 'food',
'Shed': 'wood',
'Forge': 'metal'
};
for (var B in Bs) {
if (window.game.resources[Bs[B]].owned > window.game.resources[Bs[B]].max * packMod * 0.9) {
// debug('Buying ' + B + '(' + Bs[B] + ') at ' + Math.floor(window.game.resources[Bs[B]].owned / (window.game.resources[Bs[B]].max * packMod * 0.99) * 100) + '%');
if (AutoBuyStorage() && window.canAffordBuilding(B)) {
debug('Wanna buy ' + B);
window.buyBuilding(B);
window.tooltip('hide');
}
}
}
}
}
function manualLabor() {
//if science perk level is none, dont turn on auto labor until scientists are unlocked
if (AutoManualLabor() && (window.game.global.sLevel > 0 || !window.game.jobs.Scientist.locked)) {
//If you don't have autofight and you have enough trimps, manual fight
if (((window.game.resources.trimps.owned - window.game.resources.trimps.employed) > (window.game.resources.trimps.realMax())/8 && window.game.global.world < 5) && !window.game.global.fighting && window.game.upgrades.Battle.done == 1) {
window.fightManual();
}
//If you can autofight - set autofight to true
if (window.game.upgrades.Bloodlust.done == 1 && window.game.global.pauseFight) {
window.pauseFight();
}
//set gather to whatever player has clicked. Will be nothing on fresh portal
if (game.global.playerGathering != 'buildings' && game.global.playerGathering != 'science') {
ManualGather = game.global.playerGathering;
}
//if we have more than 2 buildings in queue, or our modifier is real fast, build
if ((game.global.buildingsQueue.length > 2) || (game.global.buildingsQueue.length > 0 && game.global.playerModifier > 1000) && game.global.playerGathering != 'buildings') {
setGather('buildings');
}
//if we can gather more science in 1 min by ourselves than we currently have, get some science
else if (game.global.playerModifier * 60 > game.resources.science.owned) {
setGather('science');
}
//otherwise gather what the player chose
else {
setGather(ManualGather);
}
//trap trimps if option is checked
if (window.game.upgrades.Trapstorm.done == 1 && trapTrimps()) {
if (!window.game.global.trapBuildToggled) {
window.toggleAutoTrap();
}
if (window.game.resources.trimps.realMax() == window.game.resources.trimps.owned || window.game.buildings.Trap.owned < 100) {
window.setGather('buildings');
} else {
window.setGather('trimps');
}
}
}
}
// function manualLabor() {
// if (AutoManualLabor()) {
// if ((window.game.resources.trimps.owned - window.game.resources.trimps.employed) < 2 && window.canAffordBuilding('Trap') && window.game.global.buildingsQueue.length == 0 && (trapTrimps() || (window.game.resources.trimps.realMax() / window.game.resources.trimps.owned > 2))) {
// debug('Wanna buy Trap');
// buyBuilding('Trap');
// // window.tooltip('hide');
// }
// //If you don't have autofight and you have enough trimps, manual fight
// if (window.game.upgrades.Bloodlust.done == 0 && (window.game.resources.trimps.owned - window.game.resources.trimps.employed) > 3 && !window.game.global.fighting && window.game.upgrades.Battle.done == 1) {
// window.fightManual();
// }
// //If you can autofight - set autofight to true
// if (window.game.upgrades.Bloodlust.done == 1 && window.game.global.pauseFight) {
// window.pauseFight();
// }
// //TrapTrimps - if need trimps and have trapstorm will autotrap trimps
// //Overrides trap trimps option if total trimps is below half (presumeably at start of game)
// if (window.game.buildings.Trap.owned > 0 && (window.game.resources.trimps.realMax() - window.game.resources.trimps.owned) > 2 && window.game.upgrades.Trapstorm.done != 1 && (trapTrimps() || (window.game.resources.trimps.realMax() / window.game.resources.trimps.owned > 2))) {
// window.setGather('trimps');
// //if scientists are still locked, don't give building priority
// } else if (window.game.global.buildingsQueue.length > 2 && !window.game.jobs.Scientist.locked) {
// window.setGather('buildings');
// } else if (window.game.global.autoCraftModifier == 0 && window.game.global.buildingsQueue.length > 0 && window.game.upgrades.Scientists.allowed == 0) {
// window.setGather('buildings');
// } else {
// //Do something here :/
// var manualResourceList = {
// 'food': 'Farmer',
// 'wood': 'Lumberjack',
// 'metal': 'Miner',
// 'science': 'Scientist'
// };
// var lowestResource = 'food';
// var lowestResourceRate = -1;
// var haveWorkers = true;
// for (var resource in manualResourceList) {
// var job = manualResourceList[resource];
// var currentRate = window.game.jobs[job].owned * window.game.jobs[job].modifier;
// // debug('Current rate for ' + resource + ' is ' + currentRate + ' is hidden? ' + (document.getElementById(resource).style.visibility == 'hidden'));
// if (document.getElementById(resource).style.visibility != 'hidden') {
// // debug('INNERLOOP for resource ' +resource);
// if (currentRate == 0) {
// currentRate = window.game.resources[resource].owned;
// // debug('Current rate for ' + resource + ' is ' + currentRate + ' lowest ' + lowestResource + lowestResourceRate);
// if ((haveWorkers) || (currentRate < lowestResourceRate)) {
// // debug('New Lowest1 ' + resource + ' is ' + currentRate + ' lowest ' + lowestResource + lowestResourceRate+ ' haveworkers ' +haveWorkers);
// haveWorkers = false;
// lowestResource = resource;
// lowestResourceRate = currentRate;
// }
// }
// if ((currentRate < lowestResourceRate || lowestResourceRate == -1) && haveWorkers) {
// // debug('New Lowest2 ' + resource + ' is ' + currentRate + ' lowest ' + lowestResource + lowestResourceRate);
// lowestResource = resource;
// lowestResourceRate = currentRate;
// }
// }
// // debug('Current Stats ' + resource + ' is ' + currentRate + ' lowest ' + lowestResource + lowestResourceRate+ ' haveworkers ' +haveWorkers);
// }
// if (window.game.upgrades.Trapstorm.done == 1 && trapTrimps()) {
// if (!window.game.global.trapBuildToggled) {
// window.toggleAutoTrap();
// }
// if (window.game.resources.trimps.realMax() == window.game.resources.trimps.owned || window.game.buildings.Trap.owned < 100) {
// window.setGather('buildings')
// } else {
// window.setGather('trimps')
// }
// } else if (window.game.global.playerGathering != lowestResource) {
// // debug('Changing gather to ' + lowestResource);
// window.setGather(lowestResource);
// // window.tooltip('hide');
// }
// }
// }
// }
function autoStance() {
if (window.game.global.gridArray.length != 0 && window.game.global.challengeActive != "Electricity" && window.game.global.challengeActive != "Nom" && autoStanceChecked()) {
if (avoidFast) {
var badguyMinAtt = window.game.global.gridArray[window.game.global.lastClearedCell + 1].attack * .805; //fudge factor
var badguyMaxAtt = window.game.global.gridArray[window.game.global.lastClearedCell + 1].attack * 1.19;
var badguyFast = window.game.badGuys[window.game.global.gridArray[window.game.global.lastClearedCell + 1].name].fast;
if (window.game.global.mapsActive && !window.game.global.preMapsActive) {
badguyMinAtt = window.game.global.mapGridArray[window.game.global.lastClearedMapCell + 1].attack * .805;
badguyMaxAtt = window.game.global.mapGridArray[window.game.global.lastClearedMapCell + 1].attack * 1.19;
badguyFast = window.game.badGuys[window.game.global.mapGridArray[window.game.global.lastClearedMapCell + 1].name].fast;
}
var mysoldiers = (window.game.portal.Coordinated.level) ? window.game.portal.Coordinated.currentSend : window.game.resources.trimps.maxSoldiers;
var myblock = window.game.global.soldierCurrentBlock;
var myhealth = window.game.global.soldierHealthMax;
}
//Switch Formations
if (window.game.upgrades.Formations.done == 1 && window.game.upgrades.Dominance.done == 0) {
var healthFraction = window.game.global.soldierHealth / window.game.global.soldierHealthMax;
// If trimps are plenty, go to nostance
if (window.game.resources.trimps.owned >= window.game.resources.trimps.realMax()) {
window.setFormation('0');
} else if (healthFraction < 0.2 && window.game.global.formation == 0) {
window.setFormation('1');
// If the army is strong, switch to nostance
} else if ((healthFraction > 0.8 && window.game.global.formation == 1)) {
window.setFormation('0');
}
} else if (window.game.upgrades.Dominance.done == 1) {
healthFraction = window.game.global.soldierHealth / window.game.global.soldierHealthMax;
if (window.game.global.mapsActive && !window.game.global.preMapsActive) {
if (window.game.badGuys[window.game.global.mapGridArray[window.game.global.lastClearedMapCell + 1].name].fast && avoidFast) {
if (window.game.global.formation == 2 && myblock < badguyMaxAtt && !(window.game.resources.trimps.owned >= window.game.resources.trimps.realMax())) {
window.setFormation(1);
}
} else {
// If trimps are plenty, go to Dominance
if (window.game.resources.trimps.owned >= window.game.resources.trimps.realMax()) {
window.setFormation('2');
// If Dominance is failing, switch to None
} else if (healthFraction < 0.2 && window.game.global.formation == 2) {
window.setFormation('0');
// If None is failing, switch to Heap
} else if (healthFraction < 0.2 && window.game.global.formation == 0) {
window.setFormation('1');
// If the army is strong, switch to Dominance
} else if ((healthFraction > 0.9 && window.game.global.formation == 1) || (healthFraction > 0.6 && window.game.global.formation == 0)) {
window.setFormation('2');
} else if ((healthFraction > .8 && healthFraction < .9) && window.game.global.formation == 1) {
window.setFormation('0');
}
}
} else {
if (window.game.badGuys[window.game.global.gridArray[window.game.global.lastClearedCell + 1].name].fast && avoidFast) {
if (window.game.global.formation == 2 && !(window.game.resources.trimps.owned >= window.game.resources.trimps.realMax())) {
window.setFormation(1);
}
} else {
// If trimps are plenty, go to Dominance
if (window.game.resources.trimps.owned >= window.game.resources.trimps.realMax()) {
window.setFormation('2');
// If Dominance is failing, switch to None
} else if (healthFraction < 0.2 && window.game.global.formation == 2) {
window.setFormation('0');
// If None is failing, switch to Heap
} else if (healthFraction < 0.2 && window.game.global.formation == 0) {
window.setFormation('1');
// If the army is strong, switch to Dominance
} else if ((healthFraction > 0.9 && window.game.global.formation == 1) || (healthFraction > 0.6 && window.game.global.formation == 0)) {
window.setFormation('2');
}
}
}
}
}
}
function objectToArray(obj, key) {
var result = [];
for (var i in obj) {
if ((typeof x === 'object') && (x !== null)) {
if (key.length > 0) key += '.';
result.push
}
}
}
function flattenObject(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
};
function isNumber(obj) {
return !isNaN(parseFloat(obj))
}
function printGame() {
var flatGame = flattenObject(window.game);
var statArray = [];
for (var item in flatGame) {
if (isNumber(flatGame[item])) {
// debug(item + flatGame[item]);
}
}
// debug(result);
}
function getCurrentMap() {
var gridArray = window.game.global.gridArray;
for (var cell in gridArray) {
// debug('cell: ' + cell);
if (gridArray[cell].health > 0) {
return gridArray[cell];
}
}
return gridArray[0];
}
function buildMap(mapID) {
try {
window.buildMapGrid(mapID);
} catch (e) {
//Handle the error if you wish.
}
}
function canBeatMap(map) {
return true; //Logic below really broke things... oops... temp fix x.x
window.selectMap(map.id);
buildMap(map.id);
var cell = window.game.global.mapGridArray[window.game.global.mapGridArray.length - 1];
// debug('Build map ' + map.name + ' maxAttack ' + maxAttack + ' soldierDefence ' + getTotalDefence() + '');
return canBeatCell(cell);
}
function canBeatCell(cell) {
// debug('Running canBeatCell - Enemy Health: ' + window.game.global.getEnemyHealth(cell.level, cell.name)+ ' My damage ' +window.calculateDamage(window.game.global.soldierCurrentAttack, true, true, true)+ ' and max hits: ' +maxHitsTillStuck());
//return window.game.global.getEnemyAttack(cell.level, cell.name) < (getTotalDefence() * 0.75) && window.game.global.getEnemyHealth(cell.level, cell.name) < (window.calculateDamage(window.game.global.soldierCurrentAttack, true, true, true) * maxHitsTillStuck());
var live=false;
var hitsToTake=2;//2 hits feels low. Maybe a text box for the player to determine?
if (game.global.world>59)
{
var atk=window.game.global.getEnemyAttack(cell.level, cell.name);
if (atk*0.8>window.game.global.soldierCurrentBlock )
{
atk-=window.game.global.soldierCurrentBlock;
}
else
{
atk*=0.2;
}
live=(window.game.global.soldierHealthMax)>atk*hitsToTake;
}
else
{
live=(window.game.global.getEnemyAttack(cell.level, cell.name)-window.game.global.soldierCurrentBlock)*hitsToTake<window.game.global.soldierHealthMax;
}
return live && window.game.global.getEnemyHealth(cell.level, cell.name) < (window.calculateDamage(window.game.global.soldierCurrentAttack, true, true, true) * maxHitsTillStuck());
}
function canBeatWorld(level) {
if (level == undefined) {
level = window.game.global.gridArray.length - 1; //Checks zone boss
}