forked from genbtc/AutoTrimps
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAutoTrimps2.js
257 lines (230 loc) · 13.1 KB
/
AutoTrimps2.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
// ==UserScript==
// @name AutoTrimpsV2+unimod
// @namespace https://github.com/unihedro/AutoTrimps
// @version 2.1.5.5u3-unimod-4-17-2017+Modular
// @description try to take over the world!
// @author zininzinin, spindrjr, belaith, ishakaru, genBTC, Unihedron
// @include *trimps.github.io*
// @include *kongregate.com/games/GreenSatellite/trimps
// @grant none
// ==/UserScript==
var ATversion = '2.1.5.5u3-unimod-4-17-2017+Modular';
////////////////////////////////////////////////////////////////////////////////
//Main Loader Initialize Function (loads first, load everything else)///////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
var atscript = document.getElementById('AutoTrimps-script')
, base = 'https://unihedro.github.io/AutoTrimps/'
, module = 'modules/'
;
if (atscript !== null) {
base = atscript.getAttribute('src').replace(/AutoTrimps2\.js$/, '');
}
//Load stuff needed to load other stuff:
document.head.appendChild(document.createElement('script')).src = base + module + 'utils.js';
function initializeAutoTrimps() {
loadPageVariables();
document.head.appendChild(document.createElement('script')).src = base + 'NewUI2.js';
document.head.appendChild(document.createElement('script')).src = base + 'Graphs.js';
//Load modules:
var modules = ['query', 'upgrades', 'heirlooms', 'buildings', 'jobs', 'equipment', 'gather', 'autostance', 'battlecalc', 'automaps', 'autobreedtimer', 'dynprestige', 'autofight', 'scryer', 'magma', 'portal', 'other'];
for (var i=0,len=modules.length; i<len; i++) {
document.head.appendChild(document.createElement('script')).src = base + module + modules[i] + '.js';
}
//Autoperks
if (typeof(AutoPerks) === 'undefined')
document.head.appendChild(document.createElement('script')).src = base + module + 'autoperks.js';
else
debug('AutoPerks is now included in Autotrimps, please disable the tampermonkey script for AutoPerks to remove this message!', '*spinner3');
toggleSettingsMenu();
toggleSettingsMenu();
// dank dark graphs by Unihedron
if (game.options.menu.darkTheme.enabled == 2) {
const $link = document.createElement('link');
$link.rel = "stylesheet";
$link.type = "text/css";
$link.href = base + 'dark-graph.css';
document.head.appendChild($link);
}
//
debug('AutoTrimps v' + ATversion + ' Loaded!', '*spinner3');
}
function printChangelog() {
tooltip('confirm', null, 'update', '\
<br><b style="background-color:#002b3b">4/17 v2.1.5.5u3</b> - fix improvedautostorage hijack\
<br>Fixed a certain specific stupid bug caused by how graph overwrites some functions unnecessarily\
<br><b style="background-color:#b93e00">4/16 v2.1.5.5u2</b> - do more map stacks if not enoughHealth\
<br><span style="opacity:.8">No longer forces Buy Storage off</span>\
<br><b style="background-color:#840036">4/15 v2.1.5.5u1</b> - new settings BuyOvclock\
<br><span style="opacity:.75"><b style="background-color:#2c3c8a">4/14 v2.1.5.4u6</b> - Improved nurseries map and betterautostorage <b class="AutoEggs">4/14 v2.1.5.4u5 - Auto Eggs</b>, some more 4.3 support <b style="background-color:#D8000B">4/12 v2.1.5.4u4</b> AutoTrimps lifecycle changes <b style="background-color:#105E28">4/11 v2.1.5.4u3</b> fixed spire farming, autogen supply zone <b style="background-color:#611047">4/10 v2.1.5.4u2</b> PrestigeSkip2 <b style="background-color:#50000D">4/09 v2.1.5.4u1</b> Magma: AutoGen, AutoGen2\
<br><b style="background-color:#162955">4/08 v2.1.5.3u6</b> ForcePresZ <b style="background-color:#294D00">4/07 u5</b> FinishC2, PowerSaving <b style="background-color:#294D00">u4</b> PreferMetal, PreSpireNurseries <b style="background-color:#6E1236">u3</b> LinearZ, SupplyWall, OneTimeOnly <b style="background-color:#552700">u2</b> TrimpleZ, ScryerDieZ, IgnoreCrits <b style="background-color:#277552;">4/06 u1</b> Don\'t buy Coords / Skip challenge maps</span>\
<br><u>Report any bugs/problems please! You can find me on Discord: <span style="background-color:#ddd;color:#222">Uni#8610</span></u>\
<br><a href="https://github.com/Unihedro/AutoTrimps/commits/gh-pages" target="#">Check the commit history</a> (if you care)\
', 'cancelTooltip()', 'Script Update Notice ' + ATversion);
}
////////////////////////////////////////
//Main DELAY Loop///////////////////////
////////////////////////////////////////
//Magic Numbers/////////////////////////
var runInterval = 100; //How often to loop through logic
var startupDelay = 2000; //How long to wait for everything to load
setTimeout(delayStart, startupDelay);
function delayStart() {
initializeAutoTrimps();
printChangelog();
setTimeout(delayStartAgain, startupDelay);
}
function delayStartAgain(){
setInterval(mainLoop, runInterval);
setInterval(guiLoop, runInterval*10);
updateCustomButtons();
document.getElementById('Prestige').value = autoTrimpSettings.PrestigeBackup.selected;
//MODULESdefault = MODULES;
//MODULESdefault = Object.assign({}, MODULES);
MODULESdefault = JSON.parse(JSON.stringify(MODULES));
}
////////////////////////////////////////
//Global Main vars /////////////////////
////////////////////////////////////////
////////////////////////////////////////
var AutoTrimpsDebugTabVisible = true;
var enableDebug = true; //Spam console
var autoTrimpSettings = {};
var MODULES = {};
var MODULESdefault = {};
var autoTrimpVariables = {};
var bestBuilding;
var scienceNeeded;
var breedFire = false;
var shouldFarm = false;
var enoughDamage = true;
var enoughHealth = true;
var baseDamage = 0;
var baseBlock = 0;
var baseHealth = 0;
var preBuyAmt;
var preBuyFiring;
var preBuyTooltip;
var preBuymaxSplit;
var ATrunning = true;
var magmiteSpenderChanged = false;
var BAFsetting, oldBAFsetting;
var currentworld = 0;
var lastrunworld = 0;
var aWholeNewWorld = false;
var needGymystic = true;
var heirloomFlag = false;
var heirloomCache = game.global.heirloomsExtra.length;
//reset stuff that may not have gotten cleaned up on portal
function mainCleanup() {
lastrunworld = currentworld;
currentworld = game.global.world;
aWholeNewWorld = lastrunworld != currentworld;
//run once per portal:
if (currentworld == 1 && aWholeNewWorld) {
lastHeliumZone = 0;
zonePostpone = 0;
//for the dummies like me who always forget to turn automaps back on after portaling
if(getPageSetting('RunUniqueMaps') && !game.upgrades.Battle.done && autoTrimpSettings.AutoMaps.enabled == false)
settingChanged("AutoMaps");
return true; // Do other things
}
}
////////////////////////////////////////
//Main LOGIC Loop///////////////////////
////////////////////////////////////////
////////////////////////////////////////
function mainLoop() {
if (ATrunning == false) return;
ATrunning = true;
if(game.options.menu.showFullBreed.enabled != 1) toggleSetting("showFullBreed"); //more detail
addbreedTimerInsideText.innerHTML = parseFloat(game.global.lastBreedTime/1000).toFixed(1) + 's'; //add hidden next group breed timer;
if (armycount.className != "tooltipadded") addToolTipToArmyCount();
const newZone = currentworld != game.global.world;
if ((newZone && mainCleanup()) // Z1 new world
|| portalWindowOpen // in the portal screen (for manual portallers)
|| (!heirloomsShown && heirloomFlag) // closed heirlooms screen
|| (heirloomCache != game.global.heirloomsExtra.length)) { // inventory size changed (a drop appeared)
// also pre-portal: portal.js:111
if (getPageSetting('AutoHeirlooms2')) autoHeirlooms2(); //"Auto Heirlooms 2" (heirlooms.js)
else if (getPageSetting('AutoHeirlooms')) autoHeirlooms();//"Auto Heirlooms" (")
if (getPageSetting('AutoUpgradeHeirlooms') && !heirloomsShown) autoNull(); //"Auto Upgrade Heirlooms" (heirlooms.js)
heirloomCache = game.global.heirloomsExtra.length;
}
heirloomFlag = heirloomsShown;
if(getPageSetting('PauseScript') || game.options.menu.pauseGame.enabled || game.global.viewingUpgrades) return;
game.global.addonUser = true;
game.global.autotrimps = {
firstgiga: getPageSetting('FirstGigastation'),
deltagiga: getPageSetting('DeltaGigastation')
}
if (newZone) {
// Auto-close dialogues.
switch (document.getElementById('tipTitle').innerHTML) {
case 'The Improbability': // Breaking the Planet
case 'Corruption': // Corruption / True Corruption
case 'Spire': // Spire
case 'The Magma': // Magma
cancelTooltip();
}
setTitle(); // Set the browser title
if (getPageSetting('AutoEggs'))
easterEggClicked();
}
setScienceNeeded(); //determine how much science is needed
//EXECUTE CORE LOGIC
if (getPageSetting('ExitSpireCell') >0) exitSpireCell(); //"Exit Spire After Cell" (other.js)
if (getPageSetting('WorkerRatios')) workerRatios(); //"Auto Worker Ratios" (jobs.js)
if (getPageSetting('BuyUpgrades')) buyUpgrades(); //"Buy Upgrades" (upgrades.js)
autoGoldenUpgradesAT();
if (getPageSetting('BuyStorage'))
buyStorage(); //"Buy Storage" (buildings.js)
if (getPageSetting('BuyBuildings')) buyBuildings(); //"Buy Buildings" (buildings.js)
needGymystic = false; //reset this after buyBuildings
if (getPageSetting('BuyJobs')) buyJobs(); //"Buy Jobs" (jobs.js)
if (getPageSetting('ManualGather2')<=2) manualLabor(); //"Auto Gather/Build" (gather.js)
else if (getPageSetting('ManualGather2')==3) manualLabor2(); //"Auto Gather/Build #2" (")
if (getPageSetting('AutoMaps')) autoMap(); //"Auto Maps" (automaps.js)
if (getPageSetting('GeneticistTimer') >= 0) autoBreedTimer(); //"Geneticist Timer" / "Auto Breed Timer" (autobreedtimer.js)
if (autoTrimpSettings.AutoPortal.selected != "Off") autoPortal(); //"Auto Portal" (hidden until level 40) (portal.js)
if (getPageSetting('TrapTrimps') && game.global.trapBuildAllowed && game.global.trapBuildToggled == false) toggleAutoTrap(); //"Trap Trimps"
if (newZone && getPageSetting('AutoRoboTrimp')) autoRoboTrimp(); //"AutoRoboTrimp" (other.js)
if (newZone && getPageSetting('FinishC2')>0 && game.global.runningChallengeSquared) finishChallengeSquared(); // "Finish Challenge2" (other.js)
autoLevelEquipment(); //"Buy Armor", "Buy Armor Upgrades", "Buy Weapons", "Buy Weapons Upgrades" (equipment.js)
if (getPageSetting('UseScryerStance')) useScryerStance(); //"Use Scryer Stance" (scryer.js)
else if (getPageSetting('AutoStance')<=1) autoStance(); //"Auto Stance" (autostance.js)
else if (getPageSetting('AutoStance')==2) autoStance2(); //"Auto Stance #2" (")
if (getPageSetting('UseAutoGen')) autoGenerator(); // "Auto Generator ON" (magma.js)
BAFsetting = getPageSetting('BetterAutoFight');
if (BAFsetting==1) betterAutoFight(); //"Better Auto Fight" (autofight.js)
else if (BAFsetting==2) betterAutoFight2(); //"Better Auto Fight2" (")
else if (BAFsetting==0 && BAFsetting!=oldBAFsetting && game.global.autoBattle && game.global.pauseFight) pauseFight(); //turn on autofight on once when BAF is toggled off.
else if (BAFsetting==0 && game.global.world == 1 && game.global.autoBattle && game.global.pauseFight) pauseFight(); //turn on autofight on lvl 1 if its off.
else if (BAFsetting==0 && !game.global.autoBattle && game.global.soldierHealth == 0) betterAutoFight(); //use BAF as a backup for pre-Battle situations
oldBAFsetting = BAFsetting; //enables built-in autofight once when disabled
if (getPageSetting('DynamicPrestige2')>0&&((getPageSetting('ForcePresZ')<0)||(game.global.world<getPageSetting('ForcePresZ')))) prestigeChanging2(); //"Dynamic Prestige" (dynprestige.js)
else autoTrimpSettings.Prestige.selected = document.getElementById('Prestige').value; //if we dont want to, just make sure the UI setting and the internal setting are aligned.
//Auto Magmite Spender
try {
if (getPageSetting('AutoMagmiteSpender2')==2 && !magmiteSpenderChanged)
autoMagmiteSpender(); // magma.js
} catch (err) {
debug("Error encountered in AutoMagmiteSpender(Always): " + err.message,"general");
}
//Runs any user provided scripts - by copying and pasting a function named userscripts() into the Chrome Dev console. (F12)
if (userscriptOn) userscripts();
//rinse, repeat
return;
}
//GUI Updates happen on this thread, every 1000ms, concurrently
function guiLoop() {
updateCustomButtons();
}
// Userscript loader. write your own!
var userscriptOn = true; //controls the looping of userscripts and can be self-disabled
var globalvar0,globalvar1,globalvar2,globalvar3,globalvar4,globalvar5,globalvar6,globalvar7,globalvar8,globalvar9;
//left blank intentionally. the user will provide this. blank global vars are included as an example
function userscripts()
{
//insert code here:
}