forked from ivanlay/pokeclicker-automator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_everything.js
309 lines (282 loc) · 10.8 KB
/
auto_everything.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
// ==UserScript==
// @name Auto Everything - pokeclicker.com
// @namespace Violentmonkey Scripts
// @match https://www.pokeclicker.com/
// @grant none
// @version 1.0
// @author EHoftiezer
// @contributors daniellockard, george-dy, Ivan Lay
// @description Automate the grind out of pokeclicker
// ==/UserScript==
var option = {
"autoClick": true,
"autoBuffs": true,
"autoDungs": true,
"autoFarms": true,
"autoHatch": true,
"autoDigin": true,
}
function addMobilityMenu(){
var node = document.createElement('div');
node.innerHTML = `
<div id="automationContainer" class="card sortable border-secondary mb-3" draggable="false">
<div class="card-header p-0" data-toggle="collapse" href="#automationBody" aria-expanded="true">
<span style="text-align: center">Automation</span>
</div>
<div id="automationBody" class="card-body p-0 collapse show" style="">
<table class="table table-sm m-0">
<tbody>
<tr>
<td colspan="2" ><button id="toggleClick" class="btn btn-success" type="button">Auto Click Enabled</button></td>
<td colspan="2" ><button id="toggleDungs" class="btn btn-success" type="button">Auto Dungs Enabled</button></td>
<td colspan="2" ><button id="toggleGymin" class="btn btn-success" type="button">Auto Gymin Enabled</button></td>
</tr>
<tr>
<td colspan="2" ><button id="toggleBuffs" class="btn btn-success" type="button">Auto Buffs Enabled</button></td>
<td colspan="2" ><button id="toggleBuyin" class="btn btn-success" type="button">Auto Buyin Enabled</button></td>
<td colspan="2" ><button id="toggleHatch" class="btn btn-success" type="button">Auto Hatch Enabled</button></td>
</tr>
<tr>
<td colspan="2" ><button id="toggleFarms" class="btn btn-success" type="button">Auto Farms Enabled</button></td>
<td colspan="2" ><button id="toggleDigin" class="btn btn-success" type="button">Auto Digin Enabled</button></td>
<td colspan="2" ><button id="toggleQuest" class="btn btn-success" type="button">Auto Quest Enabled</button></td>
</tr>
</tbody>
</table>
</div>
</div>`
document.getElementById('battleContainer').before(node)
document.getElementById('toggleClick').addEventListener('click', toggle.bind(null,"Click"), false);
document.getElementById('toggleBuffs').addEventListener('click', toggle.bind(null,"Buffs"), false);
document.getElementById('toggleDungs').addEventListener('click', toggle.bind(null,"Dungs"), false);
document.getElementById('toggleFarms').addEventListener('click', toggle.bind(null,"Farms"), false);
document.getElementById('toggleHatch').addEventListener('click', toggle.bind(null,"Hatch"), false);
document.getElementById('toggleDigin').addEventListener('click', toggle.bind(null,"Digin"), false);
}
function toggle(feature){
var value = option['auto'+ feature]
option['auto'+ feature] = !value;
var button = document.getElementById('toggle' + feature);
if (value) {
button.classList.remove('btn-success');
button.classList.add('btn-danger');
button.innerText = 'Auto ' + feature + ' Disabled';
} else {
button.classList.remove('btn-danger');
button.classList.add('btn-success');
button.innerText = 'Auto ' + feature + ' Enabled';
}
}
function autoClick() {
var autoClickLoop = setInterval(function () {
if (option["autoClick"]){
// Click while in a normal battle
if (App.game.gameState == GameConstants.GameState.fighting) {
Battle.clickAttack();
}
// Click while in a gym battle
if (App.game.gameState === GameConstants.GameState.gym) {
GymBattle.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();
} else if (
DungeonRunner.map.currentTile().type() ===
GameConstants.DungeonTile.chest
) {
DungeonRunner.openChest();
} else if (
DungeonRunner.map.currentTile().type() ===
GameConstants.DungeonTile.boss &&
!DungeonRunner.fightingBoss()
) {
DungeonRunner.startBossFight();
}
}
// Click while in Safari battles
if (Safari.inBattle()) {
BattleFrontierBattle.clickAttack();
}
}
}, 50); // The app hard-caps click attacks at 50
}
function autoBuffs() {
const autoBuffsLoop = setInterval(() => {
if (option["autoBuffs"]) {
if (player.effectList.Item_magnet() <= 6){
ItemList.Item_magnet.use(1)
}
if (player.effectList.Lucky_egg() <= 6){
ItemList.Lucky_egg.use(1)
}
if (player.effectList.Lucky_incense() <= 6){
ItemList.Lucky_incense.use(1)
}
if (player.effectList.Token_collector() <= 6){
ItemList.Token_collector.use(1)
}
if (player.effectList.xAttack() <= 6){
ItemList.xAttack.use(1)
}
if (player.effectList.xClick() <= 6){
ItemList.xClick.use(1)
}
}
},50);
}
function autoDungs() {
var autoDungsLoop = setInterval(function () {
if (option["autoDungs"]){
if (App.game.gameState == GameConstants.GameState.town) {
DungeonRunner.initializeDungeon(player.town().dungeon)
}
if (App.game.gameState === GameConstants.GameState.dungeon) {
DungeonRunner.map.showAllTiles()
var allTiles = DungeonRunner.map.board()
var bossX = 0
var currentX = 0
var bossY = 0
var currentY = 0
allTiles.forEach(yTiles => {
yTiles.forEach(xTiles => {
if (xTiles.cssClass().includes("tile-boss")){
bossX = currentX
bossY = currentY
}
currentX = currentX + 1
});
currentY = currentY + 1
currentX = 0
});
// console.log("Boss found in coordinates (" + bossX + "," + bossY + ")")
var playerPosX = DungeonRunner.map.playerPosition().x
var playerPosY = DungeonRunner.map.playerPosition().y
if (playerPosX < bossX){
playerPosX = playerPosX + 1
}
if (playerPosX > bossX){
playerPosX = playerPosX - 1
}
DungeonRunner.map.moveToCoordinates(playerPosX,playerPosY)
if (playerPosY < bossY){
playerPosY = playerPosY + 1
}
if (playerPosY > bossY){
playerPosY = playerPosY - 1
}
DungeonRunner.map.moveToCoordinates(playerPosX,playerPosY)
}
}
}, 50); // The app hard-caps click attacks at 50
}
function autoFarms() {
const autoFarmsLoop = setInterval(() => {
if (option["autoFarms"]) {
// var bestBerry = App.game.farming.highestUnlockedBerry()
App.game.farming.harvestAll()
App.game.farming.plantAll(1)
}
},50);
}
function autoDigin() {
var autoDiginLoop = setInterval(function () {
if (option["autoFarms"]) {
while (
App.game.underground.getMaxEnergy() -
Math.floor(App.game.underground.energy) <=
App.game.underground.getEnergyGain() *
App.game.oakItems.calculateBonus(OakItems.OakItem.Cell_Battery)
) {
Mine.bomb();
//console.log("Mined!");
}
}
}, 10000); // Every 10 seconds
}
function autoHatch() {
const autoHatchLoop = setInterval(() => {
if (option["autoHatch"]) {
// Attempt to hatch each egg. If the egg is at 100% it will succeed
[0, 1, 2, 3].forEach((index) => App.game.breeding.hatchPokemonEgg(index));
// Now add eggs to empty slots if we can
while (App.game.breeding.canBreedPokemon() && App.game.breeding.hasFreeEggSlot()) {
// Filter the sorted list of Pokemon based on the parameters set in the Hatchery screen
// const filteredEggList = App.game.party.caughtPokemon.filter((partyPokemon) => {
// Using the below instead of the above since it seems to be the "best" list, and
const filteredEggList = PartyController.getSortedList().filter((partyPokemon) => {
// Only level 100 Pokemon
if (partyPokemon.breeding || partyPokemon.level < 100) {return false;}
// Check based on category
if (BreedingController.filter.category() >= 0) {
if (
partyPokemon.category !== BreedingController.filter.category()
) {
return false;
}
}
// Check based on shiny status
if (BreedingController.filter.shinyStatus() >= 0) {
if (
+partyPokemon.shiny !== BreedingController.filter.shinyStatus()
) {
return false;
}
}
// Check based on native region
if (BreedingController.filter.region() > -2) {
if (
PokemonHelper.calcNativeRegion(partyPokemon.name)
!== BreedingController.filter.region()
) {
return false;
}
}
// Check if either of the types match
const type1 = BreedingController.filter.type1() > -2
? BreedingController.filter.type1()
: null;
const type2 = BreedingController.filter.type2() > -2
? BreedingController.filter.type2()
: null;
if (type1 !== null || type2 !== null) {
const { type: types } = pokemonMap[partyPokemon.name];
if ([type1, type2].includes(PokemonType.None)) {
const type = type1 == PokemonType.None ? type2 : type1;
if (!BreedingController.isPureType(partyPokemon, type)) {
return false;
}
} else if (
(type1 !== null && !types.includes(type1))
|| (type2 !== null && !types.includes(type2))
) {
return false;
}
}
return true;
},);
if (App.game.breeding.canBreedPokemon() && App.game.breeding.hasFreeEggSlot()) {
App.game.breeding.addPokemonToHatchery(filteredEggList[0]);
console.log(`Added ${filteredEggList[0].name} to the Hatchery!`);
}
}
}
}, 50);
}
function waitForLoad(){
var timer = setInterval(function() {
if (!document.getElementById("game").classList.contains("loading")) {
// Check if the game window has loaded
clearInterval(timer);
addMobilityMenu();
autoClick();
autoBuffs();
autoDungs();
autoFarms();
autoDigin();
autoHatch();
}
}, 200);
}
waitForLoad();