-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTrimpz.js
2716 lines (2545 loc) · 106 KB
/
Trimpz.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
/*global game,tooltip,resolvePow,getNextPrestigeCost,adjustMap,updateMapCost,addSpecials,enteringValue*/
/*jslint plusplus: true */
//sets of constants to modify that will be switched out over the course of the game
//generally speaking, and by default, it starts with constantsEarlyGame and then uses the next set at 45,55, and then 60
//if you add an entirely new constant set, be sure to add it in order in the array "constantsSets" and set the set's "zoneToStartAt" appropriately
function ConstantSet(overrides){
"use strict";
if (overrides) {
ChangeValues(this, overrides);
}
}
function ChangeValues(theObject, values){
"use strict";
for (var x in values) {
theObject[x] = values[x];
}
}
ConstantSet.prototype = {
zoneToStartAt : 0, //where this set of constants begins being used
runInterval : 200, //how often Trimpz main loop is run
minerMultiplier : 2, //how many more miners than farmers? (multiplied)
lumberjackMultiplier : 1, //how many more lumberjacks than farmers? (multiplied)
trainerCostRatio : 0.4, //buy trainers with enough resources (0.2 = 20% of resources)
explorerCostRatio : 0.2, //buy explorers with enough resources (0.2 = 20% of resources)
minFoodOwned : 15, //minimum food on hand, required for beginning of the game
minWoodOwned : 15, //minimum wood on hand, required for beginning of the game
minTrimpsOwned : 9, //minimum trimps on hand, required for beginning of the game
minScienceOwned : 10, //minimum science on hand, required for beginning of the game
housingCostRatio : 0.3, //buy housing with enough resources (0.2 = 20% of resources)
gymCostRatio : 0.6, //buy gyms with enough resources (0.2 = 20% of resources)
maxGyms : 10000, //maximum number of gyms to buy
tributeCostRatio : 0.5, //buy tributes with enough resources (0.2 = 20% of resources)
nurseryCostRatio : 0.5, //buy nursery with enough resources (0.2 = 20% of resources)
maxLevel : 10, //maximum level of all equipment per tier unless it's really cheap(see constant above)
equipmentCostRatio : 0.5, //buy equipment with enough resources (0.2 = 20% of resources)
otherWorkersFocusRatio : 0.5, //what percent of trimps to take from each other job to focus on gaining resources for an upgrade, including science
numTrapsForAutoTrapping : 10000, //maximum number of traps to build
shieldCostRatio : 1, //buy shield with enough resources (1 = 100% of resources)
shouldSkipHpEquipment : false, //true to not buy or prestige/upgrade health equipment
getZoneToStartAt: function () { return this.zoneToStartAt; },
getRunInterval: function () { return this.runInterval; },
getTrainerCostRatio: function () { return this.trainerCostRatio; },
getMinerMultiplier: function () { return this.minerMultiplier; },
getExplorerCostRatio: function () { return this.explorerCostRatio; },
getMinFoodOwned: function () { return this.minFoodOwned; },
getMinWoodOwned: function () { return this.minWoodOwned; },
getMinTrimpsOwned: function () { return this.minTrimpsOwned; },
getMinScienceOwned: function () { return this.minScienceOwned; },
getGymCostRatio: function () { return this.gymCostRatio; },
getMaxGyms : function () { return this.maxGyms; },
getHousingCostRatio: function () { return this.housingCostRatio; },
getTributeCostRatio: function () { return this.tributeCostRatio; },
getNurseryCostRatio: function () { return this.nurseryCostRatio; },
getMaxLevel: function () {return this.maxLevel;},
getEquipmentCostRatio: function () {return this.equipmentCostRatio;},
getOtherWorkersFocusRatio: function () {return this.otherWorkersFocusRatio;},
getNumTrapsForAutoTrapping: function () {return this.numTrapsForAutoTrapping;},
getShieldCostRatio: function () {return this.shieldCostRatio;},
getLumberjackMultiplier: function () {return this.lumberjackMultiplier;},
getShouldSkipHpEquipment: function () {return this.shouldSkipHpEquipment;}
};
var constantsEarlyGame = new ConstantSet();
var constantsLateGame = new ConstantSet({
zoneToStartAt : 45,
minerMultiplier : 0.5,
lumberjackMultiplier : 0.5,
housingCostRatio : 0.1,
gymCostRatio : 0.95,
tributeCostRatio : 0.8,
nurseryCostRatio : 0.15,
maxLevel : 5,
equipmentCostRatio : 0.8
});
var constantsLateLateGame = new ConstantSet({
zoneToStartAt : 55,
minerMultiplier : 1,
lumberjackMultiplier : 0.5,
explorerCostRatio : 0.01,
housingCostRatio : 0.5,
gymCostRatio : 0.8,
tributeCostRatio : 0.9,
nurseryCostRatio : 0.2,
maxLevel : 4,
equipmentCostRatio : 0.9,
getZoneToStartAt:
function () { //don't start until enough block since last constants should be getting gyms
if (game.global.soldierCurrentBlock > 750 * 1000000000000000) { //need about 750Qa to beat 59 boss
return this.zoneToStartAt; //enough block, begin!
}
return constantsEndGame.getZoneToStartAt(); //not enough block, but need to start next constants if too late
}
});
var constantsEndGame = new ConstantSet({
zoneToStartAt : 60,
minerMultiplier : 4,
lumberjackMultiplier : 0.33,
explorerCostRatio: 0,
housingCostRatio : 0,
gymCostRatio : 0.5,
tributeCostRatio : 0.7,
nurseryCostRatio : 0.2,
maxLevel : 4,
equipmentCostRatio : 0.9
});
var constantsCorruption = new ConstantSet({
zoneToStartAt : 180,
minerMultiplier : 15,
lumberjackMultiplier : 2,
explorerCostRatio: 0,
housingCostRatio : 0,
gymCostRatio : 0.2,
tributeCostRatio : 0.7,
nurseryCostRatio : 0.2,
maxLevel : 4,
equipmentCostRatio : 0.999
});
//game variables, not for user setting
const DominanceIndex = 2;
const ScryerIndex = 4;
var constantsSets = [constantsEarlyGame, constantsLateGame, constantsLateLateGame, constantsEndGame, constantsCorruption];
var constantsIndex;
var constants;
var trimpz = 0; //"Trimpz" running indicator
var autoFighting = false; //Autofight on?
var workersFocused = false;
var workersFocusedOn;
var workersMoved = [];
var mapsWithDesiredUniqueDrops = [8,10,14,15,18,23,25,29,30,34,40,47,50,80,125]; //removed from array when done, reset on portal or refresh
var uniqueMaps = ["The Block", "The Wall", "Dimension of Anger", "Trimple Of Doom", "The Prison"];
var helium = -1;
var heliumHistory = [];
var pauseTrimpz = false;
var bionicDone = false;
var respecDone = false;
var respecAmount = 0;
var heliumLog = [];
var trimpzSettings = {};
var mapRunStatus = "";
//Loads the automation settings from browser cache
function loadPageVariables() {
"use strict";
var tmp = JSON.parse(localStorage.getItem('TrimpzSettings'));
if (tmp !== null) {
trimpzSettings = tmp;
}
if (trimpzSettings["respecAmount"] === undefined) {
trimpzSettings["respecAmount"] = {
id: "respecAmount",
name: "",
description: "Original value of Pheromones",
type: "Code Only",
value: 0
};
} else {
respecAmount = trimpzSettings["respecAmount"].value;
if (respecAmount){
respecDone = true;
}
}
}
//Saves automation settings to browser cache
function saveSettings() {
"use strict";
localStorage.setItem('TrimpzSettings', JSON.stringify(trimpzSettings));
}
function initializeUiAndSettings() {
"use strict";
loadPageVariables();
document.head.appendChild(document.createElement('script')).src = 'https://rawgit.com/driderr/AutoTrimps/TrimpzUI/NewUI.js';
}
function setMapRunStatus(status){
"use strict";
mapRunStatus = status;
var element = document.getElementById("pauseTrimpzBtn");
if (element){
if (pauseTrimpz === true){
element.innerHTML = "Paused " + status;
} else{
element.innerHTML = "Running " + status;
}
}
}
/**
* @return {boolean} return.canAfford affordable respecting the ratio?
*/
function CanBuyNonUpgrade(nonUpgradeItem, ratio) {
"use strict";
var aResource; //JSLint insisted I move declaration to top...
var needed;
for (aResource in nonUpgradeItem.cost) {
needed = nonUpgradeItem.cost[aResource];
if (typeof needed[1] != 'undefined') {
needed = resolvePow(needed, nonUpgradeItem);
}
if (typeof nonUpgradeItem.prestige != 'undefined') {//Discount equipment
needed = Math.ceil(needed * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
} else if (game.portal.Resourceful.level)
{
needed = Math.ceil(needed * (Math.pow(1 - game.portal.Resourceful.modifier, game.portal.Resourceful.level)));
}
if (game.resources[aResource].owned * ratio < needed) {
return false;
}
}
return true;
}
function GetNonUpgradePrice(nonUpgradeItem, resource) {
"use strict";
var aResource;
var needed;
for (aResource in nonUpgradeItem.cost) {
needed = nonUpgradeItem.cost[aResource];
if (typeof needed[1] != 'undefined') {
needed = resolvePow(needed, nonUpgradeItem);
}
if (typeof nonUpgradeItem.prestige != 'undefined') {//Discount equipment
needed = Math.ceil(needed * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
} else if (game.portal.Resourceful.level)
{
needed = Math.ceil(needed * (Math.pow(1 - game.portal.Resourceful.modifier, game.portal.Resourceful.level)));
}
if (resource && aResource === resource)
{
return needed;
}
}
return needed;
}
/**
* @return {number}
*/
function CanBuyWorkerWithResource(job, ratio, food, extraWorkers){
"use strict";
var cost = job.cost.food;
var price = 0;
if (typeof cost[1] != 'undefined')
price = Math.floor((cost[0] * Math.pow(cost[1], job.owned + extraWorkers)) * ((Math.pow(cost[1], 1) - 1) / (cost[1] - 1)));
else
price = cost;
if ( food * ratio >= price)
return price;
else{
return -1;
}
}
function getTotalTimeForBreeding(almostOwnedGeneticists) {
"use strict";
var trimps = game.resources.trimps;
var trimpsMax = trimps.realMax();
var potencyMod = trimps.potency;
//Broken Planet
if (game.global.brokenPlanet) potencyMod /= 10;
//Pheromones
potencyMod *= 1+ (game.portal.Pheromones.level * game.portal.Pheromones.modifier);
//Geneticist
if (game.jobs.Geneticist.owned + almostOwnedGeneticists > 0) potencyMod *= Math.pow(.98, game.jobs.Geneticist.owned + almostOwnedGeneticists);
//Quick Trimps
if (game.unlocks.quickTrimps) potencyMod *= 2;
if (game.global.challengeActive == "Toxicity" && game.challenges.Toxicity.stacks > 0){
potencyMod *= Math.pow(game.challenges.Toxicity.stackMult, game.challenges.Toxicity.stacks);
}
if (game.global.voidBuff == "slowBreed"){
potencyMod *= 0.2;
}
potencyMod = calcHeirloomBonus("Shield", "breedSpeed", potencyMod);
potencyMod = (1 + (potencyMod / 10));
var adjustedMax = (game.portal.Coordinated.level) ? game.portal.Coordinated.currentSend : trimps.maxSoldiers;
var totalTime;
if (game.options.menu.showFullBreed.enabled == 1) totalTime = log10((trimpsMax - trimps.employed) / (trimpsMax - adjustedMax - trimps.employed)) / log10(potencyMod);
else {
var threshold = Math.ceil((trimpsMax - trimps.employed) * 0.95);
totalTime = log10(threshold / (threshold - adjustedMax)) / log10(potencyMod);
}
totalTime /= 10;
return totalTime;
}
function getRemainingTimeForBreeding() {
"use strict";
var trimps = game.resources.trimps;
var trimpsMax = trimps.realMax();
var potencyMod = trimps.potency;
//Broken Planet
if (game.global.brokenPlanet) potencyMod /= 10;
//Pheromones
potencyMod *= 1+ (game.portal.Pheromones.level * game.portal.Pheromones.modifier);
//Geneticist
if (game.jobs.Geneticist.owned > 0) potencyMod *= Math.pow(.98, game.jobs.Geneticist.owned);
//Quick Trimps
if (game.unlocks.quickTrimps) potencyMod *= 2;
if (game.global.challengeActive == "Toxicity" && game.challenges.Toxicity.stacks > 0){
potencyMod *= Math.pow(game.challenges.Toxicity.stackMult, game.challenges.Toxicity.stacks);
}
if (game.global.voidBuff == "slowBreed"){
potencyMod *= 0.2;
}
potencyMod = calcHeirloomBonus("Shield", "breedSpeed", potencyMod);
potencyMod = (1 + (potencyMod / 10));
var timeRemaining = log10((trimpsMax - trimps.employed) / (trimps.owned - trimps.employed)) / log10(potencyMod);
timeRemaining /= 10;
return timeRemaining;
}
function ShouldBuyGeneticist(food, extraGeneticists) {
"use strict";
var trimps = game.resources.trimps;
var cost;
var targetBreedTime = trimpzSettings["targetBreedTime"].value;
var shouldBuy = game.jobs.Geneticist.locked === 0 &&
game.global.challengeActive !== "Electricity" &&
(cost = CanBuyWorkerWithResource(game.jobs.Geneticist, 1, food, extraGeneticists)) !== -1 &&
getTotalTimeForBreeding(extraGeneticists) < targetBreedTime &&
getRemainingTimeForBreeding() < targetBreedTime &&
(game.global.lastBreedTime / 1000 < targetBreedTime - getRemainingTimeForBreeding() + trimpzSettings["targetBreedTimeHysteresis"].value ||
trimps.owned === trimps.realMax());
return {
shouldBuy : shouldBuy,
cost : cost
};
}
function AssignFreeWorkers() {
"use strict";
var trimps = game.resources.trimps;
var food = game.resources.food.owned;
var buy = {
"Geneticist" : 0,
"Trainer" : 0,
"Explorer" : 0,
"Scientist" : 0,
"Miner" : 0,
"Lumberjack" : 0,
"Farmer" : 0
};
if (trimps.owned === 0 || game.global.firing) {
return;
}
var free = (Math.ceil(trimps.realMax() / 2) - trimps.employed);
//make room for a Geneticist
if (free === 0 && ShouldBuyGeneticist(food,0).shouldBuy){
game.global.firing = true;
game.global.buyAmt = 20;
buyJob("Farmer", null, true);
game.global.firing = false;
game.global.buyAmt = 1;
}
if (free <= 0) return;
var breedCount = (trimps.owned - trimps.employed > 2) ? Math.floor(trimps.owned - trimps.employed) : 0;
if (free > trimps.owned){
free = Math.floor(trimps.owned / 3);
}
if (autoFighting === false){
if (breedCount - trimps.employed > 0){
free = Math.min(free,Math.floor((breedCount - trimps.employed)/2));
} else {
return;
}
}
if (game.global.world > 10 && (game.resources.trimps.soldiers === 0 || getRemainingTimeForBreeding() > trimpzSettings["targetBreedTime"].value)) {
return;
}
var cost;
var maxFreeForAssignOneAtATime = 1000;
var totalMultipliers;
var assignThisMany;
while (free > 0) {
if (free > maxFreeForAssignOneAtATime && game.jobs.Miner.locked === 0){
totalMultipliers = constants.getMinerMultiplier() + constants.getLumberjackMultiplier() + 1; //1 for default/reference farmer
assignThisMany = constants.getMinerMultiplier() / totalMultipliers * (free - maxFreeForAssignOneAtATime);
buy.Miner += Math.floor(assignThisMany);
assignThisMany = constants.getLumberjackMultiplier() / totalMultipliers * (free - maxFreeForAssignOneAtATime);
buy.Lumberjack += Math.floor(assignThisMany);
assignThisMany = free - maxFreeForAssignOneAtATime - buy.Miner - buy.Lumberjack;
buy.Farmer += assignThisMany;
free -= buy.Miner + buy.Lumberjack + buy.Farmer;
}
var geneticistValues = ShouldBuyGeneticist(food, buy.Geneticist);
if (geneticistValues.shouldBuy){
food -= geneticistValues.cost;
buy.Geneticist += 1;
free--;
} else if (game.jobs.Trainer.locked === 0 &&
(cost = CanBuyWorkerWithResource(game.jobs.Trainer, constants.getTrainerCostRatio(), food , buy.Trainer)) !== -1){
food -= cost;
buy.Trainer += 1;
free--;
} else if (game.jobs.Explorer.locked === 0 &&
(cost = CanBuyWorkerWithResource(game.jobs.Explorer, constants.getExplorerCostRatio(), food, buy.Explorer)) !== -1){
food -= cost;
buy.Explorer += 1;
free--;
} else if (game.jobs.Scientist.locked === 0 && game.jobs.Scientist.owned + buy.Scientist < game.global.world + 1 &&
(cost = CanBuyWorkerWithResource(game.jobs.Scientist, 1, food, buy.Scientist)) !== -1) {
food -= cost;
buy.Scientist += 1;
free--;
} else if (game.jobs.Miner.locked === 0 && game.jobs.Miner.owned + buy.Miner < (game.jobs.Farmer.owned + buy.Farmer) * constants.getMinerMultiplier() &&
(cost = CanBuyWorkerWithResource(game.jobs.Miner, 1, food, buy.Miner)) !== -1) {
food -= cost;
buy.Miner += 1;
free--;
} else if (game.jobs.Lumberjack.locked === 0 && game.jobs.Lumberjack.owned + buy.Lumberjack < (game.jobs.Farmer.owned + buy.Farmer) * constants.getLumberjackMultiplier() &&
(cost = CanBuyWorkerWithResource(game.jobs.Lumberjack, 1, food, buy.Lumberjack)) !== -1){
food -= cost;
buy.Lumberjack += 1;
free--;
} else if ((cost = CanBuyWorkerWithResource(game.jobs.Farmer, 1, food, buy.Farmer)) !== -1){
food -= cost;
buy.Farmer += 1;
free--;
} else {
break; //Can't afford anything!
}
}
var jobName;
var numberToBuy;
for (jobName in buy){
numberToBuy = buy[jobName];
if (numberToBuy > 0){
game.global.buyAmt = numberToBuy;
buyJob(jobName, null, true);
}
}
game.global.buyAmt = 1;
}
function Fight() {
"use strict";
if (autoFighting === true && game.resources.trimps.owned > 25) { //>25 should reset autoFighting on portal
return;
}
autoFighting = false;
var pauseFightButton = document.getElementById("pauseFight");
if (pauseFightButton.offsetHeight > 0 && game.resources.trimps.owned === game.resources.trimps.realMax() || game.resources.trimps.owned > 5000000) {
if (pauseFightButton.innerHTML !== "AutoFight On") {
pauseFight();
}
autoFighting = true;
} else if (document.getElementById("battleContainer").style.visibility !== "hidden" && game.resources.trimps.owned >= 10) {
fightManual();
}
}
function ShowRunningIndicator() {
"use strict";
var rotater = ["|", "/", "-", "\\"][trimpz];
trimpz += 1;
if (trimpz > 3) {
trimpz = 0;
}
document.getElementById("trimpTitle").innerHTML = "Trimpz " + rotater;
}
function getMaxResource(resource)
{
"use strict";
var theResource = game.resources[resource];
var newMax = theResource.max + (theResource.max * game.portal.Packrat.modifier * game.portal.Packrat.level);
newMax = calcHeirloomBonus("Shield", "storageSize", newMax);
return newMax;
}
function queueContainsItem(item){
"use strict";
for (var queued in game.global.buildingsQueue) {
if (game.global.buildingsQueue[queued].indexOf(item) > -1)
return true;
}
return false;
}
function UpgradeStorage() {
"use strict";
var storageBuildings = {
'Barn': 'food',
'Shed': 'wood',
'Forge': 'metal'
};
var jestImpLoot;
var resource;
var owned;
var maxResource;
var storageBuilding;
for (var storage in storageBuildings) {
resource = storageBuildings[storage];
owned = game.resources[resource].owned;
maxResource = getMaxResource(resource);
storageBuilding = game.buildings[storage];
if (owned > storageBuilding.cost[resource]() &&
storageBuilding.locked === 0 && !queueContainsItem(storage))
if (owned > 0.9 * maxResource) {
buyBuilding(storage, true, true);
} else if ((game.global.mapsActive && game.unlocks.imps.Jestimp)) {
jestImpLoot = simpleSeconds(resource, 45);
jestImpLoot = scaleToCurrentMap(jestImpLoot);
if (jestImpLoot + owned > 0.9 * maxResource) {
buyBuilding(storage, true, true);
}
}
}
}
function ClickAllNonEquipmentUpgrades() {
"use strict";
var upgrade;
for (upgrade in game.upgrades) {
if (upgrade === "Gigastation"){
continue;
}
if (upgrade === "Potency" && !trimpzSettings["ignoreBreedForNurseries"].value){
continue;
}
if (trimpzSettings["skipShieldBlock"].value === true && upgrade === "Shieldblock"){
continue;
}
if (typeof game.upgrades[upgrade].prestiges == 'undefined' && game.upgrades[upgrade].locked === 0) {
buyUpgrade(upgrade,true,true); //Upgrade!
}
}
}
function ClickButton(button){
var btn;
if (typeof button === "string")
btn = document.getElementById(button);
else
btn = button;
if (btn && btn.click)
btn.click();
}
function FocusWorkersOn(jobToFocusOn) {
"use strict";
var jobObj;
var workersToMove;
var jobsToMoveFrom = ["Farmer", "Lumberjack", "Miner"];
var job;
if (game.jobs[jobToFocusOn].locked) {
return;
}
if (workersFocused === true && jobToFocusOn === workersFocusedOn) {
return;
}
if (workersFocused === true){ //focused on the wrong thing!
RestoreWorkerFocus();
if (workersFocused === true){
return;
}
}
workersMoved = [];
for (job in jobsToMoveFrom) {
jobObj = game.jobs[jobsToMoveFrom[job]];
if (jobObj.locked === true || jobObj.owned < 2 || jobsToMoveFrom[job] === jobToFocusOn) {
continue;
}
workersToMove = Math.floor(jobObj.owned * constants.getOtherWorkersFocusRatio());
if (game.resources.food.owned < workersToMove * game.jobs[jobToFocusOn].cost.food) {
continue;
}
game.global.buyAmt = workersToMove;
game.global.firing = true;
buyJob(jobsToMoveFrom[job], null, true);
game.global.firing = false;
buyJob(jobToFocusOn, null, true);
game.global.buyAmt = 1;
workersMoved.push([jobsToMoveFrom[job], workersToMove, jobToFocusOn]);
}
if (workersMoved.length !== 0) {
workersFocused = true;
workersFocusedOn = jobToFocusOn;
}
}
function RestoreWorkerFocus() {
"use strict";
var workersToMove;
var job;
var workersLeft = 0;
var jobMoved;
if (workersFocused === false){
return;
}
for (jobMoved in workersMoved)
{
workersToMove = workersMoved[jobMoved][1];
job = workersMoved[jobMoved][0];
if (game.resources.food.owned < workersToMove * game.jobs[job].cost.food || workersToMove === 0){
workersLeft += workersToMove;
continue;
}
game.global.buyAmt = workersToMove;
game.global.firing = true;
buyJob(workersMoved[jobMoved][2], null, true);
game.global.firing = false;
buyJob(job, null, true);
game.global.buyAmt = 1;
workersMoved[jobMoved][1] = 0;
}
if (workersLeft === 0) {
workersFocused = false;
workersFocusedOn = "";
}
}
/**
* @return {boolean}
*/
function CanBuyWarpstationSoon(){
"use strict";
//return CanBuyNonUpgrade(game.buildings.Warpstation, 2) === true;
var MaxMinutesToWait = 2;
var buildstring = canAffordBuilding("Warpstation",false,true);
if (buildstring.indexOf("Days") > -1 || buildstring.indexOf("Hours") > -1 || buildstring.indexOf("Long") > -1){
return false;
}
if (buildstring.indexOf("Mins") == -1){
return true;
}
var buildStringArray = buildstring.split(" ");
var minutesIndex = buildStringArray.indexOf("Mins");
var minutesString = buildStringArray[minutesIndex - 1].split("(")[1];
var minutes = parseInt(minutesString, 10);
if (minutesIndex == buildStringArray.lastIndexOf("Mins")){
return minutes <= MaxMinutesToWait;
}
var minutes2Index = buildStringArray.lastIndexOf("Mins");
var minutes2String = buildStringArray[minutes2Index - 1].split("(")[1];
var minutes2 = parseInt(minutes2String, 10);
return !(minutes > MaxMinutesToWait || minutes2 > MaxMinutesToWait);
}
/**
* @return {boolean} return.collectingForNonEquipment Is it collecting for upgrade?
*/
function UpgradeNonEquipment() {
"use strict";
var upgrade;
var aResource;
var needed;
for (upgrade in game.upgrades) {
if (typeof game.upgrades[upgrade].prestiges == 'undefined' && game.upgrades[upgrade].locked === 0) {
if (upgrade === "Gigastation" &&
(game.buildings.Warpstation.owned < trimpzSettings["minimumWarpStations"].value + trimpzSettings["deltaIncreaseInMinimumWarpstationsPerGigastationPurchase"].value * game.upgrades.Gigastation.done
|| (CanBuyWarpstationSoon() && CanBuyNonUpgrade(game.buildings.Warpstation, 2) === true) )){ //ratio 2 for "can buy soon"
continue;
}
if (upgrade == 'Coordination' && !canAffordCoordinationTrimps()) continue;
if (trimpzSettings["skipShieldBlock"].value === true && upgrade === "Shieldblock"){
continue;
}
if (upgrade === "Potency" && !ShouldLowerBreedWithoutGeneticists() && !trimpzSettings["ignoreBreedForNurseries"].value)
continue;
for (aResource in game.upgrades[upgrade].cost.resources) {
needed = game.upgrades[upgrade].cost.resources[aResource];
if (typeof needed[1] != 'undefined') {
needed = resolvePow(needed, game.upgrades[upgrade]);
}
if (aResource === "food" && needed > game.resources.food.owned) {
setGather("food");
FocusWorkersOn("Farmer");
return true;
}
if (aResource === "metal" && needed > game.resources.metal.owned) {
setGather("metal");
FocusWorkersOn("Miner");
return true;
}
if (aResource === "science" && needed > game.resources.science.owned && document.getElementById('scienceCollectBtn').style.display == 'block') {
setGather("science");
FocusWorkersOn("Scientist");
return true;
}
if (aResource === "wood" && needed > game.resources.wood.owned) {
setGather("wood");
FocusWorkersOn("Lumberjack");
return true;
}
}
buyUpgrade(upgrade,true,true); //Upgrade!
}
}
RestoreWorkerFocus();
return false;
}
function GetBreedSpeed() {
"use strict";
var breedArray = document.getElementById("trimpsPs").innerHTML.match(/(\d+(?:\.\d+)?)(\D+)?(?:\/sec)/);
return unprettify(breedArray);
}
/**
* @return {boolean} return.collectingForNonEquipment Is it collecting for upgrade?
*/
function UpgradeAndGather() {
"use strict";
var collectingForNonEquipment = UpgradeNonEquipment();
if (collectingForNonEquipment)
return true;
if (game.global.autoCraftModifier < 5000 && (game.global.buildingsQueue.length > 0 &&
(game.global.buildingsQueue[0] !== "Trap.1") || game.global.buildingsQueue.length > 1)) {
setGather("buildings");
}
else if (game.resources.trimps.owned < game.resources.trimps.realMax() &&
game.buildings.Trap.owned > 0 &&
GetBreedSpeed() < trimpzSettings["minBreedingSpeed"].value){
setGather("trimps");
// } else if (game.global.buildingsQueue.length > 0) {
// ClickButton("buildingsCollectBtn");
} else if (game.global.turkimpTimer > 0) {
setGather("metal");
} else {
setGather("science");
}
return false;
}
/**
* @return {boolean} return.shouldReturn Was priority found (stop further processing)?
*/
function BeginPriorityAction() { //this is really just for the beginning (after a portal)
"use strict";
if (game.global.buildingsQueue.length > 0) {//Build queue
if ( !game.global.trapBuildToggled||
game.global.buildingsQueue[0] !== "Trap.1") {
setGather("buildings");
return false;
}
}
if (game.resources.food.owned < constants.getMinFoodOwned()) {//Collect food
setGather("food");
return true;
}
if (game.resources.wood.owned < constants.getMinWoodOwned()) {//Collect wood
setGather("wood");
return true;
}
if (game.buildings.Trap.owned < 1 && !queueContainsItem("Trap")) {//Enqueue trap
buyBuilding("Trap", true, true);
setGather("buildings");
return true;
}
if (game.resources.trimps.owned < constants.getMinTrimpsOwned() &&
game.resources.trimps.owned < game.resources.trimps.realMax()/2) {//Open trap
setGather("trimps");
return true;
}
if (game.resources.science.owned < constants.getMinScienceOwned() && document.getElementById('scienceCollectBtn').style.display == 'block') {//Collect science
setGather("science");
return true;
}
return false;
}
/**
* @return {boolean}
*/
function BuyBuilding(buildingName, ratio, max, checkQueue){
"use strict";
if (typeof max === 'undefined'){
max = 999999999999999999999999999999;
}
if (typeof checkQueue === 'undefined') {
checkQueue = true;
}
if (checkQueue && queueContainsItem(buildingName)){
return false;
}
var theBuilding = game.buildings[buildingName];
if (theBuilding.locked === 0 && theBuilding.owned < max &&
CanBuyNonUpgrade(theBuilding, ratio) === true) {
buyBuilding(buildingName,true,true);
return true;
}
return false;
}
/**
* @return {boolean}
*/
function ShouldLowerBreedWithoutGeneticists(){
"use strict";
var targetBreedTime = trimpzSettings["targetBreedTime"].value;
var targetBreedTimeHysteresis = trimpzSettings["targetBreedTimeHysteresis"].value;
//noinspection RedundantIfStatementJS
if (getTotalTimeForBreeding(0) >= targetBreedTime - targetBreedTimeHysteresis ||
((game.jobs.Geneticist.locked === 1 || game.jobs.Geneticist.owned === 0) && getRemainingTimeForBreeding() >= targetBreedTime + targetBreedTimeHysteresis * 2)){
return true;
}
return false;
}
function BuyBuildings() {
"use strict";
BuyBuilding("Gym", constants.getGymCostRatio(), constants.getMaxGyms());
var targetBreedTime = trimpzSettings["targetBreedTime"].value;
var targetBreedTimeHysteresis = trimpzSettings["targetBreedTimeHysteresis"].value;
if (trimpzSettings["ignoreBreedForNurseries"].value){
game.global.buyAmt = 'Max';
game.global.maxSplit = constants.getNurseryCostRatio();
BuyBuilding("Nursery", constants.getNurseryCostRatio());
game.global.buyAmt = 1;
game.global.maxSplit = 1;
}
else if (ShouldLowerBreedWithoutGeneticists()){
BuyBuilding("Nursery", constants.getNurseryCostRatio());
}
game.global.buyAmt = 'Max';
game.global.maxSplit = constants.getTributeCostRatio();
BuyBuilding("Tribute", constants.getTributeCostRatio());
game.global.buyAmt = 1;
game.global.maxSplit = 1;
if (game.global.world > 10 &&
(game.resources.trimps.owned !== game.resources.trimps.realMax() &&
game.global.lastBreedTime / 1000 > targetBreedTime - getRemainingTimeForBreeding() + trimpzSettings["targetBreedTimeHysteresis"].value &&
game.jobs.Geneticist.owned < 10 ||
game.resources.trimps.soldiers === 0)){
return;
}
BuyBuilding("Hut", constants.getHousingCostRatio());
BuyBuilding("House", constants.getHousingCostRatio());
BuyBuilding("Mansion", constants.getHousingCostRatio());
BuyBuilding("Hotel", constants.getHousingCostRatio());
BuyBuilding("Resort", constants.getHousingCostRatio());
BuyBuilding("Gateway", constants.getHousingCostRatio());
BuyBuilding("Wormhole", 1, trimpzSettings["maxWormholes"].value);
if (game.buildings.Warpstation.locked === 1 || GetNonUpgradePrice(game.buildings.Warpstation, "gems") > GetNonUpgradePrice(game.buildings.Collector) * game.buildings.Warpstation.increase.by / game.buildings.Collector.increase.by) {
BuyBuilding("Collector", 1);
}
if (trimpzSettings["runMapsOnlyWhenNeeded"].value){
var returnNumAttacks = true;
var maxAttacksToKill = trimpzSettings["maxAttacksToKill"].value;
var bossBattle = canTakeOnBoss(returnNumAttacks);
var reallyNeedDamage = bossBattle.attacksToKillBoss > maxAttacksToKill * 3;
var reallyNeedHealth = bossBattle.attacksToKillSoldiers <= 1;
if ((reallyNeedDamage || reallyNeedHealth) && GetNonUpgradePrice(game.buildings.Warpstation, "metal") > game.resources.metal.owned * 0.1) {
return;
}
}
if (game.upgrades.Gigastation.done === game.upgrades.Gigastation.allowed && game.upgrades.Gigastation.done >= trimpzSettings["gsForEqWs"].value) {
var eqCost = FindAndBuyEquipment([], "Attack", true);
if (eqCost !== 0 && eqCost < GetNonUpgradePrice(game.buildings.Warpstation, "metal") * trimpzSettings["eqWsRatio"].value){
return;
}
}
while (BuyBuilding("Warpstation", 1,undefined,false)){}
}
function TurnOnAutoBuildTraps() {
"use strict";
if (game.buildings.Trap.owned < constants.getNumTrapsForAutoTrapping() &&
game.global.trapBuildAllowed &&
!game.global.trapBuildToggled &&
GetBreedSpeed() < trimpzSettings["minBreedingSpeed"].value) {
toggleAutoTrap();
} else if (game.global.trapBuildToggled &&
(game.buildings.Trap.owned >= constants.getNumTrapsForAutoTrapping() || GetBreedSpeed() > trimpzSettings["minBreedingSpeed"].value)){
toggleAutoTrap();
}
}
function BuyShield() {
"use strict";
var shieldUpgrade = game.upgrades.Supershield;
var shield = game.equipment.Shield;
var costOfNextLevel;
var limitEquipment = trimpzSettings["limitEquipment"].value;
if (trimpzSettings["runMapsOnlyWhenNeeded"].value){
var stat = shield.blockNow ? "block" : "health";
var upgradeStats = GetRatioForEquipmentUpgrade("Supershield",shield);
if (shield[stat + "Calculated"]/GetNonUpgradePrice(shield) > upgradeStats.gainPerMetal && //level up (don't feel like renaming gainPerMetal...)
(!limitEquipment || shield.level < constants.getMaxLevel())){
if (shield.locked === 0 && CanBuyNonUpgrade(shield, constants.getShieldCostRatio()) === true){
buyEquipment("Shield", true, true);
}
} else { //upgrade
if (shieldUpgrade.locked === 0 && canAffordTwoLevel(shieldUpgrade)){
buyUpgrade("Supershield", true, true); //Upgrade!
}
}
return;
}
if (shieldUpgrade.locked === 0 && CanAffordEquipmentUpgrade("Supershield") === true) {
costOfNextLevel = Math.ceil(getNextPrestigeCost("Supershield") * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
var costOfTwoLevels = costOfNextLevel * (1 + game.equipment.Shield.cost.wood[1]);
if (game.resources.wood.owned * constants.getShieldCostRatio() > costOfTwoLevels) {
buyUpgrade("Supershield", true, true); //Upgrade!
buyEquipment("Shield", true, true); //Buy a level!
}
}
if (shield.locked === 0 && CanBuyNonUpgrade(shield, constants.getShieldCostRatio()) === true &&
(!limitEquipment || shield.level < constants.getMaxLevel() )) {
buyEquipment("Shield", true, true);
}
}
function FindBestEquipmentToLevel(debugHpToAtkRatio, filterOnStat) {
"use strict";
var anEquipment;
var bestEquipGainPerMetal = 0;
var bestEquipment;
var bestEquipmentCost;
var gainPerMetal;
var cost;
var currentEquip;
var multiplier;
for (anEquipment in game.equipment) {
currentEquip = game.equipment[anEquipment];
if (currentEquip.locked === 1 || anEquipment === "Shield" || (constants.getShouldSkipHpEquipment() === true && typeof currentEquip.health != 'undefined')) {
continue;
}
if (trimpzSettings["limitEquipment"].value && currentEquip.level >= constants.getMaxLevel()) {
continue;
}
if (filterOnStat){
if (filterOnStat === "Health"){
if (!currentEquip.healthCalculated){
continue;
}
} else { //Attack
if (currentEquip.healthCalculated){
continue;
}
}
}
cost = GetNonUpgradePrice(currentEquip);
multiplier = currentEquip.healthCalculated ? 1 / 8 : 1;
gainPerMetal = (currentEquip.healthCalculated || currentEquip.attackCalculated) * multiplier / cost;
debugHpToAtkRatio.push([anEquipment, gainPerMetal * 1000000]);
if (gainPerMetal > bestEquipGainPerMetal) {
bestEquipGainPerMetal = gainPerMetal;
bestEquipment = anEquipment;
bestEquipmentCost = cost;
}
}
return {
bestEquipGainPerMetal: bestEquipGainPerMetal,
bestEquipment: bestEquipment,
bestEquipmentCost: bestEquipmentCost
};
}
function GetRatioForEquipmentUpgrade(upgrade, currentEquip) {
var stat;
var cost = Math.ceil(getNextPrestigeCost(upgrade) * (Math.pow(1 - game.portal.Artisanistry.modifier, game.portal.Artisanistry.level)));
var multiplier = currentEquip.healthCalculated ? 1 / 8 : 1;
if (currentEquip.blockNow) stat = "block";
else stat = (typeof currentEquip.health != 'undefined') ? "health" : "attack";
var gain = Math.round(currentEquip[stat] * Math.pow(1.19, ((currentEquip.prestige) * game.global.prestige[stat]) + 1));
var gainPerMetal = gain * multiplier / cost;
return {
gainPerMetal: gainPerMetal,
cost: cost
};
}
function FindBestEquipmentUpgrade(debugHpToAtkRatio, filterOnStat) {
"use strict";
var gainPerMetal;
var cost;
var currentEquip;
var upgrade;
var currentUpgrade;
var bestUpgradeGainPerMetal = 0;
var bestUpgrade;
var bestUpgradeCost;
var upgradeStats;