Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions enhancedautoclicker.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }');
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Comment on lines +481 to +483
Copy link
Copy Markdown
Contributor

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:

                // DungeonRunner.dungeonLeave()
                DungeonRunner.dungeonFinished(true);
                DungeonRunner.fighting(false);
                DungeonRunner.fightingBoss(false);
                MapHelper.moveToTown(DungeonRunner.dungeon.name);

If you want to take a look: AreaDestroyer

Copy link
Copy Markdown
Contributor Author

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 !

Copy link
Copy Markdown
Contributor Author

@Dionisos94 Dionisos94 Oct 28, 2022

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.

image

Copy link
Copy Markdown
Contributor

@kevingrillet kevingrillet Oct 28, 2022

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.
image

But If you don't have the problem, it's all good :p

Copy link
Copy Markdown
Contributor Author

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) ?

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

}
}
}

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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to check if it's unlocked: regionRoutes[j].isUnlocked()

{
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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to check if it's unlocked: GymList[gym[j]].isUnlocked()

{
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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to check if it's unlocked: dungeonList[dgs[j]].isUnlocked()

{
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 = []*/
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;

Expand Down