|
| 1 | +/* E Shiny Mew |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/Arduino-Source |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "Common/Cpp/PrettyPrint.h" |
| 8 | +#include "CommonFramework/Exceptions/OperationFailedException.h" |
| 9 | +#include "CommonTools/Async/InferenceRoutines.h" |
| 10 | +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" |
| 11 | +#include "CommonFramework/Notifications/ProgramNotifications.h" |
| 12 | +#include "CommonFramework/ProgramStats/StatsTracking.h" |
| 13 | +#include "CommonFramework/VideoPipeline/VideoFeed.h" |
| 14 | +#include "Pokemon/Pokemon_Strings.h" |
| 15 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 16 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" |
| 17 | +#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h" |
| 18 | +#include "PokemonRSE/PokemonRSE_Navigation.h" |
| 19 | +#include "PokemonRSE_ShinyHunt-Mew.h" |
| 20 | + |
| 21 | +namespace PokemonAutomation{ |
| 22 | +namespace NintendoSwitch{ |
| 23 | +namespace PokemonRSE{ |
| 24 | + |
| 25 | +ShinyHuntMew_Descriptor::ShinyHuntMew_Descriptor() |
| 26 | + : SingleSwitchProgramDescriptor( |
| 27 | + "PokemonRSE:ShinyHuntMew", |
| 28 | + Pokemon::STRING_POKEMON + " RSE", "Shiny Hunt - Mew", |
| 29 | + "ComputerControl/blob/master/Wiki/Programs/PokemonRSE/ShinyHuntMew.md", |
| 30 | + "Use the Run Away method to shiny hunt Mew in Emerald.", |
| 31 | + FeedbackType::VIDEO_AUDIO, |
| 32 | + AllowCommandsWhenRunning::DISABLE_COMMANDS, |
| 33 | + {SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS} |
| 34 | + ) |
| 35 | +{} |
| 36 | + |
| 37 | +struct ShinyHuntMew_Descriptor::Stats : public StatsTracker{ |
| 38 | + Stats() |
| 39 | + : resets(m_stats["Resets"]) |
| 40 | + , shinies(m_stats["Shinies"]) |
| 41 | + { |
| 42 | + m_display_order.emplace_back("Resets"); |
| 43 | + m_display_order.emplace_back("Shinies"); |
| 44 | + } |
| 45 | + std::atomic<uint64_t>& resets; |
| 46 | + std::atomic<uint64_t>& shinies; |
| 47 | +}; |
| 48 | +std::unique_ptr<StatsTracker> ShinyHuntMew_Descriptor::make_stats() const{ |
| 49 | + return std::unique_ptr<StatsTracker>(new Stats()); |
| 50 | +} |
| 51 | + |
| 52 | +ShinyHuntMew::ShinyHuntMew() |
| 53 | + : NOTIFICATION_SHINY( |
| 54 | + "Shiny Found", |
| 55 | + true, true, ImageAttachmentMode::JPG, |
| 56 | + {"Notifs", "Showcase"} |
| 57 | + ) |
| 58 | + , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) |
| 59 | + , NOTIFICATIONS({ |
| 60 | + &NOTIFICATION_SHINY, |
| 61 | + &NOTIFICATION_STATUS_UPDATE, |
| 62 | + &NOTIFICATION_PROGRAM_FINISH, |
| 63 | + }) |
| 64 | + , m_advanced_options( |
| 65 | + "<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>" |
| 66 | + ) |
| 67 | + , MEW_WAIT_TIME( |
| 68 | + "<b>Mew wait time:</b><br>Wait this long after entering for Mew to hide in the grass.", |
| 69 | + LockMode::LOCK_WHILE_RUNNING, |
| 70 | + "2000 ms" |
| 71 | + ) |
| 72 | + , DOOR_TO_GRASS_TIME( |
| 73 | + "<b>Door to grass time:</b><br>Time it takes to run from the door to the edge of the tall grass. Three steps up.", |
| 74 | + LockMode::LOCK_WHILE_RUNNING, |
| 75 | + "400 ms" |
| 76 | + ) |
| 77 | + , RIGHT_GRASS_1_TIME( |
| 78 | + "<b>First Right time:</b><br>Time it takes to turn right and take three steps. This follows the edge of the grass.", |
| 79 | + LockMode::LOCK_WHILE_RUNNING, |
| 80 | + "450 ms" |
| 81 | + ) |
| 82 | + , UP_GRASS_1_TIME( |
| 83 | + "<b>Move Up time::</b><br>Time it takes turn up and take one step.", |
| 84 | + LockMode::LOCK_WHILE_RUNNING, |
| 85 | + "200 ms" |
| 86 | + ) |
| 87 | + , RIGHT_GRASS_2_TIME( |
| 88 | + "<b>Second Right time:</b><br>Time it takes to turn right and take two steps.", |
| 89 | + LockMode::LOCK_WHILE_RUNNING, |
| 90 | + "260 ms" |
| 91 | + ) |
| 92 | + , FACE_UP_TIME( |
| 93 | + "<b>Face Up time:</b><br>Time it takes to tap the up button and face up, without taking a step.", |
| 94 | + LockMode::LOCK_WHILE_RUNNING, |
| 95 | + "150 ms" |
| 96 | + ) |
| 97 | +{ |
| 98 | + PA_ADD_OPTION(NOTIFICATIONS); |
| 99 | + PA_ADD_STATIC(m_advanced_options); |
| 100 | + PA_ADD_OPTION(MEW_WAIT_TIME); |
| 101 | + PA_ADD_OPTION(DOOR_TO_GRASS_TIME); |
| 102 | + PA_ADD_OPTION(RIGHT_GRASS_1_TIME); |
| 103 | + PA_ADD_OPTION(UP_GRASS_1_TIME); |
| 104 | + PA_ADD_OPTION(RIGHT_GRASS_2_TIME); |
| 105 | + PA_ADD_OPTION(FACE_UP_TIME); |
| 106 | +} |
| 107 | + |
| 108 | +void ShinyHuntMew::enter_mew(SingleSwitchProgramEnvironment& env, ProControllerContext& context) { |
| 109 | + BlackScreenOverWatcher enter_area(COLOR_RED, {0.282, 0.064, 0.448, 0.871}); |
| 110 | + int ret = run_until<ProControllerContext>( |
| 111 | + env.console, context, |
| 112 | + [](ProControllerContext& context){ |
| 113 | + pbf_press_dpad(context, DPAD_UP, 250, 20); |
| 114 | + pbf_wait(context, 300); |
| 115 | + }, |
| 116 | + {enter_area} |
| 117 | + ); |
| 118 | + context.wait_for_all_requests(); |
| 119 | + if (ret != 0){ |
| 120 | + env.log("Failed to enter area.", COLOR_RED); |
| 121 | + OperationFailedException::fire( |
| 122 | + ErrorReport::SEND_ERROR_REPORT, |
| 123 | + "Failed to enter area.", |
| 124 | + env.console |
| 125 | + ); |
| 126 | + } |
| 127 | + else { |
| 128 | + env.log("Entered area."); |
| 129 | + } |
| 130 | + |
| 131 | + //Wait for Mew ! animation to finish |
| 132 | + pbf_wait(context, MEW_WAIT_TIME); |
| 133 | + context.wait_for_all_requests(); |
| 134 | + |
| 135 | + //DO NOT pause while running! |
| 136 | + //Run up toward the extra tall grass - 3 steps |
| 137 | + ssf_press_button(context, BUTTON_B, 0ms, DOOR_TO_GRASS_TIME); |
| 138 | + pbf_press_dpad(context, DPAD_UP, DOOR_TO_GRASS_TIME, 0ms); |
| 139 | + |
| 140 | + //Turn right, take 3 steps |
| 141 | + ssf_press_button(context, BUTTON_B, 0ms, RIGHT_GRASS_1_TIME); |
| 142 | + pbf_press_dpad(context, DPAD_RIGHT, RIGHT_GRASS_1_TIME, 0ms); |
| 143 | + |
| 144 | + //Turn up, take 1 step |
| 145 | + ssf_press_button(context, BUTTON_B, 0ms, UP_GRASS_1_TIME); |
| 146 | + pbf_press_dpad(context, DPAD_UP, UP_GRASS_1_TIME, 0ms); |
| 147 | + |
| 148 | + //Turn right, take 2 steps |
| 149 | + ssf_press_button(context, BUTTON_B, 0ms, RIGHT_GRASS_2_TIME); |
| 150 | + pbf_press_dpad(context, DPAD_RIGHT, RIGHT_GRASS_2_TIME, 0ms); |
| 151 | + |
| 152 | + //Turn up. Start battle. |
| 153 | + pbf_press_dpad(context, DPAD_UP, FACE_UP_TIME, 0ms); |
| 154 | + |
| 155 | + context.wait_for_all_requests(); |
| 156 | +} |
| 157 | + |
| 158 | +void ShinyHuntMew::exit_mew(SingleSwitchProgramEnvironment& env, ProControllerContext& context) { |
| 159 | + ssf_press_button(context, BUTTON_B, 0, 50); |
| 160 | + pbf_press_dpad(context, DPAD_DOWN, 50, 20); |
| 161 | + |
| 162 | + ssf_press_button(context, BUTTON_B, 0, 90); |
| 163 | + pbf_press_dpad(context, DPAD_LEFT, 90, 20); |
| 164 | + |
| 165 | + ssf_press_button(context, BUTTON_B, 0, 100); |
| 166 | + pbf_press_dpad(context, DPAD_DOWN, 100, 20); |
| 167 | + |
| 168 | + BlackScreenOverWatcher exit_area(COLOR_RED, {0.282, 0.064, 0.448, 0.871}); |
| 169 | + int ret = run_until<ProControllerContext>( |
| 170 | + env.console, context, |
| 171 | + [](ProControllerContext& context){ |
| 172 | + pbf_press_dpad(context, DPAD_DOWN, 250, 20); |
| 173 | + pbf_wait(context, 300); |
| 174 | + }, |
| 175 | + {exit_area} |
| 176 | + ); |
| 177 | + context.wait_for_all_requests(); |
| 178 | + if (ret != 0){ |
| 179 | + env.log("Failed to exit area.", COLOR_RED); |
| 180 | + OperationFailedException::fire( |
| 181 | + ErrorReport::SEND_ERROR_REPORT, |
| 182 | + "Failed to exit area.", |
| 183 | + env.console |
| 184 | + ); |
| 185 | + } |
| 186 | + else { |
| 187 | + env.log("Exited area."); |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +void ShinyHuntMew::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ |
| 192 | + ShinyHuntMew_Descriptor::Stats& stats = env.current_stats<ShinyHuntMew_Descriptor::Stats>(); |
| 193 | + |
| 194 | + /* |
| 195 | + * Requires more precision to ensure a Mew encounter every time. |
| 196 | + * Movement is very configurable due to this. |
| 197 | + * Enter on the left side, run up and hug the grass to the edge just after the flower on the right |
| 198 | + * This but without the bike: |
| 199 | + * https://old.reddit.com/r/ShinyPokemon/comments/1c773oi/gen3_discuss_is_this_the_fastest_way_to_encounter/ |
| 200 | + */ |
| 201 | + |
| 202 | + while (true) { |
| 203 | + enter_mew(env, context); |
| 204 | + |
| 205 | + bool legendary_shiny = handle_encounter(env.console, context, true); |
| 206 | + if (legendary_shiny) { |
| 207 | + stats.shinies++; |
| 208 | + env.update_stats(); |
| 209 | + send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", env.console.video().snapshot(), true); |
| 210 | + break; |
| 211 | + } |
| 212 | + env.log("No shiny found."); |
| 213 | + flee_battle(env.console, context); |
| 214 | + |
| 215 | + //Close dialog |
| 216 | + pbf_mash_button(context, BUTTON_B, 250); |
| 217 | + context.wait_for_all_requests(); |
| 218 | + |
| 219 | + exit_mew(env, context); |
| 220 | + |
| 221 | + stats.resets++; |
| 222 | + env.update_stats(); |
| 223 | + } |
| 224 | + |
| 225 | + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); |
| 226 | +} |
| 227 | + |
| 228 | +} |
| 229 | +} |
| 230 | +} |
0 commit comments