forked from Ephenia/Pokeclicker-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenhancedautomine.user.js
340 lines (321 loc) · 14.5 KB
/
enhancedautomine.user.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
// ==UserScript==
// @name [Pokeclicker] Enhanced Auto Mine
// @namespace Pokeclicker Scripts
// @match https://www.pokeclicker.com/
// @grant none
// @version 1.5
// @author Ephenia (Credit: falcon71, KarmaAlex)
// @description Automatically mines the Underground with Bombs. Features adjustable settings as well.
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/enhancedautomine.user.js
// ==/UserScript==
var mineState;
var smallRestoreState;
var awaitAutoMine;
var setThreshold;
var autoMineTimer;
var mineColor;
var smallRestoreColor;
var resetInProgress;
var busyMining;
var autoMineSkip;
var layersMined;
var sellTreasureState;
var sellTreasureColor;
var sellPlateState;
var sellPlateColor;
var newSave;
var trainerCards;
function initAutoMine() {
if (mineState == "ON") {
autoMineTimer = setInterval(function () {
doAutoMine();
}, 1000);
}
if (mineState == "OFF") {
mineColor = "danger"
} else {
mineColor = "success"
}
if (smallRestoreState == "OFF") {
smallRestoreColor = "danger"
} else {
smallRestoreColor = "success"
}
if (sellTreasureState == "OFF") {
sellTreasureColor = "danger"
} else {
sellTreasureColor = "success"
}
if (sellPlateState == "OFF") {
sellPlateColor = "danger"
} else {
sellPlateColor = "success"
}
setThreshold = +setThreshold
resetInProgress = "NO"
localStorage.setItem("undergroundLayersMined", App.game.statistics.undergroundLayersMined());
layersMined = localStorage.getItem('undergroundLayersMined');
var minerHTML = document.createElement("div");
minerHTML.innerHTML = `<button id="auto-mine-start" class="col-12 col-md-3 btn btn-` + mineColor + `">Auto Mine [` + mineState + `]</button>
<button id="small-restore-start" class="col-12 col-md-3 btn btn-`+ smallRestoreColor + `">Auto Small Restore [` + smallRestoreState + `]</button>
<div id="threshold-input" class="col-12 col-md-3 btn-secondary"><img title="Money" src="assets/images/currency/money.svg" height="25px">
<input title="Enter in a value where Small Restores will stop being bought at." type="text" id="small-restore"></div>
<div id="skip-input" class="col-12 col-md-3 btn-secondary">
<input title="Auto skipping occurs if the max items in a layer is lower than the value put here." type="text" id="auto-skip"></div>`
document.querySelectorAll('#mineBody + div')[0].prepend(minerHTML);
$("#auto-mine-start").unwrap();
document.getElementById('small-restore').value = setThreshold.toLocaleString('en-US');
document.getElementById('auto-skip').value = autoMineSkip.toLocaleString('en-US');
var autoSeller = document.createElement("div");
autoSeller.innerHTML = `<div>
<button id="auto-sell-treasure" class="col-12 col-md-3 btn btn-`+ sellTreasureColor + `">Auto Sell Treasure [` + sellTreasureState + `]</button>
<button id="auto-sell-plate" class="col-12 col-md-3 btn btn-`+ sellPlateColor + `">Auto Sell Plate [` + sellPlateState + `]</button>
</div>`
document.getElementById('treasures').prepend(autoSeller);
addGlobalStyle('#threshold-input { display:flex;flex-direction:row;flex-wrap:wrap;align-content:center;justify-content:space-evenly;align-items:center; }');
addGlobalStyle('#skip-input { display:flex;flex-direction:row;flex-wrap:wrap;align-content:center;justify-content:space-evenly;align-items:center; }');
addGlobalStyle('#small-restore { width:150px; }');
addGlobalStyle('#auto-skip { width:150px; }');
$("#auto-mine-start").click(startAutoMine);
$("#small-restore-start").click(autoRestore);
$("#auto-sell-treasure").click(autoSellTreasure);
$("#auto-sell-plate").click(autoSellPlate);
function startAutoMine() {
if (mineState == "OFF") {
localStorage.setItem("autoMineState", "ON");
mineState = "ON"
autoMineTimer = setInterval(function () {
doAutoMine();
}, 1000); // Happens every 1 second
document.getElementById('auto-mine-start').innerText = `Auto Mine [` + mineState + `]`
document.getElementById("auto-mine-start").classList.remove('btn-danger');
document.getElementById("auto-mine-start").classList.add('btn-success');
} else {
endAutoMine();
}
}
function doAutoMine() {
var getEnergy = Math.floor(App.game.underground.energy);
var getMoney = App.game.wallet.currencies[GameConstants.Currency.money]();
var buriedItems = Mine.itemsBuried();
var skipsRemain = Mine.skipsRemaining();
const smallRestore = player.itemList["SmallRestore"]();
const mediumRestore = player.itemList["MediumRestore"]();
const largeRestore = player.itemList["LargeRestore"]();
var getCost = ItemList["SmallRestore"].price();
var shopWindow = document.getElementById('shopModal')
if (buriedItems >= autoMineSkip || skipsRemain == 0) {
if (smallRestoreState == "ON") {
if ((getCost == 30000) && (+smallRestore == 0) && (getMoney >= setThreshold + 30000)) {
ItemList["SmallRestore"].buy(1);
}
if (getEnergy < 10) {
if (largeRestore > 0) {
ItemList["LargeRestore"].use();
} else if (mediumRestore > 0) {
ItemList["MediumRestore"].use();
} else {
ItemList["SmallRestore"].use();
}
}
}
if (getEnergy >= 1) {
if (Mine.toolSelected() != 0) {
Mine.toolSelected(Mine.Tool.Chisel);
}
var mineEl = document.getElementById('mineBody');
var rewards = mineEl.querySelectorAll('.mineReward');
for (var ii = 0; ii < rewards.length; ii++) {
var reward = rewards[ii];
var rewardParent = reward.parentNode;
var ri = +reward.parentNode.getAttribute('data-i');
var rj = +reward.parentNode.getAttribute('data-j');
for (var i = -1; i <= 1; i++) {
for (var j = -1; j <= 1; j++) {
var ti = ri + i;
var tj = rj + j;
var checkTile = mineEl.querySelector('.mineSquare[data-i="' + ti + '"][data-j="' + tj + '"]');
if (checkTile && (
checkTile.classList.contains('rock1') ||
checkTile.classList.contains('rock2') ||
checkTile.classList.contains('rock3') ||
checkTile.classList.contains('rock4') ||
checkTile.classList.contains('rock5')
)) {
Mine.click(ti, tj);
getEnergy -= 1;
}
}
}
}
}
if (getEnergy >= 10) {
Mine.bomb();
}
} else {
if (resetInProgress == "NO") {
if (Mine.itemsBuried() >= Mine.itemsFound()) {
// Don't resolve queued up calls to checkCompleted() until completed() is finished and sets loadingNewLayer to false
if (Mine.loadingNewLayer == true) {
resetInProgress = "YES"
}
if (resetInProgress == "NO") {
Mine.loadingNewLayer = true;
setTimeout(Mine.completed, 1500);
//GameHelper.incrementObservable(App.game.statistics.undergroundLayersMined);
if (Mine.skipsRemaining() != 0) {
GameHelper.incrementObservable(Mine.skipsRemaining, -1);
}
busyMining = setTimeout(function () {
resetInProgress = "NO"
}, 1500);
} else {
resetInProgress = "NO"
}
}
}
}
if (layersMined != App.game.statistics.undergroundLayersMined()) {
var treasureLength = player.mineInventory().length;
if (sellTreasureState == "ON") {
for (var i = 0; i < treasureLength; i++) {
var valueType = player.mineInventory()[i].valueType
if (valueType == "Diamond") {
var treasureID = player.mineInventory()[i].id;
Underground.sellMineItem(treasureID, Infinity)
}
}
}
if (sellPlateState == "ON") {
for (var ii = 0; ii < treasureLength; ii++) {
var getName = player.mineInventory()[ii].name;
if (getName.includes("Plate")) {
var plateID = player.mineInventory()[ii].id;
Underground.sellMineItem(plateID, Infinity)
}
}
}
localStorage.setItem("undergroundLayersMined", App.game.statistics.undergroundLayersMined());
layersMined = localStorage.getItem('undergroundLayersMined');
}
}
document.querySelector('#small-restore').addEventListener('input', event => {
setThreshold = +event.target.value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
localStorage.setItem("autoBuyThreshold", setThreshold);
event.target.value = setThreshold.toLocaleString('en-US');
});
document.querySelector('#auto-skip').addEventListener('input', event => {
autoMineSkip = +event.target.value.replace(/[A-Za-z!@#$%^&*()]/g, '').replace(/[,]/g, "");
localStorage.setItem("autoMineSkip", autoMineSkip);
event.target.value = autoMineSkip.toLocaleString('en-US');
});
function autoRestore() {
if (smallRestoreState == "OFF") {
smallRestoreState = "ON"
document.getElementById("small-restore-start").classList.remove('btn-danger');
document.getElementById("small-restore-start").classList.add('btn-success');
} else {
smallRestoreState = "OFF"
document.getElementById("small-restore-start").classList.remove('btn-success');
document.getElementById("small-restore-start").classList.add('btn-danger');
}
document.getElementById('small-restore-start').innerText = `Auto Small Restore [` + smallRestoreState + `]`
localStorage.setItem("autoSmallRestore", smallRestoreState);
}
function autoSellTreasure() {
if (sellTreasureState == "OFF") {
sellTreasureState = "ON"
document.getElementById("auto-sell-treasure").classList.remove('btn-danger');
document.getElementById("auto-sell-treasure").classList.add('btn-success');
} else {
sellTreasureState = "OFF"
document.getElementById("auto-sell-treasure").classList.remove('btn-success');
document.getElementById("auto-sell-treasure").classList.add('btn-danger');
}
document.getElementById('auto-sell-treasure').innerText = `Auto Sell Treasure [` + sellTreasureState + `]`
localStorage.setItem("autoSellTreasure", sellTreasureState);
}
function autoSellPlate() {
if (sellPlateState == "OFF") {
sellPlateState = "ON"
document.getElementById("auto-sell-plate").classList.remove('btn-danger');
document.getElementById("auto-sell-plate").classList.add('btn-success');
} else {
sellPlateState = "OFF"
document.getElementById("auto-sell-plate").classList.remove('btn-success');
document.getElementById("auto-sell-plate").classList.add('btn-danger');
}
document.getElementById('auto-sell-plate').innerText = `Auto Sell Plate [` + sellPlateState + `]`
localStorage.setItem("autoSellPlate", sellPlateState);
}
function endAutoMine() {
localStorage.setItem("autoMineState", "OFF");
mineState = "OFF"
document.getElementById('auto-mine-start').innerText = `Auto Mine [` + mineState + `]`
document.getElementById("auto-mine-start").classList.remove('btn-success');
document.getElementById("auto-mine-start").classList.add('btn-danger');
clearTimeout(busyMining);
//clearTimeout(mineComplete);
resetInProgress = "NO";
clearInterval(autoMineTimer)
}
}
if (localStorage.getItem('autoMineState') == null) {
localStorage.setItem("autoMineState", "OFF");
}
if (localStorage.getItem('autoSmallRestore') == null) {
localStorage.setItem("autoSmallRestore", "OFF");
}
if (localStorage.getItem('autoBuyThreshold') == null) {
localStorage.setItem("autoBuyThreshold", "0");
}
if (localStorage.getItem('autoMineSkip') == null) {
localStorage.setItem("autoMineSkip", "0");
}
if (localStorage.getItem('autoSellTreasure') == null) {
localStorage.setItem("autoSellTreasure", "OFF");
}
if (localStorage.getItem('autoSellPlate') == null) {
localStorage.setItem("autoSellPlate", "OFF");
}
mineState = localStorage.getItem('autoMineState');
smallRestoreState = localStorage.getItem('autoSmallRestore');
setThreshold = localStorage.getItem('autoBuyThreshold');
autoMineSkip = localStorage.getItem('autoMineSkip');
sellTreasureState = localStorage.getItem('autoSellTreasure');
sellPlateState = localStorage.getItem('autoSellPlate');
function loadScript(){
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function(){
var result = oldInit.apply(this, arguments)
initAutoMine()
return result
}
}
var scriptName = 'enhancedautomine'
if (document.getElementById('scriptHandler') != undefined){
var scriptElement = document.createElement('div')
scriptElement.id = scriptName
document.getElementById('scriptHandler').appendChild(scriptElement)
if (localStorage.getItem(scriptName) != null){
if (localStorage.getItem(scriptName) == 'true'){
loadScript()
}
}
else{
localStorage.setItem(scriptName, 'true')
loadScript()
}
}
else{
loadScript();
}
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}