|
| 1 | +/* LGPE Gift Reset |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/ |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonFramework/Exceptions/OperationFailedException.h" |
| 8 | +#include "CommonFramework/Notifications/ProgramNotifications.h" |
| 9 | +#include "CommonFramework/ProgramStats/StatsTracking.h" |
| 10 | +#include "CommonFramework/VideoPipeline/VideoFeed.h" |
| 11 | +#include "CommonTools/Async/InferenceRoutines.h" |
| 12 | +#include "CommonTools/StartupChecks/VideoResolutionCheck.h" |
| 13 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 14 | +#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h" |
| 15 | +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" |
| 16 | +#include "Pokemon/Pokemon_Strings.h" |
| 17 | +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" |
| 18 | +#include "PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h" |
| 19 | +#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h" |
| 20 | +#include "PokemonLGPE_GiftReset.h" |
| 21 | + |
| 22 | +namespace PokemonAutomation{ |
| 23 | +namespace NintendoSwitch{ |
| 24 | +namespace PokemonLGPE{ |
| 25 | + |
| 26 | +GiftReset_Descriptor::GiftReset_Descriptor() |
| 27 | + : SingleSwitchProgramDescriptor( |
| 28 | + "PokemonLGPE:GiftReset", |
| 29 | + Pokemon::STRING_POKEMON + " LGPE", "Gift Reset", |
| 30 | + "", |
| 31 | + "Shiny hunt gift Pokemon by resetting the game.", |
| 32 | + FeedbackType::REQUIRED, |
| 33 | + AllowCommandsWhenRunning::DISABLE_COMMANDS, |
| 34 | + {ControllerFeature::NintendoSwitch_RightJoycon}, |
| 35 | + FasterIfTickPrecise::NOT_FASTER |
| 36 | + ) |
| 37 | +{} |
| 38 | + |
| 39 | +struct GiftReset_Descriptor::Stats : public StatsTracker{ |
| 40 | + Stats() |
| 41 | + : resets(m_stats["Resets"]) |
| 42 | + , shinies(m_stats["Shinies"]) |
| 43 | + { |
| 44 | + m_display_order.emplace_back("Resets"); |
| 45 | + m_display_order.emplace_back("Shinies"); |
| 46 | + } |
| 47 | + std::atomic<uint64_t>& resets; |
| 48 | + std::atomic<uint64_t>& shinies; |
| 49 | +}; |
| 50 | +std::unique_ptr<StatsTracker> GiftReset_Descriptor::make_stats() const{ |
| 51 | + return std::unique_ptr<StatsTracker>(new Stats()); |
| 52 | +} |
| 53 | + |
| 54 | +GiftReset::GiftReset() |
| 55 | + : GO_HOME_WHEN_DONE(false) |
| 56 | + , NOTIFICATION_SHINY( |
| 57 | + "Shiny Found", |
| 58 | + true, true, ImageAttachmentMode::JPG, |
| 59 | + {"Notifs", "Showcase"} |
| 60 | + ) |
| 61 | + , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) |
| 62 | + , NOTIFICATIONS({ |
| 63 | + &NOTIFICATION_SHINY, |
| 64 | + &NOTIFICATION_STATUS_UPDATE, |
| 65 | + &NOTIFICATION_PROGRAM_FINISH, |
| 66 | + }) |
| 67 | +{ |
| 68 | + PA_ADD_OPTION(GO_HOME_WHEN_DONE); |
| 69 | + PA_ADD_OPTION(NOTIFICATIONS); |
| 70 | +} |
| 71 | + |
| 72 | +void GiftReset::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){ |
| 73 | + JoyconContext context(scope, env.console.controller<JoyconController>()); |
| 74 | + assert_16_9_720p_min(env.logger(), env.console); |
| 75 | + GiftReset_Descriptor::Stats& stats = env.current_stats<GiftReset_Descriptor::Stats>(); |
| 76 | + |
| 77 | + /* |
| 78 | + Setup: |
| 79 | + Stand in front of trade NPC. |
| 80 | + Start the program in-game. |
| 81 | +
|
| 82 | + Must have 500yen for magikarp. |
| 83 | + Gift Pokemon: https://www.serebii.net/letsgopikachueevee/gift.shtml |
| 84 | + Tested with Magikarp on a new save. Should work with most of the others. |
| 85 | + Can always add a dropdown with target if it doesn't. |
| 86 | + Fossils will be handled in a different program. |
| 87 | + */ |
| 88 | + |
| 89 | + bool shiny_found = false; |
| 90 | + while (!shiny_found) { |
| 91 | + //Purchase Magikarp |
| 92 | + BlackScreenOverWatcher gift_obtained(COLOR_RED); |
| 93 | + int ret = run_until<JoyconContext>( |
| 94 | + env.console, context, |
| 95 | + [](JoyconContext& context){ |
| 96 | + pbf_mash_button(context, BUTTON_A, 20000ms); |
| 97 | + }, |
| 98 | + {gift_obtained} |
| 99 | + ); |
| 100 | + context.wait_for_all_requests(); |
| 101 | + if (ret != 0){ |
| 102 | + env.log("Failed to receive gift Pokemon.", COLOR_RED); |
| 103 | + OperationFailedException::fire( |
| 104 | + ErrorReport::SEND_ERROR_REPORT, |
| 105 | + "Failed to receive gift Pokemon.", |
| 106 | + env.console |
| 107 | + ); |
| 108 | + } |
| 109 | + else { |
| 110 | + env.log("Received gift Pokemon."); |
| 111 | + } |
| 112 | + send_program_status_notification( |
| 113 | + env, NOTIFICATION_STATUS_UPDATE, |
| 114 | + "Received gift Pokemon." |
| 115 | + ); |
| 116 | + |
| 117 | + //Wait a bit. |
| 118 | + pbf_wait(context, 2500ms); |
| 119 | + context.wait_for_all_requests(); |
| 120 | + |
| 121 | + //Open menu, open party, open boxes |
| 122 | + env.log("Opening boxes."); |
| 123 | + pbf_press_button(context, BUTTON_X, 200ms, 500ms); |
| 124 | + pbf_press_button(context, BUTTON_A, 200ms, 1500ms); |
| 125 | + pbf_press_button(context, BUTTON_Y, 200ms, 2000ms); |
| 126 | + context.wait_for_all_requests(); |
| 127 | + |
| 128 | + //Sort by order caught |
| 129 | + env.log("Sorting by order caught."); |
| 130 | + pbf_press_button(context, BUTTON_Y, 200ms, 1000ms); |
| 131 | + pbf_press_button(context, BUTTON_A, 200ms, 1000ms); |
| 132 | + pbf_press_button(context, BUTTON_A, 200ms, 1000ms); |
| 133 | + context.wait_for_all_requests(); |
| 134 | + |
| 135 | + //Press left to go to last (most recent) Pokemon |
| 136 | + env.log("Opening summary of most recent Pokemon."); |
| 137 | + pbf_move_joystick(context, 0, 128, 100ms, 100ms); |
| 138 | + context.wait_for_all_requests(); |
| 139 | + |
| 140 | + //View summary - it takes a moment to load |
| 141 | + env.log("Viewing summary."); |
| 142 | + pbf_press_button(context, BUTTON_A, 200ms, 1000ms); |
| 143 | + pbf_move_joystick(context, 128, 255, 100ms, 100ms); |
| 144 | + pbf_move_joystick(context, 128, 255, 100ms, 100ms); |
| 145 | + pbf_press_button(context, BUTTON_A, 200ms, 100ms); |
| 146 | + context.wait_for_all_requests(); |
| 147 | + |
| 148 | + pbf_wait(context, 5000ms); |
| 149 | + context.wait_for_all_requests(); |
| 150 | + |
| 151 | + //Now check for shinies. Check everything that was traded. |
| 152 | + VideoSnapshot screen = env.console.video().snapshot(); |
| 153 | + ShinySymbolDetector shiny_checker(COLOR_YELLOW); |
| 154 | + bool check = shiny_checker.read(env.console.logger(), screen); |
| 155 | + |
| 156 | + if (check) { |
| 157 | + env.log("Shiny detected!"); |
| 158 | + stats.shinies++; |
| 159 | + env.update_stats(); |
| 160 | + send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true); |
| 161 | + shiny_found = true; |
| 162 | + } |
| 163 | + else { |
| 164 | + env.log("Not shiny. Resetting game."); |
| 165 | + send_program_status_notification( |
| 166 | + env, NOTIFICATION_STATUS_UPDATE, |
| 167 | + "Not shiny. Resetting game." |
| 168 | + ); |
| 169 | + |
| 170 | + //Reset game |
| 171 | + pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms); |
| 172 | + reset_game_from_home(env, env.console, context, 3000ms); |
| 173 | + context.wait_for_all_requests(); |
| 174 | + |
| 175 | + stats.resets++; |
| 176 | + env.update_stats(); |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + if (GO_HOME_WHEN_DONE) { |
| 181 | + pbf_press_button(context, BUTTON_HOME, 200ms, 1000ms); |
| 182 | + } |
| 183 | + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); |
| 184 | +} |
| 185 | + |
| 186 | + |
| 187 | +} |
| 188 | +} |
| 189 | +} |
0 commit comments