-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathenhancedautoclicker.user.js
More file actions
738 lines (672 loc) · 27.7 KB
/
enhancedautoclicker.user.js
File metadata and controls
738 lines (672 loc) · 27.7 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
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
// ==UserScript==
// @name [Pokeclicker] Enhanced Auto Clicker
// @namespace Pokeclicker Scripts
// @author Ephenia (Original/Credit: Ivan Lay, Novie53, andrew951, Kaias26, kevingrillet)
// @description Clicks through battles appropriately depending on the game state. Also, includes a toggle button to turn Auto Clicking on or off and various insightful statistics. Now also includes an automatic Gym battler as well as Auto Dungeon with different modes, as well as being able to adjust the speed at which the Auto CLicker can click at.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 2.7
// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
// @downloadURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/enhancedautoclicker.user.js
// @updateURL https://raw.githubusercontent.com/Ephenia/Pokeclicker-Scripts/master/enhancedautoclicker.user.js
// @match https://www.pokeclicker.com/
// @icon https://www.google.com/s2/favicons?domain=pokeclicker.com
// @grant none
// @run-at document-idle
// ==/UserScript==
var clickState;
var awaitAutoClick;
var autoClickerLoop;
var autoClickDPS;
var clickDPS;
var reqDPS;
var enemySpeedRaw;
var enemySpeed;
var allSelectedGym = 0;
var gymState;
var gymSelect;
var dungeonState;
var achievementState;
var dungeonSelect;
var achievementSelect;
var foundBoss = false;
var foundBossX;
var foundBossY;
var delayAutoClick;
window.testDPS = 0;
window.defeatDPS = 0;
function initAutoClicker() {
const battleView = document.getElementsByClassName('battle-view')[0];
var elemAC = document.createElement("table");
elemAC.innerHTML = `<tbody><tr><td colspan="4">
<button id="auto-click-start" class="btn btn-${clickState ? 'success' : 'danger'} btn-block" style="font-size:8pt;">
Auto Click [${clickState ? 'ON' : 'OFF'}]<br>
<div id="auto-click-info">
<div id="click-DPS">Auto Click DPS:<br><div style="font-weight:bold;color:gold;">${clickDPS.toLocaleString('en-US')}</div></div>
<div id="req-DPS">Req. DPS:<br><div style="font-weight:bold;">0</div></div>
<div id="enemy-DPS">Enemy/s:<br><div style="font-weight:bold;color:black;">0</div></div>
</div>
</button>
<div id="click-delay-cont">
<div id="auto-click-delay-info">Click Attack Delay: ${clickDelayFixed(1000 / delayAutoClick)}/s</div>
<input type="range" min="1" max="50" value="${delayAutoClick}" id="auto-click-delay">
</div>
</td></tr>
<tr>
<td style="width: 42%;">
<button id="auto-dungeon-start" class="btn btn-block btn-${dungeonState ? 'success' : 'danger'}" style="font-size: 8pt;">
Auto Dungeon [${dungeonState ? 'ON' : 'OFF'}]</button>
</td>
<td>
<select id="dungeon-select">
<option value="0">F</option>
<option value="1">B</option>
</select>
</td>
<td style="width: 40%;">
<button id="auto-gym-start" class="btn btn-block btn-${gymState ? 'success' : 'danger'}" style="font-size: 8pt;">
Auto Gym [${gymState ? 'ON' : 'OFF'}]
</button>
</td>
<td>
<select id="gym-select">
<option value="0">#1</option>
<option value="1">#2</option>
<option value="2">#3</option>
<option value="3">#4</option>
<option value="4">#5</option>
<option value="5">All</option>
</select>
</td>
</tr>
<tr>
<td style="width: 40%;">
<button id="auto-achievement-start" class="btn btn-block btn-${achievementState ? 'success' : 'danger'}" style="font-size: 8pt;">
Auto Achievement [`+ achievementState + `]
</button>
</td>
<td>
<select id = "achievement-select">
<option value = "0">Routes</option>
<option value = "1">Gyms</option>
<option value = "2">Dungeons</option>
</select>
</td>
</tr>
</tbody>`
battleView.before(elemAC)
document.getElementById('gym-select').value = gymSelect;
document.getElementById('dungeon-select').value = dungeonSelect;
document.getElementById('achievement-select').value = achievementSelect;
document.getElementById('auto-click-start').addEventListener('click', () => { toggleAutoClick(); });
document.getElementById('auto-gym-start').addEventListener('click', event => { toggleAutoGym(event); });
document.getElementById('auto-dungeon-start').addEventListener('click', event => { toggleAutoDungeon(event); });
document.getElementById('auto-achievement-start').addEventListener('click', event => { toggleAutoAchievement(event); });
document.getElementById('gym-select').addEventListener('change', event => { changeSelectedGym(event); });
document.getElementById('dungeon-select').addEventListener('change', event => { changeSelectedDungeon(event); });
document.getElementById('achievement-select').addEventListener('change', event => { changeSelectedAchievement(event); });
document.getElementById('auto-click-delay').addEventListener('change', event => { changeClickDelay(event); });
addGlobalStyle('#auto-click-info { display: flex;flex-direction: row;justify-content: center; }');
addGlobalStyle('#auto-click-info > div { width: 33.3%; }');
addGlobalStyle('#dungeonMap { padding-bottom: 9.513%; }');
addGlobalStyle('#click-delay-cont { display: flex; flex-direction: column; align-items: stretch;}')
if (clickState) {
autoClicker();
calcClickDPS();
}
overideClickAttack();
}
function toggleAutoClick() {
const element = document.getElementById('auto-click-start');
clickState = !clickState;
clickState ? autoClicker() : clearInterval(autoClickerLoop);
clickState ? calcClickDPS() : clearInterval(autoClickDPS);
if (clickState) {
clickDPS = JSON.parse(localStorage.getItem('storedClickDPS'));
} else {
clickDPS = 0;
reqDPS = 0;
enemySpeedRaw = 0;
}
clickState ? element.classList.replace('btn-danger', 'btn-success') : element.classList.replace('btn-success', 'btn-danger');
element.innerHTML = `Auto Click [${clickState ? 'ON' : 'OFF'}]<br>
<div id="auto-click-info">
<div id="click-DPS">Auto Click DPS:<br><div style="font-weight:bold;color:gold;">${clickDPS.toLocaleString('en-US')}</div></div>
<div id="req-DPS">Req. DPS:<br><div style="font-weight:bold;">0</div></div>
<div id="enemy-DPS">Enemy/s:<br><div style="font-weight:bold;color:black;">0</div></div>
</div>`
localStorage.setItem('autoClickState', clickState);
}
function toggleAutoGym(event) {
const element = event.target;
gymState = !gymState;
gymState ? element.classList.replace('btn-danger', 'btn-success') : element.classList.replace('btn-success', 'btn-danger');
element.textContent = `Auto Gym [${gymState ? 'ON' : 'OFF'}]`;
localStorage.setItem('autoGymState', gymState);
}
function toggleAutoDungeon(event) {
const element = event.target;
dungeonState = !dungeonState;
dungeonState ? element.classList.replace('btn-danger', 'btn-success') : element.classList.replace('btn-success', 'btn-danger');
element.textContent = `Auto Dungeon [${dungeonState ? 'ON' : 'OFF'}]`;
localStorage.setItem('autoDungeonState', dungeonState);
}
function toggleAutoAchievement(event) {
const element = event.target;
achievementState = !achievementState;
achievementState ? element.classList.replace('btn-danger', 'btn-success') : element.classList.replace('btn-success', 'btn-danger');
element.textContent = `Auto Achievement [${achievementState ? 'ON' : 'OFF'}]`;
localStorage.setItem('autoAchievementState', achievementState);
// Deactivate AutoGym and AutoDungeon that could have been triggered
if(gymState === true){
document.getElementById("auto-gym-start").click();
}
if(dungeonState === true){
document.getElementById("auto-dungeon-start").click();
}
}
function changeSelectedGym(event) {
const element = event.target;
if (gymSelect != +element.value) {
gymSelect = +element.value;
localStorage.setItem("selectedGym", gymSelect);
}
}
function changeSelectedDungeon(event) {
const element = event.target;
if (dungeonSelect != +element.value) {
dungeonSelect = +element.value;
localStorage.setItem("selectedDungeon", dungeonSelect);
}
}
function changeSelectedAchievement() {
const element = event.target;
if (achievementSelect != +element.value) {
achievementSelect = +element.value;
localStorage.setItem("selectedAchievement", achievementSelect);
}
}
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
function calcClickDPS() {
autoClickDPS = setInterval(function () {
const clickSec = window.testDPS;
let enemyHealth;
try {
enemyHealth = Battle.enemyPokemon().maxHealth();
}
catch (err) {
enemyHealth = 0;
}
if (clickDPS != App.game.party.calculateClickAttack() * clickSec) {
clickDPS = App.game.party.calculateClickAttack() * clickSec;
document.getElementById('click-DPS').innerHTML = `Auto Click DPS:<br><div style="font-weight:bold;color:gold;">${Math.floor(clickDPS).toLocaleString('en-US')}</div>`
localStorage.setItem('storedClickDPS', clickDPS)
}
if (reqDPS != enemyHealth * clickSec) {
reqDPS = enemyHealth * clickSec;
document.getElementById('req-DPS').innerHTML = `Req. DPS:<br><div style="font-weight:bold;color: ${clickDPS >= reqDPS ? 'greenyellow' : 'darkred'}">${Math.ceil(reqDPS).toLocaleString('en-US')}</div>`
}
if (enemySpeedRaw != ((App.game.party.calculateClickAttack() * clickSec) / enemyHealth).toFixed(1)) {
enemySpeed = ((App.game.party.calculateClickAttack() * clickSec) / enemyHealth);
enemySpeedRaw = enemySpeed;
if (isNaN(enemySpeedRaw) || enemySpeedRaw == 'Infinity' || Battle.catching()) {
enemySpeed = 0;
}
if (enemySpeedRaw >= clickSec && enemySpeedRaw != 'Infinity' && !Battle.catching()) {
enemySpeed = window.defeatDPS;
}
if (!Number.isInteger(enemySpeed) && enemySpeed != 0) { enemySpeed = enemySpeed.toFixed(1).toString().replace('.0', '') }
document.getElementById('enemy-DPS').innerHTML = `Enemy/s:<br><div style="font-weight:bold;color:black;">${enemySpeed}</div>`
}
window.testDPS = 0;
window.defeatDPS = 0;
}, 1000);
}
function autoClicker() {
autoClickerLoop = setInterval(function () {
// Click while in a normal battle
if (App.game.gameState == GameConstants.GameState.fighting) {
Battle.clickAttack();
}
//Auto Gym checking
if (gymState) {
autoGym();
}
//Auto Dungeon checking
if (dungeonState && DungeonRunner.fighting() == false && DungeonBattle.catching() == false) {
autoDungeon();
}
//Reset the values for the boss coordinates if we timeout or turn off autoDungeon
if ((!dungeonState && foundBoss) || (dungeonState && DungeonRunner.dungeonFinished() && foundBoss)) {
foundBoss = false
bossCoords.length = 0
}
//Auto Achievement checking
if (achievementState) {
autoAchievement();
}
// Click while in a gym battle
if (App.game.gameState === GameConstants.GameState.gym) {
GymBattle.clickAttack();
}
// Click while in "Tomporary Battle" (battle ultra wormhole)
if (App.game.gameState === GameConstants.GameState.temporaryBattle) {
TemporaryBattleBattle.clickAttack();
}
// Click while in a dungeon - will also interact with non-battle tiles (e.g. chests)
if (App.game.gameState === GameConstants.GameState.dungeon) {
if (DungeonRunner.fighting() && !DungeonBattle.catching()) {
DungeonBattle.clickAttack();
}
}
}, delayAutoClick); // The app hard-caps click attacks at 50
}
function changeClickDelay(event) {
const delay = +event.target.value;
delayAutoClick = delay;
localStorage.setItem("delayAutoClick", delay);
overideClickAttack();
if (clickState) {
clearInterval(autoClickerLoop);
autoClicker();
}
let clickSec = (1000 / delayAutoClick);
document.getElementById('auto-click-delay-info').innerText = `Click Attack Delay: ${clickDelayFixed(clickSec)}/s`;
}
function clickDelayFixed(int) {
if (int != parseInt(int)) { int = int.toFixed(2) }
return int;
}
function overideClickAttack() {
// Overiding the game's function for Click Attack
Battle.clickAttack = function () {
// click attacks disabled and we already beat the starter
if (App.game.challenges.list.disableClickAttack.active() && player.starter() != GameConstants.Starter.None) {
return;
}
// TODO: figure out a better way of handling this
// Limit click attack speed, Only allow 1 attack per 50ms (20 per second)
const now = Date.now();
if (this.lastClickAttack > now - delayAutoClick) {
return;
}
this.lastClickAttack = now;
if (!this.enemyPokemon()?.isAlive()) {
return;
}
GameHelper.incrementObservable(App.game.statistics.clickAttacks);
this.enemyPokemon().damage(App.game.party.calculateClickAttack(true));
window.testDPS++;
if (!this.enemyPokemon().isAlive()) {
this.defeatPokemon();
window.defeatDPS++;
}
}
}
function autoGym() {
//Checking if Gyms exist here and grabbing them
const getGyms = player.town().content.filter((c) => ['Gym'].includes(c.constructor.name));
if (getGyms.length != 0) {
const townName = player.town().name;
if (!MapHelper.isTownCurrentLocation(townName)) {
MapHelper.moveToTown(townName)
}
/*Don't think this can ever happen
if (player.region != player.town().region) {
player.region = player.town().region
}*/
if (App.game.gameState != GameConstants.GameState.gym) {
//Checking if Champion exists here and grabbing them
const getChamp = player.town().content.filter((c) => ['Champion'].includes(c.constructor.name));
const gymChampLen = (getGyms.length + getChamp.length) - 1;
//Checking if Champion is unlocked
let champUnlocked;
try { champUnlocked = getChamp[0].isUnlocked() } catch (err) { champUnlocked = false };
//If "All" is selected we attempt to fight and loop through all Gyms, including the Champion if available and unlocked
if (gymSelect === 5) {
//Reset if exceeded
if (allSelectedGym === 5 || allSelectedGym > gymChampLen) {
allSelectedGym = 0;
}
if (champUnlocked && allSelectedGym === gymChampLen) {
//We fight the Champion if Champion exists and is unlocked
GymRunner.startGym(getChamp[0]);
} else if (getGyms[allSelectedGym].isUnlocked()) {
//We fight Gyms instead if they're unlocked
GymRunner.startGym(getGyms[allSelectedGym]);
}
allSelectedGym++;
} else {
//Making sure we don't fight Gyms that don't exist and fight the lowest if we pick higher
const selGym = Math.min(gymSelect, gymChampLen);
//#5 is purely for the Champion and typically E4 where there's 5 total
if (gymSelect == 4 && gymSelect === gymChampLen && champUnlocked) {
GymRunner.startGym(getChamp[0]);
} else if (getGyms[selGym].isUnlocked()) {
//Fighting the selected Gym here
GymRunner.startGym(getGyms[selGym])
}
}
}
}
}
var bossCoords = []
function autoDungeon() {
//Rewrite
if (player.town().hasOwnProperty("dungeon") == true && player.town().dungeon !== undefined) {
var getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken]();
var dungeonCost = player.town().dungeon.tokenCost;
const townName = player.town().name;
if (!MapHelper.isTownCurrentLocation(townName)) {
MapHelper.moveToTown(townName)
}
//Don't think this condition is ever possible
/*if (player.region != player.town().region) {
player.region = player.town().region
}*/
if (getTokens >= dungeonCost && App.game.gameState != GameConstants.GameState.dungeon) {
DungeonRunner.initializeDungeon(player.town().dungeon)
}
if (App.game.gameState === GameConstants.GameState.dungeon) {
var dungeonBoard = DungeonRunner.map.board()[DungeonRunner.map.playerPosition().floor];
//The boss can be found at any time
if (foundBoss == false) {
bossCoords = scan(dungeonBoard)
}
//Wander around until we can move to the boss tile
//Pathfinding should be implemented here, A* looks like the best algorithm
else if (foundBoss == true && dungeonSelect == 1) {
wander(dungeonBoard, bossCoords)
}
else if (dungeonSelect == 0) {
fullClear(dungeonBoard, bossCoords)
}
}
}
}
function autoAchievement()
{
let currentRoute = player.route();
let currentRegion = player.region;
let currentDungeon = player.town().dungeon?.name;
let currentGym = player.town().name;
//Route
if(achievementSelect == 0)
{
let newRoute = getNextRoute();
currentRoute = player.route();
if(newRoute && newRoute.number != currentRoute || newRoute.region != currentRegion)
{
currentRoute = newRoute.number;
currentRegion = newRoute.region;
if(newRoute.region != player.subregion)
{
player.subregion = newRoute.subRegion;
}
MapHelper.moveToRoute(newRoute.number, newRoute.region);
}
}
//Gym
else if(achievementSelect == 1)
{
//Toggle Auto Gym ON
if (gymState === false) {
document.getElementById("auto-gym-start").click();
}
let newGym = getNextGym();
if(newGym && newGym != currentGym)
{
currentGym = newGym;
player.subregion = TownList[newGym].subRegion;
MapHelper.moveToTown(newGym);
}
}
//Dungeon
else if(achievementSelect == 2)
{
//Toggle Auto Dungeon ON
if (dungeonState === false) {
document.getElementById("auto-dungeon-start").click();
}
//Move
let newDungeon = getNextDungeon();
if(newDungeon && newDungeon != currentDungeon)
{
currentDungeon = newDungeon;
player.subregion = TownList[newDungeon].subRegion;
MapHelper.moveToTown(newDungeon);
}
}
}
function getNextRoute()
{
let regionRoutes = Routes.getRoutesByRegion(player.region);
for(let j = 0; j < regionRoutes.length; j ++)
{
if(getDefeatedOnRoute(player.region, regionRoutes[j].number) < GameConstants.ACHIEVEMENT_DEFEAT_ROUTE_VALUES[GameConstants.ACHIEVEMENT_DEFEAT_ROUTE_VALUES.length-1])
{
return regionRoutes[j];
}
}
}
function getNextGym()
{
let regionGyms = GameConstants.RegionGyms[player.region];
for(let j = 0; j < regionGyms.length; j ++)
{
if(getDefeatedOnGym(regionGyms[j]) < GameConstants.ACHIEVEMENT_DEFEAT_GYM_VALUES[GameConstants.ACHIEVEMENT_DEFEAT_GYM_VALUES.length-1])
{
return regionGyms[j];
}
}
}
function getNextDungeon()
{
let regionDungeons = GameConstants.RegionDungeons[player.region];
for(let j = 0; j < regionDungeons.length; j ++)
{
if(getDefeatedOnDungeon(regionDungeons[j]) < GameConstants.ACHIEVEMENT_DEFEAT_DUNGEON_VALUES[GameConstants.ACHIEVEMENT_DEFEAT_DUNGEON_VALUES.length-1])
{
return regionDungeons[j];
}
}
}
function getDefeatedOnRoute(region, route)
{
return App.game.statistics.routeKills[region][route]();
}
function getDefeatedOnGym(gymName)
{
return App.game.statistics.gymsDefeated[GameConstants.getGymIndex(gymName)]();
}
function getDefeatedOnDungeon(dungeonName)
{
return App.game.statistics.dungeonsCleared[GameConstants.getDungeonIndex(dungeonName)]();
}
function scan(dungeonBoard) {
/*var bossCoords = []
var playerCoords = []*/
for (var i = 0; i < dungeonBoard.length; i++) {
for (var j = 0; j < dungeonBoard[i].length; j++) {
if (dungeonBoard[i][j].type() == GameConstants.DungeonTile.boss || dungeonBoard[i][j].type() == GameConstants.DungeonTile.ladder) {
foundBoss = true
return [i, j]
}
//Required for pathfinding, if ever implemented
/*if (dungeonBoard[i][j].hasPlayer == true){
playerCoords = [i, j]
}*/
}
}
}
function wander(dungeonBoard, bossCoords) {
var moves = []
//Attempt to move to the boss if the coordinates are within movable range
DungeonRunner.map.moveToCoordinates(bossCoords[1], bossCoords[0])
if (DungeonRunner.map.currentTile().type() == GameConstants.DungeonTile.boss) {
foundBoss = false
bossCoords.length = 0
DungeonRunner.startBossFight()
}
if (DungeonRunner.map.currentTile().type() == GameConstants.DungeonTile.ladder) {
foundBoss = false
bossCoords.length = 0
DungeonRunner.nextFloor()
}
//Iterates through the board and compiles all possible moves
for (var i = 0; i < dungeonBoard.length; i++) {
for (var j = 0; j < dungeonBoard[i].length; j++) {
//The entrance doesn't count as visited on first entering a dungeon so this OR is required
if (dungeonBoard[i][j].isVisited == true || dungeonBoard[i][j].type() == GameConstants.DungeonTile.entrance) {
//This is required because if the column doesn't exist it throws an attribute of undefined error
if (dungeonBoard[i + 1] != undefined) {
if (dungeonBoard[i + 1][j] != undefined) {
if (dungeonBoard[i + 1][j].isVisited == false) moves.push([i + 1, j])
}
}
if (dungeonBoard[i - 1] != undefined) {
if (dungeonBoard[i - 1][j] != undefined) {
if (dungeonBoard[i - 1][j].isVisited == false) moves.push([i - 1, j])
}
}
if (dungeonBoard[i][j + 1] != undefined) {
if (dungeonBoard[i][j + 1].isVisited == false) moves.push([i, j + 1])
}
if (dungeonBoard[i][j - 1] != undefined) {
if (dungeonBoard[i][j - 1].isVisited == false) moves.push([i, j - 1])
}
}
}
}
//Select a random move from compiled list of possible ones
var moveTo = moves[getRandomInt(moves.length)]
//Coordinates saved in couples of [y, x] so we swap them when we want to move
DungeonRunner.map.moveToCoordinates(moveTo[1], moveTo[0])
//Reset moves array
moves.length = 0
}
function fullClear(dungeonBoard, bossCoords) {
//Get number of invisible tiles, if 0 we have the map
const invisTile = document.getElementById('dungeonMap').querySelectorAll('.tile-invisible').length;
//Chests
const getChests = document.getElementById('dungeonMap').querySelectorAll('.tile-chest').length;
//Enemies
const getEnemy = document.getElementById('dungeonMap').querySelectorAll('.tile-enemy').length;
for (var i = 0; i < dungeonBoard.length; i++) {
for (var j = 0; j < dungeonBoard[i].length; j++) {
//Basically just attempts to move to all tiles that aren't cleared
if (dungeonBoard[i][j].isVisited == false) {
DungeonRunner.map.moveToCoordinates(j, i);
}
if (DungeonRunner.map.currentTile().type() == GameConstants.DungeonTile.chest) {
DungeonRunner.openChest();
}
}
}
//If we cleared the entire floor, move to the boss room and start the fight
if (invisTile == 0 && getChests == 0 && getEnemy == 0 && foundBoss == true) {
DungeonRunner.map.moveToCoordinates(bossCoords[1], bossCoords[0]);
foundBoss = false;
bossCoords.length = 0;
if (DungeonRunner.map.currentTile().type() == GameConstants.DungeonTile.boss) {
DungeonRunner.startBossFight();
} else if (DungeonRunner.map.currentTile().type() == GameConstants.DungeonTile.ladder) {
DungeonRunner.nextFloor();
}
}
}
if (!validParse(localStorage.getItem('autoClickState'))) {
localStorage.setItem("autoClickState", false);
}
if (!validParse(localStorage.getItem('storedClickDPS'))) {
localStorage.setItem("storedClickDPS", 0);
}
if (!validParse(localStorage.getItem('autoGymState'))) {
localStorage.setItem("autoGymState", false);
}
if (!validParse(localStorage.getItem('selectedGym'))) {
localStorage.setItem("selectedGym", 0);
}
if (!validParse(localStorage.getItem('autoDungeonState'))) {
localStorage.setItem("autoDungeonState", false);
}
if (!validParse(localStorage.getItem('autoAchievementState'))) {
localStorage.setItem("autoAchievementState", false);
}
if (!validParse(localStorage.getItem('selectedAchievement'))) {
localStorage.setItem("selectedAchievement", 0);
}
if (!validParse(localStorage.getItem('selectedDungeon'))) {
localStorage.setItem("selectedDungeon", 0);
}
if (!validParse(localStorage.getItem('delayAutoClick'))) {
localStorage.setItem("delayAutoClick", 50);
}
clickState = JSON.parse(localStorage.getItem('autoClickState'));
gymState = JSON.parse(localStorage.getItem('autoGymState'));
gymSelect = JSON.parse(localStorage.getItem('selectedGym'));
try {
dungeonState = JSON.parse(localStorage.getItem('autoDungeonState'));
} catch (error) {
dungeonState = false
localStorage.setItem("autoDungeonState", false);
}
try {
achievementState = JSON.parse(localStorage.getItem('autoAchievementState'));
} catch (error) {
achievementState = false
localStorage.setItem("autoAchievementState", false);
}
dungeonSelect = JSON.parse(localStorage.getItem('selectedDungeon'));
achievementSelect = JSON.parse(localStorage.getItem('selectedAchievement'));
delayAutoClick = JSON.parse(localStorage.getItem('delayAutoClick'));
clickDPS = clickState ? JSON.parse(localStorage.getItem('storedClickDPS')) : 0;
function loadScript() {
var oldInit = Preload.hideSplashScreen
Preload.hideSplashScreen = function () {
var result = oldInit.apply(this, arguments)
initAutoClicker()
return result
}
}
var scriptName = 'enhancedautoclicker'
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 validParse(key) {
try {
if (key === null) {
throw new Error;
}
JSON.parse(key);
return true;
} catch (e) {
return false;
}
}
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);
}