Skip to content
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

BBQ Solo Farmer #407

Merged
merged 34 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8798cac
BBQ farmer, options, functions file created
kichithewolf Feb 9, 2024
bbba542
read quests infra
kichithewolf Feb 9, 2024
673d20f
categorize quests, process quest list
kichithewolf Feb 9, 2024
b6154ea
string to enum
kichithewolf Feb 10, 2024
0626969
make tm
kichithewolf Feb 10, 2024
5bc9ca4
travel 500 units
kichithewolf Feb 10, 2024
84579c6
read and process quests vector, photo fly swim
kichithewolf Feb 13, 2024
b940cef
photo: coastal, canyon, savanna
kichithewolf Feb 13, 2024
94fedab
tera to defeat a wild pokemon, bugfixes
kichithewolf Feb 14, 2024
e19c07b
catch quest, extra complete check, fix time option
kichithewolf Feb 16, 2024
ec2738b
sneak up, photo bug rock, some catchs
kichithewolf Feb 16, 2024
3f67c4b
catch photo ice, kill wild tera
kichithewolf Feb 17, 2024
ba1c78a
wash quest, some work on dark fight
kichithewolf Feb 18, 2024
72f2eb5
separate out catch and photo quests, cleanup
kichithewolf Feb 18, 2024
c5973c1
hatch egg quest
kichithewolf Feb 20, 2024
6f6fbae
sandwiches, num retries option, enable saving
kichithewolf Feb 20, 2024
4c9f589
tera raid, bbq terarium movement functions
kichithewolf Feb 23, 2024
4d4a92c
catch photo fairy dark fly, expand jump_glide_fly
kichithewolf Feb 24, 2024
d201fe9
photo catch electric
kichithewolf Feb 24, 2024
7aa5da4
catch photo steel poison
kichithewolf Feb 25, 2024
ff41bda
out of eggs options, catch photo fighting
kichithewolf Feb 26, 2024
0065577
catch water, fix time for egg option, bugfixes
kichithewolf Feb 26, 2024
7dd901b
unlock options, improve flying, bugfixes
kichithewolf Mar 1, 2024
1385796
catch ice is now lapras, improved make tm, fixes
kichithewolf Mar 2, 2024
b2731c3
autobattle 10/30, move to dev mode
kichithewolf Mar 3, 2024
baf9671
cleanup and fix warnings
kichithewolf Mar 3, 2024
89d89b7
sandwich and navigation fixes for rebase
kichithewolf Mar 31, 2024
3f5c314
remove unused bool
kichithewolf Mar 31, 2024
ac504dd
current_quest, remove unneeded
kichithewolf Apr 11, 2024
1c613b3
const bbq options, adjust num retries
kichithewolf Apr 12, 2024
29e0d8f
unlock options
kichithewolf Apr 12, 2024
a44f36d
throw ball for catch quest
kichithewolf Apr 13, 2024
2b44896
const ball, indentation
kichithewolf Apr 13, 2024
25a5ce3
const ref
kichithewolf Apr 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, BotBaseContext&

//Test a specific quest
/*
BBQuests test_quest = BBQuests::auto_10;
bool questTest = process_and_do_quest(env, env.realtime_dispatcher(), env.console, context, BBQ_OPTIONS, test_quest, eggs_hatched);
BBQuests test_quest = BBQuests::catch_bug;
bool questTest = process_and_do_quest(env, env.console, context, BBQ_OPTIONS, test_quest, eggs_hatched);
if (questTest) {
env.log("Finished quest.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "PokemonSV_BlueberryQuests.h"

#include<vector>
#include "PokemonSV_BlueberryCatchPhoto.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand Down Expand Up @@ -324,9 +325,10 @@ void quest_photo(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext
static_cast<AudioInferenceCallback&>(encounter_watcher),
}
);
if (ret == 0) {
encounter_watcher.throw_if_no_sound();

if (ret >= 0) {
console.log("Battle menu detected.");
encounter_watcher.throw_if_no_sound();

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
if (is_shiny) {
Expand Down Expand Up @@ -608,6 +610,57 @@ void quest_catch_navi(const ProgramInfo& info, ConsoleHandle& console, BotBaseCo

}

void quest_catch_throw_ball(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, Language language, std::string selected_ball) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::string selected_ball -> const std::string& selected_ball since it's not being modified and is not a primitive.

BattleBallReader reader(console, language);
std::string ball_reader = "";
WallClock start = current_time();

console.log("Opening ball menu...");
while (ball_reader == "") {
if (current_time() - start > std::chrono::minutes(2)) {
console.log("Timed out trying to read ball after 2 minutes.", COLOR_RED);
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Timed out trying to read ball after 2 minutes.",
true
);
}

//Mash B to exit anything else
pbf_mash_button(context, BUTTON_B, 125);
context.wait_for_all_requests();

//Press X to open Ball menu
pbf_press_button(context, BUTTON_X, 20, 100);
context.wait_for_all_requests();

VideoSnapshot screen = console.video().snapshot();
ball_reader = reader.read_ball(screen);
}

console.log("Selecting ball.");
int quantity = move_to_ball(reader, console, context, selected_ball);
if (quantity == 0) {
console.log("Unable to find ball.");
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Unable to find ball.",
true
);
}
if (quantity < 0) {
console.log("Unable to read ball quantity.", COLOR_RED);
}

//Throw ball
console.log("Throwing ball.");
pbf_mash_button(context, BUTTON_A, 150);
context.wait_for_all_requests();

pbf_mash_button(context, BUTTON_B, 900);
context.wait_for_all_requests();
}

void quest_catch_handle_battle(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, const BBQOption& BBQ_OPTIONS, BBQuests current_quest) {
console.log("Catching Pokemon.");
AdvanceDialogWatcher advance_dialog(COLOR_MAGENTA);
Expand Down Expand Up @@ -664,158 +717,71 @@ void quest_catch_handle_battle(const ProgramInfo& info, ConsoleHandle& console,
//Do not throw if target is a tera pokemon.
if (use_quickball && !quickball_thrown && tera_target == false) {
console.log("Quick Ball option checked. Throwing Quick Ball.");
BattleBallReader reader(console, BBQ_OPTIONS.LANGUAGE);
std::string ball_reader = "";
WallClock start = current_time();

console.log("Opening ball menu...");
while (ball_reader == "") {
if (current_time() - start > std::chrono::minutes(2)) {
console.log("Timed out trying to read ball after 2 minutes.", COLOR_RED);
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Timed out trying to read ball after 2 minutes.",
true
);
}

//Mash B to exit anything else
pbf_mash_button(context, BUTTON_B, 125);
context.wait_for_all_requests();

//Press X to open Ball menu
pbf_press_button(context, BUTTON_X, 20, 100);
context.wait_for_all_requests();

VideoSnapshot screen = console.video().snapshot();
ball_reader = reader.read_ball(screen);
}

console.log("Selecting Quick Ball.");
int quantity = move_to_ball(reader, console, context, "quick-ball");
if (quantity == 0) {
//Stop so user can check they have quick balls.
console.log("Unable to find Quick Ball on turn 1.");
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Unable to find Quick Ball on turn 1.",
true
);
}
if (quantity < 0) {
console.log("Unable to read ball quantity.", COLOR_RED);
}

//Throw ball
console.log("Throwing Quick Ball.");
pbf_mash_button(context, BUTTON_A, 150);
context.wait_for_all_requests();

quest_catch_throw_ball(info, console, context, BBQ_OPTIONS.LANGUAGE, "quick-ball");
quickball_thrown = true;
pbf_mash_button(context, BUTTON_B, 900);
context.wait_for_all_requests();
}
else {
BattleBallReader reader(console, BBQ_OPTIONS.LANGUAGE);
std::string ball_reader = "";
WallClock start = current_time();

console.log("Opening ball menu...");
while (ball_reader == "") {
if (current_time() - start > std::chrono::minutes(2)) {
console.log("Timed out trying to read ball after 2 minutes.", COLOR_RED);
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Timed out trying to read ball after 2 minutes.",
true
);
}

//Mash B to exit anything else
pbf_mash_button(context, BUTTON_B, 125);
context.wait_for_all_requests();
console.log("Throwing selected ball.");
quest_catch_throw_ball(info, console, context, BBQ_OPTIONS.LANGUAGE, BBQ_OPTIONS.BALL_SELECT.slug());
}

//Press X to open Ball menu
pbf_press_button(context, BUTTON_X, 20, 100);
//Check for battle menu, if found use fourth attack this turn
NormalBattleMenuWatcher battle_menu(COLOR_YELLOW);
int ret = wait_until(
console, context,
std::chrono::seconds(4),
{ battle_menu }
);
if (ret == 0) {
console.log("Battle menu detected early. Using fourth attack.");
MoveSelectWatcher move_watcher(COLOR_BLUE);
MoveSelectDetector move_select(COLOR_BLUE);

int ret_move_select = run_until(
console, context,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indentation

[&](BotBaseContext& context) {
pbf_press_button(context, BUTTON_A, 10, 50);
pbf_wait(context, 100);
context.wait_for_all_requests();

VideoSnapshot screen = console.video().snapshot();
ball_reader = reader.read_ball(screen);
}

console.log("Selecting ball.");
int quantity = move_to_ball(reader, console, context, BBQ_OPTIONS.BALL_SELECT.slug());
if (quantity == 0) {
console.log("Unable to find appropriate ball/out of balls.");
break;
},
{ move_watcher }
);
if (ret_move_select != 0) {
console.log("Could not find move select.");
}
if (quantity < 0) {
console.log("Unable to read ball quantity.", COLOR_RED);
else {
console.log("Move select found!");
}

//Throw ball
console.log("Throwing selected ball.");
context.wait_for_all_requests();
move_select.move_to_slot(console, context, 3);
pbf_mash_button(context, BUTTON_A, 150);
pbf_wait(context, 100);
context.wait_for_all_requests();

//Check for battle menu, if found use fourth attack this turn
NormalBattleMenuWatcher battle_menu(COLOR_YELLOW);
int ret = wait_until(
//Check for battle menu
//If found after a second, assume out of PP and stop as this is a setup issue
//None of the target pokemon for this program have disable, taunt, etc.
NormalBattleMenuWatcher battle_menu2(COLOR_YELLOW);
int ret3 = wait_until(
console, context,
std::chrono::seconds(4),
{ battle_menu }
{ battle_menu2 }
);
if (ret == 0) {
console.log("Battle menu detected early. Using fourth attack.");
MoveSelectWatcher move_watcher(COLOR_BLUE);
MoveSelectDetector move_select(COLOR_BLUE);

int ret_move_select = run_until(
console, context,
[&](BotBaseContext& context) {
pbf_press_button(context, BUTTON_A, 10, 50);
pbf_wait(context, 100);
context.wait_for_all_requests();
},
{ move_watcher }
);
if (ret_move_select != 0) {
console.log("Could not find move select.");
}
else {
console.log("Move select found!");
}

context.wait_for_all_requests();
move_select.move_to_slot(console, context, 3);
pbf_mash_button(context, BUTTON_A, 150);
pbf_wait(context, 100);
context.wait_for_all_requests();

//Check for battle menu
//If found after a second, assume out of PP and stop as this is a setup issue
//None of the target pokemon for this program have disable, taunt, etc.
NormalBattleMenuWatcher battle_menu2(COLOR_YELLOW);
int ret3 = wait_until(
console, context,
std::chrono::seconds(4),
{ battle_menu2 }
if (ret3 == 0) {
console.log("Battle menu detected early. Out of PP/No move in slot, please check your setup.");
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Battle menu detected early. Out of PP, please check your setup.",
true
);
if (ret3 == 0) {
console.log("Battle menu detected early. Out of PP/No move in slot, please check your setup.");
throw OperationFailedException(
ErrorReport::SEND_ERROR_REPORT, console,
"Battle menu detected early. Out of PP, please check your setup.",
true
);
}
}
else {
//Wild pokemon's turn/wait for catch animation
pbf_mash_button(context, BUTTON_B, 900);
context.wait_for_all_requests();
}
}
else {
//Wild pokemon's turn/wait for catch animation
pbf_mash_button(context, BUTTON_B, 900);
context.wait_for_all_requests();
}
}

NormalBattleMenuWatcher battle_menu(COLOR_YELLOW);
Expand Down Expand Up @@ -900,9 +866,10 @@ void quest_catch(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext
static_cast<AudioInferenceCallback&>(encounter_watcher),
}
);
if (ret == 0) {
encounter_watcher.throw_if_no_sound();

if (ret >= 0) {
console.log("Battle menu detected.");
encounter_watcher.throw_if_no_sound();

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
if (is_shiny) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ void quest_photo(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext
//Navigate to a catch target
void quest_catch_navi(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, const BBQOption& BBQ_OPTIONS, BBQuests current_quest);

//Select and throw ball
void quest_catch_throw_ball(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, Language language, std::string selected_ball);

//Handle catching the target
void quest_catch_handle_battle(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, const BBQOption& BBQ_OPTIONS, BBQuests current_quest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,12 @@ void quest_tera_self_defeat(const ProgramInfo& info, ConsoleHandle& console, Bot
static_cast<AudioInferenceCallback&>(encounter_watcher),
}
);
if (ret == 0) {
encounter_watcher.throw_if_no_sound();

if (ret >= 0) {
console.log("Battle menu detected.");
}

encounter_watcher.throw_if_no_sound();

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
if (is_shiny) {
console.log("Shiny detected!");
Expand Down Expand Up @@ -639,10 +639,10 @@ void quest_sneak_up(const ProgramInfo& info, ConsoleHandle& console, BotBaseCont
static_cast<AudioInferenceCallback&>(encounter_watcher),
}
);
if (ret == 0) {
console.log("Battle menu detected.");
encounter_watcher.throw_if_no_sound();

encounter_watcher.throw_if_no_sound();
if (ret >= 0) {
console.log("Battle menu detected.");

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
if (is_shiny) {
Expand Down Expand Up @@ -749,12 +749,12 @@ void quest_wild_tera(const ProgramInfo& info, ConsoleHandle& console, BotBaseCon
static_cast<AudioInferenceCallback&>(encounter_watcher),
}
);
if (ret == 0) {
encounter_watcher.throw_if_no_sound();

if (ret >= 0) {
console.log("Battle menu detected.");
}

encounter_watcher.throw_if_no_sound();

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
if (is_shiny) {
console.log("Shiny detected!");
Expand Down Expand Up @@ -1073,9 +1073,10 @@ void quest_tera_raid(ProgramEnvironment& env, ConsoleHandle& console, BotBaseCon
static_cast<AudioInferenceCallback&>(encounter_watcher),
}
);
encounter_watcher.throw_if_no_sound();

if (ret >= 0) {
console.log("Battle menu detected.");
encounter_watcher.throw_if_no_sound();

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
if (is_shiny) {
Expand Down