|
| 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_05.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_05::name() const{ |
| 39 | + return "05: First Arven Battle"; |
| 40 | +} |
| 41 | + |
| 42 | +std::string AutoStory_Segment_05::start_text() const{ |
| 43 | + return "Start: Saved the Legendary. Escaped from the Houndoom cave."; |
| 44 | +} |
| 45 | + |
| 46 | +std::string AutoStory_Segment_05::end_text() const{ |
| 47 | + return "End: Battled Arven, received Legendary's Pokeball. Talked to Nemona at Lighthouse."; |
| 48 | +} |
| 49 | + |
| 50 | +void AutoStory_Segment_05::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 05: First Arven Battle", COLOR_ORANGE); |
| 55 | + env.console.overlay().add_log("Start Segment 05: First Arven Battle", COLOR_ORANGE); |
| 56 | + |
| 57 | + checkpoint_09(env, context, options.notif_status_update); |
| 58 | + checkpoint_10(env, context, options.notif_status_update); |
| 59 | + |
| 60 | + context.wait_for_all_requests(); |
| 61 | + env.console.log("End Segment 05: First Arven Battle", COLOR_GREEN); |
| 62 | + env.console.overlay().add_log("End Segment 05: First Arven Battle", COLOR_GREEN); |
| 63 | + stats.m_segment++; |
| 64 | + env.update_stats(); |
| 65 | + |
| 66 | +} |
| 67 | + |
| 68 | + |
| 69 | +void checkpoint_09( |
| 70 | + SingleSwitchProgramEnvironment& env, |
| 71 | + BotBaseContext& context, |
| 72 | + EventNotificationOption& notif_status_update |
| 73 | +){ |
| 74 | + AutoStoryStats& stats = env.current_stats<AutoStoryStats>(); |
| 75 | + bool first_attempt = true; |
| 76 | + while (true){ |
| 77 | + try{ |
| 78 | + if (first_attempt){ |
| 79 | + checkpoint_save(env, context, notif_status_update); |
| 80 | + first_attempt = false; |
| 81 | + } |
| 82 | + context.wait_for_all_requests(); |
| 83 | + |
| 84 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 230, 120, 100); |
| 85 | + env.console.log("overworld_navigation: Go to Arven at the tower."); |
| 86 | + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_ONLY, 128, 0, true, true); |
| 87 | + |
| 88 | + context.wait_for_all_requests(); |
| 89 | + env.console.log("Found Arven"); |
| 90 | + env.console.overlay().add_log("Found Arven", COLOR_WHITE); |
| 91 | + // can lose battle, and story will still continue |
| 92 | + mash_button_till_overworld(env.console, context, BUTTON_A); |
| 93 | + context.wait_for_all_requests(); |
| 94 | + env.console.log("Receive legendary ball"); |
| 95 | + env.console.overlay().add_log("Receive legendary ball", COLOR_WHITE); |
| 96 | + |
| 97 | + break; |
| 98 | + }catch(...){ |
| 99 | + context.wait_for_all_requests(); |
| 100 | + env.console.log("Resetting from checkpoint."); |
| 101 | + reset_game(env.program_info(), env.console, context); |
| 102 | + stats.m_reset++; |
| 103 | + env.update_stats(); |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +void checkpoint_10( |
| 109 | + SingleSwitchProgramEnvironment& env, |
| 110 | + BotBaseContext& context, |
| 111 | + EventNotificationOption& notif_status_update |
| 112 | +){ |
| 113 | + AutoStoryStats& stats = env.current_stats<AutoStoryStats>(); |
| 114 | + bool first_attempt = true; |
| 115 | + while (true){ |
| 116 | + try{ |
| 117 | + if (first_attempt){ |
| 118 | + checkpoint_save(env, context, notif_status_update); |
| 119 | + first_attempt = false; |
| 120 | + } |
| 121 | + context.wait_for_all_requests(); |
| 122 | + env.console.log("Lighthouse view"); |
| 123 | + env.console.overlay().add_log("Lighthouse view", COLOR_WHITE); |
| 124 | + do_action_and_monitor_for_battles(env.program_info(), env.console, context, |
| 125 | + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ |
| 126 | + realign_player(env.program_info(), console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 230, 110, 100); |
| 127 | + pbf_move_left_joystick(context, 128, 0, 6 * TICKS_PER_SECOND, 8 * TICKS_PER_SECOND); |
| 128 | + pbf_move_left_joystick(context, 128, 0, 4 * TICKS_PER_SECOND, 20); |
| 129 | + pbf_move_left_joystick(context, 255, 128, 15, 20); |
| 130 | + pbf_press_button(context, BUTTON_L, 20, 20); |
| 131 | + pbf_move_left_joystick(context, 128, 0, 7 * TICKS_PER_SECOND, 20); |
| 132 | + } |
| 133 | + ); |
| 134 | + |
| 135 | + env.console.log("overworld_navigation: Go to Nemona on the lighthouse."); |
| 136 | + overworld_navigation(env.program_info(), env.console, context, NavigationStopCondition::STOP_DIALOG, NavigationMovementMode::DIRECTIONAL_SPAM_A, 128, 0, 20, true, true); |
| 137 | + |
| 138 | + mash_button_till_overworld(env.console, context, BUTTON_A); |
| 139 | + |
| 140 | + break; |
| 141 | + }catch(...){ |
| 142 | + context.wait_for_all_requests(); |
| 143 | + env.console.log("Resetting from checkpoint."); |
| 144 | + reset_game(env.program_info(), env.console, context); |
| 145 | + stats.m_reset++; |
| 146 | + env.update_stats(); |
| 147 | + } |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | +} |
| 155 | +} |
| 156 | +} |
0 commit comments