forked from WG-SpaceCoder/AutoTrimps
-
Notifications
You must be signed in to change notification settings - Fork 51
/
AutoTrimps2.js
285 lines (262 loc) · 14 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
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
// ==UserScript==
// @name AutoTrimpsV2-genBTC
// @version 2.1.7.0-genbtc-beta
// @updateURL https://genBTC.github.io/AutoTrimps/AutoTrimps2.js
// @downloadURL https://genBTC.github.io/AutoTrimps/AutoTrimps2.js
// @description Automate all the trimps!
// @author zininzinin, spindrjr, belaith, ishakaru, genBTC, Unihedron, coderPatsy, Zorn192, Zeker0
// @match *trimps.github.io*
// @match *kongregate.com/games/GreenSatellite/trimps
// @grant none
// ==/UserScript==
var ATversion = '2.1.7.0-genbtc-beta';
////////////////////////////////////////////////////////////////////////////////
//Main Loader Initialize Function (loads first, load everything else)///////////
var atscript = document.getElementById('AutoTrimps-script')
, basepath = 'https://genBTC.github.io/AutoTrimps/'
, modulepath = 'modules/'
;
//This should redirect the script to wherever its being mirrored from.
if (atscript !== null) {
basepath = atscript.src.replace(/AutoTrimps2\.js$/, '');
}
//Script can be loaded like this: ATscriptLoad(modulepath, 'utils.js');
function ATscriptLoad(pathname, modulename) {
if (modulename == null) debug("Wrong Syntax. Script could not be loaded. Try ATscriptLoad(modulepath, 'example.js'); ");
var script = document.createElement('script');
if (pathname == null) pathname = '';
script.src = basepath + pathname + modulename + '.js';
script.id = modulename + '_MODULE';
document.head.appendChild(script);
}
//Scripts can be unloaded like this: ATscriptUnload('scryer');
function ATscriptUnload(id) {
var $link = document.getElementById(id + '_MODULE');
if (!$link) return;
document.head.removeChild($link);
debug("Removing " + id + "_MODULE","other");
}
ATscriptLoad(modulepath, 'utils'); //Load stuff needed to load other stuff:
//This starts up after 2.5 seconds.
function initializeAutoTrimps() {
loadPageVariables(); //get autoTrimpSettings
ATscriptLoad('','SettingsGUI'); //populate Settings GUI
ATscriptLoad('','Graphs'); //populate Graphs
//Load modules:
ATmoduleList = ['query', 'portal', 'upgrades', 'heirlooms', 'calc', 'buildings', 'jobs', 'equipment', 'gather', 'stance', 'battlecalc', 'maps', 'breedtimer', 'dynprestige', 'fight', 'scryer', 'magmite', 'other', 'import-export', 'client-server', 'perks', /* 'perky', */ 'fight-info', 'performance'];
for (var m in ATmoduleList) {
ATscriptLoad(modulepath, ATmoduleList[m]);
}
debug('AutoTrimps v' + ATversion + ' Loaded!', '*spinner3');
}
var changelogList = [];
//changelogList.push({date: " ", version: " ", description: "", isNew: true}); //TEMPLATE
changelogList.push({date: "11/4/2023", version: "v2.1.7.0-beta", description: "Start new code merging from Zorn/Zek", isNew: true});
changelogList.push({date: "11/2/2023", version: "v2.1.6.9c", description: "<br>Update Script for 2023 and Trimps v5.9 - so it works again!", isNew: true});
changelogList.push({date: "April 2018", version: "v2.1.6.9", description: "Current Long Term Stable Version ", isNew: false});
changelogList.push({date: "March 2018", version: "v2.1.6.5", description: "Previous Old Stable Version ", isNew: false});
function assembleChangelog(date,version,description,isNew) {
return (isNew)
? (`<b class="AutoEggs">${date} ${version} </b><b style="background-color:#32CD32"> New:</b> ${description}<br>`)
: (`<b>${date} ${version} </b> ${description}<br>`);
}
function printChangelog() {
var body="";
for (var i in changelogList) {
var $item = changelogList[i];
var result = assembleChangelog($item.date,$item.version,$item.description,$item.isNew);
body+=result;
};
var footer =
'<b>genBTC fork is outdated, use Zorn192 / Zeker for best outcome, or YMMV</b>\
There is no relation to bitcoin, genBTC is merely my nickname.\
<br> See <a target="#" href="https://github.com/genbtc/AutoTrimps/blob/gh-pages/README.md">ReadMe</a>\
<br> Or <a target="#" href="https://github.com/genBTC/AutoTrimps/commits/gh-pages" target="#">the commit history</a>.'
, action = 'cancelTooltip()'
, title = 'Script Update Notice<br>' + ATversion
, acceptBtnText = "Thank you for playing AutoTrimps. Accept and Continue."
, hideCancel = true;
tooltip('confirm', null, 'update', body+footer, action, title, acceptBtnText, null, hideCancel);
}
//TODO: These clobber each other and the lowlevel notice keeps coming up.
function printLowerLevelPlayerNotice() {
tooltip('confirm', null, 'update', 'NOTE: Script not really designed for level 60 or under. YMMV. <br>-genBTC','cancelTooltip()', '<b>LowLevelPlayer Notes:</b><br><b>PSA: </b><u>AutoTrimps was not designed for new/low-level players.</u>', "I understand I am on my own and I Accept and Continue.", null, true);
}
////////////////////////////////////////
//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
//Start Loops
setTimeout(delayStart, startupDelay);
function delayStart() {
initializeAutoTrimps();
printChangelog();
setTimeout(delayStartAgain, startupDelay);
}
function delayStartAgain(){
if (game.achievements.zones.finished < 8 && !autoTrimpSettings.lowlevel) { //z60
printLowerLevelPlayerNotice();
autoTrimpSettings.lowlevel = true;
}
//Set some game vars after we load.
game.global.addonUser = true;
game.global.autotrimps = true;
//Actually Start mainLoop and guiLoop
MODULESdefault = JSON.parse(JSON.stringify(MODULES));
setInterval(mainLoop, runInterval);
setInterval(guiLoop, runInterval*10);
if (autoTrimpSettings.PrestigeBackup !== undefined && autoTrimpSettings.PrestigeBackup.selected != "")
document.getElementById('Prestige').value = autoTrimpSettings.PrestigeBackup.selected;
if (document.getElementById('Prestige').value === "")
document.getElementById('Prestige').value = "Off";
}
////////////////////////////////////////
//Global Main vars /////////////////////
var ATrunning = true; //status var
var ATmessageLogTabVisible = true; //show an AutoTrimps tab after Story/Loot/Unlocks/Combat message Log Container
var enableDebug = true; //Spam console.log with debug info
var autoTrimpSettings = {};
var MODULES = {};
var MODULESdefault = {};
var ATMODULES = {};
var ATmoduleList = [];
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 currentworld = 0;
var lastrunworld = 0;
var aWholeNewWorld = false;
var heirloomFlag = false;
var heirloomCache = game.global.heirloomsExtra.length;
var magmiteSpenderChanged = false;
var autoTrapButtonRemoved = false;
////////////////////////////////////////
//Main LOGIC Loop///////////////////////
function mainLoop() {
if (ATrunning == false) return;
if(getPageSetting('PauseScript') || game.options.menu.pauseGame.enabled || game.global.viewingUpgrades) 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;
addToolTipToArmyCount(); //Add hidden tooltip for army count (SettingsGUI.js @ end)
//Heirloom:
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('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;
//Stuff to do Every new Zone
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();
}
if (getPageSetting('AutoEggs'))
easterEggClicked();
setTitle(); // Set the browser title
}
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)
var agu = getPageSetting('AutoGoldenUpgrades');
if (agu && agu!='Off') autoGoldenUpgradesAT(agu); //"Golden Upgrades" (other.js)
if (getPageSetting('BuyStorage')) buyStorage(); //"Buy Storage" (buildings.js)
if (getPageSetting('BuyBuildings')) buyBuildings(); //"Buy Buildings" (buildings.js)
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" (")
getPageSetting('AutoMaps') > 0 ? autoMap() : updateAutoMapsStatus(); //"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 && (autoTrapButtonRemoved == false)) { // only runs on initial run
if (game.global.trapBuildToggled == false)
toggleAutoTraps();
else { // if (game.global.trapBuildToggled == true)
var autoTrapBtn = document.getElementById("autoTrapBtn");
//remove AutoTraps button if its locked on green anyway
if (autoTrapBtn && autoTrapBtn.parentNode.removeChild(autoTrapBtn))
autoTrapButtonRemoved=true;
}
}
if (aWholeNewWorld && getPageSetting('AutoRoboTrimp')) autoRoboTrimp(); //"AutoRoboTrimp" (other.js)
if (aWholeNewWorld && 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" (magmite.js)
ATselectAutoFight(); // pick the right version of Fight/AutoFight/BetterAutoFight/BAF2 (fight.js)
var forcePrecZ = (getPageSetting('ForcePresZ')<0) || (game.global.world<getPageSetting('ForcePresZ'));
if (getPageSetting('DynamicPrestige2')>0 && forcePrecZ) prestigeChanging2(); //"Dynamic Prestige" (dynprestige.js)
else autoTrimpSettings.Prestige.selected = document.getElementById('Prestige').value; //just make sure the UI setting and the internal setting are aligned.
if (getPageSetting('AutoMagmiteSpender2')==2 && !magmiteSpenderChanged) autoMagmiteSpender(); //Auto Magmite Spender (magmite.js)
if (getPageSetting('AutoNatureTokens')) autoNatureTokens(); //Nature (other.js)
//
//Runs any user provided scripts, see line 253 below
if (userscriptOn) userscripts();
//
//rinse, repeat, done
return;
}
//GUI Updates happen on this thread, every 1000ms
function guiLoop() {
updateCustomButtons();
//Store the diff of our custom MODULES vars in the localStorage bin.
safeSetItems('storedMODULES', JSON.stringify(compareModuleVars()));
//Swiffy UI/Display tab
if(getPageSetting('EnhanceGrids'))
MODULES["fightinfo"].Update();
if(typeof MODULES !== 'undefined' && typeof MODULES["performance"] !== 'undefined' && MODULES["performance"].isAFK)
MODULES["performance"].UpdateAFKOverlay();
}
//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('AutoMaps')==1 && !game.upgrades.Battle.done && getPageSetting('AutoMaps') == 0)
settingChanged("AutoMaps");
return true; // Do other things
}
}
//test error
function throwErrorfromMain() {
throw new Error("We have successfully read the thrown error message out of the main file");
}
// Userscript loader. write your own scripts!
//Copy and paste this function named userscripts() into the JS Dev console. (F12)
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()
{
//empty stub. leave blank for user code
}