-
Notifications
You must be signed in to change notification settings - Fork 270
Add autoAchievement #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add autoAchievement #240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,9 @@ var allSelectedGym = 0; | |
| var gymState; | ||
| var gymSelect; | ||
| var dungeonState; | ||
| var achievementState; | ||
| var dungeonSelect; | ||
| var achievementSelect; | ||
| var foundBoss = false; | ||
| var foundBossX; | ||
| var foundBossY; | ||
|
|
@@ -81,18 +83,35 @@ function initAutoClicker() { | |
| <option value="4">#5</option> | ||
| <option value="5">All</option> | ||
| </select> | ||
| </td> | ||
| </tr> | ||
| <tr> | ||
| <td style="width: 40%;"> | ||
| <button id="auto-achievement-start" class="btn btn-block btn-${achievementState ? 'success' : 'danger'}" style="font-size: 8pt;"> | ||
| Auto Achievement [`+ achievementState + `] | ||
| </button> | ||
| </td> | ||
| <td> | ||
| <select id = "achievement-select"> | ||
| <option value = "0">Routes</option> | ||
| <option value = "1">Gyms</option> | ||
| <option value = "2">Dungeons</option> | ||
| </select> | ||
| </td> | ||
| </tr> | ||
| </tbody>` | ||
| battleView.before(elemAC) | ||
| document.getElementById('gym-select').value = gymSelect; | ||
| document.getElementById('dungeon-select').value = dungeonSelect; | ||
| document.getElementById('achievement-select').value = achievementSelect; | ||
|
|
||
| document.getElementById('auto-click-start').addEventListener('click', () => { toggleAutoClick(); }); | ||
| document.getElementById('auto-gym-start').addEventListener('click', event => { toggleAutoGym(event); }); | ||
| document.getElementById('auto-dungeon-start').addEventListener('click', event => { toggleAutoDungeon(event); }); | ||
| document.getElementById('auto-achievement-start').addEventListener('click', event => { toggleAutoAchievement(event); }); | ||
| document.getElementById('gym-select').addEventListener('change', event => { changeSelectedGym(event); }); | ||
| document.getElementById('dungeon-select').addEventListener('change', event => { changeSelectedDungeon(event); }); | ||
| document.getElementById('achievement-select').addEventListener('change', event => { changeSelectedAchievement(event); }); | ||
| document.getElementById('auto-click-delay').addEventListener('change', event => { changeClickDelay(event); }); | ||
|
|
||
| addGlobalStyle('#auto-click-info { display: flex;flex-direction: row;justify-content: center; }'); | ||
|
|
@@ -145,6 +164,23 @@ function toggleAutoDungeon(event) { | |
| localStorage.setItem('autoDungeonState', dungeonState); | ||
| } | ||
|
|
||
| function toggleAutoAchievement(event) { | ||
| const element = event.target; | ||
| achievementState = !achievementState; | ||
| achievementState ? element.classList.replace('btn-danger', 'btn-success') : element.classList.replace('btn-success', 'btn-danger'); | ||
| element.textContent = `Auto Achievement [${achievementState ? 'ON' : 'OFF'}]`; | ||
| localStorage.setItem('autoAchievementState', achievementState); | ||
|
|
||
| // Deactivate AutoGym and AutoDungeon that could have been triggered | ||
| if(gymState === true){ | ||
| document.getElementById("auto-gym-start").click(); | ||
| } | ||
|
|
||
| if(dungeonState === true){ | ||
| document.getElementById("auto-dungeon-start").click(); | ||
| } | ||
| } | ||
|
|
||
| function changeSelectedGym(event) { | ||
| const element = event.target; | ||
| if (gymSelect != +element.value) { | ||
|
|
@@ -161,6 +197,14 @@ function changeSelectedDungeon(event) { | |
| } | ||
| } | ||
|
|
||
| function changeSelectedAchievement() { | ||
| const element = event.target; | ||
| if (achievementSelect != +element.value) { | ||
| achievementSelect = +element.value; | ||
| localStorage.setItem("selectedAchievement", achievementSelect); | ||
| } | ||
| } | ||
|
|
||
| function getRandomInt(max) { | ||
| return Math.floor(Math.random() * max); | ||
| } | ||
|
|
@@ -223,6 +267,11 @@ function autoClicker() { | |
| bossCoords.length = 0 | ||
| } | ||
|
|
||
| //Auto Achievement checking | ||
| if (achievementState) { | ||
| autoAchievement(); | ||
| } | ||
|
|
||
| // Click while in a gym battle | ||
| if (App.game.gameState === GameConstants.GameState.gym) { | ||
| GymBattle.clickAttack(); | ||
|
|
@@ -373,6 +422,121 @@ function autoDungeon() { | |
| } | ||
| } | ||
|
|
||
| function autoAchievement() | ||
| { | ||
|
|
||
| let currentRoute = player.route(); | ||
| let currentRegion = player.region; | ||
| let currentDungeon = player.town().dungeon?.name; | ||
| let currentGym = player.town().name; | ||
|
|
||
| //Route | ||
| if(achievementSelect == 0) | ||
| { | ||
| let newRoute = getNextRoute(); | ||
| currentRoute = player.route(); | ||
| if(newRoute && newRoute.number != currentRoute || newRoute.region != currentRegion) | ||
| { | ||
| currentRoute = newRoute.number; | ||
| currentRegion = newRoute.region; | ||
|
|
||
| if(newRoute.region != player.subregion) | ||
| { | ||
| player.subregion = newRoute.subRegion; | ||
| } | ||
| MapHelper.moveToRoute(newRoute.number, newRoute.region); | ||
| } | ||
| } | ||
| //Gym | ||
|
|
||
| else if(achievementSelect == 1) | ||
| { | ||
| //Toggle Auto Gym ON | ||
| if (gymState === false) { | ||
| document.getElementById("auto-gym-start").click(); | ||
| } | ||
|
|
||
| let newGym = getNextGym(); | ||
| if(newGym && newGym != currentGym) | ||
| { | ||
| currentGym = newGym; | ||
| player.subregion = TownList[newGym].subRegion; | ||
| MapHelper.moveToTown(newGym); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| //Dungeon | ||
| else if(achievementSelect == 2) | ||
| { | ||
| //Toggle Auto Dungeon ON | ||
| if (dungeonState === false) { | ||
| document.getElementById("auto-dungeon-start").click(); | ||
| } | ||
|
|
||
| //Move | ||
| let newDungeon = getNextDungeon(); | ||
| if(newDungeon && newDungeon != currentDungeon) | ||
| { | ||
| currentDungeon = newDungeon; | ||
| player.subregion = TownList[newDungeon].subRegion; | ||
| MapHelper.moveToTown(newDungeon); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function getNextRoute() | ||
| { | ||
| let regionRoutes = Routes.getRoutesByRegion(player.region); | ||
| for(let j = 0; j < regionRoutes.length; j ++) | ||
| { | ||
| if(getDefeatedOnRoute(player.region, regionRoutes[j].number) < GameConstants.ACHIEVEMENT_DEFEAT_ROUTE_VALUES[GameConstants.ACHIEVEMENT_DEFEAT_ROUTE_VALUES.length-1]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to check if it's unlocked: |
||
| { | ||
| return regionRoutes[j]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function getNextGym() | ||
| { | ||
| let regionGyms = GameConstants.RegionGyms[player.region]; | ||
| for(let j = 0; j < regionGyms.length; j ++) | ||
| { | ||
| if(getDefeatedOnGym(regionGyms[j]) < GameConstants.ACHIEVEMENT_DEFEAT_GYM_VALUES[GameConstants.ACHIEVEMENT_DEFEAT_GYM_VALUES.length-1]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to check if it's unlocked: |
||
| { | ||
| return regionGyms[j]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function getNextDungeon() | ||
| { | ||
| let regionDungeons = GameConstants.RegionDungeons[player.region]; | ||
| for(let j = 0; j < regionDungeons.length; j ++) | ||
| { | ||
| if(getDefeatedOnDungeon(regionDungeons[j]) < GameConstants.ACHIEVEMENT_DEFEAT_DUNGEON_VALUES[GameConstants.ACHIEVEMENT_DEFEAT_DUNGEON_VALUES.length-1]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to check if it's unlocked: |
||
| { | ||
| return regionDungeons[j]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function getDefeatedOnRoute(region, route) | ||
| { | ||
| return App.game.statistics.routeKills[region][route](); | ||
| } | ||
|
|
||
| function getDefeatedOnGym(gymName) | ||
| { | ||
| return App.game.statistics.gymsDefeated[GameConstants.getGymIndex(gymName)](); | ||
| } | ||
|
|
||
| function getDefeatedOnDungeon(dungeonName) | ||
| { | ||
| return App.game.statistics.dungeonsCleared[GameConstants.getDungeonIndex(dungeonName)](); | ||
| } | ||
|
|
||
|
|
||
| function scan(dungeonBoard) { | ||
| /*var bossCoords = [] | ||
| var playerCoords = []*/ | ||
|
|
@@ -486,6 +650,12 @@ if (!validParse(localStorage.getItem('selectedGym'))) { | |
| if (!validParse(localStorage.getItem('autoDungeonState'))) { | ||
| localStorage.setItem("autoDungeonState", false); | ||
| } | ||
| if (!validParse(localStorage.getItem('autoAchievementState'))) { | ||
| localStorage.setItem("autoAchievementState", false); | ||
| } | ||
| if (!validParse(localStorage.getItem('selectedAchievement'))) { | ||
| localStorage.setItem("selectedAchievement", 0); | ||
| } | ||
| if (!validParse(localStorage.getItem('selectedDungeon'))) { | ||
| localStorage.setItem("selectedDungeon", 0); | ||
| } | ||
|
|
@@ -503,7 +673,15 @@ try { | |
| localStorage.setItem("autoDungeonState", false); | ||
| } | ||
|
|
||
| try { | ||
| achievementState = JSON.parse(localStorage.getItem('autoAchievementState')); | ||
| } catch (error) { | ||
| achievementState = false | ||
| localStorage.setItem("autoAchievementState", false); | ||
| } | ||
|
|
||
| dungeonSelect = JSON.parse(localStorage.getItem('selectedDungeon')); | ||
| achievementSelect = JSON.parse(localStorage.getItem('selectedAchievement')); | ||
| delayAutoClick = JSON.parse(localStorage.getItem('delayAutoClick')); | ||
| clickDPS = clickState ? JSON.parse(localStorage.getItem('storedClickDPS')) : 0; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this really work?
When you go from a dungeon to another, does the script keep working?
When playing around with it, I needed to leave the dungeon before going to another one...
So I added this:
If you want to take a look: AreaDestroyer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for flagging it, I will have a look during the day !
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a test.
Are you talking about the next dungeon not starting or the fact the character is not physically moved to the right subregion ?
In Galar, I went from Rose Tower to Dusty Bowl to Courageous Cavern without trouble.
Only issue I had is that my character was not on the Courageous Cavern but on Hammerlocke city when I quitted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, sometimes when you go from a dungeon to another one the script just freezes and autodungeon stop to work.

But If you don't have the problem, it's all good :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be that you beated all Dungeons to more than 500 (assuming you didn't change the value in the code) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enter a dungeon, then try to enter it again ;)
MapHelper.moveToTown(player.town().dungeon.name);It end up breaking something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will try ! Thanks for raising it