From c7da6d7d978fccbe7260f787aae480f824acbbac Mon Sep 17 00:00:00 2001 From: Alexander Yee Date: Sat, 21 Dec 2024 20:22:56 -0800 Subject: [PATCH] Make TeraMultiFarmer work for one-catch mons if joiner has already caught. --- .../DevPrograms/TestProgramSwitch.cpp | 5 +- .../Inference/NintendoSwitch_DateReader.cpp | 7 ++- .../Inference/NintendoSwitch_DateReader.h | 2 +- .../TeraRaids/PokemonSV_TeraMultiFarmer.cpp | 60 ++++++++++++++----- .../TeraRaids/PokemonSV_TeraRoutines.cpp | 8 +++ 5 files changed, 62 insertions(+), 20 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp index 287421d09..216fd6ab3 100644 --- a/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp +++ b/SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp @@ -279,13 +279,14 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope& BotBaseContext context(scope, console.botbase()); VideoOverlaySet overlays(overlay); - +#if 0 PokemonSwSh::MaxLairInternal::PokemonSwapMenuReader reader(console, overlay, Language::English); ImageRGB32 image("20241221-123730238930.png"); double hp[4]; reader.read_hp(image, hp); +#endif // reader.read_opponent_in_summary(logger, image); @@ -340,7 +341,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope& ); #endif -#if 0 +#if 1 VideoSnapshot image = feed.snapshot(); // ImageRGB32 image("screenshot-20241124-135028529403.png"); diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp index b3550985f..4de390de0 100644 --- a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp @@ -112,6 +112,7 @@ bool DateReader::detect(const ImageViewRGB32& screen) const{ return true; } +#if 0 int8_t DateReader::read_hours(Logger& logger, const ImageViewRGB32& screen) const{ if (!detect(screen)){ return -1; @@ -158,7 +159,9 @@ int8_t DateReader::read_hours(Logger& logger, const ImageViewRGB32& screen) cons } return (int8_t)hours; } + } +#endif void DateReader::set_hours( @@ -187,7 +190,9 @@ void DateReader::set_hours( // Read the hour. VideoSnapshot snapshot = console.video().snapshot(); - int8_t current_hour = read_hours(console.logger(), snapshot); +// int8_t current_hour = read_hours(console, snapshot); + int8_t current_hour = read_date(console, snapshot).second.hour; + if (current_hour < 0){ throw_and_log( console, ErrorReport::SEND_ERROR_REPORT, diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h index 32edd0b22..56e5048d4 100644 --- a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h @@ -39,7 +39,7 @@ class DateReader : public StaticScreenDetector{ // Read the hours (0 - 23) while on the date change window. // Returns -1 if unable to read. - int8_t read_hours(Logger& logger, const ImageViewRGB32& screen) const; +// int8_t read_hours(Logger& logger, std::shared_ptr screen) const; void set_hours( const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, diff --git a/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.cpp b/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.cpp index 7a68d7cbd..a513ade00 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.cpp @@ -31,6 +31,10 @@ #include "PokemonSV_AutoHostLobbyWaiter.h" #include "PokemonSV_TeraMultiFarmer.h" +//#include +//using std::cout; +//using std::endl; + namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonSV{ @@ -322,7 +326,12 @@ void TeraMultiFarmer::join_lobby( TeraMultiFarmer_Descriptor::Stats& stats = env.current_stats(); - for (size_t attempts = 0;; attempts++){ +// cout << "Joining Lobby" << endl; + + bool seen_code_entry = false; + bool seen_dialog = false; + size_t attempts = 0; + while (true){ if (attempts >= 3){ OperationFailedException::fire( console, ErrorReport::SEND_ERROR_REPORT, @@ -330,36 +339,55 @@ void TeraMultiFarmer::join_lobby( ); } - enter_code(console, context, FastCodeEntrySettings(), normalized_code, false); - + CodeEntryWatcher code_entry(COLOR_GREEN); TeraLobbyWatcher lobby(console.logger(), env.realtime_dispatcher(), COLOR_RED); - AdvanceDialogWatcher wrong_code(COLOR_YELLOW); - CodeEntryWatcher incomplete_code(COLOR_GREEN); + AdvanceDialogWatcher dialog(COLOR_YELLOW, std::chrono::seconds(2)); + TeraRaidSearchWatcher raid_search(COLOR_CYAN); context.wait_for_all_requests(); context.wait_for(std::chrono::seconds(3)); int ret = wait_until( console, context, std::chrono::seconds(60), { - {lobby, std::chrono::milliseconds(500)}, - wrong_code, - incomplete_code, + code_entry, + lobby, + dialog, + raid_search, } ); switch (ret){ case 0: + console.log("Detected code entry.", COLOR_RED); + if (seen_code_entry){ + console.log("Failed to enter code! Backing out and trying again...", COLOR_RED); + stats.m_errors++; + attempts++; + pbf_press_button(context, BUTTON_X, 20, 480); + enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE); + seen_code_entry = false; + continue; + } + seen_code_entry = true; + enter_code(console, context, FastCodeEntrySettings(), normalized_code, false); + context.wait_for(std::chrono::seconds(1)); + continue; + case 1: console.log("Entered raid lobby!"); - pbf_mash_button(context, BUTTON_A, 125); + pbf_mash_button(context, BUTTON_A, 5 * TICKS_PER_SECOND); break; - case 1: - console.log("Wrong code! Backing out and trying again...", COLOR_RED); - stats.m_errors++; + case 2: + console.log("Detected dialog...", COLOR_ORANGE); + seen_dialog = true; pbf_press_button(context, BUTTON_B, 20, 230); - enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE); continue; - case 2: - console.log("Failed to enter code! Backing out and trying again...", COLOR_RED); + case 3: + if (!seen_dialog){ + context.wait_for(std::chrono::seconds(1)); + continue; + } + console.log("Wrong code! Backing out and trying again...", COLOR_RED); stats.m_errors++; - pbf_press_button(context, BUTTON_X, 20, 230); + attempts++; +// pbf_press_button(context, BUTTON_B, 20, 230); enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE); continue; default: diff --git a/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.cpp b/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.cpp index 74726cd9c..61c6040b8 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.cpp @@ -139,6 +139,7 @@ void open_hosting_lobby( recovery_mode = true; } +// AdvanceDialogWatcher dialog(COLOR_GREEN); TeraCardWatcher card_detector(COLOR_YELLOW); TeraLobbyWatcher lobby(console.logger(), env.realtime_dispatcher(), COLOR_BLUE); context.wait_for_all_requests(); @@ -147,6 +148,7 @@ void open_hosting_lobby( std::chrono::seconds(30), { overworld, +// dialog, card_detector, {lobby, std::chrono::milliseconds(500)} } @@ -163,6 +165,12 @@ void open_hosting_lobby( ); } continue; +#if 0 + case 1: + console.log("Detect possible uncatchable dialog...", COLOR_ORANGE); + pbf_press_button(context, BUTTON_B, 20, 230); + continue; +#endif case 1: console.log("Detected Tera card."); if (mode != HostingMode::LOCAL){