|
| 1 | +/* RS Starter Reset |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/Arduino-Source |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonFramework/Exceptions/OperationFailedException.h" |
| 8 | +#include "CommonFramework/ProgramStats/StatsTracking.h" |
| 9 | +#include "CommonFramework/VideoPipeline/VideoFeed.h" |
| 10 | +#include "CommonTools/Async/InferenceRoutines.h" |
| 11 | +#include "CommonFramework/Notifications/ProgramNotifications.h" |
| 12 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 13 | +#include "Pokemon/Pokemon_Strings.h" |
| 14 | +#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h" |
| 15 | +#include "PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h" |
| 16 | +#include "PokemonRSE/PokemonRSE_Navigation.h" |
| 17 | +#include "PokemonRSE_AudioStarterReset.h" |
| 18 | + |
| 19 | +namespace PokemonAutomation{ |
| 20 | +namespace NintendoSwitch{ |
| 21 | +namespace PokemonRSE{ |
| 22 | + |
| 23 | +AudioStarterReset_Descriptor::AudioStarterReset_Descriptor() |
| 24 | + : SingleSwitchProgramDescriptor( |
| 25 | + "PokemonRSE:AudioStarterReset", |
| 26 | + Pokemon::STRING_POKEMON + " RSE", "Starter Reset (Ruby/Sapphire)", |
| 27 | + "ComputerControl/blob/master/Wiki/Programs/PokemonRSE/AudioStarterReset.md", |
| 28 | + "Soft reset for a shiny starter. Ruby and Sapphire only.", |
| 29 | + FeedbackType::VIDEO_AUDIO, |
| 30 | + AllowCommandsWhenRunning::DISABLE_COMMANDS, |
| 31 | + {SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS} |
| 32 | + ) |
| 33 | +{} |
| 34 | + |
| 35 | +struct AudioStarterReset_Descriptor::Stats : public StatsTracker{ |
| 36 | + Stats() |
| 37 | + : resets(m_stats["Resets"]) |
| 38 | + , poochyena(m_stats["Shiny Poochyena"]) |
| 39 | + , shinystarter(m_stats["Shiny Starter"]) |
| 40 | + { |
| 41 | + m_display_order.emplace_back("Resets"); |
| 42 | + m_display_order.emplace_back("Shiny Poochyena"); |
| 43 | + m_display_order.emplace_back("Shiny Starter"); |
| 44 | + } |
| 45 | + std::atomic<uint64_t>& resets; |
| 46 | + std::atomic<uint64_t>& poochyena; |
| 47 | + std::atomic<uint64_t>& shinystarter; |
| 48 | +}; |
| 49 | +std::unique_ptr<StatsTracker> AudioStarterReset_Descriptor::make_stats() const{ |
| 50 | + return std::unique_ptr<StatsTracker>(new Stats()); |
| 51 | +} |
| 52 | + |
| 53 | +AudioStarterReset::AudioStarterReset() |
| 54 | + : TARGET( |
| 55 | + "<b>Starter:</b><br>", |
| 56 | + { |
| 57 | + {Target::treecko, "treecko", "Treecko"}, |
| 58 | + {Target::torchic, "torchic", "Torchic"}, |
| 59 | + {Target::mudkip, "mudkip", "Mudkip"}, |
| 60 | + }, |
| 61 | + LockMode::LOCK_WHILE_RUNNING, |
| 62 | + Target::treecko |
| 63 | + ) |
| 64 | + , NOTIFICATION_SHINY_POOCH( |
| 65 | + "Shiny Poochyena", |
| 66 | + false, false, ImageAttachmentMode::JPG, |
| 67 | + {"Notifs"} |
| 68 | + ) |
| 69 | + , NOTIFICATION_SHINY_STARTER( |
| 70 | + "Shiny Starter", |
| 71 | + true, true, ImageAttachmentMode::JPG, |
| 72 | + {"Notifs", "Showcase"} |
| 73 | + ) |
| 74 | + , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) |
| 75 | + , NOTIFICATIONS({ |
| 76 | + &NOTIFICATION_SHINY_POOCH, |
| 77 | + &NOTIFICATION_SHINY_STARTER, |
| 78 | + &NOTIFICATION_STATUS_UPDATE, |
| 79 | + &NOTIFICATION_PROGRAM_FINISH, |
| 80 | + }) |
| 81 | +{ |
| 82 | + PA_ADD_OPTION(TARGET); |
| 83 | + PA_ADD_OPTION(NOTIFICATIONS); |
| 84 | +} |
| 85 | + |
| 86 | +void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){ |
| 87 | + AudioStarterReset_Descriptor::Stats& stats = env.current_stats<AudioStarterReset_Descriptor::Stats>(); |
| 88 | + |
| 89 | + /* |
| 90 | + * Settings: Text Speed fast. |
| 91 | + * Full screen, no filter? The device I'm using to test has similar looking output, but I don't have switch online+. |
| 92 | + * If on a retro handheld, make sure the screen matches that of NSO+. |
| 93 | + * |
| 94 | + * Setup: Stand in front of the Professor's bag and save the game. |
| 95 | + * |
| 96 | + * Required to fight, so have to do the SR method instead of run away |
| 97 | + * Soft reset programs are only for Ruby/Sapphire, as Emerald has the 0 seed issue. |
| 98 | + * |
| 99 | + * This also assumes no dry battery. |
| 100 | + */ |
| 101 | + |
| 102 | + bool shiny_starter = false; |
| 103 | + while (!shiny_starter) { |
| 104 | + float shiny_coefficient = 1.0; |
| 105 | + ShinySoundDetector pooch_detector(env.console, [&](float error_coefficient) -> bool{ |
| 106 | + shiny_coefficient = error_coefficient; |
| 107 | + return true; |
| 108 | + }); |
| 109 | + |
| 110 | + env.log("Opening bag and selecting starter."); |
| 111 | + pbf_press_button(context, BUTTON_A, 40, 180); |
| 112 | + |
| 113 | + switch (TARGET) { |
| 114 | + case Target::treecko: |
| 115 | + pbf_press_dpad(context, DPAD_LEFT, 40, 100); |
| 116 | + break; |
| 117 | + case Target::torchic: |
| 118 | + //Default cursor position, do nothing. |
| 119 | + break; |
| 120 | + case Target::mudkip: |
| 121 | + pbf_press_dpad(context, DPAD_RIGHT, 40, 100); |
| 122 | + break; |
| 123 | + default: |
| 124 | + OperationFailedException::fire( |
| 125 | + ErrorReport::SEND_ERROR_REPORT, |
| 126 | + "AudioStarterReset: Invalid target.", |
| 127 | + env.console |
| 128 | + ); |
| 129 | + break; |
| 130 | + } |
| 131 | + pbf_mash_button(context, BUTTON_A, 540); |
| 132 | + context.wait_for_all_requests(); |
| 133 | + |
| 134 | + env.log("Starter selected. Checking for shiny Poochyena."); |
| 135 | + AdvanceBattleDialogWatcher pooch_appeared(COLOR_YELLOW); |
| 136 | + |
| 137 | + int res = run_until<SwitchControllerContext>( |
| 138 | + env.console, context, |
| 139 | + [&](SwitchControllerContext& context) { |
| 140 | + int ret = wait_until( |
| 141 | + env.console, context, |
| 142 | + std::chrono::seconds(20), |
| 143 | + {{pooch_appeared}} |
| 144 | + ); |
| 145 | + if (ret == 0) { |
| 146 | + env.log("Advance arrow detected."); |
| 147 | + } |
| 148 | + pbf_wait(context, 125); |
| 149 | + context.wait_for_all_requests(); |
| 150 | + }, |
| 151 | + {{pooch_detector}} |
| 152 | + ); |
| 153 | + pooch_detector.throw_if_no_sound(); |
| 154 | + if (res == 0){ |
| 155 | + env.log("Shiny Poochyena detected!"); |
| 156 | + stats.poochyena++; |
| 157 | + env.update_stats(); |
| 158 | + send_program_notification(env, NOTIFICATION_SHINY_POOCH, COLOR_YELLOW, "Shiny Poochyena found", {}, "", env.console.video().snapshot(), true); |
| 159 | + } |
| 160 | + else { |
| 161 | + env.log("Poochyena is not shiny."); |
| 162 | + } |
| 163 | + context.wait_for_all_requests(); |
| 164 | + |
| 165 | + float shiny_coefficient2 = 1.0; |
| 166 | + ShinySoundDetector starter_detector(env.console, [&](float error_coefficient) -> bool{ |
| 167 | + shiny_coefficient2 = error_coefficient; |
| 168 | + return true; |
| 169 | + }); |
| 170 | + |
| 171 | + BattleMenuWatcher battle_menu(COLOR_RED); |
| 172 | + int res2 = run_until<SwitchControllerContext>( |
| 173 | + env.console, context, |
| 174 | + [&](SwitchControllerContext& context) { |
| 175 | + env.log("Sending out selected starter."); |
| 176 | + pbf_press_button(context, BUTTON_A, 40, 40); |
| 177 | + |
| 178 | + int ret = wait_until( |
| 179 | + env.console, context, |
| 180 | + std::chrono::seconds(20), |
| 181 | + {{battle_menu}} |
| 182 | + ); |
| 183 | + if (ret == 0) { |
| 184 | + env.log("Battle menu detecteed!"); |
| 185 | + } |
| 186 | + pbf_wait(context, 125); |
| 187 | + context.wait_for_all_requests(); |
| 188 | + }, |
| 189 | + {{starter_detector}} |
| 190 | + ); |
| 191 | + starter_detector.throw_if_no_sound(); |
| 192 | + context.wait_for_all_requests(); |
| 193 | + if (res2 == 0){ |
| 194 | + env.log("Shiny starter detected!"); |
| 195 | + stats.shinystarter++; |
| 196 | + env.update_stats(); |
| 197 | + send_program_notification(env, NOTIFICATION_SHINY_STARTER, COLOR_YELLOW, "Shiny starter found!", {}, "", env.console.video().snapshot(), true); |
| 198 | + shiny_starter = true; |
| 199 | + } |
| 200 | + else { |
| 201 | + env.log("Starter is not shiny."); |
| 202 | + env.log("Soft resetting."); |
| 203 | + send_program_status_notification( |
| 204 | + env, NOTIFICATION_STATUS_UPDATE, |
| 205 | + "Soft resetting." |
| 206 | + ); |
| 207 | + stats.resets++; |
| 208 | + env.update_stats(); |
| 209 | + soft_reset(env.program_info(), env.console, context); |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + //if system set to nintendo switch, have go home when done option? |
| 214 | + |
| 215 | + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); |
| 216 | +} |
| 217 | + |
| 218 | +} |
| 219 | +} |
| 220 | +} |
| 221 | + |
0 commit comments