From 7005c9d95b67241312353c83cc8546a2b7fc0b17 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Wed, 1 Jun 2022 01:45:09 +0200 Subject: [PATCH 01/17] Auto quest location --- custom/autoquestcompleter.js | 264 ++++++++++++++++++++++++++++++++++- 1 file changed, 261 insertions(+), 3 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 10b9fea1..53382ed4 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -3,11 +3,30 @@ // @namespace Pokeclicker Scripts // @match https://www.pokeclicker.com/ // @grant none -// @version 1.1 -// @author KarmaAlex (Credit: Ephenia) +// @version 1.2 +// @author KarmaAlex (Credit: Ephenia, Sorrow) // @description Removes the limit for the number of quests you can do at once and auto completes/starts new ones. // ==/UserScript== +let questTypes = []; +let autoQuestCanBeStopped; +let questLocationInProgress = false; +let completeQuestLocationLoop; +let regionSelect; +let subRegionSelect; +let routeSelect; +let townSelect; +let dungeonStateSelect; +let gymStateSelect; +let dungeonQuestEnable; +let gymStart; +let dungeonStart; + +//On Alola map subregion not available on Town, Route or Dungeon +const alola_subregion_0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Hau'oli City Extension", "Melemele Woods", "Melemele Woods Extension", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"] +const alola_subregion_1 = ["Route 4", "Route 4 Extension", "Route 5", "Route 5 Extension", "Route 6", "Route 6 Extension", "Route 7", "Route 7 Extension", "Route 8", "Route 8 Extension", "Route 9", "Route 9 Extension", "Akala Outskirts", "Akala Outskirts Extension--", "Heahea City", "Heahea City Extension", "Paniola Town", "Royal Avenue", "Royal Avenue Extension", "Konikoni City", "Konikoni City Extension", "Aether Paradise", "Roadside Motel", "Roadside Motel Extension", "Pikachu Valley", "Pikachu Valley Extension", "Paniola Ranch", "Brooklet Hill", "Brooklet Hill Extension", "Wela Volcano Park", "Wela Volcano Park Extension", "Lush Jungle", "Lush Jungle Extension", "Diglett's Tunnel", "Diglett's Tunnel Extension", "Memorial Hill", "Memorial Hill Extension", "Aether Foundation", "Aether Foundation Extension", "Ruins of Life"] +const alola_subregion_2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 11 Extension", "Route 12", "Route 12 Extension", "Route 13", "Haina Desert", "Route 14", "Route 14 Extension", "Route 15", "Route 15 Extension", "Route 16", "Route 17", "Route 17 Extension", "Poni Wilds", "Poni Wilds Extension", "Ancient Poni Path", "Ancient Poni Path Extension", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Poni Gauntlet Extension", "Aether Paradise", "Malie City", "Malie City Extension", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Pokémon League Alola Extension", "Vast Poni Canyon Extension", "Lake of the Sunne and Moone"] + function initAutoQuests(){ //Allows to start infinite quests App.game.quests.canStartNewQuest = function(){ @@ -18,7 +37,6 @@ function initAutoQuests(){ localStorage.setItem('autoQuestEnable', 'true') } //Define quest types - let questTypes = []; if (localStorage.getItem('autoQuestTypes') == null){ for (const type in QuestHelper.quests) { questTypes.push(type); @@ -26,6 +44,7 @@ function initAutoQuests(){ localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)) } else { questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); + dungeonQuestEnable = questTypes.includes("DefeatDungeonQuest"); } resetQuestModify(); //Track the last refresh @@ -50,20 +69,38 @@ function initAutoQuests(){ document.getElementById('toggle-auto-quest').textContent = 'Auto [ON]' } }, false) + //Retrieving autoclicker buttons + gymStart = document.getElementById("auto-gym-start"); + dungeonStart = document.getElementById("auto-dungeon-start"); //Checks for new quests to add to the list and claims completed ones var autoQuest = setInterval(function(){ let questsNeed = 0; if (trackRefresh != App.game.quests.lastRefresh) { trackRefresh = App.game.quests.lastRefresh; + stopCompleteQuestLocation(); + //Reload quest types from local storage to re-enter the dungeon if they are deleted because there are not enough dungeon tokens left. + questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); resetQuestModify(); } if (localStorage.getItem('autoQuestEnable') == 'true'){ + autoQuestCanBeStopped = true; if (App.game.quests.currentQuests().length > 0){ //Claim all completed quest & check if quests should refresh App.game.quests.currentQuests().forEach(quest => { if (quest.notified == true){ App.game.quests.claimQuest(quest.index) + } else { + //Processes quests with location + if(!questLocationInProgress) { + if(quest instanceof DefeatGymQuest) { + completeDefeatGymQuest(quest) + } else if(quest instanceof DefeatPokemonsQuest) { + completeDefeatPokemonQuest(quest) + } else if(quest instanceof DefeatDungeonQuest) { + completeDefeatDungeonQuest(quest) + } + } } if (questTypes.includes(quest.constructor.name)) { questsNeed++; @@ -83,6 +120,9 @@ function initAutoQuests(){ App.game.quests.beginQuest(quest.index); } }) + } else if (autoQuestCanBeStopped) { + autoQuestCanBeStopped = false; + stopCompleteQuestLocation(); } }, 500) @@ -107,6 +147,25 @@ function initAutoQuests(){ } localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); } + + function stopCompleteQuestLocation() { + if(questLocationInProgress) { + //Reset loop when quest is refreshed or auto quest is disabled + if(typeof completeQuestLocationLoop !== 'undefined') { + clearInterval(completeQuestLocationLoop); + completeQuestLocationLoop = null; + } + stopAutoDungeon(); + stopAutoGym(); + let resetPlayerStateLoop = setInterval(function() { + if(playerCanMove()) { + playerResetState(); + clearInterval(resetPlayerStateLoop); + } + }, 50); + questLocationInProgress = false; + } + } } function loadScript(){ @@ -138,3 +197,202 @@ if (document.getElementById('scriptHandler') != undefined){ else{ loadScript(); } + +function startQuest() { + playerSaveState(); + stopAutoDungeonAndGym(); +} + +function endQuest() { + //Executed when the quest is completed + questLocationInProgress = false; + clearInterval(completeQuestLocationLoop); + completeQuestLocationLoop = null; + stopAutoDungeon(); + stopAutoGym(); + playerResetState(); +} + +function completeDefeatDungeonQuest(dungeonQuest) { + //Can't farm the dungeons without the autoclicker + if(!dungeonStart) return; + + //Remove dungeon quest for current cycle if total token needed not available + const questName = "DefeatDungeonQuest" + const indexPos = questTypes.indexOf(questName); + if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { + if(indexPos !== -1) { + questTypes[indexPos] = null; + } + endQuest(); + return; + } + + playerSaveState(); + //Move player to quest dungeon + if (playerCanMove()) { + playerMoveToTown(dungeonQuest.dungeon, dungeonQuest.region); + } + + if(player.town().name === dungeonQuest.dungeon) { + stopAutoGym(); + questLocationInProgress = true; + completeQuestLocationLoop = setInterval(function() { + if(!dungeonQuest.notified) { + if(dungeonStart && !dungeonStart.classList.contains("btn-success")) { + dungeonStart.click(); + } + } else if(playerCanMove()) { + endQuest(); + } + }, 50); + } +} + +function completeDefeatGymQuest(gymQuest) { + playerSaveState(); + //Find town associate to gym + const gymListAsArray = Object.entries(GymList); + const town = gymListAsArray.filter(([key, value]) => key === gymQuest.gymTown)[0][1]; + + //Move player to quest town + if (playerCanMove()) { + playerMoveToTown(town.parent.name, town.parent.region); + } + + if(player.town().name === town.parent.name) { + stopAutoDungeon(); + stopAutoGym(); + //Find gym in town + for(const gym of player.town().content) { + if(gym.town === gymQuest.gymTown) { + questLocationInProgress = true; + completeQuestLocationLoop = setInterval(function() { + if(!gymQuest.notified) { + if(App.game.gameState !== GameConstants.GameState.gym) { + gym.protectedOnclick(); + } + } else if(playerCanMove()) { + endQuest(); + } + }, 50); + } + } + } +} + +function completeDefeatPokemonQuest(pokemonQuest) { + playerSaveState(); + //Move player to quest route + if (playerCanMove()) { + playerMoveToRoute(pokemonQuest.route, pokemonQuest.region); + } + + if(player.route() === pokemonQuest.route && player.region === pokemonQuest.region) { + stopAutoDungeon(); + stopAutoGym(); + questLocationInProgress = true; + completeQuestLocationLoop = setInterval(function() { + if(pokemonQuest.notified) { + endQuest(); + } + }, 50); + } +} + +function playerSaveState() { + //Save last location of player in temp variable + regionSelect = player.region; + subRegionSelect = player.subregion; + routeSelect = player.route(); + townSelect = player.town().name; + + if(dungeonStart && dungeonStart.classList.contains("btn-danger")) { + dungeonStateSelect = false; + } else if(dungeonStart && dungeonStart.classList.contains("btn-success")) { + dungeonStateSelect = true; + } + if(gymStart && gymStart.classList.contains("btn-danger")) { + gymStateSelect = false; + } else if(gymStart && gymStart.classList.contains("btn-success")) { + gymStateSelect = true; + } +} + +function playerResetState() { + if(regionSelect && player.region !== regionSelect) { + player.region = regionSelect; + } + if(subRegionSelect && player.subregion !== subRegionSelect) { + player.subregion = subRegionSelect; + } + if(routeSelect && player.route() !== routeSelect) { + MapHelper.moveToRoute(routeSelect, regionSelect); + } + if(townSelect && routeSelect === 0) { + MapHelper.moveToTown(townSelect); + } + if (dungeonStart) { + if(dungeonStateSelect && !dungeonStart.classList.contains("btn-success")) { + dungeonStart.click(); + } else if(!dungeonStateSelect && !dungeonStart.classList.contains("btn-danger")) { + dungeonStart.click(); + } + } + if (gymStart) { + if(gymStateSelect && !gymStart.classList.contains("btn-success")) { + gymStart.click(); + } else if(!gymStateSelect && !gymStart.classList.contains("btn-danger")) { + gymStart.click(); + } + } +} + +function playerCanMove() { + return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() && !DungeonBattle.catching() && !GymRunner.running() +} + +function playerMoveToTown(town, region) { + if(player.region !== region || player.town().name !== town) { + player.region = region; + if(region === 6) { + setAlolaSubRegion(town) + } else { + player.subregion = 0 + } + MapHelper.moveToTown(town); + } +} + +function playerMoveToRoute(route, region) { + if(player.region !== region || player.route() !== route) { + player.region = region; + if(region === 6) { + setAlolaSubRegion(route) + } else { + player.subregion = 0 + } + MapHelper.moveToRoute(route, region); + } +} + +function playerCanPayDungeonEntrance(dungeonName, progressText) { + const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon + let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); + let dungeonCost = dungeon.tokenCost; + let progress = progressText.split('/').map(element => parseInt(element.trim())); + let amountRemaining = progress[1] - progress[0]; + return getTokens >= dungeonCost * amountRemaining; +} + +function stopAutoDungeon() { + if(dungeonStart && !dungeonStart.classList.contains("btn-danger")) { + dungeonStart.click(); + } +} + +function stopAutoGym() { + if(gymStart && !gymStart.classList.contains("btn-danger")) { + gymStart.click(); + } +} From 0500ceba58a4c92fc709620486fb93d94b144461 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Wed, 1 Jun 2022 01:54:07 +0200 Subject: [PATCH 02/17] Remove unused function --- custom/autoquestcompleter.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 53382ed4..0e58bf78 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -198,11 +198,6 @@ else{ loadScript(); } -function startQuest() { - playerSaveState(); - stopAutoDungeonAndGym(); -} - function endQuest() { //Executed when the quest is completed questLocationInProgress = false; From a19bcb6280cb95fb3ff6be054af8bf5bd23ac4a5 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Wed, 1 Jun 2022 09:23:16 +0200 Subject: [PATCH 03/17] Add function to set Alola subregion --- custom/autoquestcompleter.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 0e58bf78..3b7dc039 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -22,11 +22,6 @@ let dungeonQuestEnable; let gymStart; let dungeonStart; -//On Alola map subregion not available on Town, Route or Dungeon -const alola_subregion_0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Hau'oli City Extension", "Melemele Woods", "Melemele Woods Extension", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"] -const alola_subregion_1 = ["Route 4", "Route 4 Extension", "Route 5", "Route 5 Extension", "Route 6", "Route 6 Extension", "Route 7", "Route 7 Extension", "Route 8", "Route 8 Extension", "Route 9", "Route 9 Extension", "Akala Outskirts", "Akala Outskirts Extension--", "Heahea City", "Heahea City Extension", "Paniola Town", "Royal Avenue", "Royal Avenue Extension", "Konikoni City", "Konikoni City Extension", "Aether Paradise", "Roadside Motel", "Roadside Motel Extension", "Pikachu Valley", "Pikachu Valley Extension", "Paniola Ranch", "Brooklet Hill", "Brooklet Hill Extension", "Wela Volcano Park", "Wela Volcano Park Extension", "Lush Jungle", "Lush Jungle Extension", "Diglett's Tunnel", "Diglett's Tunnel Extension", "Memorial Hill", "Memorial Hill Extension", "Aether Foundation", "Aether Foundation Extension", "Ruins of Life"] -const alola_subregion_2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 11 Extension", "Route 12", "Route 12 Extension", "Route 13", "Haina Desert", "Route 14", "Route 14 Extension", "Route 15", "Route 15 Extension", "Route 16", "Route 17", "Route 17 Extension", "Poni Wilds", "Poni Wilds Extension", "Ancient Poni Path", "Ancient Poni Path Extension", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Poni Gauntlet Extension", "Aether Paradise", "Malie City", "Malie City Extension", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Pokémon League Alola Extension", "Vast Poni Canyon Extension", "Lake of the Sunne and Moone"] - function initAutoQuests(){ //Allows to start infinite quests App.game.quests.canStartNewQuest = function(){ @@ -391,3 +386,18 @@ function stopAutoGym() { gymStart.click(); } } + +function setAlolaSubRegion(locationName) { + //On Alola map subregion not available on Town, Route or Dungeon + const alola_subregion_0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Hau'oli City Extension", "Melemele Woods", "Melemele Woods Extension", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"] + const alola_subregion_1 = ["Route 4", "Route 4 Extension", "Route 5", "Route 5 Extension", "Route 6", "Route 6 Extension", "Route 7", "Route 7 Extension", "Route 8", "Route 8 Extension", "Route 9", "Route 9 Extension", "Akala Outskirts", "Akala Outskirts Extension--", "Heahea City", "Heahea City Extension", "Paniola Town", "Royal Avenue", "Royal Avenue Extension", "Konikoni City", "Konikoni City Extension", "Aether Paradise", "Roadside Motel", "Roadside Motel Extension", "Pikachu Valley", "Pikachu Valley Extension", "Paniola Ranch", "Brooklet Hill", "Brooklet Hill Extension", "Wela Volcano Park", "Wela Volcano Park Extension", "Lush Jungle", "Lush Jungle Extension", "Diglett's Tunnel", "Diglett's Tunnel Extension", "Memorial Hill", "Memorial Hill Extension", "Aether Foundation", "Aether Foundation Extension", "Ruins of Life"] + const alola_subregion_2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 11 Extension", "Route 12", "Route 12 Extension", "Route 13", "Haina Desert", "Route 14", "Route 14 Extension", "Route 15", "Route 15 Extension", "Route 16", "Route 17", "Route 17 Extension", "Poni Wilds", "Poni Wilds Extension", "Ancient Poni Path", "Ancient Poni Path Extension", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Poni Gauntlet Extension", "Aether Paradise", "Malie City", "Malie City Extension", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Pokémon League Alola Extension", "Vast Poni Canyon Extension", "Lake of the Sunne and Moone"] + + if(alola_subregion_0.includes(locationName)) { + player.subregion = 0 + } else if(alola_subregion_1.includes(locationName)) { + player.subregion = 1 + } else if(alola_subregion_2.includes(locationName)) { + player.subregion = 2 + } +} \ No newline at end of file From 82bd9d8460d20967964d25f655ec55f27b5bbedf Mon Sep 17 00:00:00 2001 From: Sorrow Date: Wed, 1 Jun 2022 13:49:09 +0200 Subject: [PATCH 04/17] Remove unused location --- custom/autoquestcompleter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 3b7dc039..ec5684ec 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -389,9 +389,9 @@ function stopAutoGym() { function setAlolaSubRegion(locationName) { //On Alola map subregion not available on Town, Route or Dungeon - const alola_subregion_0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Hau'oli City Extension", "Melemele Woods", "Melemele Woods Extension", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"] - const alola_subregion_1 = ["Route 4", "Route 4 Extension", "Route 5", "Route 5 Extension", "Route 6", "Route 6 Extension", "Route 7", "Route 7 Extension", "Route 8", "Route 8 Extension", "Route 9", "Route 9 Extension", "Akala Outskirts", "Akala Outskirts Extension--", "Heahea City", "Heahea City Extension", "Paniola Town", "Royal Avenue", "Royal Avenue Extension", "Konikoni City", "Konikoni City Extension", "Aether Paradise", "Roadside Motel", "Roadside Motel Extension", "Pikachu Valley", "Pikachu Valley Extension", "Paniola Ranch", "Brooklet Hill", "Brooklet Hill Extension", "Wela Volcano Park", "Wela Volcano Park Extension", "Lush Jungle", "Lush Jungle Extension", "Diglett's Tunnel", "Diglett's Tunnel Extension", "Memorial Hill", "Memorial Hill Extension", "Aether Foundation", "Aether Foundation Extension", "Ruins of Life"] - const alola_subregion_2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 11 Extension", "Route 12", "Route 12 Extension", "Route 13", "Haina Desert", "Route 14", "Route 14 Extension", "Route 15", "Route 15 Extension", "Route 16", "Route 17", "Route 17 Extension", "Poni Wilds", "Poni Wilds Extension", "Ancient Poni Path", "Ancient Poni Path Extension", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Poni Gauntlet Extension", "Aether Paradise", "Malie City", "Malie City Extension", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Pokémon League Alola Extension", "Vast Poni Canyon Extension", "Lake of the Sunne and Moone"] + const alola_subregion_0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Hau'oli City Extension", "Melemele Woods", "Melemele Woods Extension", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"]; + const alola_subregion_1 = ["Route 4", "Route 5", "Route 6", "Route 7", "Route 8", "Route 9", "Akala Outskirts", "Heahea City", "Paniola Town", "Royal Avenue", "Konikoni City", "Aether Paradise", "Roadside Motel", "Pikachu Valley", "Paniola Ranch", "Brooklet Hill", "Wela Volcano Park", "Lush Jungle", "Diglett's Tunnel", "Memorial Hill", "Aether Foundation", "Ruins of Life"]; + const alola_subregion_2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 12", "Route 13", "Haina Desert", "Route 14", "Route 15", "Route 16", "Route 17", "Poni Wilds", "Ancient Poni Path", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Aether Paradise", "Malie City", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Vast Poni Canyon", "Lake of the Sunne and Moone"]; if(alola_subregion_0.includes(locationName)) { player.subregion = 0 From 88fc34b463692fb08da64232331c0ce3aef147bf Mon Sep 17 00:00:00 2001 From: Sorrow Date: Wed, 1 Jun 2022 18:48:41 +0200 Subject: [PATCH 05/17] Improved enabling and disabling of autodungeon and autogym --- custom/autoquestcompleter.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index ec5684ec..497be582 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -10,6 +10,7 @@ let questTypes = []; let autoQuestCanBeStopped; +let questLocationReadyToStart = false; let questLocationInProgress = false; let completeQuestLocationLoop; let regionSelect; @@ -158,6 +159,7 @@ function initAutoQuests(){ clearInterval(resetPlayerStateLoop); } }, 50); + questLocationReadyToStart = false; questLocationInProgress = false; } } @@ -195,6 +197,7 @@ else{ function endQuest() { //Executed when the quest is completed + questLocationReadyToStart = false; questLocationInProgress = false; clearInterval(completeQuestLocationLoop); completeQuestLocationLoop = null; @@ -208,8 +211,7 @@ function completeDefeatDungeonQuest(dungeonQuest) { if(!dungeonStart) return; //Remove dungeon quest for current cycle if total token needed not available - const questName = "DefeatDungeonQuest" - const indexPos = questTypes.indexOf(questName); + const indexPos = questTypes.indexOf("DefeatDungeonQuest"); if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { if(indexPos !== -1) { questTypes[indexPos] = null; @@ -218,14 +220,18 @@ function completeDefeatDungeonQuest(dungeonQuest) { return; } - playerSaveState(); + if(!questLocationReadyToStart) { + playerSaveState(); + stopAutoGym(); + questLocationReadyToStart = true; + } + //Move player to quest dungeon if (playerCanMove()) { playerMoveToTown(dungeonQuest.dungeon, dungeonQuest.region); } if(player.town().name === dungeonQuest.dungeon) { - stopAutoGym(); questLocationInProgress = true; completeQuestLocationLoop = setInterval(function() { if(!dungeonQuest.notified) { @@ -240,19 +246,22 @@ function completeDefeatDungeonQuest(dungeonQuest) { } function completeDefeatGymQuest(gymQuest) { - playerSaveState(); //Find town associate to gym const gymListAsArray = Object.entries(GymList); const town = gymListAsArray.filter(([key, value]) => key === gymQuest.gymTown)[0][1]; + if(!questLocationReadyToStart) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + questLocationReadyToStart = true; + } //Move player to quest town if (playerCanMove()) { playerMoveToTown(town.parent.name, town.parent.region); } if(player.town().name === town.parent.name) { - stopAutoDungeon(); - stopAutoGym(); //Find gym in town for(const gym of player.town().content) { if(gym.town === gymQuest.gymTown) { @@ -272,15 +281,19 @@ function completeDefeatGymQuest(gymQuest) { } function completeDefeatPokemonQuest(pokemonQuest) { - playerSaveState(); + if(!questLocationReadyToStart) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + questLocationReadyToStart = true; + } + //Move player to quest route if (playerCanMove()) { playerMoveToRoute(pokemonQuest.route, pokemonQuest.region); } if(player.route() === pokemonQuest.route && player.region === pokemonQuest.region) { - stopAutoDungeon(); - stopAutoGym(); questLocationInProgress = true; completeQuestLocationLoop = setInterval(function() { if(pokemonQuest.notified) { From 15ecdf265e3fc337bf41c7cde95898e8ae350a1e Mon Sep 17 00:00:00 2001 From: Sorrow Date: Thu, 2 Jun 2022 22:30:30 +0200 Subject: [PATCH 06/17] Clean location --- custom/autoquestcompleter.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 497be582..93ef75ce 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -401,16 +401,18 @@ function stopAutoGym() { } function setAlolaSubRegion(locationName) { + //TODO: Find a solution to retrieve locations by sub-region in a programmatic way //On Alola map subregion not available on Town, Route or Dungeon - const alola_subregion_0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Hau'oli City Extension", "Melemele Woods", "Melemele Woods Extension", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"]; - const alola_subregion_1 = ["Route 4", "Route 5", "Route 6", "Route 7", "Route 8", "Route 9", "Akala Outskirts", "Heahea City", "Paniola Town", "Royal Avenue", "Konikoni City", "Aether Paradise", "Roadside Motel", "Pikachu Valley", "Paniola Ranch", "Brooklet Hill", "Wela Volcano Park", "Lush Jungle", "Diglett's Tunnel", "Memorial Hill", "Aether Foundation", "Ruins of Life"]; - const alola_subregion_2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 12", "Route 13", "Haina Desert", "Route 14", "Route 15", "Route 16", "Route 17", "Poni Wilds", "Ancient Poni Path", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Aether Paradise", "Malie City", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Vast Poni Canyon", "Lake of the Sunne and Moone"]; + //Location found from https://github.com/pokeclicker/pokeclicker/blob/ff8b53478cf714c61de8b33d73cd1275ce785688/src/components/AlolaSVG.html + const alolaSubregion0 = ["Route 1", "Route 1 Hau'oli Outskirts", "Route 2", "Route 3", "Melemele Sea", "Kala'e Bay", "Iki Town Outskirts", "Iki Town", "Professor Kukui\'s Lab", "Hau'oli City", "Melemele Woods", "Roadside Motel", "Trainers School", "Hau'oli Cemetery", "Seaward Cave", "Ten Carat Hill"]; + const alolaSubregion1 = ["Route 4", "Route 5", "Route 6", "Route 7", "Route 8", "Route 9", "Akala Outskirts", "Heahea City", "Paniola Town", "Royal Avenue", "Konikoni City", "Aether Paradise", "Roadside Motel", "Pikachu Valley", "Paniola Ranch", "Brooklet Hill", "Wela Volcano Park", "Lush Jungle", "Diglett's Tunnel", "Memorial Hill", "Aether Foundation", "Ruins of Life"]; + const alolaSubregion2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 12", "Route 13", "Haina Desert", "Route 14", "Route 15", "Route 16", "Route 17", "Poni Wilds", "Ancient Poni Path", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Aether Paradise", "Malie City", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Vast Poni Canyon", "Lake of the Sunne and Moone"]; - if(alola_subregion_0.includes(locationName)) { + if(alolaSubregion0.includes(locationName)) { player.subregion = 0 - } else if(alola_subregion_1.includes(locationName)) { + } else if(alolaSubregion1.includes(locationName)) { player.subregion = 1 - } else if(alola_subregion_2.includes(locationName)) { + } else if(alolaSubregion2.includes(locationName)) { player.subregion = 2 } } \ No newline at end of file From 6f873a057becadb861d002e267a61ad0e144f344 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Fri, 3 Jun 2022 02:26:55 +0200 Subject: [PATCH 07/17] Add CatchShiniesQuest, CapturePokemonTypesQuest and UsePokeballQuest --- custom/autoquestcompleter.js | 148 +++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 7 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 93ef75ce..525dcc89 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -12,13 +12,18 @@ let questTypes = []; let autoQuestCanBeStopped; let questLocationReadyToStart = false; let questLocationInProgress = false; +let questPokeballReadyToStart = false; +let questPokeballInProgress = false; let completeQuestLocationLoop; +let completeQuestPokeballLoop; +let forceCapture = false; let regionSelect; let subRegionSelect; let routeSelect; let townSelect; let dungeonStateSelect; let gymStateSelect; +let pokeballAlreadyCaughtSelect; let dungeonQuestEnable; let gymStart; let dungeonStart; @@ -82,9 +87,9 @@ function initAutoQuests(){ if (localStorage.getItem('autoQuestEnable') == 'true'){ autoQuestCanBeStopped = true; if (App.game.quests.currentQuests().length > 0){ - //Claim all completed quest & check if quests should refresh App.game.quests.currentQuests().forEach(quest => { if (quest.notified == true){ + //Claim all completed quest App.game.quests.claimQuest(quest.index) } else { //Processes quests with location @@ -97,7 +102,23 @@ function initAutoQuests(){ completeDefeatDungeonQuest(quest) } } + if (!questPokeballInProgress) { + if (quest instanceof UsePokeballQuest) { + completeUsePokeballQuest(quest) + } + } + } + //Complete quest when you use pokeball to capture pokemon like shiny and type + if (App.game.gameState === GameConstants.GameState.fighting) { + changePokeballForQuest(quest) + } + + //TODO: For "CapturePokemonsQuest" and "CapturePokemonTypesQuest" + //If autohatchery exist start and sort pokemon + //Else use changePokeballForQuest() for "CapturePokemonsQuest" + + //Check if quests should refresh if (questTypes.includes(quest.constructor.name)) { questsNeed++; } @@ -118,6 +139,7 @@ function initAutoQuests(){ }) } else if (autoQuestCanBeStopped) { autoQuestCanBeStopped = false; + endPokeballQuest(); stopCompleteQuestLocation(); } }, 500) @@ -159,9 +181,9 @@ function initAutoQuests(){ clearInterval(resetPlayerStateLoop); } }, 50); - questLocationReadyToStart = false; questLocationInProgress = false; } + questLocationReadyToStart = false; } } @@ -195,7 +217,7 @@ else{ loadScript(); } -function endQuest() { +function endLocationQuest() { //Executed when the quest is completed questLocationReadyToStart = false; questLocationInProgress = false; @@ -206,6 +228,23 @@ function endQuest() { playerResetState(); } +function endPokeballQuest() { + //Executed when the quest is completed + questPokeballInProgress = false; + clearInterval(completeQuestPokeballLoop); + completeQuestPokeballLoop = null; + if (questPokeballReadyToStart) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); + questPokeballReadyToStart = false; + } +} + +function endShiniesQuest() { + if (pokeballAlreadyCaughtSelect) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); + } +} + function completeDefeatDungeonQuest(dungeonQuest) { //Can't farm the dungeons without the autoclicker if(!dungeonStart) return; @@ -216,7 +255,7 @@ function completeDefeatDungeonQuest(dungeonQuest) { if(indexPos !== -1) { questTypes[indexPos] = null; } - endQuest(); + endLocationQuest(); return; } @@ -239,7 +278,7 @@ function completeDefeatDungeonQuest(dungeonQuest) { dungeonStart.click(); } } else if(playerCanMove()) { - endQuest(); + endLocationQuest(); } }, 50); } @@ -272,7 +311,7 @@ function completeDefeatGymQuest(gymQuest) { gym.protectedOnclick(); } } else if(playerCanMove()) { - endQuest(); + endLocationQuest(); } }, 50); } @@ -297,12 +336,85 @@ function completeDefeatPokemonQuest(pokemonQuest) { questLocationInProgress = true; completeQuestLocationLoop = setInterval(function() { if(pokemonQuest.notified) { - endQuest(); + endLocationQuest(); } }, 50); } } +function completeUsePokeballQuest(pokeballQuest) { + if (!questPokeballInProgress) { + //Remove use pokeball quest for current cycle if total pokeball needed not available + const indexPos = questTypes.indexOf("UsePokeballQuest"); + if(!playerHasPokeballForPokemonQuest(pokeballQuest.pokeball, pokeballQuest.progressText())) { + if(indexPos !== -1) { + questTypes[indexPos] = null; + } + endPokeballQuest(); + return; + } + + questPokeballInProgress = true; + + //Save and set pokeball already caught selection + if (!questPokeballReadyToStart) { + playerSavePokeballAlreadyCaught(); + } + playerSetAlreadyCaughtPokeball(pokeballQuest.pokeball) + + completeQuestPokeballLoop = setInterval(function() { + if(pokeballQuest.notified) { + endPokeballQuest() + } + }, 1000); + } +} + +function changePokeballForQuest(quest) { + let catchShiniesQuest = App.game.quests.currentQuests().filter(x => x instanceof CatchShiniesQuest); + let capturePokemonTypesQuest = App.game.quests.currentQuests().filter(x => x instanceof CapturePokemonTypesQuest); + + if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball) { + if (catchShiniesQuest.length > 0) { + if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { + forceCapture = true; + } + } + if (capturePokemonTypesQuest.length > 0) { + for(const quest of capturePokemonTypesQuest) { + if(quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { + forceCapture = true; + break; + } + } + } + + if (forceCapture) { + //Check if player have pokeball to catch pokemon + let pokeball = -1; + for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { + if(playerHasPokeballForPokemonQuest(i)) { + pokeball = i; + break; + } + } + if (pokeball === -1) { + const indexPos = questTypes.indexOf(quest.constructor.name); + if(indexPos !== -1) { + questTypes[indexPos] = null; + } + return; + } + if (!questPokeballReadyToStart) { + playerSavePokeballAlreadyCaught(); + } + playerSetAlreadyCaughtPokeball(pokeball) + } else if (questPokeballReadyToStart && !questPokeballInProgress) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect) + } + } +} + function playerSaveState() { //Save last location of player in temp variable regionSelect = player.region; @@ -322,6 +434,11 @@ function playerSaveState() { } } +function playerSavePokeballAlreadyCaught() { + pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + questPokeballReadyToStart = true; +} + function playerResetState() { if(regionSelect && player.region !== regionSelect) { player.region = regionSelect; @@ -388,6 +505,23 @@ function playerCanPayDungeonEntrance(dungeonName, progressText) { return getTokens >= dungeonCost * amountRemaining; } +function playerHasPokeballForPokemonQuest(pokeball, progressText = null) { + let amountRemaining = 0; + if (progressText) { + const progress = progressText.split('/').map(element => parseInt(element.trim())); + amountRemaining = progress[1] - progress[0]; + } else { + amountRemaining = 1; + } + return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; +} + +function playerSetAlreadyCaughtPokeball(pokeball) { + if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { + App.game.pokeballs._alreadyCaughtSelection(pokeball); + } +} + function stopAutoDungeon() { if(dungeonStart && !dungeonStart.classList.contains("btn-danger")) { dungeonStart.click(); From 8f00ae45ee5bb8d4b15c7cc58f1fbf6306b89492 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Fri, 3 Jun 2022 03:00:08 +0200 Subject: [PATCH 08/17] Fix pokeball reset when pokemon type is captured --- custom/autoquestcompleter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom/autoquestcompleter.js b/custom/autoquestcompleter.js index 525dcc89..a9b446b1 100644 --- a/custom/autoquestcompleter.js +++ b/custom/autoquestcompleter.js @@ -16,7 +16,6 @@ let questPokeballReadyToStart = false; let questPokeballInProgress = false; let completeQuestLocationLoop; let completeQuestPokeballLoop; -let forceCapture = false; let regionSelect; let subRegionSelect; let routeSelect; @@ -374,7 +373,8 @@ function changePokeballForQuest(quest) { let catchShiniesQuest = App.game.quests.currentQuests().filter(x => x instanceof CatchShiniesQuest); let capturePokemonTypesQuest = App.game.quests.currentQuests().filter(x => x instanceof CapturePokemonTypesQuest); - if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball) { + let forceCapture = false; + if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball || questPokeballReadyToStart) { if (catchShiniesQuest.length > 0) { if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { forceCapture = true; @@ -411,6 +411,7 @@ function changePokeballForQuest(quest) { playerSetAlreadyCaughtPokeball(pokeball) } else if (questPokeballReadyToStart && !questPokeballInProgress) { playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect) + questPokeballReadyToStart = false; } } } From 44783b0a0fb7eb6daf4da9e06bf602880c61afc6 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Sat, 4 Jun 2022 03:06:42 +0200 Subject: [PATCH 09/17] Improve CapturePokemonTypesQuest and add CapturePokemonsQuest --- custom/autoquestcompleter.user.js | 286 +++++++++++++++++++++++------- 1 file changed, 226 insertions(+), 60 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index c7e135bd..7a99253d 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -13,10 +13,17 @@ let questTypes = []; let autoQuestCanBeStopped; let questLocationReadyToStart = false; let questLocationInProgress = false; +let completeQuestLocationLoop; let questPokeballReadyToStart = false; let questPokeballInProgress = false; -let completeQuestLocationLoop; let completeQuestPokeballLoop; +let questCapturePokemonsReadyToStart = false; +let questCapturePokemonsInProgress = false; +let completeQuestCapturePokemonsLoop; +let questCapturePokemonTypesReadyToStart = false; +let questCapturePokemonTypesInProgress = false; +let completeQuestCapturePokemonTypesLoop; +let pokeballChangedForCapturePokemonQuest = false; let regionSelect; let subRegionSelect; let routeSelect; @@ -24,9 +31,19 @@ let townSelect; let dungeonStateSelect; let gymStateSelect; let pokeballAlreadyCaughtSelect; +let previousPokeballAlreadyCaughtSelect; +let hatcheryCategorySelect; +let hatcheryShinyStatusSelect; +let hatcheryRegionSelect; +let hatcheryType1Select; +let hatcheryType2Select; +let hatcherySortSelect; +let hatcherySortDirectionSelect; +let hatcheryStateSelect; let dungeonQuestEnable; let gymStart; let dungeonStart; +let hatcheryStart; function initAutoQuests(){ //Allows to start infinite quests @@ -73,6 +90,7 @@ function initAutoQuests(){ //Retrieving autoclicker buttons gymStart = document.getElementById("auto-gym-start"); dungeonStart = document.getElementById("auto-dungeon-start"); + hatcheryStart = document.getElementById("auto-hatch-start"); //Checks for new quests to add to the list and claims completed ones var autoQuest = setInterval(function(){ @@ -86,6 +104,14 @@ function initAutoQuests(){ } if (localStorage.getItem('autoQuestEnable') == 'true'){ autoQuestCanBeStopped = true; + //Attempt to start all available quests & quit the filtered ones + App.game.quests.questList().forEach(quest => { + if (quest.inProgress() == true && !questTypes.includes(quest.constructor.name)) { + App.game.quests.quitQuest(quest.index); + } else if (quest.isCompleted() == false && quest.inProgress() == false && questTypes.includes(quest.constructor.name)){ + App.game.quests.beginQuest(quest.index); + } + }) if (App.game.quests.currentQuests().length > 0){ App.game.quests.currentQuests().forEach(quest => { if (quest.notified == true){ @@ -102,22 +128,27 @@ function initAutoQuests(){ completeDefeatDungeonQuest(quest) } } + if (!questCapturePokemonsInProgress) { + if (quest instanceof CapturePokemonsQuest) { + completeCapturePokemonsQuest(quest) + } + } + if (!questCapturePokemonTypesInProgress) { + if (quest instanceof CapturePokemonTypesQuest) { + completeCapturePokemonTypesQuest(quest) + } + } if (!questPokeballInProgress) { if (quest instanceof UsePokeballQuest) { completeUsePokeballQuest(quest) } } - } //Complete quest when you use pokeball to capture pokemon like shiny and type if (App.game.gameState === GameConstants.GameState.fighting) { - changePokeballForQuest(quest) + changePokeballForPokemonQuest() } - //TODO: For "CapturePokemonsQuest" and "CapturePokemonTypesQuest" - //If autohatchery exist start and sort pokemon - //Else use changePokeballForQuest() for "CapturePokemonsQuest" - //Check if quests should refresh if (questTypes.includes(quest.constructor.name)) { questsNeed++; @@ -129,16 +160,10 @@ function initAutoQuests(){ App.game.quests.refreshQuests(); } } - //Attempt to start all available quests & quit the filtered ones - App.game.quests.questList().forEach(quest => { - if (quest.inProgress() == true && !questTypes.includes(quest.constructor.name)) { - App.game.quests.quitQuest(quest.index); - } else if (quest.isCompleted() == false && quest.inProgress() == false && questTypes.includes(quest.constructor.name)){ - App.game.quests.beginQuest(quest.index); - } - }) } else if (autoQuestCanBeStopped) { autoQuestCanBeStopped = false; + endCapturePokemonsQuest(); + endCapturePokemonTypesQuest(); endPokeballQuest(); stopCompleteQuestLocation(); } @@ -155,7 +180,8 @@ function initAutoQuests(){ function retrieveQuestName(event) { const index = +event.target.getAttribute('data-src'); - const questName = App.game.quests.questList()[index].constructor.name; + const quest = App.game.quests.questList()[index]; + const questName = quest.constructor.name const indexPos = questTypes.indexOf(questName); if (indexPos != -1) { questTypes[indexPos] = null; @@ -163,6 +189,17 @@ function initAutoQuests(){ const empty = questTypes.indexOf(null); questTypes[empty] = questName; } + + //Stop current quests in progress + if(questLocationInProgress && (quest instanceof DefeatGymQuest || quest instanceof DefeatPokemonsQuest || quest instanceof DefeatDungeonQuest)) { + stopCompleteQuestLocation(); + } else if (questCapturePokemonsInProgress && quest instanceof CapturePokemonsQuest) { + endCapturePokemonsQuest(); + } else if (questCapturePokemonTypesInProgress && quest instanceof CapturePokemonTypesQuest) { + endCapturePokemonTypesQuest(); + } else if (questPokeballInProgress && quest instanceof UsePokeballQuest) { + endPokeballQuest(); + } localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); } @@ -217,31 +254,10 @@ else{ loadScript(); } -function endLocationQuest() { - //Executed when the quest is completed - questLocationReadyToStart = false; - questLocationInProgress = false; - clearInterval(completeQuestLocationLoop); - completeQuestLocationLoop = null; - stopAutoDungeon(); - stopAutoGym(); - playerResetState(); -} - -function endPokeballQuest() { - //Executed when the quest is completed - questPokeballInProgress = false; - clearInterval(completeQuestPokeballLoop); - completeQuestPokeballLoop = null; - if (questPokeballReadyToStart) { - playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); - questPokeballReadyToStart = false; - } -} - -function endShiniesQuest() { - if (pokeballAlreadyCaughtSelect) { - playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); +function removeQuestTemporarily(quest) { + const indexPos = questTypes.indexOf(quest.constructor.name); + if (indexPos !== -1) { + questTypes[indexPos] = null; } } @@ -250,11 +266,8 @@ function completeDefeatDungeonQuest(dungeonQuest) { if(!dungeonStart) return; //Remove dungeon quest for current cycle if total token needed not available - const indexPos = questTypes.indexOf("DefeatDungeonQuest"); if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { - if(indexPos !== -1) { - questTypes[indexPos] = null; - } + removeQuestTemporarily(dungeonQuest); endLocationQuest(); return; } @@ -342,14 +355,22 @@ function completeDefeatPokemonQuest(pokemonQuest) { } } +function endLocationQuest() { + //Executed when the quest is completed + questLocationReadyToStart = false; + questLocationInProgress = false; + clearInterval(completeQuestLocationLoop); + completeQuestLocationLoop = null; + stopAutoDungeon(); + stopAutoGym(); + playerResetState(); +} + function completeUsePokeballQuest(pokeballQuest) { if (!questPokeballInProgress) { //Remove use pokeball quest for current cycle if total pokeball needed not available - const indexPos = questTypes.indexOf("UsePokeballQuest"); if(!playerHasPokeballForPokemonQuest(pokeballQuest.pokeball, pokeballQuest.progressText())) { - if(indexPos !== -1) { - questTypes[indexPos] = null; - } + removeQuestTemporarily(pokeballQuest); endPokeballQuest(); return; } @@ -370,12 +391,121 @@ function completeUsePokeballQuest(pokeballQuest) { } } -function changePokeballForQuest(quest) { +function endPokeballQuest() { + //Executed when the quest is completed + questPokeballInProgress = false; + clearInterval(completeQuestPokeballLoop); + completeQuestPokeballLoop = null; + if (questPokeballReadyToStart) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); + questPokeballReadyToStart = false; + } +} + +function completeCapturePokemonsQuest(captureQuest) { + //Can't use hatchery without autohatchery + if(!hatcheryStart) return; + + //No need to run the code if autohatchery is enabled + if(hatcheryStart.classList.contains("btn-success")) { + return; + } + + if(!questCapturePokemonsReadyToStart) { + if (!questCapturePokemonTypesInProgress) { + playerSaveHatcheryState(); + } + questCapturePokemonsReadyToStart = true; + } + + if (!questCapturePokemonsInProgress) { + questCapturePokemonsInProgress = true; + if (!questCapturePokemonTypesInProgress) { + //Set all filter breeding to default to avoid empty list + BreedingController.filter.category(-1) + BreedingController.filter.shinyStatus(-2) + BreedingController.filter.region(-2) + BreedingController.filter.type1(-2) + BreedingController.filter.type2(-2) + Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient + Settings.getSetting('hatcherySortDirection').observableValue(true) + } + + completeQuestCapturePokemonsLoop = setInterval(function() { + if(!captureQuest.notified) { + if(hatcheryStart.classList.contains("btn-danger")) { + hatcheryStart.click(); + } + } else { + endCapturePokemonsQuest() + } + }, 5000); + } +} + +function endCapturePokemonsQuest() { + questCapturePokemonsReadyToStart = false; + questCapturePokemonsInProgress = false; + clearInterval(completeQuestCapturePokemonsLoop) + completeQuestCapturePokemonsLoop = null; + if (!questCapturePokemonTypesInProgress) { + playerResetHatcheryState() + } +} + +function completeCapturePokemonTypesQuest(captureQuest) { + //Can't use hatchery without autohatchery + if(!hatcheryStart) return; + + if(!questCapturePokemonTypesReadyToStart) { + if (!questCapturePokemonsReadyToStart) { + playerSaveHatcheryState(); + } + questCapturePokemonTypesReadyToStart = true; + } + + if (!questCapturePokemonTypesInProgress) { + questCapturePokemonTypesInProgress = true; + //Set all filter breeding to default to avoid empty list + BreedingController.filter.category(-1) + BreedingController.filter.shinyStatus(-2) + BreedingController.filter.region(-2) + BreedingController.filter.type1(captureQuest.type) + BreedingController.filter.type2(-2) + Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient + Settings.getSetting('hatcherySortDirection').observableValue(true) + + completeQuestCapturePokemonTypesLoop = setInterval(function() { + if(!captureQuest.notified) { + if(hatcheryStart.classList.contains("btn-danger")) { + hatcheryStart.click(); + } + } else { + endCapturePokemonTypesQuest() + } + }, 5000); + } +} + +function endCapturePokemonTypesQuest() { + questCapturePokemonTypesReadyToStart = false; + questCapturePokemonTypesInProgress = false; + clearInterval(completeQuestCapturePokemonTypesLoop) + completeQuestCapturePokemonTypesLoop = null; + if (!questCapturePokemonsInProgress) { + playerResetHatcheryState() + } else { + //Set type1 to all if pokemon quest capture is in progress + BreedingController.filter.type1(-2) + } +} + +function changePokeballForPokemonQuest() { let catchShiniesQuest = App.game.quests.currentQuests().filter(x => x instanceof CatchShiniesQuest); let capturePokemonTypesQuest = App.game.quests.currentQuests().filter(x => x instanceof CapturePokemonTypesQuest); let forceCapture = false; - if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball || questPokeballReadyToStart) { + if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball || pokeballChangedForCapturePokemonQuest) { if (catchShiniesQuest.length > 0) { if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { forceCapture = true; @@ -383,6 +513,7 @@ function changePokeballForQuest(quest) { } if (capturePokemonTypesQuest.length > 0) { for(const quest of capturePokemonTypesQuest) { + //Check if pokemon type is catchable if(quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { forceCapture = true; break; @@ -400,19 +531,16 @@ function changePokeballForQuest(quest) { } } if (pokeball === -1) { - const indexPos = questTypes.indexOf(quest.constructor.name); - if(indexPos !== -1) { - questTypes[indexPos] = null; - } + removeQuestTemporarily(quest); return; } - if (!questPokeballReadyToStart) { - playerSavePokeballAlreadyCaught(); + if (!pokeballChangedForCapturePokemonQuest) { + playerSavePreviousPokeballAlreadyCaught(); } playerSetAlreadyCaughtPokeball(pokeball) - } else if (questPokeballReadyToStart && !questPokeballInProgress) { - playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect) - questPokeballReadyToStart = false; + } else if (pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect) + pokeballChangedForCapturePokemonQuest = false; } } } @@ -441,6 +569,44 @@ function playerSavePokeballAlreadyCaught() { questPokeballReadyToStart = true; } +function playerSavePreviousPokeballAlreadyCaught() { + previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + pokeballChangedForCapturePokemonQuest = true; +} + +function playerSaveHatcheryState() { + hatcheryCategorySelect = BreedingController.filter.category() + hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus() + hatcheryRegionSelect = BreedingController.filter.region() + hatcheryType1Select = BreedingController.filter.type1() + hatcheryType2Select = BreedingController.filter.type2() + hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue() + hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue() + + if(hatcheryStart && hatcheryStart.classList.contains("btn-danger")) { + hatcheryStateSelect = false; + } else if(hatcheryStart && hatcheryStart.classList.contains("btn-success")) { + hatcheryStateSelect = true; + } +} + +function playerResetHatcheryState() { + BreedingController.filter.category(hatcheryCategorySelect) + BreedingController.filter.shinyStatus(hatcheryShinyStatusSelect) + BreedingController.filter.region(hatcheryRegionSelect) + BreedingController.filter.type1(hatcheryType1Select) + BreedingController.filter.type2(hatcheryType2Select) + Settings.getSetting('hatcherySort').observableValue(hatcherySortSelect) + Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirectionSelect) + if (hatcheryStart) { + if(hatcheryStateSelect && !hatcheryStart.classList.contains("btn-success")) { + hatcheryStart.click(); + } else if(!hatcheryStateSelect && !hatcheryStart.classList.contains("btn-danger")) { + hatcheryStart.click(); + } + } +} + function playerResetState() { if(regionSelect && player.region !== regionSelect) { player.region = regionSelect; From 5ab96b4fdc5203c5cb484d9db6370d36f02ef389 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Sat, 4 Jun 2022 03:49:56 +0200 Subject: [PATCH 10/17] Improved auto quest --- README.md | 18 +++++++++++++++++- custom/autoquestcompleter.user.js | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e96a162a..86c3b787 100644 --- a/README.md +++ b/README.md @@ -279,12 +279,28 @@ In addition it will also prevent the weather from changing and will remember you
## **[Custom] Auto Quest Completer** ([autoquestcompleter.user.js](//github.com/Ephenia/Pokeclicker-Scripts/blob/master/custom/autoquestcompleter.user.js)) -This script automatically completes and starts quests and can be toggled with this button:
+This script automatically claim and starts quests and can be toggled with this button:
![image](https://i.imgur.com/3AYaNes.png) It also is able to ignore the limit of quests you can enable at once, letting you complete all 10 at the same time. +You can ignore a quest type by clicking on it in the quest modal. + +![image](https://i.imgur.com/cdOXAWU.png) + +The script can be able to complete this quests. + +| Type | Required Script | Description | +|--------------------------|---------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| DefeatGymQuest | None | Move player to the gym and beats him. | +| DefeatPokemonsQuest | None | Move player to route and deafeat him. | +| DefeatDungeonQuest | [**Enhanced Auto Clicker** ](//github.com/Ephenia/Pokeclicker-Scripts#enhanced-auto-clicker-enhancedautoclickeruserjs) | Checks that the number of tokens is available, moves the player and starts the dungeon. If not, skip the quest. | +| CapturePokemonsQuest | [**Enhanced Auto Hatchery** ](//github.com/Ephenia/Pokeclicker-Scripts#enhanced-auto-hatchery-enhancedautohatcheryuserjs) | Start the hatchery and set the filters to all. | +| CapturePokemonTypesQuest | [**Enhanced Auto Hatchery** ](//github.com/Ephenia/Pokeclicker-Scripts#enhanced-auto-hatchery-enhancedautohatcheryuserjs) | Starts the hatchery and sets the filters to all and changes the filter from type1. It also captures pokemon when it encounters the type. | +| UsePokeballQuest | None | If enough pokeballs are available, change the pokeballs for pokemons already caught. Priority will be given to ultraballs and then to a decreasing type of them. Otherwise it skip the quest. | +| CatchShiniesQuest | None | If enough pokeballs are available, change the pokeballs for pokemons already caught. Priority will be given to ultraballs and then to a decreasing type of them. | +
More to be added soon. diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index 7a99253d..ef0526af 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -174,6 +174,7 @@ function initAutoQuests(){ const questHTML = document.getElementById('QuestModal').querySelector('tbody').children; for (let i = 0; i < questHTML.length; i++) { questHTML[i].querySelector('td:nth-child(1)').setAttribute('data-src', i); + questHTML[i].classList.add("clickable"); questHTML[i].addEventListener('click', () => {retrieveQuestName(event)}) } } From 0d6f39592d93899dcfd1401488928dc40c84dd7f Mon Sep 17 00:00:00 2001 From: Sorrow Date: Sat, 4 Jun 2022 13:56:27 +0200 Subject: [PATCH 11/17] Fix bug with saving pokeball for already caught --- custom/autoquestcompleter.user.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index ef0526af..18bfe01c 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -368,7 +368,8 @@ function endLocationQuest() { } function completeUsePokeballQuest(pokeballQuest) { - if (!questPokeballInProgress) { + //If the script has to change the pokeball for a capture, we wait until it has reset the selected already caught pokeball + if (!questPokeballInProgress && !pokeballChangedForCapturePokemonQuest) { //Remove use pokeball quest for current cycle if total pokeball needed not available if(!playerHasPokeballForPokemonQuest(pokeballQuest.pokeball, pokeballQuest.progressText())) { removeQuestTemporarily(pokeballQuest); From 7083e1c84dab9f9f4474c2c50f6a968b52a8f9ec Mon Sep 17 00:00:00 2001 From: Sorrow Date: Sat, 4 Jun 2022 16:30:37 +0200 Subject: [PATCH 12/17] Fix bug with saving pokeball for already caught --- custom/autoquestcompleter.user.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index 18bfe01c..e44a8e16 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -166,6 +166,9 @@ function initAutoQuests(){ endCapturePokemonTypesQuest(); endPokeballQuest(); stopCompleteQuestLocation(); + if (pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); + } } }, 500) @@ -523,25 +526,28 @@ function changePokeballForPokemonQuest() { } } - if (forceCapture) { + if (forceCapture && !Battle.catching()) { //Check if player have pokeball to catch pokemon let pokeball = -1; for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { - if(playerHasPokeballForPokemonQuest(i)) { + if (playerHasPokeballForPokemonQuest(i)) { pokeball = i; break; } } if (pokeball === -1) { - removeQuestTemporarily(quest); + //Pokeball not available return; } if (!pokeballChangedForCapturePokemonQuest) { playerSavePreviousPokeballAlreadyCaught(); } playerSetAlreadyCaughtPokeball(pokeball) + } else if (forceCapture && Battle.catching() && pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); + pokeballChangedForCapturePokemonQuest = false; } else if (pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect) + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); pokeballChangedForCapturePokemonQuest = false; } } From 206981fa9b42e72fef785a79f66332a8de239ef6 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Sat, 4 Jun 2022 17:08:22 +0200 Subject: [PATCH 13/17] Avoids that the buttons of other scripts do not exist yet --- custom/autoquestcompleter.user.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index e44a8e16..e8946b8e 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -87,10 +87,13 @@ function initAutoQuests(){ document.getElementById('toggle-auto-quest').textContent = 'Auto [ON]' } }, false) - //Retrieving autoclicker buttons - gymStart = document.getElementById("auto-gym-start"); - dungeonStart = document.getElementById("auto-dungeon-start"); - hatcheryStart = document.getElementById("auto-hatch-start"); + + //Avoids that the buttons of other scripts do not exist yet + setTimeout(function() { + gymStart = document.getElementById("auto-gym-start"); + dungeonStart = document.getElementById("auto-dungeon-start"); + hatcheryStart = document.getElementById("auto-hatch-start"); + }, 2000); //Checks for new quests to add to the list and claims completed ones var autoQuest = setInterval(function(){ From f2930b93d05811586c02c984416752a781039fdc Mon Sep 17 00:00:00 2001 From: Sorrow Date: Thu, 9 Jun 2022 01:40:09 +0200 Subject: [PATCH 14/17] Refactoring and start of implementing UseOakItemQuest --- custom/autoquestcompleter.user.js | 778 +++++++++++++----------------- 1 file changed, 324 insertions(+), 454 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index e8946b8e..47c4f20a 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -11,27 +11,16 @@ let questTypes = []; let autoQuestCanBeStopped; -let questLocationReadyToStart = false; -let questLocationInProgress = false; -let completeQuestLocationLoop; -let questPokeballReadyToStart = false; -let questPokeballInProgress = false; -let completeQuestPokeballLoop; -let questCapturePokemonsReadyToStart = false; -let questCapturePokemonsInProgress = false; -let completeQuestCapturePokemonsLoop; -let questCapturePokemonTypesReadyToStart = false; -let questCapturePokemonTypesInProgress = false; -let completeQuestCapturePokemonTypesLoop; -let pokeballChangedForCapturePokemonQuest = false; +let locationQuestInProgress = false; +let usePokeballQuestInProgress = false; +let capturePokemonsQuestInProgress = false; +let capturePokemonTypesQuestInProgress = false; let regionSelect; let subRegionSelect; let routeSelect; let townSelect; let dungeonStateSelect; let gymStateSelect; -let pokeballAlreadyCaughtSelect; -let previousPokeballAlreadyCaughtSelect; let hatcheryCategorySelect; let hatcheryShinyStatusSelect; let hatcheryRegionSelect; @@ -40,10 +29,13 @@ let hatcheryType2Select; let hatcherySortSelect; let hatcherySortDirectionSelect; let hatcheryStateSelect; -let dungeonQuestEnable; -let gymStart; -let dungeonStart; -let hatcheryStart; +let autoGym; +let autoDungeon; +let autoHatchery; +let playerHasMoved = false; +let pokeballAlreadyCaughtSelect; +let pokeballChangedForCapturePokemonQuest; +let previousPokeballAlreadyCaughtSelect; function initAutoQuests(){ //Allows to start infinite quests @@ -55,6 +47,7 @@ function initAutoQuests(){ localStorage.setItem('autoQuestEnable', 'true') } //Define quest types + let questTypes = []; if (localStorage.getItem('autoQuestTypes') == null){ for (const type in QuestHelper.quests) { questTypes.push(type); @@ -62,7 +55,6 @@ function initAutoQuests(){ localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)) } else { questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); - dungeonQuestEnable = questTypes.includes("DefeatDungeonQuest"); } resetQuestModify(); //Track the last refresh @@ -90,19 +82,19 @@ function initAutoQuests(){ //Avoids that the buttons of other scripts do not exist yet setTimeout(function() { - gymStart = document.getElementById("auto-gym-start"); - dungeonStart = document.getElementById("auto-dungeon-start"); - hatcheryStart = document.getElementById("auto-hatch-start"); - }, 2000); + autoGym = document.getElementById("auto-gym-start"); + autoDungeon = document.getElementById("auto-dungeon-start"); + autoHatchery = document.getElementById("auto-hatch-start"); + }, 1000); + //Checks for new quests to add to the list and claims completed ones var autoQuest = setInterval(function(){ let questsNeed = 0; if (trackRefresh != App.game.quests.lastRefresh) { - trackRefresh = App.game.quests.lastRefresh; - stopCompleteQuestLocation(); //Reload quest types from local storage to re-enter the dungeon if they are deleted because there are not enough dungeon tokens left. questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); + trackRefresh = App.game.quests.lastRefresh; resetQuestModify(); } if (localStorage.getItem('autoQuestEnable') == 'true'){ @@ -116,43 +108,15 @@ function initAutoQuests(){ } }) if (App.game.quests.currentQuests().length > 0){ + //Claim all completed quest & check if quests should refresh App.game.quests.currentQuests().forEach(quest => { if (quest.notified == true){ - //Claim all completed quest App.game.quests.claimQuest(quest.index) - } else { - //Processes quests with location - if(!questLocationInProgress) { - if(quest instanceof DefeatGymQuest) { - completeDefeatGymQuest(quest) - } else if(quest instanceof DefeatPokemonsQuest) { - completeDefeatPokemonQuest(quest) - } else if(quest instanceof DefeatDungeonQuest) { - completeDefeatDungeonQuest(quest) - } - } - if (!questCapturePokemonsInProgress) { - if (quest instanceof CapturePokemonsQuest) { - completeCapturePokemonsQuest(quest) - } - } - if (!questCapturePokemonTypesInProgress) { - if (quest instanceof CapturePokemonTypesQuest) { - completeCapturePokemonTypesQuest(quest) - } - } - if (!questPokeballInProgress) { - if (quest instanceof UsePokeballQuest) { - completeUsePokeballQuest(quest) - } - } + endQuest(quest); } - //Complete quest when you use pokeball to capture pokemon like shiny and type - if (App.game.gameState === GameConstants.GameState.fighting) { - changePokeballForPokemonQuest() + else { + startQuest(quest); } - - //Check if quests should refresh if (questTypes.includes(quest.constructor.name)) { questsNeed++; } @@ -165,13 +129,9 @@ function initAutoQuests(){ } } else if (autoQuestCanBeStopped) { autoQuestCanBeStopped = false; - endCapturePokemonsQuest(); - endCapturePokemonTypesQuest(); - endPokeballQuest(); - stopCompleteQuestLocation(); - if (pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); - } + App.game.quests.questList().forEach(quest => { + endQuest(quest); + }) } }, 500) @@ -180,15 +140,13 @@ function initAutoQuests(){ const questHTML = document.getElementById('QuestModal').querySelector('tbody').children; for (let i = 0; i < questHTML.length; i++) { questHTML[i].querySelector('td:nth-child(1)').setAttribute('data-src', i); - questHTML[i].classList.add("clickable"); questHTML[i].addEventListener('click', () => {retrieveQuestName(event)}) } } function retrieveQuestName(event) { const index = +event.target.getAttribute('data-src'); - const quest = App.game.quests.questList()[index]; - const questName = quest.constructor.name + const questName = App.game.quests.questList()[index].constructor.name; const indexPos = questTypes.indexOf(questName); if (indexPos != -1) { questTypes[indexPos] = null; @@ -196,38 +154,44 @@ function initAutoQuests(){ const empty = questTypes.indexOf(null); questTypes[empty] = questName; } + localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); + } - //Stop current quests in progress - if(questLocationInProgress && (quest instanceof DefeatGymQuest || quest instanceof DefeatPokemonsQuest || quest instanceof DefeatDungeonQuest)) { - stopCompleteQuestLocation(); - } else if (questCapturePokemonsInProgress && quest instanceof CapturePokemonsQuest) { - endCapturePokemonsQuest(); - } else if (questCapturePokemonTypesInProgress && quest instanceof CapturePokemonTypesQuest) { - endCapturePokemonTypesQuest(); - } else if (questPokeballInProgress && quest instanceof UsePokeballQuest) { - endPokeballQuest(); + function startQuest(quest) { + if(quest instanceof DefeatGymQuest) { + completeDefeatGymQuest(quest); + } else if(quest instanceof DefeatPokemonsQuest) { + completeDefeatPokemonQuest(quest); + } else if(quest instanceof DefeatDungeonQuest) { + completeDefeatDungeonQuest(quest); + } else if (quest instanceof UsePokeballQuest) { + completeUsePokeballQuest(quest); + } else if (quest instanceof CatchShiniesQuest) { + changePokeballForPokemonQuest(quest); + } else if (quest instanceof CapturePokemonsQuest) { + completeCapturePokemonsQuest(); + } else if (quest instanceof CapturePokemonTypesQuest) { + changePokeballForPokemonQuest(quest); + completeCapturePokemonTypesQuest(quest); + } else if (quest instanceof UseOakItemQuest) { + changePokeballForPokemonQuest(quest); } - localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); } - function stopCompleteQuestLocation() { - if(questLocationInProgress) { - //Reset loop when quest is refreshed or auto quest is disabled - if(typeof completeQuestLocationLoop !== 'undefined') { - clearInterval(completeQuestLocationLoop); - completeQuestLocationLoop = null; - } - stopAutoDungeon(); - stopAutoGym(); - let resetPlayerStateLoop = setInterval(function() { - if(playerCanMove()) { - playerResetState(); - clearInterval(resetPlayerStateLoop); - } - }, 50); - questLocationInProgress = false; + function endQuest(quest) { + if(quest instanceof DefeatGymQuest) { + endLocationQuest(quest); + } else if(quest instanceof DefeatPokemonsQuest) { + endLocationQuest(quest); + } else if(quest instanceof DefeatDungeonQuest) { + endLocationQuest(quest); + }else if (quest instanceof UsePokeballQuest) { + endUsePokeballQuest(quest); + } else if (quest instanceof CapturePokemonsQuest) { + endCapturePokemonsQuest(quest); + } else if (quest instanceof CapturePokemonTypesQuest) { + endCapturePokemonTypesQuest(quest); } - questLocationReadyToStart = false; } } @@ -268,452 +232,357 @@ function removeQuestTemporarily(quest) { } } -function completeDefeatDungeonQuest(dungeonQuest) { - //Can't farm the dungeons without the autoclicker - if(!dungeonStart) return; - - //Remove dungeon quest for current cycle if total token needed not available - if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { - removeQuestTemporarily(dungeonQuest); - endLocationQuest(); - return; +function stopAutoDungeon() { + if(autoDungeon && !autoDungeon.classList.contains("btn-danger")) { + autoDungeon.click(); } +} - if(!questLocationReadyToStart) { - playerSaveState(); - stopAutoGym(); - questLocationReadyToStart = true; +function stopAutoGym() { + if (autoGym && !autoGym.classList.contains("btn-danger")) { + autoGym.click(); } +} - //Move player to quest dungeon - if (playerCanMove()) { - playerMoveToTown(dungeonQuest.dungeon, dungeonQuest.region); +function playerSaveState() { + //Save last location of player in temp variable + regionSelect = player.region; + subRegionSelect = player.subregion; + routeSelect = player.route(); + townSelect = player.town().name; + + if(autoDungeon && autoDungeon.classList.contains("btn-danger")) { + dungeonStateSelect = false; + } else if(autoDungeon && autoDungeon.classList.contains("btn-success")) { + dungeonStateSelect = true; } + if(autoGym && autoGym.classList.contains("btn-danger")) { + gymStateSelect = false; + } else if(autoGym && autoGym.classList.contains("btn-success")) { + gymStateSelect = true; + } +} - if(player.town().name === dungeonQuest.dungeon) { - questLocationInProgress = true; - completeQuestLocationLoop = setInterval(function() { - if(!dungeonQuest.notified) { - if(dungeonStart && !dungeonStart.classList.contains("btn-success")) { - dungeonStart.click(); - } - } else if(playerCanMove()) { - endLocationQuest(); - } - }, 50); +function playerResetState() { + playerMoveTo(regionSelect, townSelect, routeSelect) + if (autoDungeon) { + if(dungeonStateSelect && !autoDungeon.classList.contains("btn-success")) { + autoDungeon.click(); + } else if(!dungeonStateSelect && !autoDungeon.classList.contains("btn-danger")) { + autoDungeon.click(); + } + } + if (autoGym) { + if(gymStateSelect && !autoGym.classList.contains("btn-success")) { + autoGym.click(); + } else if(!gymStateSelect && !autoGym.classList.contains("btn-danger")) { + autoGym.click(); + } } } -function completeDefeatGymQuest(gymQuest) { - //Find town associate to gym - const gymListAsArray = Object.entries(GymList); - const town = gymListAsArray.filter(([key, value]) => key === gymQuest.gymTown)[0][1]; +function playerSaveHatcheryFilters() { + hatcheryCategorySelect = BreedingController.filter.category() + hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus() + hatcheryRegionSelect = BreedingController.filter.region() + hatcheryType1Select = BreedingController.filter.type1() + hatcheryType2Select = BreedingController.filter.type2() + hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue() + hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue() - if(!questLocationReadyToStart) { - playerSaveState(); - stopAutoDungeon(); - stopAutoGym(); - questLocationReadyToStart = true; - } - //Move player to quest town - if (playerCanMove()) { - playerMoveToTown(town.parent.name, town.parent.region); + if(autoHatchery && autoHatchery.classList.contains("btn-danger")) { + hatcheryStateSelect = false; + } else if(autoHatchery && autoHatchery.classList.contains("btn-success")) { + hatcheryStateSelect = true; } +} - if(player.town().name === town.parent.name) { - //Find gym in town - for(const gym of player.town().content) { - if(gym.town === gymQuest.gymTown) { - questLocationInProgress = true; - completeQuestLocationLoop = setInterval(function() { - if(!gymQuest.notified) { - if(App.game.gameState !== GameConstants.GameState.gym) { - gym.protectedOnclick(); - } - } else if(playerCanMove()) { - endLocationQuest(); - } - }, 50); - } +function playerResetHatcheryFilters() { + playerSetHatcheryFilters(hatcheryCategorySelect, hatcheryShinyStatusSelect, hatcheryRegionSelect, hatcheryType1Select, hatcheryType2Select, hatcherySortSelect, hatcherySortDirectionSelect) + if (autoHatchery) { + if(hatcheryStateSelect && !autoHatchery.classList.contains("btn-success")) { + autoHatchery.click(); + } else if(!hatcheryStateSelect && !autoHatchery.classList.contains("btn-danger")) { + autoHatchery.click(); } } } -function completeDefeatPokemonQuest(pokemonQuest) { - if(!questLocationReadyToStart) { - playerSaveState(); - stopAutoDungeon(); - stopAutoGym(); - questLocationReadyToStart = true; +function playerSetHatcheryFilters(category, shinyStatus, region, type1, type2, hatcherySort, hatcherySortDirection) { + if (BreedingController.filter.category() !== category) { + BreedingController.filter.category(category) } - - //Move player to quest route - if (playerCanMove()) { - playerMoveToRoute(pokemonQuest.route, pokemonQuest.region); + if (BreedingController.filter.shinyStatus() !== shinyStatus) { + BreedingController.filter.shinyStatus(shinyStatus) + } + if (BreedingController.filter.region() !== region) { + BreedingController.filter.region(region) + } + if (BreedingController.filter.type1() !== type1) { + BreedingController.filter.type1(type1) + } + if (BreedingController.filter.type2() !== type2) { + BreedingController.filter.type2(type2) + } + if (Settings.getSetting('hatcherySort').observableValue() !== hatcherySort) { + Settings.getSetting('hatcherySort').observableValue(hatcherySort) // Breeding efficient } + if (Settings.getSetting('hatcherySort').observableValue() !== hatcherySortDirection) { + Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirection) + } +} - if(player.route() === pokemonQuest.route && player.region === pokemonQuest.region) { - questLocationInProgress = true; - completeQuestLocationLoop = setInterval(function() { - if(pokemonQuest.notified) { - endLocationQuest(); - } - }, 50); +function playerMoveTo(region, town, route) { + if (playerCanMove()) { + if (region === 6) { + player.subregion = getAlolaSubRegionFromLocation(town) + } + if (route !== 0) { + MapHelper.moveToRoute(route, region); + } else if (town !== null) { + MapHelper.moveToTown(town); + } + playerHasMoved = true; } } -function endLocationQuest() { - //Executed when the quest is completed - questLocationReadyToStart = false; - questLocationInProgress = false; - clearInterval(completeQuestLocationLoop); - completeQuestLocationLoop = null; - stopAutoDungeon(); - stopAutoGym(); - playerResetState(); +function playerCanMove() { + return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() + && !DungeonBattle.catching() && !GymRunner.running() } -function completeUsePokeballQuest(pokeballQuest) { - //If the script has to change the pokeball for a capture, we wait until it has reset the selected already caught pokeball - if (!questPokeballInProgress && !pokeballChangedForCapturePokemonQuest) { - //Remove use pokeball quest for current cycle if total pokeball needed not available - if(!playerHasPokeballForPokemonQuest(pokeballQuest.pokeball, pokeballQuest.progressText())) { - removeQuestTemporarily(pokeballQuest); - endPokeballQuest(); - return; - } +function playerCanPayDungeonEntrance(dungeonName, progressText) { + const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon + let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); + let dungeonCost = dungeon.tokenCost; + let progress = progressText.split('/').map(element => parseInt(element.trim())); + let amountRemaining = progress[1] - progress[0]; + return getTokens >= dungeonCost * amountRemaining; +} - questPokeballInProgress = true; +function playerHasPokeballs(pokeball, progressText = null) { + let amountRemaining; + if (progressText) { + const progress = progressText.split('/').map(element => parseInt(element.trim())); + amountRemaining = progress[1] - progress[0]; + } else { + amountRemaining = 1; + } + return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; +} - //Save and set pokeball already caught selection - if (!questPokeballReadyToStart) { - playerSavePokeballAlreadyCaught(); - } - playerSetAlreadyCaughtPokeball(pokeballQuest.pokeball) +function playerSavePokeballAlreadyCaught() { + pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + questPokeballReadyToStart = true; +} - completeQuestPokeballLoop = setInterval(function() { - if(pokeballQuest.notified) { - endPokeballQuest() - } - }, 1000); +function playerSetAlreadyCaughtPokeball(pokeball) { + if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { + App.game.pokeballs._alreadyCaughtSelection(pokeball); } } -function endPokeballQuest() { - //Executed when the quest is completed - questPokeballInProgress = false; - clearInterval(completeQuestPokeballLoop); - completeQuestPokeballLoop = null; - if (questPokeballReadyToStart) { - playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); - questPokeballReadyToStart = false; +function playerBestPokeballAvailable() { + //Check if player have pokeball to catch pokemon + let pokeball = -1; + for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { + if (playerHasPokeballs(i)) { + pokeball = i; + break; + } } + return pokeball; } -function completeCapturePokemonsQuest(captureQuest) { - //Can't use hatchery without autohatchery - if(!hatcheryStart) return; +function changePokeballForPokemonQuest(quest) { + if (!pokeballChangedForCapturePokemonQuest && App.game.pokeballs.alreadyCaughtSelection >= GameConstants.Pokeball.Ultraball) return; + if (App.game.gameState !== GameConstants.GameState.fighting) return; + if (Battle.catching()) return; - //No need to run the code if autohatchery is enabled - if(hatcheryStart.classList.contains("btn-success")) { - return; - } - if(!questCapturePokemonsReadyToStart) { - if (!questCapturePokemonTypesInProgress) { - playerSaveHatcheryState(); + let forceCapture = false; + if (quest instanceof CapturePokemonTypesQuest) { + if (quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { + forceCapture = true; + } + } + if (quest instanceof CatchShiniesQuest) { + if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { + forceCapture = true; } - questCapturePokemonsReadyToStart = true; - } - - if (!questCapturePokemonsInProgress) { - questCapturePokemonsInProgress = true; - if (!questCapturePokemonTypesInProgress) { - //Set all filter breeding to default to avoid empty list - BreedingController.filter.category(-1) - BreedingController.filter.shinyStatus(-2) - BreedingController.filter.region(-2) - BreedingController.filter.type1(-2) - BreedingController.filter.type2(-2) - Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient - Settings.getSetting('hatcherySortDirection').observableValue(true) + } + if (quest instanceof UseOakItemQuest) { + if (quest.item === OakItemType.Magic_Ball) { + forceCapture = true; } + } - completeQuestCapturePokemonsLoop = setInterval(function() { - if(!captureQuest.notified) { - if(hatcheryStart.classList.contains("btn-danger")) { - hatcheryStart.click(); - } - } else { - endCapturePokemonsQuest() - } - }, 5000); + if (forceCapture) { + //Check if player have pokeball to catch pokemon + let pokeball = playerBestPokeballAvailable(); + if (pokeball === -1) return; + previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + playerSetAlreadyCaughtPokeball(pokeball) + pokeballChangedForCapturePokemonQuest = true; + } else if (pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect) + pokeballChangedForCapturePokemonQuest = true; } } -function endCapturePokemonsQuest() { - questCapturePokemonsReadyToStart = false; - questCapturePokemonsInProgress = false; - clearInterval(completeQuestCapturePokemonsLoop) - completeQuestCapturePokemonsLoop = null; - if (!questCapturePokemonTypesInProgress) { - playerResetHatcheryState() +function endLocationQuest() { + //Executed when the quest is completed + if (locationQuestInProgress) { + locationQuestInProgress = false; + stopAutoDungeon(); + stopAutoGym(); + playerResetState(); + playerHasMoved = false; } } -function completeCapturePokemonTypesQuest(captureQuest) { - //Can't use hatchery without autohatchery - if(!hatcheryStart) return; +function endUsePokeballQuest() { + //Executed when the quest is completed + usePokeballQuestInProgress = false; + if (pokeballAlreadyCaughtSelect !== undefined) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); + } +} - if(!questCapturePokemonTypesReadyToStart) { - if (!questCapturePokemonsReadyToStart) { - playerSaveHatcheryState(); - } - questCapturePokemonTypesReadyToStart = true; - } - - if (!questCapturePokemonTypesInProgress) { - questCapturePokemonTypesInProgress = true; - //Set all filter breeding to default to avoid empty list - BreedingController.filter.category(-1) - BreedingController.filter.shinyStatus(-2) - BreedingController.filter.region(-2) - BreedingController.filter.type1(captureQuest.type) - BreedingController.filter.type2(-2) - Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient - Settings.getSetting('hatcherySortDirection').observableValue(true) - - completeQuestCapturePokemonTypesLoop = setInterval(function() { - if(!captureQuest.notified) { - if(hatcheryStart.classList.contains("btn-danger")) { - hatcheryStart.click(); - } - } else { - endCapturePokemonTypesQuest() - } - }, 5000); +function endCapturePokemonsQuest() { + capturePokemonsQuestInProgress = false; + if (!capturePokemonTypesQuestInProgress) { + playerResetHatcheryFilters() } } function endCapturePokemonTypesQuest() { - questCapturePokemonTypesReadyToStart = false; - questCapturePokemonTypesInProgress = false; - clearInterval(completeQuestCapturePokemonTypesLoop) - completeQuestCapturePokemonTypesLoop = null; - if (!questCapturePokemonsInProgress) { - playerResetHatcheryState() + capturePokemonTypesQuestInProgress = false; + if (!capturePokemonsQuestInProgress) { + playerResetHatcheryFilters() } else { //Set type1 to all if pokemon quest capture is in progress BreedingController.filter.type1(-2) } } -function changePokeballForPokemonQuest() { - let catchShiniesQuest = App.game.quests.currentQuests().filter(x => x instanceof CatchShiniesQuest); - let capturePokemonTypesQuest = App.game.quests.currentQuests().filter(x => x instanceof CapturePokemonTypesQuest); +function completeDefeatGymQuest(quest) { + if(!locationQuestInProgress) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + locationQuestInProgress = true; + } + //Find town associate to gym + const gymListAsArray = Object.entries(GymList); + const town = gymListAsArray.filter(([key, value]) => key === quest.gymTown)[0][1]; - let forceCapture = false; - if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball || pokeballChangedForCapturePokemonQuest) { - if (catchShiniesQuest.length > 0) { - if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { - forceCapture = true; - } - } - if (capturePokemonTypesQuest.length > 0) { - for(const quest of capturePokemonTypesQuest) { - //Check if pokemon type is catchable - if(quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { - forceCapture = true; - break; - } - } - } + //Move player to quest town + if (!playerHasMoved) { + playerMoveTo(town.parent.region, town.parent.name, 0) + } - if (forceCapture && !Battle.catching()) { - //Check if player have pokeball to catch pokemon - let pokeball = -1; - for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { - if (playerHasPokeballForPokemonQuest(i)) { - pokeball = i; - break; - } - } - if (pokeball === -1) { - //Pokeball not available - return; - } - if (!pokeballChangedForCapturePokemonQuest) { - playerSavePreviousPokeballAlreadyCaught(); + //Find gym in town + if(player.town().name === town.parent.name) { + for(const gym of player.town().content) { + if(gym.town === quest.gymTown && App.game.gameState !== GameConstants.GameState.gym) { + gym.protectedOnclick(); } - playerSetAlreadyCaughtPokeball(pokeball) - } else if (forceCapture && Battle.catching() && pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); - pokeballChangedForCapturePokemonQuest = false; - } else if (pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); - pokeballChangedForCapturePokemonQuest = false; } } } -function playerSaveState() { - //Save last location of player in temp variable - regionSelect = player.region; - subRegionSelect = player.subregion; - routeSelect = player.route(); - townSelect = player.town().name; - - if(dungeonStart && dungeonStart.classList.contains("btn-danger")) { - dungeonStateSelect = false; - } else if(dungeonStart && dungeonStart.classList.contains("btn-success")) { - dungeonStateSelect = true; - } - if(gymStart && gymStart.classList.contains("btn-danger")) { - gymStateSelect = false; - } else if(gymStart && gymStart.classList.contains("btn-success")) { - gymStateSelect = true; +function completeDefeatPokemonQuest(quest) { + if(!locationQuestInProgress) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + locationQuestInProgress = true; } -} - -function playerSavePokeballAlreadyCaught() { - pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; - questPokeballReadyToStart = true; -} -function playerSavePreviousPokeballAlreadyCaught() { - previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; - pokeballChangedForCapturePokemonQuest = true; + //Move player to quest route + if (!playerHasMoved) { + playerMoveTo(quest.region, null, quest.route) + } } -function playerSaveHatcheryState() { - hatcheryCategorySelect = BreedingController.filter.category() - hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus() - hatcheryRegionSelect = BreedingController.filter.region() - hatcheryType1Select = BreedingController.filter.type1() - hatcheryType2Select = BreedingController.filter.type2() - hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue() - hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue() +function completeDefeatDungeonQuest(dungeonQuest) { + //Can't farm the dungeons without the autoclicker + if(!autoDungeon) return; - if(hatcheryStart && hatcheryStart.classList.contains("btn-danger")) { - hatcheryStateSelect = false; - } else if(hatcheryStart && hatcheryStart.classList.contains("btn-success")) { - hatcheryStateSelect = true; + //Remove dungeon quest for current cycle if total token needed not available + if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { + removeQuestTemporarily(dungeonQuest); + return; } -} -function playerResetHatcheryState() { - BreedingController.filter.category(hatcheryCategorySelect) - BreedingController.filter.shinyStatus(hatcheryShinyStatusSelect) - BreedingController.filter.region(hatcheryRegionSelect) - BreedingController.filter.type1(hatcheryType1Select) - BreedingController.filter.type2(hatcheryType2Select) - Settings.getSetting('hatcherySort').observableValue(hatcherySortSelect) - Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirectionSelect) - if (hatcheryStart) { - if(hatcheryStateSelect && !hatcheryStart.classList.contains("btn-success")) { - hatcheryStart.click(); - } else if(!hatcheryStateSelect && !hatcheryStart.classList.contains("btn-danger")) { - hatcheryStart.click(); - } + if(!locationQuestInProgress) { + playerSaveState(); + stopAutoGym(); + locationQuestInProgress = true; } -} -function playerResetState() { - if(regionSelect && player.region !== regionSelect) { - player.region = regionSelect; - } - if(subRegionSelect && player.subregion !== subRegionSelect) { - player.subregion = subRegionSelect; - } - if(routeSelect && player.route() !== routeSelect) { - MapHelper.moveToRoute(routeSelect, regionSelect); - } - if(townSelect && routeSelect === 0) { - MapHelper.moveToTown(townSelect); - } - if (dungeonStart) { - if(dungeonStateSelect && !dungeonStart.classList.contains("btn-success")) { - dungeonStart.click(); - } else if(!dungeonStateSelect && !dungeonStart.classList.contains("btn-danger")) { - dungeonStart.click(); - } - } - if (gymStart) { - if(gymStateSelect && !gymStart.classList.contains("btn-success")) { - gymStart.click(); - } else if(!gymStateSelect && !gymStart.classList.contains("btn-danger")) { - gymStart.click(); - } + //Move player to quest dungeon + if (!playerHasMoved) { + playerMoveTo(dungeonQuest.region, dungeonQuest.dungeon, 0) } -} -function playerCanMove() { - return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() && !DungeonBattle.catching() && !GymRunner.running() -} - -function playerMoveToTown(town, region) { - if(player.region !== region || player.town().name !== town) { - player.region = region; - if(region === 6) { - setAlolaSubRegion(town) - } else { - player.subregion = 0 + if(player.town().name === dungeonQuest.dungeon) { + if(autoDungeon && !autoDungeon.classList.contains("btn-success")) { + autoDungeon.click(); } - MapHelper.moveToTown(town); } } -function playerMoveToRoute(route, region) { - if(player.region !== region || player.route() !== route) { - player.region = region; - if(region === 6) { - setAlolaSubRegion(route) - } else { - player.subregion = 0 +function completeUsePokeballQuest(pokeballQuest) { + if (!usePokeballQuestInProgress) { + //Remove use pokeball quest for current cycle if total pokeball needed not available + if(!playerHasPokeballs(pokeballQuest.pokeball, pokeballQuest.progressText())) { + removeQuestTemporarily(pokeballQuest); + return; } - MapHelper.moveToRoute(route, region); + + playerSavePokeballAlreadyCaught(); + playerSetAlreadyCaughtPokeball(pokeballQuest.pokeball) + usePokeballQuestInProgress = true; } } -function playerCanPayDungeonEntrance(dungeonName, progressText) { - const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon - let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); - let dungeonCost = dungeon.tokenCost; - let progress = progressText.split('/').map(element => parseInt(element.trim())); - let amountRemaining = progress[1] - progress[0]; - return getTokens >= dungeonCost * amountRemaining; -} +function completeCapturePokemonsQuest() { + //Can't use hatchery without autohatchery + if(!autoHatchery) return; -function playerHasPokeballForPokemonQuest(pokeball, progressText = null) { - let amountRemaining = 0; - if (progressText) { - const progress = progressText.split('/').map(element => parseInt(element.trim())); - amountRemaining = progress[1] - progress[0]; - } else { - amountRemaining = 1; - } - return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; -} + if (!capturePokemonsQuestInProgress && !capturePokemonTypesQuestInProgress) { + if (!capturePokemonTypesQuestInProgress) { + playerSaveHatcheryFilters(); + } -function playerSetAlreadyCaughtPokeball(pokeball) { - if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { - App.game.pokeballs._alreadyCaughtSelection(pokeball); - } -} + capturePokemonsQuestInProgress = true; + playerSetHatcheryFilters(-1, -2, -2, -2, -2, 6, true) -function stopAutoDungeon() { - if(dungeonStart && !dungeonStart.classList.contains("btn-danger")) { - dungeonStart.click(); + if(autoHatchery.classList.contains("btn-danger")) { + autoHatchery.click(); + } } } -function stopAutoGym() { - if(gymStart && !gymStart.classList.contains("btn-danger")) { - gymStart.click(); +function completeCapturePokemonTypesQuest(captureQuest) { + //Can't use hatchery without autohatchery + if(!autoHatchery) return; + + if(!capturePokemonTypesQuestInProgress) { + if (!capturePokemonsQuestInProgress) { + playerSaveHatcheryFilters(); + } + playerSetHatcheryFilters(-1, -2, -2, captureQuest.type, -2, 6, true) + capturePokemonTypesQuestInProgress = true; + if(autoHatchery.classList.contains("btn-danger")) { + autoHatchery.click(); + } } } -function setAlolaSubRegion(locationName) { +function getAlolaSubRegionFromLocation(locationName) { //TODO: Find a solution to retrieve locations by sub-region in a programmatic way //On Alola map subregion not available on Town, Route or Dungeon //Location found from https://github.com/pokeclicker/pokeclicker/blob/ff8b53478cf714c61de8b33d73cd1275ce785688/src/components/AlolaSVG.html @@ -722,10 +591,11 @@ function setAlolaSubRegion(locationName) { const alolaSubregion2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 12", "Route 13", "Haina Desert", "Route 14", "Route 15", "Route 16", "Route 17", "Poni Wilds", "Ancient Poni Path", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Aether Paradise", "Malie City", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Vast Poni Canyon", "Lake of the Sunne and Moone"]; if(alolaSubregion0.includes(locationName)) { - player.subregion = 0 + return 0; } else if(alolaSubregion1.includes(locationName)) { - player.subregion = 1 + return 1; } else if(alolaSubregion2.includes(locationName)) { - player.subregion = 2 + return 2; } + return 0; } \ No newline at end of file From b2769c8d19ba998c64acd13bff6403f6275fd126 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Thu, 9 Jun 2022 01:50:26 +0200 Subject: [PATCH 15/17] Revert "Avoids that the buttons of other scripts do not exist yet" This reverts commit 206981fa --- custom/autoquestcompleter.user.js | 781 +++++++++++++++++------------- 1 file changed, 454 insertions(+), 327 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index 47c4f20a..e44a8e16 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -11,16 +11,27 @@ let questTypes = []; let autoQuestCanBeStopped; -let locationQuestInProgress = false; -let usePokeballQuestInProgress = false; -let capturePokemonsQuestInProgress = false; -let capturePokemonTypesQuestInProgress = false; +let questLocationReadyToStart = false; +let questLocationInProgress = false; +let completeQuestLocationLoop; +let questPokeballReadyToStart = false; +let questPokeballInProgress = false; +let completeQuestPokeballLoop; +let questCapturePokemonsReadyToStart = false; +let questCapturePokemonsInProgress = false; +let completeQuestCapturePokemonsLoop; +let questCapturePokemonTypesReadyToStart = false; +let questCapturePokemonTypesInProgress = false; +let completeQuestCapturePokemonTypesLoop; +let pokeballChangedForCapturePokemonQuest = false; let regionSelect; let subRegionSelect; let routeSelect; let townSelect; let dungeonStateSelect; let gymStateSelect; +let pokeballAlreadyCaughtSelect; +let previousPokeballAlreadyCaughtSelect; let hatcheryCategorySelect; let hatcheryShinyStatusSelect; let hatcheryRegionSelect; @@ -29,13 +40,10 @@ let hatcheryType2Select; let hatcherySortSelect; let hatcherySortDirectionSelect; let hatcheryStateSelect; -let autoGym; -let autoDungeon; -let autoHatchery; -let playerHasMoved = false; -let pokeballAlreadyCaughtSelect; -let pokeballChangedForCapturePokemonQuest; -let previousPokeballAlreadyCaughtSelect; +let dungeonQuestEnable; +let gymStart; +let dungeonStart; +let hatcheryStart; function initAutoQuests(){ //Allows to start infinite quests @@ -47,7 +55,6 @@ function initAutoQuests(){ localStorage.setItem('autoQuestEnable', 'true') } //Define quest types - let questTypes = []; if (localStorage.getItem('autoQuestTypes') == null){ for (const type in QuestHelper.quests) { questTypes.push(type); @@ -55,6 +62,7 @@ function initAutoQuests(){ localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)) } else { questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); + dungeonQuestEnable = questTypes.includes("DefeatDungeonQuest"); } resetQuestModify(); //Track the last refresh @@ -79,22 +87,19 @@ function initAutoQuests(){ document.getElementById('toggle-auto-quest').textContent = 'Auto [ON]' } }, false) - - //Avoids that the buttons of other scripts do not exist yet - setTimeout(function() { - autoGym = document.getElementById("auto-gym-start"); - autoDungeon = document.getElementById("auto-dungeon-start"); - autoHatchery = document.getElementById("auto-hatch-start"); - }, 1000); - + //Retrieving autoclicker buttons + gymStart = document.getElementById("auto-gym-start"); + dungeonStart = document.getElementById("auto-dungeon-start"); + hatcheryStart = document.getElementById("auto-hatch-start"); //Checks for new quests to add to the list and claims completed ones var autoQuest = setInterval(function(){ let questsNeed = 0; if (trackRefresh != App.game.quests.lastRefresh) { + trackRefresh = App.game.quests.lastRefresh; + stopCompleteQuestLocation(); //Reload quest types from local storage to re-enter the dungeon if they are deleted because there are not enough dungeon tokens left. questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); - trackRefresh = App.game.quests.lastRefresh; resetQuestModify(); } if (localStorage.getItem('autoQuestEnable') == 'true'){ @@ -108,15 +113,43 @@ function initAutoQuests(){ } }) if (App.game.quests.currentQuests().length > 0){ - //Claim all completed quest & check if quests should refresh App.game.quests.currentQuests().forEach(quest => { if (quest.notified == true){ + //Claim all completed quest App.game.quests.claimQuest(quest.index) - endQuest(quest); + } else { + //Processes quests with location + if(!questLocationInProgress) { + if(quest instanceof DefeatGymQuest) { + completeDefeatGymQuest(quest) + } else if(quest instanceof DefeatPokemonsQuest) { + completeDefeatPokemonQuest(quest) + } else if(quest instanceof DefeatDungeonQuest) { + completeDefeatDungeonQuest(quest) + } + } + if (!questCapturePokemonsInProgress) { + if (quest instanceof CapturePokemonsQuest) { + completeCapturePokemonsQuest(quest) + } + } + if (!questCapturePokemonTypesInProgress) { + if (quest instanceof CapturePokemonTypesQuest) { + completeCapturePokemonTypesQuest(quest) + } + } + if (!questPokeballInProgress) { + if (quest instanceof UsePokeballQuest) { + completeUsePokeballQuest(quest) + } + } } - else { - startQuest(quest); + //Complete quest when you use pokeball to capture pokemon like shiny and type + if (App.game.gameState === GameConstants.GameState.fighting) { + changePokeballForPokemonQuest() } + + //Check if quests should refresh if (questTypes.includes(quest.constructor.name)) { questsNeed++; } @@ -129,9 +162,13 @@ function initAutoQuests(){ } } else if (autoQuestCanBeStopped) { autoQuestCanBeStopped = false; - App.game.quests.questList().forEach(quest => { - endQuest(quest); - }) + endCapturePokemonsQuest(); + endCapturePokemonTypesQuest(); + endPokeballQuest(); + stopCompleteQuestLocation(); + if (pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); + } } }, 500) @@ -140,13 +177,15 @@ function initAutoQuests(){ const questHTML = document.getElementById('QuestModal').querySelector('tbody').children; for (let i = 0; i < questHTML.length; i++) { questHTML[i].querySelector('td:nth-child(1)').setAttribute('data-src', i); + questHTML[i].classList.add("clickable"); questHTML[i].addEventListener('click', () => {retrieveQuestName(event)}) } } function retrieveQuestName(event) { const index = +event.target.getAttribute('data-src'); - const questName = App.game.quests.questList()[index].constructor.name; + const quest = App.game.quests.questList()[index]; + const questName = quest.constructor.name const indexPos = questTypes.indexOf(questName); if (indexPos != -1) { questTypes[indexPos] = null; @@ -154,44 +193,38 @@ function initAutoQuests(){ const empty = questTypes.indexOf(null); questTypes[empty] = questName; } - localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); - } - function startQuest(quest) { - if(quest instanceof DefeatGymQuest) { - completeDefeatGymQuest(quest); - } else if(quest instanceof DefeatPokemonsQuest) { - completeDefeatPokemonQuest(quest); - } else if(quest instanceof DefeatDungeonQuest) { - completeDefeatDungeonQuest(quest); - } else if (quest instanceof UsePokeballQuest) { - completeUsePokeballQuest(quest); - } else if (quest instanceof CatchShiniesQuest) { - changePokeballForPokemonQuest(quest); - } else if (quest instanceof CapturePokemonsQuest) { - completeCapturePokemonsQuest(); - } else if (quest instanceof CapturePokemonTypesQuest) { - changePokeballForPokemonQuest(quest); - completeCapturePokemonTypesQuest(quest); - } else if (quest instanceof UseOakItemQuest) { - changePokeballForPokemonQuest(quest); + //Stop current quests in progress + if(questLocationInProgress && (quest instanceof DefeatGymQuest || quest instanceof DefeatPokemonsQuest || quest instanceof DefeatDungeonQuest)) { + stopCompleteQuestLocation(); + } else if (questCapturePokemonsInProgress && quest instanceof CapturePokemonsQuest) { + endCapturePokemonsQuest(); + } else if (questCapturePokemonTypesInProgress && quest instanceof CapturePokemonTypesQuest) { + endCapturePokemonTypesQuest(); + } else if (questPokeballInProgress && quest instanceof UsePokeballQuest) { + endPokeballQuest(); } + localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); } - function endQuest(quest) { - if(quest instanceof DefeatGymQuest) { - endLocationQuest(quest); - } else if(quest instanceof DefeatPokemonsQuest) { - endLocationQuest(quest); - } else if(quest instanceof DefeatDungeonQuest) { - endLocationQuest(quest); - }else if (quest instanceof UsePokeballQuest) { - endUsePokeballQuest(quest); - } else if (quest instanceof CapturePokemonsQuest) { - endCapturePokemonsQuest(quest); - } else if (quest instanceof CapturePokemonTypesQuest) { - endCapturePokemonTypesQuest(quest); + function stopCompleteQuestLocation() { + if(questLocationInProgress) { + //Reset loop when quest is refreshed or auto quest is disabled + if(typeof completeQuestLocationLoop !== 'undefined') { + clearInterval(completeQuestLocationLoop); + completeQuestLocationLoop = null; + } + stopAutoDungeon(); + stopAutoGym(); + let resetPlayerStateLoop = setInterval(function() { + if(playerCanMove()) { + playerResetState(); + clearInterval(resetPlayerStateLoop); + } + }, 50); + questLocationInProgress = false; } + questLocationReadyToStart = false; } } @@ -232,357 +265,452 @@ function removeQuestTemporarily(quest) { } } -function stopAutoDungeon() { - if(autoDungeon && !autoDungeon.classList.contains("btn-danger")) { - autoDungeon.click(); - } -} +function completeDefeatDungeonQuest(dungeonQuest) { + //Can't farm the dungeons without the autoclicker + if(!dungeonStart) return; -function stopAutoGym() { - if (autoGym && !autoGym.classList.contains("btn-danger")) { - autoGym.click(); + //Remove dungeon quest for current cycle if total token needed not available + if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { + removeQuestTemporarily(dungeonQuest); + endLocationQuest(); + return; } -} -function playerSaveState() { - //Save last location of player in temp variable - regionSelect = player.region; - subRegionSelect = player.subregion; - routeSelect = player.route(); - townSelect = player.town().name; - - if(autoDungeon && autoDungeon.classList.contains("btn-danger")) { - dungeonStateSelect = false; - } else if(autoDungeon && autoDungeon.classList.contains("btn-success")) { - dungeonStateSelect = true; - } - if(autoGym && autoGym.classList.contains("btn-danger")) { - gymStateSelect = false; - } else if(autoGym && autoGym.classList.contains("btn-success")) { - gymStateSelect = true; + if(!questLocationReadyToStart) { + playerSaveState(); + stopAutoGym(); + questLocationReadyToStart = true; } -} -function playerResetState() { - playerMoveTo(regionSelect, townSelect, routeSelect) - if (autoDungeon) { - if(dungeonStateSelect && !autoDungeon.classList.contains("btn-success")) { - autoDungeon.click(); - } else if(!dungeonStateSelect && !autoDungeon.classList.contains("btn-danger")) { - autoDungeon.click(); - } + //Move player to quest dungeon + if (playerCanMove()) { + playerMoveToTown(dungeonQuest.dungeon, dungeonQuest.region); } - if (autoGym) { - if(gymStateSelect && !autoGym.classList.contains("btn-success")) { - autoGym.click(); - } else if(!gymStateSelect && !autoGym.classList.contains("btn-danger")) { - autoGym.click(); - } + + if(player.town().name === dungeonQuest.dungeon) { + questLocationInProgress = true; + completeQuestLocationLoop = setInterval(function() { + if(!dungeonQuest.notified) { + if(dungeonStart && !dungeonStart.classList.contains("btn-success")) { + dungeonStart.click(); + } + } else if(playerCanMove()) { + endLocationQuest(); + } + }, 50); } } -function playerSaveHatcheryFilters() { - hatcheryCategorySelect = BreedingController.filter.category() - hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus() - hatcheryRegionSelect = BreedingController.filter.region() - hatcheryType1Select = BreedingController.filter.type1() - hatcheryType2Select = BreedingController.filter.type2() - hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue() - hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue() +function completeDefeatGymQuest(gymQuest) { + //Find town associate to gym + const gymListAsArray = Object.entries(GymList); + const town = gymListAsArray.filter(([key, value]) => key === gymQuest.gymTown)[0][1]; - if(autoHatchery && autoHatchery.classList.contains("btn-danger")) { - hatcheryStateSelect = false; - } else if(autoHatchery && autoHatchery.classList.contains("btn-success")) { - hatcheryStateSelect = true; + if(!questLocationReadyToStart) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + questLocationReadyToStart = true; + } + //Move player to quest town + if (playerCanMove()) { + playerMoveToTown(town.parent.name, town.parent.region); } -} -function playerResetHatcheryFilters() { - playerSetHatcheryFilters(hatcheryCategorySelect, hatcheryShinyStatusSelect, hatcheryRegionSelect, hatcheryType1Select, hatcheryType2Select, hatcherySortSelect, hatcherySortDirectionSelect) - if (autoHatchery) { - if(hatcheryStateSelect && !autoHatchery.classList.contains("btn-success")) { - autoHatchery.click(); - } else if(!hatcheryStateSelect && !autoHatchery.classList.contains("btn-danger")) { - autoHatchery.click(); + if(player.town().name === town.parent.name) { + //Find gym in town + for(const gym of player.town().content) { + if(gym.town === gymQuest.gymTown) { + questLocationInProgress = true; + completeQuestLocationLoop = setInterval(function() { + if(!gymQuest.notified) { + if(App.game.gameState !== GameConstants.GameState.gym) { + gym.protectedOnclick(); + } + } else if(playerCanMove()) { + endLocationQuest(); + } + }, 50); + } } } } -function playerSetHatcheryFilters(category, shinyStatus, region, type1, type2, hatcherySort, hatcherySortDirection) { - if (BreedingController.filter.category() !== category) { - BreedingController.filter.category(category) - } - if (BreedingController.filter.shinyStatus() !== shinyStatus) { - BreedingController.filter.shinyStatus(shinyStatus) - } - if (BreedingController.filter.region() !== region) { - BreedingController.filter.region(region) - } - if (BreedingController.filter.type1() !== type1) { - BreedingController.filter.type1(type1) - } - if (BreedingController.filter.type2() !== type2) { - BreedingController.filter.type2(type2) - } - if (Settings.getSetting('hatcherySort').observableValue() !== hatcherySort) { - Settings.getSetting('hatcherySort').observableValue(hatcherySort) // Breeding efficient - } - if (Settings.getSetting('hatcherySort').observableValue() !== hatcherySortDirection) { - Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirection) +function completeDefeatPokemonQuest(pokemonQuest) { + if(!questLocationReadyToStart) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + questLocationReadyToStart = true; } -} -function playerMoveTo(region, town, route) { + //Move player to quest route if (playerCanMove()) { - if (region === 6) { - player.subregion = getAlolaSubRegionFromLocation(town) - } - if (route !== 0) { - MapHelper.moveToRoute(route, region); - } else if (town !== null) { - MapHelper.moveToTown(town); - } - playerHasMoved = true; + playerMoveToRoute(pokemonQuest.route, pokemonQuest.region); } -} -function playerCanMove() { - return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() - && !DungeonBattle.catching() && !GymRunner.running() + if(player.route() === pokemonQuest.route && player.region === pokemonQuest.region) { + questLocationInProgress = true; + completeQuestLocationLoop = setInterval(function() { + if(pokemonQuest.notified) { + endLocationQuest(); + } + }, 50); + } } -function playerCanPayDungeonEntrance(dungeonName, progressText) { - const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon - let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); - let dungeonCost = dungeon.tokenCost; - let progress = progressText.split('/').map(element => parseInt(element.trim())); - let amountRemaining = progress[1] - progress[0]; - return getTokens >= dungeonCost * amountRemaining; +function endLocationQuest() { + //Executed when the quest is completed + questLocationReadyToStart = false; + questLocationInProgress = false; + clearInterval(completeQuestLocationLoop); + completeQuestLocationLoop = null; + stopAutoDungeon(); + stopAutoGym(); + playerResetState(); } -function playerHasPokeballs(pokeball, progressText = null) { - let amountRemaining; - if (progressText) { - const progress = progressText.split('/').map(element => parseInt(element.trim())); - amountRemaining = progress[1] - progress[0]; - } else { - amountRemaining = 1; - } - return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; -} +function completeUsePokeballQuest(pokeballQuest) { + //If the script has to change the pokeball for a capture, we wait until it has reset the selected already caught pokeball + if (!questPokeballInProgress && !pokeballChangedForCapturePokemonQuest) { + //Remove use pokeball quest for current cycle if total pokeball needed not available + if(!playerHasPokeballForPokemonQuest(pokeballQuest.pokeball, pokeballQuest.progressText())) { + removeQuestTemporarily(pokeballQuest); + endPokeballQuest(); + return; + } -function playerSavePokeballAlreadyCaught() { - pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; - questPokeballReadyToStart = true; -} + questPokeballInProgress = true; -function playerSetAlreadyCaughtPokeball(pokeball) { - if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { - App.game.pokeballs._alreadyCaughtSelection(pokeball); + //Save and set pokeball already caught selection + if (!questPokeballReadyToStart) { + playerSavePokeballAlreadyCaught(); + } + playerSetAlreadyCaughtPokeball(pokeballQuest.pokeball) + + completeQuestPokeballLoop = setInterval(function() { + if(pokeballQuest.notified) { + endPokeballQuest() + } + }, 1000); } } -function playerBestPokeballAvailable() { - //Check if player have pokeball to catch pokemon - let pokeball = -1; - for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { - if (playerHasPokeballs(i)) { - pokeball = i; - break; - } +function endPokeballQuest() { + //Executed when the quest is completed + questPokeballInProgress = false; + clearInterval(completeQuestPokeballLoop); + completeQuestPokeballLoop = null; + if (questPokeballReadyToStart) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); + questPokeballReadyToStart = false; } - return pokeball; } -function changePokeballForPokemonQuest(quest) { - if (!pokeballChangedForCapturePokemonQuest && App.game.pokeballs.alreadyCaughtSelection >= GameConstants.Pokeball.Ultraball) return; - if (App.game.gameState !== GameConstants.GameState.fighting) return; - if (Battle.catching()) return; +function completeCapturePokemonsQuest(captureQuest) { + //Can't use hatchery without autohatchery + if(!hatcheryStart) return; + //No need to run the code if autohatchery is enabled + if(hatcheryStart.classList.contains("btn-success")) { + return; + } - let forceCapture = false; - if (quest instanceof CapturePokemonTypesQuest) { - if (quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { - forceCapture = true; + if(!questCapturePokemonsReadyToStart) { + if (!questCapturePokemonTypesInProgress) { + playerSaveHatcheryState(); } - } - if (quest instanceof CatchShiniesQuest) { - if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { - forceCapture = true; + questCapturePokemonsReadyToStart = true; + } + + if (!questCapturePokemonsInProgress) { + questCapturePokemonsInProgress = true; + if (!questCapturePokemonTypesInProgress) { + //Set all filter breeding to default to avoid empty list + BreedingController.filter.category(-1) + BreedingController.filter.shinyStatus(-2) + BreedingController.filter.region(-2) + BreedingController.filter.type1(-2) + BreedingController.filter.type2(-2) + Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient + Settings.getSetting('hatcherySortDirection').observableValue(true) } - } - if (quest instanceof UseOakItemQuest) { - if (quest.item === OakItemType.Magic_Ball) { - forceCapture = true; - } - } - if (forceCapture) { - //Check if player have pokeball to catch pokemon - let pokeball = playerBestPokeballAvailable(); - if (pokeball === -1) return; - previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; - playerSetAlreadyCaughtPokeball(pokeball) - pokeballChangedForCapturePokemonQuest = true; - } else if (pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect) - pokeballChangedForCapturePokemonQuest = true; + completeQuestCapturePokemonsLoop = setInterval(function() { + if(!captureQuest.notified) { + if(hatcheryStart.classList.contains("btn-danger")) { + hatcheryStart.click(); + } + } else { + endCapturePokemonsQuest() + } + }, 5000); } } -function endLocationQuest() { - //Executed when the quest is completed - if (locationQuestInProgress) { - locationQuestInProgress = false; - stopAutoDungeon(); - stopAutoGym(); - playerResetState(); - playerHasMoved = false; +function endCapturePokemonsQuest() { + questCapturePokemonsReadyToStart = false; + questCapturePokemonsInProgress = false; + clearInterval(completeQuestCapturePokemonsLoop) + completeQuestCapturePokemonsLoop = null; + if (!questCapturePokemonTypesInProgress) { + playerResetHatcheryState() } } -function endUsePokeballQuest() { - //Executed when the quest is completed - usePokeballQuestInProgress = false; - if (pokeballAlreadyCaughtSelect !== undefined) { - playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); - } -} +function completeCapturePokemonTypesQuest(captureQuest) { + //Can't use hatchery without autohatchery + if(!hatcheryStart) return; -function endCapturePokemonsQuest() { - capturePokemonsQuestInProgress = false; - if (!capturePokemonTypesQuestInProgress) { - playerResetHatcheryFilters() + if(!questCapturePokemonTypesReadyToStart) { + if (!questCapturePokemonsReadyToStart) { + playerSaveHatcheryState(); + } + questCapturePokemonTypesReadyToStart = true; + } + + if (!questCapturePokemonTypesInProgress) { + questCapturePokemonTypesInProgress = true; + //Set all filter breeding to default to avoid empty list + BreedingController.filter.category(-1) + BreedingController.filter.shinyStatus(-2) + BreedingController.filter.region(-2) + BreedingController.filter.type1(captureQuest.type) + BreedingController.filter.type2(-2) + Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient + Settings.getSetting('hatcherySortDirection').observableValue(true) + + completeQuestCapturePokemonTypesLoop = setInterval(function() { + if(!captureQuest.notified) { + if(hatcheryStart.classList.contains("btn-danger")) { + hatcheryStart.click(); + } + } else { + endCapturePokemonTypesQuest() + } + }, 5000); } } function endCapturePokemonTypesQuest() { - capturePokemonTypesQuestInProgress = false; - if (!capturePokemonsQuestInProgress) { - playerResetHatcheryFilters() + questCapturePokemonTypesReadyToStart = false; + questCapturePokemonTypesInProgress = false; + clearInterval(completeQuestCapturePokemonTypesLoop) + completeQuestCapturePokemonTypesLoop = null; + if (!questCapturePokemonsInProgress) { + playerResetHatcheryState() } else { //Set type1 to all if pokemon quest capture is in progress BreedingController.filter.type1(-2) } } -function completeDefeatGymQuest(quest) { - if(!locationQuestInProgress) { - playerSaveState(); - stopAutoDungeon(); - stopAutoGym(); - locationQuestInProgress = true; - } - //Find town associate to gym - const gymListAsArray = Object.entries(GymList); - const town = gymListAsArray.filter(([key, value]) => key === quest.gymTown)[0][1]; +function changePokeballForPokemonQuest() { + let catchShiniesQuest = App.game.quests.currentQuests().filter(x => x instanceof CatchShiniesQuest); + let capturePokemonTypesQuest = App.game.quests.currentQuests().filter(x => x instanceof CapturePokemonTypesQuest); - //Move player to quest town - if (!playerHasMoved) { - playerMoveTo(town.parent.region, town.parent.name, 0) - } + let forceCapture = false; + if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball || pokeballChangedForCapturePokemonQuest) { + if (catchShiniesQuest.length > 0) { + if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { + forceCapture = true; + } + } + if (capturePokemonTypesQuest.length > 0) { + for(const quest of capturePokemonTypesQuest) { + //Check if pokemon type is catchable + if(quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { + forceCapture = true; + break; + } + } + } - //Find gym in town - if(player.town().name === town.parent.name) { - for(const gym of player.town().content) { - if(gym.town === quest.gymTown && App.game.gameState !== GameConstants.GameState.gym) { - gym.protectedOnclick(); + if (forceCapture && !Battle.catching()) { + //Check if player have pokeball to catch pokemon + let pokeball = -1; + for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { + if (playerHasPokeballForPokemonQuest(i)) { + pokeball = i; + break; + } + } + if (pokeball === -1) { + //Pokeball not available + return; + } + if (!pokeballChangedForCapturePokemonQuest) { + playerSavePreviousPokeballAlreadyCaught(); } + playerSetAlreadyCaughtPokeball(pokeball) + } else if (forceCapture && Battle.catching() && pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); + pokeballChangedForCapturePokemonQuest = false; + } else if (pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); + pokeballChangedForCapturePokemonQuest = false; } } } -function completeDefeatPokemonQuest(quest) { - if(!locationQuestInProgress) { - playerSaveState(); - stopAutoDungeon(); - stopAutoGym(); - locationQuestInProgress = true; - } +function playerSaveState() { + //Save last location of player in temp variable + regionSelect = player.region; + subRegionSelect = player.subregion; + routeSelect = player.route(); + townSelect = player.town().name; - //Move player to quest route - if (!playerHasMoved) { - playerMoveTo(quest.region, null, quest.route) + if(dungeonStart && dungeonStart.classList.contains("btn-danger")) { + dungeonStateSelect = false; + } else if(dungeonStart && dungeonStart.classList.contains("btn-success")) { + dungeonStateSelect = true; + } + if(gymStart && gymStart.classList.contains("btn-danger")) { + gymStateSelect = false; + } else if(gymStart && gymStart.classList.contains("btn-success")) { + gymStateSelect = true; } } -function completeDefeatDungeonQuest(dungeonQuest) { - //Can't farm the dungeons without the autoclicker - if(!autoDungeon) return; +function playerSavePokeballAlreadyCaught() { + pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + questPokeballReadyToStart = true; +} - //Remove dungeon quest for current cycle if total token needed not available - if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { - removeQuestTemporarily(dungeonQuest); - return; - } +function playerSavePreviousPokeballAlreadyCaught() { + previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + pokeballChangedForCapturePokemonQuest = true; +} - if(!locationQuestInProgress) { - playerSaveState(); - stopAutoGym(); - locationQuestInProgress = true; - } +function playerSaveHatcheryState() { + hatcheryCategorySelect = BreedingController.filter.category() + hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus() + hatcheryRegionSelect = BreedingController.filter.region() + hatcheryType1Select = BreedingController.filter.type1() + hatcheryType2Select = BreedingController.filter.type2() + hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue() + hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue() - //Move player to quest dungeon - if (!playerHasMoved) { - playerMoveTo(dungeonQuest.region, dungeonQuest.dungeon, 0) + if(hatcheryStart && hatcheryStart.classList.contains("btn-danger")) { + hatcheryStateSelect = false; + } else if(hatcheryStart && hatcheryStart.classList.contains("btn-success")) { + hatcheryStateSelect = true; } +} - if(player.town().name === dungeonQuest.dungeon) { - if(autoDungeon && !autoDungeon.classList.contains("btn-success")) { - autoDungeon.click(); +function playerResetHatcheryState() { + BreedingController.filter.category(hatcheryCategorySelect) + BreedingController.filter.shinyStatus(hatcheryShinyStatusSelect) + BreedingController.filter.region(hatcheryRegionSelect) + BreedingController.filter.type1(hatcheryType1Select) + BreedingController.filter.type2(hatcheryType2Select) + Settings.getSetting('hatcherySort').observableValue(hatcherySortSelect) + Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirectionSelect) + if (hatcheryStart) { + if(hatcheryStateSelect && !hatcheryStart.classList.contains("btn-success")) { + hatcheryStart.click(); + } else if(!hatcheryStateSelect && !hatcheryStart.classList.contains("btn-danger")) { + hatcheryStart.click(); } } } -function completeUsePokeballQuest(pokeballQuest) { - if (!usePokeballQuestInProgress) { - //Remove use pokeball quest for current cycle if total pokeball needed not available - if(!playerHasPokeballs(pokeballQuest.pokeball, pokeballQuest.progressText())) { - removeQuestTemporarily(pokeballQuest); - return; +function playerResetState() { + if(regionSelect && player.region !== regionSelect) { + player.region = regionSelect; + } + if(subRegionSelect && player.subregion !== subRegionSelect) { + player.subregion = subRegionSelect; + } + if(routeSelect && player.route() !== routeSelect) { + MapHelper.moveToRoute(routeSelect, regionSelect); + } + if(townSelect && routeSelect === 0) { + MapHelper.moveToTown(townSelect); + } + if (dungeonStart) { + if(dungeonStateSelect && !dungeonStart.classList.contains("btn-success")) { + dungeonStart.click(); + } else if(!dungeonStateSelect && !dungeonStart.classList.contains("btn-danger")) { + dungeonStart.click(); + } + } + if (gymStart) { + if(gymStateSelect && !gymStart.classList.contains("btn-success")) { + gymStart.click(); + } else if(!gymStateSelect && !gymStart.classList.contains("btn-danger")) { + gymStart.click(); } - - playerSavePokeballAlreadyCaught(); - playerSetAlreadyCaughtPokeball(pokeballQuest.pokeball) - usePokeballQuestInProgress = true; } } -function completeCapturePokemonsQuest() { - //Can't use hatchery without autohatchery - if(!autoHatchery) return; +function playerCanMove() { + return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() && !DungeonBattle.catching() && !GymRunner.running() +} - if (!capturePokemonsQuestInProgress && !capturePokemonTypesQuestInProgress) { - if (!capturePokemonTypesQuestInProgress) { - playerSaveHatcheryFilters(); +function playerMoveToTown(town, region) { + if(player.region !== region || player.town().name !== town) { + player.region = region; + if(region === 6) { + setAlolaSubRegion(town) + } else { + player.subregion = 0 } + MapHelper.moveToTown(town); + } +} - capturePokemonsQuestInProgress = true; - playerSetHatcheryFilters(-1, -2, -2, -2, -2, 6, true) - - if(autoHatchery.classList.contains("btn-danger")) { - autoHatchery.click(); +function playerMoveToRoute(route, region) { + if(player.region !== region || player.route() !== route) { + player.region = region; + if(region === 6) { + setAlolaSubRegion(route) + } else { + player.subregion = 0 } + MapHelper.moveToRoute(route, region); } } -function completeCapturePokemonTypesQuest(captureQuest) { - //Can't use hatchery without autohatchery - if(!autoHatchery) return; +function playerCanPayDungeonEntrance(dungeonName, progressText) { + const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon + let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); + let dungeonCost = dungeon.tokenCost; + let progress = progressText.split('/').map(element => parseInt(element.trim())); + let amountRemaining = progress[1] - progress[0]; + return getTokens >= dungeonCost * amountRemaining; +} - if(!capturePokemonTypesQuestInProgress) { - if (!capturePokemonsQuestInProgress) { - playerSaveHatcheryFilters(); - } - playerSetHatcheryFilters(-1, -2, -2, captureQuest.type, -2, 6, true) - capturePokemonTypesQuestInProgress = true; - if(autoHatchery.classList.contains("btn-danger")) { - autoHatchery.click(); - } +function playerHasPokeballForPokemonQuest(pokeball, progressText = null) { + let amountRemaining = 0; + if (progressText) { + const progress = progressText.split('/').map(element => parseInt(element.trim())); + amountRemaining = progress[1] - progress[0]; + } else { + amountRemaining = 1; + } + return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; +} + +function playerSetAlreadyCaughtPokeball(pokeball) { + if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { + App.game.pokeballs._alreadyCaughtSelection(pokeball); + } +} + +function stopAutoDungeon() { + if(dungeonStart && !dungeonStart.classList.contains("btn-danger")) { + dungeonStart.click(); + } +} + +function stopAutoGym() { + if(gymStart && !gymStart.classList.contains("btn-danger")) { + gymStart.click(); } } -function getAlolaSubRegionFromLocation(locationName) { +function setAlolaSubRegion(locationName) { //TODO: Find a solution to retrieve locations by sub-region in a programmatic way //On Alola map subregion not available on Town, Route or Dungeon //Location found from https://github.com/pokeclicker/pokeclicker/blob/ff8b53478cf714c61de8b33d73cd1275ce785688/src/components/AlolaSVG.html @@ -591,11 +719,10 @@ function getAlolaSubRegionFromLocation(locationName) { const alolaSubregion2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 12", "Route 13", "Haina Desert", "Route 14", "Route 15", "Route 16", "Route 17", "Poni Wilds", "Ancient Poni Path", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Aether Paradise", "Malie City", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Vast Poni Canyon", "Lake of the Sunne and Moone"]; if(alolaSubregion0.includes(locationName)) { - return 0; + player.subregion = 0 } else if(alolaSubregion1.includes(locationName)) { - return 1; + player.subregion = 1 } else if(alolaSubregion2.includes(locationName)) { - return 2; + player.subregion = 2 } - return 0; } \ No newline at end of file From a94b95a89a50529400800b7ebbece6fd1da248f8 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Sun, 12 Jun 2022 01:57:51 +0200 Subject: [PATCH 16/17] Refactoring and implementing UseOakItemQuest Magic Ball --- custom/autoquestcompleter.user.js | 816 ++++++++++++++---------------- 1 file changed, 368 insertions(+), 448 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index e44a8e16..b5bd1e95 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -11,27 +11,17 @@ let questTypes = []; let autoQuestCanBeStopped; -let questLocationReadyToStart = false; -let questLocationInProgress = false; -let completeQuestLocationLoop; -let questPokeballReadyToStart = false; -let questPokeballInProgress = false; -let completeQuestPokeballLoop; -let questCapturePokemonsReadyToStart = false; -let questCapturePokemonsInProgress = false; -let completeQuestCapturePokemonsLoop; -let questCapturePokemonTypesReadyToStart = false; -let questCapturePokemonTypesInProgress = false; -let completeQuestCapturePokemonTypesLoop; -let pokeballChangedForCapturePokemonQuest = false; +let locationQuestInProgress = false; +let usePokeballQuestInProgress = false; +let useOakMagicBallQuestInProgress = false; +let capturePokemonsQuestInProgress = false; +let capturePokemonTypesQuestInProgress = false; let regionSelect; let subRegionSelect; let routeSelect; let townSelect; let dungeonStateSelect; let gymStateSelect; -let pokeballAlreadyCaughtSelect; -let previousPokeballAlreadyCaughtSelect; let hatcheryCategorySelect; let hatcheryShinyStatusSelect; let hatcheryRegionSelect; @@ -40,10 +30,13 @@ let hatcheryType2Select; let hatcherySortSelect; let hatcherySortDirectionSelect; let hatcheryStateSelect; -let dungeonQuestEnable; -let gymStart; -let dungeonStart; -let hatcheryStart; +let autoGym; +let autoDungeon; +let autoHatchery; +let playerHasMoved = false; +let pokeballAlreadyCaughtSelect; +let pokeballChangedForCapturePokemonQuest; +let previousPokeballAlreadyCaughtSelect; function initAutoQuests(){ //Allows to start infinite quests @@ -62,7 +55,6 @@ function initAutoQuests(){ localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)) } else { questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); - dungeonQuestEnable = questTypes.includes("DefeatDungeonQuest"); } resetQuestModify(); //Track the last refresh @@ -87,19 +79,26 @@ function initAutoQuests(){ document.getElementById('toggle-auto-quest').textContent = 'Auto [ON]' } }, false) - //Retrieving autoclicker buttons - gymStart = document.getElementById("auto-gym-start"); - dungeonStart = document.getElementById("auto-dungeon-start"); - hatcheryStart = document.getElementById("auto-hatch-start"); + + //Avoids that the buttons of other scripts do not exist yet + setTimeout(function() { + autoGym = document.getElementById("auto-gym-start"); + autoDungeon = document.getElementById("auto-dungeon-start"); + autoHatchery = document.getElementById("auto-hatch-start"); + }, 1000); + //Checks for new quests to add to the list and claims completed ones var autoQuest = setInterval(function(){ let questsNeed = 0; if (trackRefresh != App.game.quests.lastRefresh) { - trackRefresh = App.game.quests.lastRefresh; - stopCompleteQuestLocation(); //Reload quest types from local storage to re-enter the dungeon if they are deleted because there are not enough dungeon tokens left. questTypes = JSON.parse(localStorage.getItem('autoQuestTypes')); + trackRefresh = App.game.quests.lastRefresh; + if (playerHasMoved) { + playerResetState(); + } + endUsePokeballQuest(); resetQuestModify(); } if (localStorage.getItem('autoQuestEnable') == 'true'){ @@ -108,48 +107,21 @@ function initAutoQuests(){ App.game.quests.questList().forEach(quest => { if (quest.inProgress() == true && !questTypes.includes(quest.constructor.name)) { App.game.quests.quitQuest(quest.index); + endQuest(quest); } else if (quest.isCompleted() == false && quest.inProgress() == false && questTypes.includes(quest.constructor.name)){ App.game.quests.beginQuest(quest.index); } }) if (App.game.quests.currentQuests().length > 0){ + //Claim all completed quest & check if quests should refresh App.game.quests.currentQuests().forEach(quest => { if (quest.notified == true){ - //Claim all completed quest App.game.quests.claimQuest(quest.index) - } else { - //Processes quests with location - if(!questLocationInProgress) { - if(quest instanceof DefeatGymQuest) { - completeDefeatGymQuest(quest) - } else if(quest instanceof DefeatPokemonsQuest) { - completeDefeatPokemonQuest(quest) - } else if(quest instanceof DefeatDungeonQuest) { - completeDefeatDungeonQuest(quest) - } - } - if (!questCapturePokemonsInProgress) { - if (quest instanceof CapturePokemonsQuest) { - completeCapturePokemonsQuest(quest) - } - } - if (!questCapturePokemonTypesInProgress) { - if (quest instanceof CapturePokemonTypesQuest) { - completeCapturePokemonTypesQuest(quest) - } - } - if (!questPokeballInProgress) { - if (quest instanceof UsePokeballQuest) { - completeUsePokeballQuest(quest) - } - } + endQuest(quest); } - //Complete quest when you use pokeball to capture pokemon like shiny and type - if (App.game.gameState === GameConstants.GameState.fighting) { - changePokeballForPokemonQuest() + else { + startQuest(quest); } - - //Check if quests should refresh if (questTypes.includes(quest.constructor.name)) { questsNeed++; } @@ -160,15 +132,17 @@ function initAutoQuests(){ App.game.quests.refreshQuests(); } } + //Check if location of player has reset + if (!locationQuestInProgress && playerHasMoved) { + playerResetState(); + } } else if (autoQuestCanBeStopped) { autoQuestCanBeStopped = false; - endCapturePokemonsQuest(); - endCapturePokemonTypesQuest(); - endPokeballQuest(); - stopCompleteQuestLocation(); - if (pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); - } + App.game.quests.questList().forEach(quest => { + endQuest(quest); + }) + } else if (playerHasMoved) { + playerResetState(); } }, 500) @@ -184,8 +158,7 @@ function initAutoQuests(){ function retrieveQuestName(event) { const index = +event.target.getAttribute('data-src'); - const quest = App.game.quests.questList()[index]; - const questName = quest.constructor.name + const questName = App.game.quests.questList()[index].constructor.name; const indexPos = questTypes.indexOf(questName); if (indexPos != -1) { questTypes[indexPos] = null; @@ -193,38 +166,50 @@ function initAutoQuests(){ const empty = questTypes.indexOf(null); questTypes[empty] = questName; } + localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); + } - //Stop current quests in progress - if(questLocationInProgress && (quest instanceof DefeatGymQuest || quest instanceof DefeatPokemonsQuest || quest instanceof DefeatDungeonQuest)) { - stopCompleteQuestLocation(); - } else if (questCapturePokemonsInProgress && quest instanceof CapturePokemonsQuest) { - endCapturePokemonsQuest(); - } else if (questCapturePokemonTypesInProgress && quest instanceof CapturePokemonTypesQuest) { - endCapturePokemonTypesQuest(); - } else if (questPokeballInProgress && quest instanceof UsePokeballQuest) { - endPokeballQuest(); + function startQuest(quest) { + if(quest instanceof DefeatGymQuest) { + completeDefeatGymQuest(quest); + } else if(quest instanceof DefeatPokemonsQuest) { + completeDefeatPokemonQuest(quest); + } else if(quest instanceof DefeatDungeonQuest) { + completeDefeatDungeonQuest(quest); + } else if (quest instanceof UsePokeballQuest) { + completeUsePokeballQuest(quest); + } else if (quest instanceof CatchShiniesQuest) { + changePokeballForPokemonQuest(); + } else if (quest instanceof CapturePokemonsQuest) { + completeCapturePokemonsQuest(); + } else if (quest instanceof CapturePokemonTypesQuest) { + changePokeballForPokemonQuest(); + completeCapturePokemonTypesQuest(quest); + } else if (quest instanceof UseOakItemQuest) { + if (quest.item === OakItemType.Magic_Ball) { + completeUseOakMagicBallQuest(quest); + } } - localStorage.setItem('autoQuestTypes', JSON.stringify(questTypes)); } - function stopCompleteQuestLocation() { - if(questLocationInProgress) { - //Reset loop when quest is refreshed or auto quest is disabled - if(typeof completeQuestLocationLoop !== 'undefined') { - clearInterval(completeQuestLocationLoop); - completeQuestLocationLoop = null; + function endQuest(quest) { + if(quest instanceof DefeatGymQuest) { + endLocationQuest(quest); + } else if(quest instanceof DefeatPokemonsQuest) { + endLocationQuest(quest); + } else if(quest instanceof DefeatDungeonQuest) { + endLocationQuest(quest); + }else if (quest instanceof UsePokeballQuest) { + endUsePokeballQuest(); + } else if (quest instanceof CapturePokemonsQuest) { + endCapturePokemonsQuest(quest); + } else if (quest instanceof CapturePokemonTypesQuest) { + endCapturePokemonTypesQuest(quest); + } else if (quest instanceof UseOakItemQuest) { + if (quest.item === OakItemType.Magic_Ball) { + endUseOakMagicBallQuest(); } - stopAutoDungeon(); - stopAutoGym(); - let resetPlayerStateLoop = setInterval(function() { - if(playerCanMove()) { - playerResetState(); - clearInterval(resetPlayerStateLoop); - } - }, 50); - questLocationInProgress = false; } - questLocationReadyToStart = false; } } @@ -265,452 +250,386 @@ function removeQuestTemporarily(quest) { } } -function completeDefeatDungeonQuest(dungeonQuest) { - //Can't farm the dungeons without the autoclicker - if(!dungeonStart) return; - - //Remove dungeon quest for current cycle if total token needed not available - if(!playerCanPayDungeonEntrance(dungeonQuest.dungeon, dungeonQuest.progressText())) { - removeQuestTemporarily(dungeonQuest); - endLocationQuest(); - return; +function stopAutoDungeon() { + if(autoDungeon && !autoDungeon.classList.contains("btn-danger")) { + autoDungeon.click(); } +} - if(!questLocationReadyToStart) { - playerSaveState(); - stopAutoGym(); - questLocationReadyToStart = true; +function stopAutoGym() { + if (autoGym && !autoGym.classList.contains("btn-danger")) { + autoGym.click(); } +} - //Move player to quest dungeon - if (playerCanMove()) { - playerMoveToTown(dungeonQuest.dungeon, dungeonQuest.region); +function playerSaveState() { + //Save last location of player in temp variable + regionSelect = player.region; + subRegionSelect = player.subregion; + routeSelect = player.route(); + townSelect = player.town().name; + + if(autoDungeon && autoDungeon.classList.contains("btn-danger")) { + dungeonStateSelect = false; + } else if(autoDungeon && autoDungeon.classList.contains("btn-success")) { + dungeonStateSelect = true; } + if(autoGym && autoGym.classList.contains("btn-danger")) { + gymStateSelect = false; + } else if(autoGym && autoGym.classList.contains("btn-success")) { + gymStateSelect = true; + } +} - if(player.town().name === dungeonQuest.dungeon) { - questLocationInProgress = true; - completeQuestLocationLoop = setInterval(function() { - if(!dungeonQuest.notified) { - if(dungeonStart && !dungeonStart.classList.contains("btn-success")) { - dungeonStart.click(); - } - } else if(playerCanMove()) { - endLocationQuest(); - } - }, 50); +function playerResetState() { + if (playerMoveTo(regionSelect, townSelect, routeSelect)) { + playerHasMoved = false; + } + if (autoDungeon) { + if(dungeonStateSelect && !autoDungeon.classList.contains("btn-success")) { + autoDungeon.click(); + } else if(!dungeonStateSelect && !autoDungeon.classList.contains("btn-danger")) { + autoDungeon.click(); + } + } + if (autoGym) { + if(gymStateSelect && !autoGym.classList.contains("btn-success")) { + autoGym.click(); + } else if(!gymStateSelect && !autoGym.classList.contains("btn-danger")) { + autoGym.click(); + } } } -function completeDefeatGymQuest(gymQuest) { - //Find town associate to gym - const gymListAsArray = Object.entries(GymList); - const town = gymListAsArray.filter(([key, value]) => key === gymQuest.gymTown)[0][1]; +function playerSaveHatcheryFilters() { + hatcheryCategorySelect = BreedingController.filter.category(); + hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus(); + hatcheryRegionSelect = BreedingController.filter.region(); + hatcheryType1Select = BreedingController.filter.type1(); + hatcheryType2Select = BreedingController.filter.type2(); + hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue(); + hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue(); - if(!questLocationReadyToStart) { - playerSaveState(); - stopAutoDungeon(); - stopAutoGym(); - questLocationReadyToStart = true; - } - //Move player to quest town - if (playerCanMove()) { - playerMoveToTown(town.parent.name, town.parent.region); + if(autoHatchery && autoHatchery.classList.contains("btn-danger")) { + hatcheryStateSelect = false; + } else if(autoHatchery && autoHatchery.classList.contains("btn-success")) { + hatcheryStateSelect = true; } +} - if(player.town().name === town.parent.name) { - //Find gym in town - for(const gym of player.town().content) { - if(gym.town === gymQuest.gymTown) { - questLocationInProgress = true; - completeQuestLocationLoop = setInterval(function() { - if(!gymQuest.notified) { - if(App.game.gameState !== GameConstants.GameState.gym) { - gym.protectedOnclick(); - } - } else if(playerCanMove()) { - endLocationQuest(); - } - }, 50); - } +function playerResetHatcheryFilters() { + playerSetHatcheryFilters(hatcheryCategorySelect, hatcheryShinyStatusSelect, hatcheryRegionSelect, hatcheryType1Select, hatcheryType2Select, hatcherySortSelect, hatcherySortDirectionSelect) + if (autoHatchery) { + if(hatcheryStateSelect && !autoHatchery.classList.contains("btn-success")) { + autoHatchery.click(); + } else if(!hatcheryStateSelect && !autoHatchery.classList.contains("btn-danger")) { + autoHatchery.click(); } } } -function completeDefeatPokemonQuest(pokemonQuest) { - if(!questLocationReadyToStart) { - playerSaveState(); - stopAutoDungeon(); - stopAutoGym(); - questLocationReadyToStart = true; +function playerSetHatcheryFilters(category, shinyStatus, region, type1, type2, hatcherySort, hatcherySortDirection) { + if (BreedingController.filter.category() !== category) { + BreedingController.filter.category(category); } - - //Move player to quest route - if (playerCanMove()) { - playerMoveToRoute(pokemonQuest.route, pokemonQuest.region); + if (BreedingController.filter.shinyStatus() !== shinyStatus) { + BreedingController.filter.shinyStatus(shinyStatus); } - - if(player.route() === pokemonQuest.route && player.region === pokemonQuest.region) { - questLocationInProgress = true; - completeQuestLocationLoop = setInterval(function() { - if(pokemonQuest.notified) { - endLocationQuest(); - } - }, 50); + if (BreedingController.filter.region() !== region) { + BreedingController.filter.region(region); + } + if (BreedingController.filter.type1() !== type1) { + BreedingController.filter.type1(type1); + } + if (BreedingController.filter.type2() !== type2) { + BreedingController.filter.type2(type2); + } + if (Settings.getSetting('hatcherySort').observableValue() !== hatcherySort) { + Settings.getSetting('hatcherySort').observableValue(hatcherySort); // Breeding efficient + } + if (Settings.getSetting('hatcherySort').observableValue() !== hatcherySortDirection) { + Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirection); } } -function endLocationQuest() { - //Executed when the quest is completed - questLocationReadyToStart = false; - questLocationInProgress = false; - clearInterval(completeQuestLocationLoop); - completeQuestLocationLoop = null; - stopAutoDungeon(); - stopAutoGym(); - playerResetState(); -} - -function completeUsePokeballQuest(pokeballQuest) { - //If the script has to change the pokeball for a capture, we wait until it has reset the selected already caught pokeball - if (!questPokeballInProgress && !pokeballChangedForCapturePokemonQuest) { - //Remove use pokeball quest for current cycle if total pokeball needed not available - if(!playerHasPokeballForPokemonQuest(pokeballQuest.pokeball, pokeballQuest.progressText())) { - removeQuestTemporarily(pokeballQuest); - endPokeballQuest(); - return; +function playerMoveTo(region, town, route) { + if (playerCanMove()) { + if (region === 6) { + player.subregion = getAlolaSubRegionFromLocation(town); } - - questPokeballInProgress = true; - - //Save and set pokeball already caught selection - if (!questPokeballReadyToStart) { - playerSavePokeballAlreadyCaught(); + if (route !== 0) { + MapHelper.moveToRoute(route, region); + } else if (town !== null) { + player.region = region; + MapHelper.moveToTown(town); } - playerSetAlreadyCaughtPokeball(pokeballQuest.pokeball) - - completeQuestPokeballLoop = setInterval(function() { - if(pokeballQuest.notified) { - endPokeballQuest() - } - }, 1000); + return true; } + return false; } -function endPokeballQuest() { - //Executed when the quest is completed - questPokeballInProgress = false; - clearInterval(completeQuestPokeballLoop); - completeQuestPokeballLoop = null; - if (questPokeballReadyToStart) { - playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); - questPokeballReadyToStart = false; - } +function playerCanMove() { + return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() + && !DungeonBattle.catching() && !GymRunner.running(); } -function completeCapturePokemonsQuest(captureQuest) { - //Can't use hatchery without autohatchery - if(!hatcheryStart) return; - - //No need to run the code if autohatchery is enabled - if(hatcheryStart.classList.contains("btn-success")) { - return; - } - - if(!questCapturePokemonsReadyToStart) { - if (!questCapturePokemonTypesInProgress) { - playerSaveHatcheryState(); - } - questCapturePokemonsReadyToStart = true; - } - - if (!questCapturePokemonsInProgress) { - questCapturePokemonsInProgress = true; - if (!questCapturePokemonTypesInProgress) { - //Set all filter breeding to default to avoid empty list - BreedingController.filter.category(-1) - BreedingController.filter.shinyStatus(-2) - BreedingController.filter.region(-2) - BreedingController.filter.type1(-2) - BreedingController.filter.type2(-2) - Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient - Settings.getSetting('hatcherySortDirection').observableValue(true) - } +function playerCanPayDungeonEntrance(dungeonName, progressText) { + const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon + let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); + let dungeonCost = dungeon.tokenCost; + let progress = progressText.split('/').map(element => parseInt(element.trim())); + let amountRemaining = progress[1] - progress[0]; + return getTokens >= dungeonCost * amountRemaining; +} - completeQuestCapturePokemonsLoop = setInterval(function() { - if(!captureQuest.notified) { - if(hatcheryStart.classList.contains("btn-danger")) { - hatcheryStart.click(); - } - } else { - endCapturePokemonsQuest() - } - }, 5000); +function playerHasPokeballs(pokeball, progressText = null) { + let amountRemaining; + if (progressText) { + const progress = progressText.split('/').map(element => parseInt(element.trim())); + amountRemaining = progress[1] - progress[0]; + } else { + amountRemaining = 1; } + return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; } -function endCapturePokemonsQuest() { - questCapturePokemonsReadyToStart = false; - questCapturePokemonsInProgress = false; - clearInterval(completeQuestCapturePokemonsLoop) - completeQuestCapturePokemonsLoop = null; - if (!questCapturePokemonTypesInProgress) { - playerResetHatcheryState() +function playerSavePokeballAlreadyCaught() { + if (!usePokeballQuestInProgress && !useOakMagicBallQuestInProgress) { + pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; } } -function completeCapturePokemonTypesQuest(captureQuest) { - //Can't use hatchery without autohatchery - if(!hatcheryStart) return; - - if(!questCapturePokemonTypesReadyToStart) { - if (!questCapturePokemonsReadyToStart) { - playerSaveHatcheryState(); - } - questCapturePokemonTypesReadyToStart = true; - } - - if (!questCapturePokemonTypesInProgress) { - questCapturePokemonTypesInProgress = true; - //Set all filter breeding to default to avoid empty list - BreedingController.filter.category(-1) - BreedingController.filter.shinyStatus(-2) - BreedingController.filter.region(-2) - BreedingController.filter.type1(captureQuest.type) - BreedingController.filter.type2(-2) - Settings.getSetting('hatcherySort').observableValue(6) // Breeding efficient - Settings.getSetting('hatcherySortDirection').observableValue(true) - - completeQuestCapturePokemonTypesLoop = setInterval(function() { - if(!captureQuest.notified) { - if(hatcheryStart.classList.contains("btn-danger")) { - hatcheryStart.click(); - } - } else { - endCapturePokemonTypesQuest() - } - }, 5000); +function playerSetAlreadyCaughtPokeball(pokeball) { + if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { + App.game.pokeballs._alreadyCaughtSelection(pokeball); } } -function endCapturePokemonTypesQuest() { - questCapturePokemonTypesReadyToStart = false; - questCapturePokemonTypesInProgress = false; - clearInterval(completeQuestCapturePokemonTypesLoop) - completeQuestCapturePokemonTypesLoop = null; - if (!questCapturePokemonsInProgress) { - playerResetHatcheryState() - } else { - //Set type1 to all if pokemon quest capture is in progress - BreedingController.filter.type1(-2) +function playerBestPokeballAvailable() { + //Check if player have pokeball to catch pokemon + let pokeball = -1; + for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { + if (playerHasPokeballs(i)) { + pokeball = i; + break; + } } + return pokeball; } function changePokeballForPokemonQuest() { - let catchShiniesQuest = App.game.quests.currentQuests().filter(x => x instanceof CatchShiniesQuest); - let capturePokemonTypesQuest = App.game.quests.currentQuests().filter(x => x instanceof CapturePokemonTypesQuest); + if (!pokeballChangedForCapturePokemonQuest && App.game.pokeballs.alreadyCaughtSelection >= GameConstants.Pokeball.Ultraball) return; + if (App.game.gameState !== GameConstants.GameState.fighting) return; + if (Battle.catching()) return; + + let currentQuests = App.game.quests.currentQuests(); + let capturePokemonTypesQuest = currentQuests.find(e => e instanceof CapturePokemonTypesQuest); + let catchShiniesQuest = currentQuests.find(e => e instanceof CatchShiniesQuest); let forceCapture = false; - if (App.game.pokeballs.alreadyCaughtSelection < GameConstants.Pokeball.Ultraball || pokeballChangedForCapturePokemonQuest) { - if (catchShiniesQuest.length > 0) { - if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { - forceCapture = true; - } + if (capturePokemonTypesQuest !== undefined) { + if (capturePokemonTypesQuest.type === Battle.enemyPokemon().type1 || capturePokemonTypesQuest.type === Battle.enemyPokemon().type2) { + forceCapture = true; } - if (capturePokemonTypesQuest.length > 0) { - for(const quest of capturePokemonTypesQuest) { - //Check if pokemon type is catchable - if(quest.type === Battle.enemyPokemon().type1 || quest.type === Battle.enemyPokemon().type2) { - forceCapture = true; - break; - } - } + } + if (catchShiniesQuest !== undefined) { + if (Battle.enemyPokemon().shiny || DungeonBattle.enemyPokemon().shiny) { + forceCapture = true; } + } - if (forceCapture && !Battle.catching()) { - //Check if player have pokeball to catch pokemon - let pokeball = -1; - for (let i = GameConstants.Pokeball.Ultraball; i >= 0; i--) { - if (playerHasPokeballForPokemonQuest(i)) { - pokeball = i; - break; - } - } - if (pokeball === -1) { - //Pokeball not available - return; - } - if (!pokeballChangedForCapturePokemonQuest) { - playerSavePreviousPokeballAlreadyCaught(); - } - playerSetAlreadyCaughtPokeball(pokeball) - } else if (forceCapture && Battle.catching() && pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); - pokeballChangedForCapturePokemonQuest = false; - } else if (pokeballChangedForCapturePokemonQuest) { - playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); - pokeballChangedForCapturePokemonQuest = false; + if (forceCapture) { + //Check if player have pokeball to catch pokemon + let pokeball = playerBestPokeballAvailable(); + if (pokeball === -1) return; + if (!pokeballChangedForCapturePokemonQuest) { + previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; + pokeballChangedForCapturePokemonQuest = true; } + playerSetAlreadyCaughtPokeball(pokeball); + } else if (pokeballChangedForCapturePokemonQuest) { + playerSetAlreadyCaughtPokeball(previousPokeballAlreadyCaughtSelect); + pokeballChangedForCapturePokemonQuest = false; } } -function playerSaveState() { - //Save last location of player in temp variable - regionSelect = player.region; - subRegionSelect = player.subregion; - routeSelect = player.route(); - townSelect = player.town().name; +function endLocationQuest() { + //Executed when the quest is completed + if (locationQuestInProgress) { + locationQuestInProgress = false; + stopAutoDungeon(); + stopAutoGym(); + playerResetState(); + } +} - if(dungeonStart && dungeonStart.classList.contains("btn-danger")) { - dungeonStateSelect = false; - } else if(dungeonStart && dungeonStart.classList.contains("btn-success")) { - dungeonStateSelect = true; +function endUsePokeballQuest() { + //Executed when the quest is completed + usePokeballQuestInProgress = false; + if (pokeballAlreadyCaughtSelect !== undefined) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); } - if(gymStart && gymStart.classList.contains("btn-danger")) { - gymStateSelect = false; - } else if(gymStart && gymStart.classList.contains("btn-success")) { - gymStateSelect = true; +} + +function endUseOakMagicBallQuest() { + //Executed when the quest is completed + useOakMagicBallQuestInProgress = false; + if (pokeballAlreadyCaughtSelect !== undefined) { + playerSetAlreadyCaughtPokeball(pokeballAlreadyCaughtSelect); } } -function playerSavePokeballAlreadyCaught() { - pokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; - questPokeballReadyToStart = true; +function endCapturePokemonsQuest() { + capturePokemonsQuestInProgress = false; + if (!capturePokemonTypesQuestInProgress) { + playerResetHatcheryFilters(); + } } -function playerSavePreviousPokeballAlreadyCaught() { - previousPokeballAlreadyCaughtSelect = App.game.pokeballs.alreadyCaughtSelection; - pokeballChangedForCapturePokemonQuest = true; +function endCapturePokemonTypesQuest() { + capturePokemonTypesQuestInProgress = false; + if (!capturePokemonsQuestInProgress) { + playerResetHatcheryFilters(); + } else { + //Set type1 to all if pokemon quest capture is in progress + BreedingController.filter.type1(-2); + } } -function playerSaveHatcheryState() { - hatcheryCategorySelect = BreedingController.filter.category() - hatcheryShinyStatusSelect = BreedingController.filter.shinyStatus() - hatcheryRegionSelect = BreedingController.filter.region() - hatcheryType1Select = BreedingController.filter.type1() - hatcheryType2Select = BreedingController.filter.type2() - hatcherySortSelect = Settings.getSetting('hatcherySort').observableValue() - hatcherySortDirectionSelect = Settings.getSetting('hatcherySortDirection').observableValue() +function completeDefeatGymQuest(quest) { + if(!locationQuestInProgress) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + locationQuestInProgress = true; + } + //Find town associate to gym + const gymListAsArray = Object.entries(GymList); + const town = gymListAsArray.filter(([key, value]) => key === quest.gymTown)[0][1]; - if(hatcheryStart && hatcheryStart.classList.contains("btn-danger")) { - hatcheryStateSelect = false; - } else if(hatcheryStart && hatcheryStart.classList.contains("btn-success")) { - hatcheryStateSelect = true; + //Move player to quest town + if (!playerHasMoved && playerMoveTo(town.parent.region, town.parent.name, 0)) { + playerHasMoved = true; } -} -function playerResetHatcheryState() { - BreedingController.filter.category(hatcheryCategorySelect) - BreedingController.filter.shinyStatus(hatcheryShinyStatusSelect) - BreedingController.filter.region(hatcheryRegionSelect) - BreedingController.filter.type1(hatcheryType1Select) - BreedingController.filter.type2(hatcheryType2Select) - Settings.getSetting('hatcherySort').observableValue(hatcherySortSelect) - Settings.getSetting('hatcherySortDirection').observableValue(hatcherySortDirectionSelect) - if (hatcheryStart) { - if(hatcheryStateSelect && !hatcheryStart.classList.contains("btn-success")) { - hatcheryStart.click(); - } else if(!hatcheryStateSelect && !hatcheryStart.classList.contains("btn-danger")) { - hatcheryStart.click(); + //Find gym in town + if(player.town().name === town.parent.name) { + for(const gym of player.town().content) { + if(gym.town === quest.gymTown && App.game.gameState !== GameConstants.GameState.gym) { + gym.protectedOnclick(); + } } } } -function playerResetState() { - if(regionSelect && player.region !== regionSelect) { - player.region = regionSelect; +function completeDefeatPokemonQuest(quest) { + if(!locationQuestInProgress) { + playerSaveState(); + stopAutoDungeon(); + stopAutoGym(); + locationQuestInProgress = true; } - if(subRegionSelect && player.subregion !== subRegionSelect) { - player.subregion = subRegionSelect; + + //Move player to quest route + if (!playerHasMoved && playerMoveTo(quest.region, null, quest.route)) { + playerHasMoved = true; } - if(routeSelect && player.route() !== routeSelect) { - MapHelper.moveToRoute(routeSelect, regionSelect); +} + +function completeDefeatDungeonQuest(quest) { + //Can't farm the dungeons without the autoclicker + if(!autoDungeon) return; + + //Remove dungeon quest for current cycle if total token needed not available + if(!playerCanPayDungeonEntrance(quest.dungeon, quest.progressText())) { + removeQuestTemporarily(quest); + return; } - if(townSelect && routeSelect === 0) { - MapHelper.moveToTown(townSelect); + + if(!locationQuestInProgress) { + playerSaveState(); + stopAutoGym(); + locationQuestInProgress = true; } - if (dungeonStart) { - if(dungeonStateSelect && !dungeonStart.classList.contains("btn-success")) { - dungeonStart.click(); - } else if(!dungeonStateSelect && !dungeonStart.classList.contains("btn-danger")) { - dungeonStart.click(); - } + + //Move player to quest dungeon + if (!playerHasMoved && playerMoveTo(quest.region, quest.dungeon, 0)) { + playerHasMoved = true; } - if (gymStart) { - if(gymStateSelect && !gymStart.classList.contains("btn-success")) { - gymStart.click(); - } else if(!gymStateSelect && !gymStart.classList.contains("btn-danger")) { - gymStart.click(); + + if(player.town().name === quest.dungeon) { + if(autoDungeon && !autoDungeon.classList.contains("btn-success")) { + autoDungeon.click(); } } } -function playerCanMove() { - return !DungeonRunner.fighting() && !DungeonRunner.fightingBoss() && !DungeonBattle.catching() && !GymRunner.running() -} +function completeUsePokeballQuest(quest) { + if (!usePokeballQuestInProgress && !pokeballChangedForCapturePokemonQuest) { + playerSavePokeballAlreadyCaught(); + usePokeballQuestInProgress = true; + } -function playerMoveToTown(town, region) { - if(player.region !== region || player.town().name !== town) { - player.region = region; - if(region === 6) { - setAlolaSubRegion(town) - } else { - player.subregion = 0 + if (usePokeballQuestInProgress) { + //Remove use pokeball quest for current cycle if total pokeball needed not available + if(!playerHasPokeballs(quest.pokeball, quest.progressText())) { + removeQuestTemporarily(quest); + return; } - MapHelper.moveToTown(town); + playerSetAlreadyCaughtPokeball(quest.pokeball); } } -function playerMoveToRoute(route, region) { - if(player.region !== region || player.route() !== route) { - player.region = region; - if(region === 6) { - setAlolaSubRegion(route) - } else { - player.subregion = 0 +function completeUseOakMagicBallQuest(quest) { + if (!usePokeballQuestInProgress&& !pokeballChangedForCapturePokemonQuest) { + playerSavePokeballAlreadyCaught(); + useOakMagicBallQuestInProgress = true; + } + if (useOakMagicBallQuestInProgress) { + //Remove use pokeball quest for current cycle if total pokeball needed not available + let pokeball = playerBestPokeballAvailable(); + if (pokeball === -1) { + removeQuestTemporarily(quest); } - MapHelper.moveToRoute(route, region); + playerSetAlreadyCaughtPokeball(pokeball); } } -function playerCanPayDungeonEntrance(dungeonName, progressText) { - const dungeon = Object.entries(TownList).filter(([key, value]) => key === dungeonName)[0][1].dungeon - let getTokens = App.game.wallet.currencies[GameConstants.Currency.dungeonToken](); - let dungeonCost = dungeon.tokenCost; - let progress = progressText.split('/').map(element => parseInt(element.trim())); - let amountRemaining = progress[1] - progress[0]; - return getTokens >= dungeonCost * amountRemaining; -} +function completeCapturePokemonsQuest() { + //Can't use hatchery without autohatchery + if(!autoHatchery) return; -function playerHasPokeballForPokemonQuest(pokeball, progressText = null) { - let amountRemaining = 0; - if (progressText) { - const progress = progressText.split('/').map(element => parseInt(element.trim())); - amountRemaining = progress[1] - progress[0]; - } else { - amountRemaining = 1; - } - return App.game.pokeballs.pokeballs[pokeball].quantity() >= amountRemaining; -} + if (!capturePokemonsQuestInProgress && !capturePokemonTypesQuestInProgress) { + if (!capturePokemonTypesQuestInProgress) { + playerSaveHatcheryFilters(); + } -function playerSetAlreadyCaughtPokeball(pokeball) { - if (App.game.pokeballs.alreadyCaughtSelection !== pokeball) { - App.game.pokeballs._alreadyCaughtSelection(pokeball); - } -} + capturePokemonsQuestInProgress = true; + playerSetHatcheryFilters(-1, -2, -2, -2, -2, 6, true); -function stopAutoDungeon() { - if(dungeonStart && !dungeonStart.classList.contains("btn-danger")) { - dungeonStart.click(); + if(autoHatchery.classList.contains("btn-danger")) { + autoHatchery.click(); + } } } -function stopAutoGym() { - if(gymStart && !gymStart.classList.contains("btn-danger")) { - gymStart.click(); +function completeCapturePokemonTypesQuest(captureQuest) { + //Can't use hatchery without autohatchery + if(!autoHatchery) return; + + if(!capturePokemonTypesQuestInProgress) { + if (!capturePokemonsQuestInProgress) { + playerSaveHatcheryFilters(); + } + playerSetHatcheryFilters(-1, -2, -2, captureQuest.type, -2, 6, true) + capturePokemonTypesQuestInProgress = true; + if(autoHatchery.classList.contains("btn-danger")) { + autoHatchery.click(); + } } } -function setAlolaSubRegion(locationName) { +function getAlolaSubRegionFromLocation(locationName) { //TODO: Find a solution to retrieve locations by sub-region in a programmatic way //On Alola map subregion not available on Town, Route or Dungeon //Location found from https://github.com/pokeclicker/pokeclicker/blob/ff8b53478cf714c61de8b33d73cd1275ce785688/src/components/AlolaSVG.html @@ -719,10 +638,11 @@ function setAlolaSubRegion(locationName) { const alolaSubregion2 = ["Route 10", "Mount Hokulani", "Route 11", "Route 12", "Route 13", "Haina Desert", "Route 14", "Route 15", "Route 16", "Route 17", "Poni Wilds", "Ancient Poni Path", "Poni Breaker Coast", "Poni Grove", "Poni Plains", "Poni Coast", "Poni Gauntlet", "Aether Paradise", "Malie City", "Tapu Village", "Seafolk Village", "Exeggutor Island", "Altar of the Sunne and Moone", "Pokémon League Alola", "Vast Poni Canyon", "Lake of the Sunne and Moone"]; if(alolaSubregion0.includes(locationName)) { - player.subregion = 0 + return 0; } else if(alolaSubregion1.includes(locationName)) { - player.subregion = 1 + return 1; } else if(alolaSubregion2.includes(locationName)) { - player.subregion = 2 + return 2; } + return 0; } \ No newline at end of file From 2c188c8e0e52303a723871a6fea2e0be410b5240 Mon Sep 17 00:00:00 2001 From: Sorrow Date: Wed, 15 Jun 2022 00:16:37 +0200 Subject: [PATCH 17/17] Fix bug --- custom/autoquestcompleter.user.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/custom/autoquestcompleter.user.js b/custom/autoquestcompleter.user.js index b5bd1e95..3f732d0c 100644 --- a/custom/autoquestcompleter.user.js +++ b/custom/autoquestcompleter.user.js @@ -497,7 +497,7 @@ function endCapturePokemonTypesQuest() { } function completeDefeatGymQuest(quest) { - if(!locationQuestInProgress) { + if(!locationQuestInProgress && !playerHasMoved) { playerSaveState(); stopAutoDungeon(); stopAutoGym(); @@ -523,7 +523,7 @@ function completeDefeatGymQuest(quest) { } function completeDefeatPokemonQuest(quest) { - if(!locationQuestInProgress) { + if(!locationQuestInProgress && !playerHasMoved) { playerSaveState(); stopAutoDungeon(); stopAutoGym(); @@ -546,8 +546,9 @@ function completeDefeatDungeonQuest(quest) { return; } - if(!locationQuestInProgress) { + if(!locationQuestInProgress && !playerHasMoved) { playerSaveState(); + stopAutoDungeon(); stopAutoGym(); locationQuestInProgress = true; }