// ==UserScript==
// @name [Pokeclicker] Enhanced Auto Clicker
// @namespace Pokeclicker Scripts
// @match https://www.pokeclicker.com/
// @grant none
// @version 1.6
// @author Ephenia (Original/Credit: Ivan Lay, Novie53)
// @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.
// @downloadURL none
// ==/UserScript==
var clickState;
var clickColor;
var awaitAutoClick;
var autoClickerLoop;
var autoClickDPS;
var clickDPS;
var reqDPS;
var enemySpeedRaw;
var enemySpeed;
var colorDPS;
var allSelectedGym = 0;
var gymState;
var gymColor;
var gymSelect;
var dungeonState;
var dungeonColor;
var dungeonSelect;
var foundBoss = false;
var foundBossX;
var foundBossY;
var newSave;
var trainerCards;
var battleView = document.getElementsByClassName('battle-view')[0];
function initAutoClicker() {
if (clickState == "OFF") {
clickColor = "danger"
clickDPS = 0
} else {
clickColor = "success"
clickDPS = +localStorage.getItem('storedClickDPS');
}
if (gymState == "OFF") {
gymColor = "danger"
} else {
gymColor = "success"
}
if (dungeonState == "OFF") {
dungeonColor = "danger"
} else {
dungeonColor = "success"
}
var elemAC = document.createElement("table");
elemAC.innerHTML = `
`
}
}, 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 == "ON") {
autoGym();
}
//Auto Dungeon checking
if (dungeonState == "ON" && DungeonRunner.fighting() == false && DungeonBattle.catching() == false) {
autoDungeon();
}
//Reset the values for the boss coordinates if we timeout or turn off autoDungeon
if ((dungeonState == "OFF" && foundBoss) || (dungeonState == "ON" && DungeonRunner.dungeonFinished() && foundBoss)){
foundBoss = false
bossCoords.length = 0
}
// 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();
}
}
}, 50); // The app hard-caps click attacks at 50
}
function autoGym() {
if (player.town().content.length != 0) {
//Might break in some towns, needs more testing
if (player.town().content[0] instanceof Gym) {
if (MapHelper.calculateTownCssClass(player.town().name) != "currentLocation") {
MapHelper.moveToTown(player.town().name)
}
/*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) {
//If "All" is selected, then go through list of league from 0-4
if (gymSelect === 5 &&
(player.town().content[gymSelect] instanceof Gym && player.town().content[gymSelect].isUnlocked()) ||
(player.town().content[gymSelect] instanceof Champion && player.town().content[gymSelect].isUnlocked())) {
GymRunner.startGym(player.town().content[allSelectedGym])
allSelectedGym++
if(allSelectedGym === 5) {
allSelectedGym = 0
}
} else {
//If the content is a Gym or league champion and we unlocked it we fight
if ((player.town().content[gymSelect] instanceof Gym && player.town().content[gymSelect].isUnlocked()) || (player.town().content[gymSelect] instanceof Champion && player.town().content[gymSelect].isUnlocked())){
GymRunner.startGym(player.town().content[gymSelect])
}
else {
//Otherwise we try to fight the previous gyms (elite 4)
for (var i = player.town().content.length - 1; i >= 0; i--){
if ((player.town().content[i] instanceof Gym && player.town().content[i].isUnlocked()) || (player.town().content[i] instanceof Champion && player.town().content[i].isUnlocked())){
GymRunner.startGym(player.town().content[i])
break
}
}
}
}
}
}
}
}
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;
if (MapHelper.calculateTownCssClass(player.town().name) != "currentLocation") {
MapHelper.moveToTown(player.town().name)
}
//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();
//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 scan(dungeonBoard){
/*var bossCoords = []
var playerCoords = []*/
for (var i = 0; i < dungeonBoard.length; i++){
for (var j = 0; j