forked from genbtc/AutoTrimps
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutoTrimps2.js
More file actions
240 lines (209 loc) · 10.4 KB
/
AutoTrimps2.js
File metadata and controls
240 lines (209 loc) · 10.4 KB
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
// ==UserScript==
// @name AutoTrimpsV2+coderpatsy
// @namespace https://github.com/coderpatsy/AutoTrimps
// @version 2.1.5.9p10-coderpatsy-12-1-2017+Mod+Uni
// @description Automate all the trimps!
// @author zininzinin, spindrjr, belaith, Ishkaru, genBTC, Unihedron, coderpatsy
// @include *trimps.github.io*
// @include *kongregate.com/games/GreenSatellite/trimps
// @grant none
// ==/UserScript==
var ATversion = '2.1.5.9p10-coderpatsy-12-1-2017+Mod+Uni';
////////////////////////////////////////////////////////////////////////////////
//Main Loader Initialize Function (loads first, load everything else)///////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
var atscript = document.getElementById('AutoTrimps-script')
, base = 'https://coderpatsy.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';
}
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');
}
////////////////////////////////////////
//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();
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(!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 = ((game.jobs.Amalgamator.owned > 0) ? Math.floor((new Date().getTime() - game.global.lastSoldierSentAt) / 1000) : Math.floor(game.global.lastBreedTime / 1000)) + 's'; //add breed time for next army;
//if (armycount.className != "tooltipadded") addToolTipToArmyCount();
if (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('AutoHeirlooms')) autoHeirlooms();//"Auto Heirlooms" (")
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 (aWholeNewWorld) {
// 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('BuyUpgrades')) buyUpgrades(); //"Buy Upgrades" (upgrades.js)
autoGoldenUpgradesAT();
if (getPageSetting('BuyStorage'))
buyStorage(); //"Buy Storage" (buildings.js)
if (game.global.lastClearedCell > 88) { // Sadly I removed some settings from AT so things stopped working in AutoPortal etc. :) cell 88 is to work inside voids
autoHeirlooms(); // Carry heirlooms (heirlooms.js)
}
// Now let's always buy Meteorologists and Smithy; for now here but code is implemented in buildings.js too, we just do not use it anymore
// Smithy (U2)
if (!game.buildings.Smithy.locked && (game.global.challengeActive != "Quest" || game.global.world > 70)) safeBuyBuilding('Smithy');
//Meteorologist (U2) - also technically a job but I retired that part from AT and it is not in AutoJobs at the moment
if (!game.jobs.Meteorologist.locked) safeBuyJob('Meteorologist', 1);
needGymystic = false; //reset this after buyBuildings
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)
else updateAutoMapsStatus();
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 (aWholeNewWorld && getPageSetting('AutoRoboTrimp')) autoRoboTrimp(); //"AutoRoboTrimp" (other.js)
autoLevelEquipment(); //"Buy Armor", "Buy Armor Upgrades", "Buy Weapons", "Buy Weapons Upgrades" (equipment.js)
BAFsetting = getPageSetting('BetterAutoFight');
if (BAFsetting==1) betterAutoFight(); //"Better Auto Fight" (autofight.js)
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('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)
//Auto Magmite Spender
try {
if (getPageSetting('AutoMagmiteSpender2')==2 && !magmiteSpenderChanged)
autoMagmiteSpender(); // magma.js
} catch (err) {
debug("Error encountered in AutoMagmiteSpender(Always): " + err.message,"general");
}
if (getPageSetting('AutoNatureTokens')) autoNatureTokens();
//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:
}