|
| 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/Overworld/PokemonSV_DirectionDetector.h" |
| 20 | +#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h" |
| 21 | +#include "PokemonSV_AutoStoryTools.h" |
| 22 | +#include "PokemonSV_AutoStory_Segment_17.h" |
| 23 | + |
| 24 | +//#include <iostream> |
| 25 | +//using std::cout; |
| 26 | +//using std::endl; |
| 27 | +//#include <unordered_map> |
| 28 | +//#include <algorithm> |
| 29 | + |
| 30 | +namespace PokemonAutomation{ |
| 31 | +namespace NintendoSwitch{ |
| 32 | +namespace PokemonSV{ |
| 33 | + |
| 34 | +using namespace Pokemon; |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +std::string AutoStory_Segment_17::name() const{ |
| 40 | + return "13.2: Cascarrafa Gym (Water): Gym challenge and Gym battle"; |
| 41 | +} |
| 42 | + |
| 43 | +std::string AutoStory_Segment_17::start_text() const{ |
| 44 | + return "Start: Received Kofu's wallet. At Porto Marinada Pokecenter."; |
| 45 | +} |
| 46 | + |
| 47 | +std::string AutoStory_Segment_17::end_text() const{ |
| 48 | + return "End: Defeated Cascarrafa Gym (Water). At Cascarrafa Gym."; |
| 49 | +} |
| 50 | + |
| 51 | +void AutoStory_Segment_17::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{ |
| 52 | + AutoStoryStats& stats = env.current_stats<AutoStoryStats>(); |
| 53 | + |
| 54 | + context.wait_for_all_requests(); |
| 55 | + env.console.overlay().add_log("Start Segment 13.2: Cascarrafa Gym (Water): Gym battle", COLOR_ORANGE); |
| 56 | + |
| 57 | + checkpoint_37(env, context, options.notif_status_update); |
| 58 | + checkpoint_38(env, context, options.notif_status_update); |
| 59 | + |
| 60 | + context.wait_for_all_requests(); |
| 61 | + env.console.log("End Segment 13.2: Cascarrafa Gym (Water): Gym battle", COLOR_GREEN); |
| 62 | + stats.m_segment++; |
| 63 | + env.update_stats(); |
| 64 | + |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +void checkpoint_37( |
| 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 | + DirectionDetector direction; |
| 83 | + do_action_and_monitor_for_battles(env.program_info(), env.console, context, |
| 84 | + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ |
| 85 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 0, 255, 50); |
| 86 | + |
| 87 | + // section 1 |
| 88 | + direction.change_direction(env.program_info(), env.console, context, 1.606); |
| 89 | + pbf_move_left_joystick(context, 128, 0, 200, 100); |
| 90 | + |
| 91 | + get_on_ride(env.program_info(), env.console, context); |
| 92 | + |
| 93 | + // section 2 |
| 94 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER); |
| 95 | + }); |
| 96 | + |
| 97 | + overworld_navigation(env.program_info(), env.console, context, |
| 98 | + NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY, |
| 99 | + 128, 0, 30, 10, false); |
| 100 | + // section 3. set marker to shop/Kofu |
| 101 | + realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 0, 140, 27); |
| 102 | + walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 20); |
| 103 | + |
| 104 | + clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW}); |
| 105 | + run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}); |
| 106 | + mash_button_till_overworld(env.console, context, BUTTON_A, 360); |
| 107 | + |
| 108 | + |
| 109 | + break; |
| 110 | + }catch (...){ |
| 111 | + context.wait_for_all_requests(); |
| 112 | + env.console.log("Resetting from checkpoint."); |
| 113 | + reset_game(env.program_info(), env.console, context); |
| 114 | + stats.m_reset++; |
| 115 | + env.update_stats(); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | +} |
| 120 | + |
| 121 | +void checkpoint_38( |
| 122 | + SingleSwitchProgramEnvironment& env, |
| 123 | + BotBaseContext& context, |
| 124 | + EventNotificationOption& notif_status_update |
| 125 | +){ |
| 126 | + AutoStoryStats& stats = env.current_stats<AutoStoryStats>(); |
| 127 | + bool first_attempt = true; |
| 128 | + while (true){ |
| 129 | + try{ |
| 130 | + if (first_attempt){ |
| 131 | + checkpoint_save(env, context, notif_status_update); |
| 132 | + first_attempt = false; |
| 133 | + } |
| 134 | + context.wait_for_all_requests(); |
| 135 | + move_cursor_towards_flypoint_and_go_there(env.program_info(), env.console, context, {ZoomChange::KEEP_ZOOM, 255, 180, 170}); |
| 136 | + DirectionDetector direction; |
| 137 | + do_action_and_monitor_for_battles(env.program_info(), env.console, context, |
| 138 | + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ |
| 139 | + direction.change_direction(env.program_info(), env.console, context, 0.3491); |
| 140 | + pbf_move_left_joystick(context, 128, 0, 400, 100); |
| 141 | + direction.change_direction(env.program_info(), env.console, context, 5.075911); |
| 142 | + pbf_move_left_joystick(context, 128, 0, 525, 100); |
| 143 | + }); |
| 144 | + |
| 145 | + direction.change_direction(env.program_info(), env.console, context, 3.771252); |
| 146 | + get_on_ride(env.program_info(), env.console, context); |
| 147 | + // walk towards elevator |
| 148 | + pbf_move_left_joystick(context, 128, 0, 700, 100); |
| 149 | + // jump to ensure you get on elevator |
| 150 | + pbf_controller_state(context, BUTTON_B, DPAD_NONE, 128, 0, 128, 128, 200); |
| 151 | + pbf_wait(context, 3 * TICKS_PER_SECOND); |
| 152 | + // wait for overworld to reappear after stepping off elevator |
| 153 | + wait_for_overworld(env.program_info(), env.console, context, 30); |
| 154 | + |
| 155 | + pbf_move_left_joystick(context, 128, 0, 120, 100); |
| 156 | + |
| 157 | + direction.change_direction(env.program_info(), env.console, context, 5.11); |
| 158 | + pbf_move_left_joystick(context, 128, 0, 1600, 100); |
| 159 | + direction.change_direction(env.program_info(), env.console, context, 3.2245); |
| 160 | + |
| 161 | + |
| 162 | + handle_when_stationary_in_overworld(env.program_info(), env.console, context, |
| 163 | + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ |
| 164 | + walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 18); |
| 165 | + }, |
| 166 | + [&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){ |
| 167 | + pbf_move_left_joystick(context, 255, 0, 100, 50); |
| 168 | + pbf_move_left_joystick(context, 0, 0, 100, 50); |
| 169 | + } |
| 170 | + ); |
| 171 | + // talk to Nemona |
| 172 | + mash_button_till_overworld(env.console, context, BUTTON_A, 360); |
| 173 | + |
| 174 | + // talk to reception. Battle Kofu |
| 175 | + walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10); |
| 176 | + clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW}); |
| 177 | + run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true); |
| 178 | + mash_button_till_overworld(env.console, context, BUTTON_A, 360); |
| 179 | + |
| 180 | + break; |
| 181 | + }catch (...){ |
| 182 | + context.wait_for_all_requests(); |
| 183 | + env.console.log("Resetting from checkpoint."); |
| 184 | + reset_game(env.program_info(), env.console, context); |
| 185 | + stats.m_reset++; |
| 186 | + env.update_stats(); |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | +} |
| 191 | + |
| 192 | + |
| 193 | +} |
| 194 | +} |
| 195 | +} |
0 commit comments