Skip to content

Commit

Permalink
Focus.Quest: Add support for the new BattleFrontier quest
Browse files Browse the repository at this point in the history
v0.10.14 introduced ClearBattleFrontier quests.

When this quest is active, it will be picked after any other
handled type of quests.
The player will be moved to Battle Frontier town.
The BattleFrontier mode will be entered and the session will start
automatically (from the last checkpoint, if any).

When the quest objective is met, or the automation is turned off,
the BattleFrontier mode will be left.
  • Loading branch information
Farigh committed Aug 22, 2023
1 parent 9ae1bc0 commit 2d91b6a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 19 deletions.
17 changes: 16 additions & 1 deletion src/lib/BattleFrontier.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@
}
}

/**
* @brief Forces the automation to stop
*/
static ForceStop()
{
// Stop the automation
this.__internal__toggleBattleFrontierFight(false);

// Exit the battle frontier
BattleFrontierRunner.end();

// Leave the menu
App.game.battleFrontier.leave();
}

/*********************************************************************\
|*** Internal members, should never be used by other classes ***|
\*********************************************************************/
Expand Down Expand Up @@ -110,7 +125,7 @@
return;
}

// Start a new run, using the checkpoint if available
// Start a new run, using the last checkpoint if available
BattleFrontierRunner.start(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Focus/Achievements.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class AutomationFocusAchievements
{
Automation.Utils.Route.moveToTown(targetedDungeonName);

// Let a tick to the menu to show up
// Let a tick for the menu to show up
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Focus/PokerusCure.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class AutomationFocusPokerusCure
{
Automation.Utils.Route.moveToTown(this.__internal__currentDungeonData.dungeon.name);

// Let a tick to the menu to show up
// Let a tick for the menu to show up
return;
}

Expand Down
81 changes: 66 additions & 15 deletions src/lib/Focus/Quests.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class AutomationFocusQuests
this.__internal__questLabels["DefeatPokemonsQuest"] = "Defeat <n> Pokémon on <Route>.";
this.__internal__questLabels["CapturePokemonsQuest"] = "Capture <n> Pokémon.";
this.__internal__questLabels["CapturePokemonTypesQuest"] = "Capture <n> <Type> Pokémon.";
this.__internal__questLabels["ClearBattleFrontier"] = "Clear <n> stages in the Battle Frontier.";
this.__internal__questLabels["GainFarmPointsQuest"] = "Gain <n> Farm Points.";
this.__internal__questLabels["GainMoneyQuest"] = "Gain <n> Pokédollars.";
this.__internal__questLabels["GainTokensQuest"] = "Gain <n> Dungeon Tokens.";
Expand Down Expand Up @@ -224,9 +225,12 @@ class AutomationFocusQuests
Automation.Farm.toggleAutoFarming();
Automation.Underground.toggleAutoMining();

// Stop gym auto-fight
// Stop any gym auto-fight
Automation.Menu.forceAutomationState(Automation.Gym.Settings.FeatureEnabled, false);

// Stop any Battle Frontier fight
Automation.BattleFrontier.ForceStop();

// Re-enable other modes button
Automation.Menu.setButtonDisabledState(Automation.Click.Settings.FeatureEnabled, false);
Automation.Menu.setButtonDisabledState(Automation.Hatchery.Settings.FeatureEnabled, false);
Expand All @@ -250,20 +254,25 @@ class AutomationFocusQuests
// Make sure to always have some balls to catch pokemons
this.__internal__tryBuyBallIfUnderThreshold(Automation.Focus.__pokeballToUseSelectElem.value, 10);

// Disable best route if needed
Automation.Menu.forceAutomationState("bestRouteClickEnabled", false);

this.__internal__claimCompletedQuests();
this.__internal__selectNewQuests();

const filteredQuests = this.__internal__getFilteredCurrentQuests();

// Skip any unwanted quest
if (this.__internal__getFilteredCurrentQuests().length == 0)
if (filteredQuests.length == 0)
{
// Stop any running Battle Frontier instance
if (App.game.gameState == GameConstants.GameState.battleFrontier)
{
Automation.BattleFrontier.ForceStop();
}

this.__internal__skipRemainingQuests();
}
else
{
this.__internal__workOnQuest();
this.__internal__workOnQuest(filteredQuests);
this.__internal__workOnBackgroundQuests();
}
}
Expand Down Expand Up @@ -354,23 +363,19 @@ class AutomationFocusQuests

/**
* @brief Works on the most efficient quest available.
*
* @param currentQuests: The currently active quests to process
*/
static __internal__workOnQuest()
static __internal__workOnQuest(currentQuests)
{
// Already fighting, nothing to do for now
if (Automation.Utils.isInInstanceState())
if ((App.game.gameState != GameConstants.GameState.battleFrontier) && Automation.Utils.isInInstanceState())
{
Automation.Dungeon.AutomationRequestedMode = Automation.Dungeon.InternalModes.StopAfterThisRun;
return;
}
Automation.Dungeon.AutomationRequestedMode = Automation.Dungeon.InternalModes.None;

const currentQuests = this.__internal__getFilteredCurrentQuests();
if (currentQuests.length == 0)
{
return;
}

// Sort quest to work on the most relevant one
currentQuests.sort(this.__internal__sortQuestByPriority, this);

Expand All @@ -388,6 +393,18 @@ class AutomationFocusQuests

const quest = filteredQuests[0];

if (Automation.Utils.isInstanceOf(quest, "ClearBattleFrontier"))
{
this.__internal__workOnClearBattleFrontier();
return;
}
else if (App.game.gameState == GameConstants.GameState.battleFrontier)
{
// Cleanup battle frontier, if needed
Automation.BattleFrontier.ForceStop();
return;
}

// Defeat gym quest
if (Automation.Utils.isInstanceOf(quest, "CapturePokemonsQuest")
|| Automation.Utils.isInstanceOf(quest, "GainTokensQuest"))
Expand Down Expand Up @@ -516,6 +533,37 @@ class AutomationFocusQuests
}
}

/**
* @brief Works on a quest requiring to clear Battle Frontier battles.
*/
static __internal__workOnClearBattleFrontier()
{
if (BattleFrontierRunner.started())
{
// Nothing else to do
return;
}

// Move to Battle Frontier town if not already there
const battleFrontierTownName = "Battle Frontier";
if (!Automation.Utils.Route.isPlayerInTown(battleFrontierTownName))
{
Automation.Utils.Route.moveToTown(battleFrontierTownName);
}

// Enter Battle Frontier
if (App.game.gameState != GameConstants.GameState.battleFrontier)
{
App.game.battleFrontier.enter();

// Let a tick for the menu to show up
return;
}

// Start the automation
Automation.Menu.forceAutomationState(Automation.BattleFrontier.Settings.FeatureEnabled, true);
}

/**
* @brief Works on a DefeatDungeonQuest.
*
Expand Down Expand Up @@ -544,7 +592,7 @@ class AutomationFocusQuests
{
Automation.Utils.Route.moveToTown(quest.dungeon);

// Let a tick to the menu to show up
// Let a tick for the menu to show up
return;
}

Expand Down Expand Up @@ -847,6 +895,9 @@ class AutomationFocusQuests
if (Automation.Utils.isInstanceOf(a, "DefeatPokemonsQuest")) return -1;
if (Automation.Utils.isInstanceOf(b, "DefeatPokemonsQuest")) return 1;

if (Automation.Utils.isInstanceOf(a, "ClearBattleFrontier")) return -1;
if (Automation.Utils.isInstanceOf(b, "ClearBattleFrontier")) return 1;

// Then the gain pokedollar one
if (Automation.Utils.isInstanceOf(a, "GainMoneyQuest")) return -1;
if (Automation.Utils.isInstanceOf(b, "GainMoneyQuest")) return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ class AutomationMenu
.automation-setting-menu-container[automation-visible]
{
max-width: 650px;
max-height: 600px;
max-height: 650px;
transition-property: max-width, max-height;
transition-timing-function: ease-in, ease-in;
Expand Down

0 comments on commit 2d91b6a

Please sign in to comment.