From da1a04cb688dae116decd52ebe91b0ac73c445ea Mon Sep 17 00:00:00 2001 From: jw098 Date: Fri, 4 Oct 2024 19:03:04 -0700 Subject: [PATCH] segment 02 to 04 --- SerialPrograms/CMakeLists.txt | 8 +- SerialPrograms/SerialPrograms.pro | 6 + .../AutoStory/PokemonSV_AutoStory.cpp | 22 +- .../AutoStory/PokemonSV_AutoStoryTools.cpp | 9 +- .../AutoStory/PokemonSV_AutoStoryTools.h | 7 +- .../PokemonSV_AutoStory_Segment_02.cpp | 122 +++++++++++ .../PokemonSV_AutoStory_Segment_02.h | 43 ++++ .../PokemonSV_AutoStory_Segment_03.cpp | 201 +++++++++++++++++ .../PokemonSV_AutoStory_Segment_03.h | 51 +++++ .../PokemonSV_AutoStory_Segment_04.cpp | 204 ++++++++++++++++++ .../PokemonSV_AutoStory_Segment_04.h | 43 ++++ 11 files changed, 697 insertions(+), 19 deletions(-) create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp create mode 100644 SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index a4b77f40a..4cdac8cc4 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -1429,7 +1429,13 @@ file(GLOB MAIN_SOURCES Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.cpp Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.h Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp - Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp diff --git a/SerialPrograms/SerialPrograms.pro b/SerialPrograms/SerialPrograms.pro index 6fb8ba213..7442647cb 100644 --- a/SerialPrograms/SerialPrograms.pro +++ b/SerialPrograms/SerialPrograms.pro @@ -714,6 +714,9 @@ SOURCES += \ Source/PokemonSV/PokemonSV_Settings.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.cpp \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \ Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \ @@ -1802,6 +1805,9 @@ HEADERS += \ Source/PokemonSV/PokemonSV_Settings.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_00.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_01.h \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h \ + Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \ Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \ diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp index 35b9e5016..5481137af 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp @@ -17,9 +17,9 @@ #include "PokemonSV/Programs/PokemonSV_GameEntry.h" #include "PokemonSV_AutoStory_Segment_00.h" #include "PokemonSV_AutoStory_Segment_01.h" -// #include "PokemonSV_AutoStory_Segment_02.h" -// #include "PokemonSV_AutoStory_Segment_03.h" -// #include "PokemonSV_AutoStory_Segment_04.h" +#include "PokemonSV_AutoStory_Segment_02.h" +#include "PokemonSV_AutoStory_Segment_03.h" +#include "PokemonSV_AutoStory_Segment_04.h" // #include "PokemonSV_AutoStory_Segment_05.h" // #include "PokemonSV_AutoStory_Segment_06.h" // #include "PokemonSV_AutoStory_Segment_07.h" @@ -50,9 +50,9 @@ std::vector> make_autoStory_segment_list(){ std::vector> segment_list; segment_list.emplace_back(std::make_unique()); segment_list.emplace_back(std::make_unique()); - // segment_list.emplace_back(std::make_unique()); - // segment_list.emplace_back(std::make_unique()); - // segment_list.emplace_back(std::make_unique()); + segment_list.emplace_back(std::make_unique()); + segment_list.emplace_back(std::make_unique()); + segment_list.emplace_back(std::make_unique()); // segment_list.emplace_back(std::make_unique()); // segment_list.emplace_back(std::make_unique()); // segment_list.emplace_back(std::make_unique()); @@ -461,11 +461,11 @@ void AutoStory::test_checkpoints( checkpoint_list.push_back([&](){checkpoint_01(env, context, notif_status_update, language);}); checkpoint_list.push_back([&](){checkpoint_02(env, context, notif_status_update);}); checkpoint_list.push_back([&](){checkpoint_03(env, context, notif_status_update, language, starter_choice);}); - // checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);}); - // checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);}); - // checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);}); - // checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);}); - // checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);}); + checkpoint_list.push_back([&](){checkpoint_04(env, context, notif_status_update);}); + checkpoint_list.push_back([&](){checkpoint_05(env, context, notif_status_update);}); + checkpoint_list.push_back([&](){checkpoint_06(env, context, notif_status_update);}); + checkpoint_list.push_back([&](){checkpoint_07(env, context, notif_status_update);}); + checkpoint_list.push_back([&](){checkpoint_08(env, context, notif_status_update);}); // checkpoint_list.push_back([&](){checkpoint_09(env, context, notif_status_update);}); // checkpoint_list.push_back([&](){checkpoint_10(env, context, notif_status_update);}); // checkpoint_list.push_back([&](){checkpoint_11(env, context, notif_status_update);}); diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp index 7196a80dc..d78124a78 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp @@ -297,7 +297,8 @@ void overworld_navigation( NavigationMovementMode movement_mode, uint8_t x, uint8_t y, uint16_t seconds_timeout, uint16_t seconds_realign, - bool auto_heal + bool auto_heal, + bool detect_wipeout ){ bool should_realign = true; if (seconds_timeout <= seconds_realign){ @@ -527,11 +528,11 @@ void change_settings(SingleSwitchProgramEnvironment& env, BotBaseContext& contex } void do_action_and_monitor_for_battles( - SingleSwitchProgramEnvironment& env, + const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, std::function< - void(SingleSwitchProgramEnvironment& env, + void(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context) >&& action @@ -541,7 +542,7 @@ void do_action_and_monitor_for_battles( console, context, [&](BotBaseContext& context){ context.wait_for_all_requests(); - action(env, console, context); + action(info, console, context); }, {battle_menu} ); diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h index 3d3f0952b..0434575ce 100644 --- a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h @@ -121,7 +121,8 @@ void overworld_navigation(const ProgramInfo& info, ConsoleHandle& console, BotBa NavigationMovementMode movement_mode, uint8_t x, uint8_t y, uint16_t seconds_timeout = 60, uint16_t seconds_realign = 60, - bool auto_heal = true + bool auto_heal = false, + bool detect_wipeout = false ); void config_option(BotBaseContext& context, int change_option_value); @@ -131,11 +132,11 @@ void swap_starter_moves(const ProgramInfo& info, ConsoleHandle& console, BotBase // run the given `action`. if detect a battle, stop the action, and throw exception void do_action_and_monitor_for_battles( - SingleSwitchProgramEnvironment& env, + const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context, std::function< - void(SingleSwitchProgramEnvironment& env, + void(const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context) >&& action diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp new file mode 100644 index 000000000..9dc1a1ee2 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.cpp @@ -0,0 +1,122 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include "CommonFramework/GlobalSettingsPanel.h" +#include "CommonFramework/Exceptions/FatalProgramException.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/InferenceInfra/InferenceRoutines.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/Tools/StatsTracking.h" +#include "CommonFramework/Tools/VideoResolutionCheck.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Pokemon_Strings.h" +#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" +#include "PokemonSV/Programs/PokemonSV_GameEntry.h" +#include "PokemonSV/Programs/PokemonSV_SaveGame.h" +#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h" +#include "PokemonSV_AutoStoryTools.h" +#include "PokemonSV_AutoStory_Segment_02.h" + +//#include +//using std::cout; +//using std::endl; +//#include +//#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +using namespace Pokemon; + + + + +std::string AutoStory_Segment_02::name() const{ + return "02: First Nemona Battle"; +} + +std::string AutoStory_Segment_02::start_text() const{ + return "Start: Picked the starter."; +} + +std::string AutoStory_Segment_02::end_text() const{ + return "End: Battled Nemona on the beach."; +} + +void AutoStory_Segment_02::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{ + AutoStoryStats& stats = env.current_stats(); + + context.wait_for_all_requests(); + env.console.log("Start Segment 02: First Nemona Battle", COLOR_ORANGE); + env.console.overlay().add_log("Start Segment 02: First Nemona Battle", COLOR_ORANGE); + + checkpoint_04(env, context, options.notif_status_update); + + context.wait_for_all_requests(); + env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN); + env.console.overlay().add_log("End Segment 02: First Nemona Battle", COLOR_GREEN); + stats.m_segment++; + env.update_stats(); + +} + + +void checkpoint_04( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + context.wait_for_all_requests(); + + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 220, 245, 50); + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND); + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 128, 50); + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND); + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 60, 50); + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); + env.console.log("overworld_navigation: Go to Nemona at the beach."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_SPAM_A, 128, 0, 8); + + context.wait_for_all_requests(); + env.console.overlay().add_log("Found Nemona", COLOR_WHITE); + + context.wait_for_all_requests(); + env.console.log("Starting battle..."); + env.console.overlay().add_log("Starting battle...", COLOR_WHITE); + // TODO: Battle start prompt detection + // can lose this battle, and story will continue + mash_button_till_overworld(env.console, context); + context.wait_for_all_requests(); + env.console.log("Finished battle."); + env.console.overlay().add_log("Finished battle.", COLOR_WHITE); + + break; + }catch(...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } + +} + + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h new file mode 100644 index 000000000..3b58420e2 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_02.h @@ -0,0 +1,43 @@ +/* Autostory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_02_H +#define PokemonAutomation_PokemonSV_AutoStory_Segment_02_H + +#include +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "CommonFramework/Options/LanguageOCROption.h" +#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h" +#include "PokemonSV/Programs/PokemonSV_Navigation.h" +#include "PokemonSV_AutoStoryTools.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +class AutoStory_Segment_02 : public AutoStory_Segment{ +public: + virtual std::string name() const override; + virtual std::string start_text() const override; + virtual std::string end_text() const override; + virtual void run_segment( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + AutoStoryOptions options) const override; +}; + + +// start: Received starter pokemon and changed move order. Cleared autoheal tutorial. +// end: Battled Nemona on the beach. +void checkpoint_04(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp new file mode 100644 index 000000000..9d3badf0e --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.cpp @@ -0,0 +1,201 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include "CommonFramework/GlobalSettingsPanel.h" +#include "CommonFramework/Exceptions/FatalProgramException.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/InferenceInfra/InferenceRoutines.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/Tools/StatsTracking.h" +#include "CommonFramework/Tools/VideoResolutionCheck.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Pokemon_Strings.h" +#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" +#include "PokemonSV/Programs/PokemonSV_GameEntry.h" +#include "PokemonSV/Programs/PokemonSV_SaveGame.h" +#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h" +#include "PokemonSV_AutoStoryTools.h" +#include "PokemonSV_AutoStory_Segment_03.h" + +//#include +//using std::cout; +//using std::endl; +//#include +//#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +using namespace Pokemon; + + + + +std::string AutoStory_Segment_03::name() const{ + return "03: Catch Tutorial"; +} + +std::string AutoStory_Segment_03::start_text() const{ + return "Start: Battled Nemona on the beach."; +} + +std::string AutoStory_Segment_03::end_text() const{ + return "End: Finished catch tutorial. Walked to the cliff and heard mystery cry."; +} + +void AutoStory_Segment_03::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{ + AutoStoryStats& stats = env.current_stats(); + + context.wait_for_all_requests(); + env.console.log("Start Segment 03: Catch Tutorial", COLOR_ORANGE); + env.console.overlay().add_log("Start Segment 03: Catch Tutorial", COLOR_ORANGE); + + checkpoint_05(env, context, options.notif_status_update); + checkpoint_06(env, context, options.notif_status_update); + checkpoint_07(env, context, options.notif_status_update); + + context.wait_for_all_requests(); + env.console.log("End Segment 03: Catch Tutorial", COLOR_GREEN); + env.console.overlay().add_log("End Segment 03: Catch Tutorial", COLOR_GREEN); + stats.m_segment++; + env.update_stats(); + +} + + +void checkpoint_05( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + context.wait_for_all_requests(); + + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 40, 160, 60); + pbf_move_left_joystick(context, 128, 0, 7 * TICKS_PER_SECOND, 20); + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 40, 84, 60); + env.console.log("overworld_navigation: Go to mom at the gate."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, 20); + + context.wait_for_all_requests(); + env.console.log("Get mom's sandwich"); + env.console.overlay().add_log("Get mom's sandwich", COLOR_WHITE); + mash_button_till_overworld(env.console, context); + break; + }catch(...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } +} + +void checkpoint_06( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + + context.wait_for_all_requests(); + + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 40, 82, 60); + pbf_move_left_joystick(context, 128, 0, 6 * TICKS_PER_SECOND, 20); + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 110, 10, 60); + env.console.log("overworld_navigation: Go to Nemona."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, 20); + + context.wait_for_all_requests(); + env.console.log("clear_dialog: Talk with Nemona to start catch tutorial. Stop when detect battle."); + clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, + {CallbackEnum::WHITE_A_BUTTON, CallbackEnum::TUTORIAL, CallbackEnum::BATTLE}); + + // can die in catch tutorial, and the story will continue + env.console.log("run_battle_press_A: Battle Lechonk in catch tutorial. Stop when detect dialog."); + run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG); + + env.console.log("clear_dialog: Talk with Nemona to finish catch tutorial. Stop when detect overworld."); + clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, + {CallbackEnum::TUTORIAL, CallbackEnum::OVERWORLD}); + + context.wait_for_all_requests(); + env.console.log("Finished catch tutorial"); + env.console.overlay().add_log("Finished catch tutorial", COLOR_WHITE); + + break; + }catch(...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } +} + +void checkpoint_07( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + + context.wait_for_all_requests(); + env.console.log("Move to cliff"); + env.console.overlay().add_log("Move to cliff", COLOR_WHITE); + + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 240, 60, 80); + env.console.log("overworld_navigation: Go to cliff."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 116, 0, 72, 24, true, true); + + env.console.log("clear_dialog: Talk to Nemona at the cliff. Stop when detect overworld."); + clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD}); + + context.wait_for_all_requests(); + env.console.log("Mystery cry"); + env.console.overlay().add_log("Mystery cry", COLOR_WHITE); + + break; + }catch(...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } +} + + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h new file mode 100644 index 000000000..633608cbb --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_03.h @@ -0,0 +1,51 @@ +/* Autostory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_03_H +#define PokemonAutomation_PokemonSV_AutoStory_Segment_03_H + +#include +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "CommonFramework/Options/LanguageOCROption.h" +#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h" +#include "PokemonSV/Programs/PokemonSV_Navigation.h" +#include "PokemonSV_AutoStoryTools.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +class AutoStory_Segment_03 : public AutoStory_Segment{ +public: + virtual std::string name() const override; + virtual std::string start_text() const override; + virtual std::string end_text() const override; + virtual void run_segment( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + AutoStoryOptions options) const override; +}; + + +// start: Battled Nemona on the beach. +// end: Met mom at gate. Received mom's sandwich. +void checkpoint_05(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + +// start: Met mom at gate. Received mom's sandwich. +// end: Cleared catch tutorial. +void checkpoint_06(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + +// start: Cleared catch tutorial. +// end: Moved to cliff. Heard mystery cry. +void checkpoint_07(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + + +} +} +} +#endif diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp new file mode 100644 index 000000000..b944e0393 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.cpp @@ -0,0 +1,204 @@ +/* AutoStory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#include "CommonFramework/GlobalSettingsPanel.h" +#include "CommonFramework/Exceptions/FatalProgramException.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/InferenceInfra/InferenceRoutines.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/Tools/StatsTracking.h" +#include "CommonFramework/Tools/VideoResolutionCheck.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/Pokemon_Strings.h" +#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" +#include "PokemonSV/Programs/PokemonSV_GameEntry.h" +#include "PokemonSV/Programs/PokemonSV_SaveGame.h" +#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h" +#include "PokemonSV_AutoStoryTools.h" +#include "PokemonSV_AutoStory_Segment_04.h" + +//#include +//using std::cout; +//using std::endl; +//#include +//#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +using namespace Pokemon; + + + + +std::string AutoStory_Segment_04::name() const{ + return "04: Rescue Legendary"; +} + +std::string AutoStory_Segment_04::start_text() const{ + return "Start: Finished catch tutorial. Walked to the cliff and heard mystery cry."; +} + +std::string AutoStory_Segment_04::end_text() const{ + return "End: Saved the Legendary. Escaped from the Houndoom cave."; +} + +void AutoStory_Segment_04::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{ + AutoStoryStats& stats = env.current_stats(); + + context.wait_for_all_requests(); + env.console.log("Start Segment 04: Rescue Legendary", COLOR_ORANGE); + env.console.overlay().add_log("Start Segment 04: Rescue Legendary", COLOR_ORANGE); + + checkpoint_08(env, context, options.notif_status_update); + + context.wait_for_all_requests(); + env.console.log("End Segment 04: Rescue Legendary", COLOR_GREEN); + env.console.overlay().add_log("End Segment 04: Rescue Legendary", COLOR_GREEN); + stats.m_segment++; + env.update_stats(); + +} + +void checkpoint_08( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + EventNotificationOption& notif_status_update +){ + AutoStoryStats& stats = env.current_stats(); + bool first_attempt = true; + while (true){ + try{ + if (first_attempt){ + checkpoint_save(env, context, notif_status_update); + first_attempt = false; + } + context.wait_for_all_requests(); + + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 230, 70, 100); + env.console.log("overworld_navigation: Go to cliff."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, true, true); + + env.console.log("clear_dialog: Look over the injured Miraidon/Koraidon on the beach. Fall down the cliff"); + clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 30, {}); + // long animation + env.console.log("overworld_navigation: Go to Legendary pokemon laying on the beach."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, 30, true, true); + + env.console.log("clear_dialog: Offer Miraidon/Koraidon a sandwich."); + clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {}); + + // TODO: Bag menu navigation + context.wait_for_all_requests(); + env.console.log("Feed mom's sandwich"); + env.console.overlay().add_log("Feed mom's sandwich", COLOR_WHITE); + + GradientArrowWatcher arrow(COLOR_RED, GradientArrowType::RIGHT, {0.104, 0.312, 0.043, 0.08}); + context.wait_for_all_requests(); + + int ret = run_until( + env.console, context, + [](BotBaseContext& context){ + for (int i = 0; i < 10; i++){ + pbf_press_dpad(context, DPAD_UP, 20, 250); + } + }, + {arrow} + ); + if (ret < 0){ + throw OperationFailedException( + ErrorReport::SEND_ERROR_REPORT, env.console, + "Failed to feed mom's sandwich.", + true + ); + } + + // only press A when the sandwich is selected + pbf_mash_button(context, BUTTON_A, 100); + + env.console.log("clear_dialog: Miraidon/Koraidon gets up and walks to cave entrance."); + clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 35, {}); + // long animation + + // First Nemona cave conversation + context.wait_for_all_requests(); + env.console.log("Enter cave"); + env.console.overlay().add_log("Enter cave", COLOR_WHITE); + do_action_and_monitor_for_battles(env.program_info(), env.console, context, + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ + pbf_move_left_joystick(context, 128, 20, 10 * TICKS_PER_SECOND, 20); + pbf_move_left_joystick(context, 150, 20, 1 * TICKS_PER_SECOND, 20); + pbf_move_left_joystick(context, 128, 20, 8 * TICKS_PER_SECOND, 20); + pbf_move_left_joystick(context, 150, 20, 2 * TICKS_PER_SECOND, 20); + } + ); + + env.console.log("overworld_navigation: Go to cave."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 20, 10, true, true); + + env.console.log("clear_dialog: Talk to Nemona yelling down, while you're down in the cave."); + clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG}); + + do_action_and_monitor_for_battles(env.program_info(), env.console, context, + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ + // Legendary rock break + context.wait_for_all_requests(); + console.log("Rock break"); + console.overlay().add_log("Rock break", COLOR_WHITE); + pbf_move_left_joystick(context, 128, 20, 3 * TICKS_PER_SECOND, 20); + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NO_MARKER, 230, 25, 30); + pbf_move_left_joystick(context, 128, 0, 2 * TICKS_PER_SECOND, 5 * TICKS_PER_SECOND); + + // Houndour wave + context.wait_for_all_requests(); + console.log("Houndour wave"); + console.overlay().add_log("Houndour wave", COLOR_WHITE); + pbf_move_left_joystick(context, 140, 20, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NO_MARKER, 220, 15, 30); + pbf_move_left_joystick(context, 128, 20, 5 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); + pbf_move_left_joystick(context, 128, 20, 6 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NO_MARKER, 220, 25, 20); + pbf_move_left_joystick(context, 128, 20, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); + pbf_move_left_joystick(context, 128, 20, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NO_MARKER, 220, 25, 25); + pbf_move_left_joystick(context, 128, 20, 6 * TICKS_PER_SECOND, 20 * TICKS_PER_SECOND); + + // Houndoom encounter + context.wait_for_all_requests(); + console.log("Houndoom encounter"); + console.overlay().add_log("Houndoom encounter", COLOR_WHITE); + pbf_move_left_joystick(context, 128, 20, 4 * TICKS_PER_SECOND, 20); + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NO_MARKER, 245, 20, 20); + pbf_move_left_joystick(context, 128, 20, 2 * TICKS_PER_SECOND, 20); + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NO_MARKER, 255, 90, 20); + pbf_move_left_joystick(context, 128, 20, 8 * TICKS_PER_SECOND, 8 * TICKS_PER_SECOND); + pbf_press_button(context, BUTTON_L, 20, 20); + } + ); + + env.console.log("overworld_navigation: Go to Houndoom."); + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 20, 40, true, true); + + mash_button_till_overworld(env.console, context, BUTTON_A); + + break; + }catch(...){ + context.wait_for_all_requests(); + env.console.log("Resetting from checkpoint."); + reset_game(env.program_info(), env.console, context); + stats.m_reset++; + env.update_stats(); + } + } + +} + + + +} +} +} diff --git a/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h new file mode 100644 index 000000000..ec69d58e3 --- /dev/null +++ b/SerialPrograms/Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_04.h @@ -0,0 +1,43 @@ +/* Autostory + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_04_H +#define PokemonAutomation_PokemonSV_AutoStory_Segment_04_H + +#include +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "CommonFramework/Options/LanguageOCROption.h" +#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h" +#include "PokemonSV/Programs/PokemonSV_Navigation.h" +#include "PokemonSV_AutoStoryTools.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + +class AutoStory_Segment_04 : public AutoStory_Segment{ +public: + virtual std::string name() const override; + virtual std::string start_text() const override; + virtual std::string end_text() const override; + virtual void run_segment( + SingleSwitchProgramEnvironment& env, + BotBaseContext& context, + AutoStoryOptions options) const override; +}; + + +// start: Moved to cliff. Heard mystery cry. +// end: Rescued Koraidon/Miraidon and escaped from the Houndoom Cave. +void checkpoint_08(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update); + + +} +} +} +#endif