|
| 1 | +/* AutoStory |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/Arduino-Source |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonFramework/GlobalSettingsPanel.h" |
| 8 | +#include "CommonFramework/Exceptions/FatalProgramException.h" |
| 9 | +#include "CommonFramework/Exceptions/OperationFailedException.h" |
| 10 | +#include "CommonFramework/InferenceInfra/InferenceRoutines.h" |
| 11 | +#include "CommonFramework/Notifications/ProgramNotifications.h" |
| 12 | +#include "CommonFramework/Tools/StatsTracking.h" |
| 13 | +#include "CommonFramework/Tools/VideoResolutionCheck.h" |
| 14 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 15 | +#include "Pokemon/Pokemon_Strings.h" |
| 16 | +#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" |
| 17 | +#include "PokemonSV/Programs/PokemonSV_GameEntry.h" |
| 18 | +#include "PokemonSV/Programs/PokemonSV_SaveGame.h" |
| 19 | +#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h" |
| 20 | +#include "PokemonSV_AutoStoryTools.h" |
| 21 | +#include "PokemonSV_AutoStory_Segment_02.h" |
| 22 | + |
| 23 | +//#include <iostream> |
| 24 | +//using std::cout; |
| 25 | +//using std::endl; |
| 26 | +//#include <unordered_map> |
| 27 | +//#include <algorithm> |
| 28 | + |
| 29 | +namespace PokemonAutomation{ |
| 30 | +namespace NintendoSwitch{ |
| 31 | +namespace PokemonSV{ |
| 32 | + |
| 33 | +using namespace Pokemon; |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +std::string AutoStory_Segment_02::name() const{ |
| 39 | + return "02: First Nemona Battle"; |
| 40 | +} |
| 41 | + |
| 42 | +std::string AutoStory_Segment_02::start_text() const{ |
| 43 | + return "Start: Picked the starter."; |
| 44 | +} |
| 45 | + |
| 46 | +std::string AutoStory_Segment_02::end_text() const{ |
| 47 | + return "End: Battled Nemona on the beach."; |
| 48 | +} |
| 49 | + |
| 50 | +void AutoStory_Segment_02::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{ |
| 51 | + AutoStoryStats& stats = env.current_stats<AutoStoryStats>(); |
| 52 | + |
| 53 | + context.wait_for_all_requests(); |
| 54 | + env.console.log("Start Segment 02: First Nemona Battle", COLOR_ORANGE); |
| 55 | + env.console.overlay().add_log("Start Segment 02: First Nemona Battle", COLOR_ORANGE); |
| 56 | + |
| 57 | + checkpoint_04(env, context, options.notif_status_update); |
| 58 | + |
| 59 | + context.wait_for_all_requests(); |
| 60 | + env.console.log("End Segment 02: First Nemona Battle", COLOR_GREEN); |
| 61 | + env.console.overlay().add_log("End Segment 02: First Nemona Battle", COLOR_GREEN); |
| 62 | + stats.m_segment++; |
| 63 | + env.update_stats(); |
| 64 | + |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +void checkpoint_04( |
| 69 | + SingleSwitchProgramEnvironment& env, |
| 70 | + BotBaseContext& context, |
| 71 | + EventNotificationOption& notif_status_update |
| 72 | +){ |
| 73 | + AutoStoryStats& stats = env.current_stats<AutoStoryStats>(); |
| 74 | + bool first_attempt = true; |
| 75 | + while (true){ |
| 76 | + try{ |
| 77 | + if (first_attempt){ |
| 78 | + checkpoint_save(env, context, notif_status_update); |
| 79 | + first_attempt = false; |
| 80 | + } |
| 81 | + context.wait_for_all_requests(); |
| 82 | + |
| 83 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 220, 245, 50); |
| 84 | + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND); |
| 85 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 128, 50); |
| 86 | + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 1 * TICKS_PER_SECOND); |
| 87 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 255, 60, 50); |
| 88 | + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 2 * TICKS_PER_SECOND); |
| 89 | + env.console.log("overworld_navigation: Go to Nemona at the beach."); |
| 90 | + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_SPAM_A, 128, 0, 8); |
| 91 | + |
| 92 | + context.wait_for_all_requests(); |
| 93 | + env.console.overlay().add_log("Found Nemona", COLOR_WHITE); |
| 94 | + |
| 95 | + context.wait_for_all_requests(); |
| 96 | + env.console.log("Starting battle..."); |
| 97 | + env.console.overlay().add_log("Starting battle...", COLOR_WHITE); |
| 98 | + // TODO: Battle start prompt detection |
| 99 | + // can lose this battle, and story will continue |
| 100 | + mash_button_till_overworld(env.console, context); |
| 101 | + context.wait_for_all_requests(); |
| 102 | + env.console.log("Finished battle."); |
| 103 | + env.console.overlay().add_log("Finished battle.", COLOR_WHITE); |
| 104 | + |
| 105 | + break; |
| 106 | + }catch(...){ |
| 107 | + context.wait_for_all_requests(); |
| 108 | + env.console.log("Resetting from checkpoint."); |
| 109 | + reset_game(env.program_info(), env.console, context); |
| 110 | + stats.m_reset++; |
| 111 | + env.update_stats(); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | +} |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +} |
| 121 | +} |
| 122 | +} |
0 commit comments