|
4 | 4 | * |
5 | 5 | */ |
6 | 6 |
|
| 7 | + #include "CommonTools/Async/InferenceRoutines.h" |
7 | 8 | #include "CommonFramework/GlobalSettingsPanel.h" |
8 | 9 | #include "CommonFramework/Notifications/ProgramNotifications.h" |
9 | 10 | #include "CommonFramework/VideoPipeline/VideoFeed.h" |
|
12 | 13 | #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
13 | 14 | #include "Pokemon/Pokemon_Strings.h" |
14 | 15 | #include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h" |
| 16 | +#include "NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h" |
| 17 | +#include "NintendoSwitch/Inference/NintendoSwitch_ConsoleTypeDetector.h" |
15 | 18 | #include "PokemonSV/Inference/PokemonSV_MainMenuDetector.h" |
16 | 19 | #include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h" |
17 | 20 | #include "PokemonSV/Programs/PokemonSV_GameEntry.h" |
| 21 | +#include "PokemonSV/Programs/PokemonSV_SaveGame.h" |
18 | 22 | #include "PokemonSV/Programs/PokemonSV_MenuNavigation.h" |
19 | 23 | #include "PokemonSV/Programs/PokemonSV_WorldNavigation.h" |
20 | 24 | #include "PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h" |
@@ -133,17 +137,68 @@ void ClaimMysteryGift::enter_mystery_gift_code(SingleSwitchProgramEnvironment& e |
133 | 137 | } |
134 | 138 |
|
135 | 139 | void ClaimMysteryGift::claim_mystery_gift(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){ |
136 | | - |
137 | | - enter_menu_from_overworld(env.program_info(), env.console, context, menu_index); |
138 | | - pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND); |
139 | | - pbf_press_dpad(context, DPAD_UP, 20, 105); |
140 | | - pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND); |
141 | | - pbf_press_dpad(context, DPAD_DOWN, 20, 105); |
142 | | - pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND); |
143 | | - pbf_press_button(context, BUTTON_A, 20, 10 * TICKS_PER_SECOND); |
144 | | - clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10); |
145 | | - |
146 | | - enter_mystery_gift_code(env, context); |
| 140 | + save_game_from_menu_or_overworld(env.program_info(), env.console, context, false); |
| 141 | + |
| 142 | + size_t max_attempts = 5; |
| 143 | + for (size_t i = 0; i < max_attempts; i++){ |
| 144 | + enter_menu_from_overworld(env.program_info(), env.console, context, menu_index); |
| 145 | + pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND); |
| 146 | + pbf_press_dpad(context, DPAD_UP, 20, 105); |
| 147 | + pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND); |
| 148 | + pbf_press_dpad(context, DPAD_DOWN, 20, 105); |
| 149 | + pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND); |
| 150 | + pbf_press_button(context, BUTTON_A, 20, 10 * TICKS_PER_SECOND); |
| 151 | + clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG}); |
| 152 | + |
| 153 | + context.wait_for_all_requests(); |
| 154 | + context.wait_for(Milliseconds(300)); |
| 155 | + // we expect to be within Mystery Gift window, with the keyboard visible and "1" being highlighted |
| 156 | + // |
| 157 | + |
| 158 | + ConsoleType console_type = env.console.state().console_type(); |
| 159 | + |
| 160 | + if (console_type == ConsoleType::Unknown){ |
| 161 | + env.console.log("Unknown Switch type. Try to detect."); |
| 162 | + console_type = detect_console_type_from_in_game(env.console, context); |
| 163 | + } |
| 164 | + |
| 165 | + ImageFloatBox key1_box; |
| 166 | + ImageFloatBox other_setting1; |
| 167 | + ImageFloatBox other_setting2; |
| 168 | + ImageFloatBox background; |
| 169 | + |
| 170 | + if (is_switch1(console_type)){ |
| 171 | + key1_box = {0.037322, 0.451172, 0.009879, 0.113281}; |
| 172 | + other_setting1 = {0.01, 0.451172, 0.009879, 0.113281}; |
| 173 | + other_setting2 = {0.02, 0.451172, 0.009879, 0.113281}; |
| 174 | + background = {0.0, 0.451172, 0.009879, 0.113281}; |
| 175 | + }else if (is_switch2(console_type)){ |
| 176 | + key1_box = {0.062706, 0.510763, 0.009901, 0.097847}; |
| 177 | + other_setting1 = {0.02, 0.510763, 0.009901, 0.097847}; |
| 178 | + other_setting2 = {0.04, 0.510763, 0.009901, 0.097847}; |
| 179 | + background = {0.0, 0.510763, 0.009901, 0.097847}; |
| 180 | + }else{ |
| 181 | + throw UserSetupError( |
| 182 | + env.console, |
| 183 | + "Please select a valid Switch console type." |
| 184 | + ); |
| 185 | + } |
| 186 | + |
| 187 | + SelectedSettingWatcher key1_selected(key1_box, other_setting1, other_setting2, background); |
| 188 | + int ret = wait_until( |
| 189 | + env.console, context, |
| 190 | + Milliseconds(5000), |
| 191 | + {key1_selected} |
| 192 | + ); |
| 193 | + if (ret < 0){ // failed to detect Key 1 being highlighted. Reset game and re-try |
| 194 | + env.console.log("claim_mystery_gift: Failed to detect the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW); |
| 195 | + reset_game(env.program_info(), env.console, context); |
| 196 | + continue; |
| 197 | + } |
| 198 | + |
| 199 | + enter_mystery_gift_code(env, context); |
| 200 | + return; |
| 201 | + } |
147 | 202 | } |
148 | 203 |
|
149 | 204 | void ClaimMysteryGift::run_autostory_until_pokeportal_unlocked(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ |
|
0 commit comments