|
| 1 | +/* LGPE Legendary 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/Battles/PokemonLGPE_BattleMenuDetector.h" |
| 19 | +#include "PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h" |
| 20 | +#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h" |
| 21 | +#include "PokemonLGPE_LegendaryReset.h" |
| 22 | + |
| 23 | +namespace PokemonAutomation{ |
| 24 | +namespace NintendoSwitch{ |
| 25 | +namespace PokemonLGPE{ |
| 26 | + |
| 27 | +LegendaryReset_Descriptor::LegendaryReset_Descriptor() |
| 28 | + : SingleSwitchProgramDescriptor( |
| 29 | + "PokemonLGPE:LegendaryReset", |
| 30 | + Pokemon::STRING_POKEMON + " LGPE", "Legendary Reset", |
| 31 | + "ComputerControl/blob/master/Wiki/Programs/PokemonLGPE/LegendaryReset.md", |
| 32 | + "Shiny hunt Legendary Pokemon by resetting the game.", |
| 33 | + FeedbackType::VIDEO_AUDIO, |
| 34 | + AllowCommandsWhenRunning::DISABLE_COMMANDS, |
| 35 | + {ControllerFeature::NintendoSwitch_RightJoycon}, |
| 36 | + FasterIfTickPrecise::NOT_FASTER |
| 37 | + ) |
| 38 | +{} |
| 39 | + |
| 40 | +struct LegendaryReset_Descriptor::Stats : public StatsTracker{ |
| 41 | + Stats() |
| 42 | + : resets(m_stats["Resets"]) |
| 43 | + , shinies(m_stats["Shinies"]) |
| 44 | + { |
| 45 | + m_display_order.emplace_back("Resets"); |
| 46 | + m_display_order.emplace_back("Shinies"); |
| 47 | + } |
| 48 | + std::atomic<uint64_t>& resets; |
| 49 | + std::atomic<uint64_t>& shinies; |
| 50 | +}; |
| 51 | +std::unique_ptr<StatsTracker> LegendaryReset_Descriptor::make_stats() const{ |
| 52 | + return std::unique_ptr<StatsTracker>(new Stats()); |
| 53 | +} |
| 54 | + |
| 55 | +LegendaryReset::LegendaryReset() |
| 56 | + : GO_HOME_WHEN_DONE(true) |
| 57 | + , NOTIFICATION_SHINY( |
| 58 | + "Shiny Found", |
| 59 | + true, true, ImageAttachmentMode::JPG, |
| 60 | + {"Notifs", "Showcase"} |
| 61 | + ) |
| 62 | + , NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600)) |
| 63 | + , NOTIFICATIONS({ |
| 64 | + &NOTIFICATION_SHINY, |
| 65 | + &NOTIFICATION_STATUS_UPDATE, |
| 66 | + &NOTIFICATION_PROGRAM_FINISH, |
| 67 | + }) |
| 68 | +{ |
| 69 | + PA_ADD_OPTION(GO_HOME_WHEN_DONE); |
| 70 | + PA_ADD_OPTION(NOTIFICATIONS); |
| 71 | +} |
| 72 | + |
| 73 | +bool LegendaryReset::run_battle(SingleSwitchProgramEnvironment& env, JoyconContext& context){ |
| 74 | + float shiny_coefficient = 1.0; |
| 75 | + ShinySoundDetector shiny_detector(env.logger(), [&](float error_coefficient) -> bool{ |
| 76 | + shiny_coefficient = error_coefficient; |
| 77 | + return true; |
| 78 | + }); |
| 79 | + BattleMenuWatcher battle_started(COLOR_YELLOW); |
| 80 | + |
| 81 | + env.log("Starting battle."); |
| 82 | + pbf_mash_button(context, BUTTON_A, 25000ms); //10000ms |
| 83 | + context.wait_for_all_requests(); |
| 84 | + |
| 85 | + int res = run_until<JoyconContext>( |
| 86 | + env.console, context, |
| 87 | + [&](JoyconContext& context) { |
| 88 | + int ret = wait_until( |
| 89 | + env.console, context, |
| 90 | + std::chrono::seconds(90), |
| 91 | + {{battle_started}} |
| 92 | + ); |
| 93 | + if (ret == 0) { |
| 94 | + env.log("HP boxes detected."); |
| 95 | + } else { |
| 96 | + OperationFailedException::fire( |
| 97 | + ErrorReport::SEND_ERROR_REPORT, |
| 98 | + "run_battle(): Did not detect battle start.", |
| 99 | + env.console |
| 100 | + ); |
| 101 | + } |
| 102 | + pbf_wait(context, 1000ms); |
| 103 | + context.wait_for_all_requests(); |
| 104 | + }, |
| 105 | + {{shiny_detector}} |
| 106 | + ); |
| 107 | + shiny_detector.throw_if_no_sound(); |
| 108 | + if (res == 0){ |
| 109 | + env.log("Shiny detected!"); |
| 110 | + return true; |
| 111 | + } |
| 112 | + env.log("Shiny not found."); |
| 113 | + |
| 114 | + return false; |
| 115 | +} |
| 116 | + |
| 117 | +void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){ |
| 118 | + JoyconContext context(scope, env.console.controller<JoyconController>()); |
| 119 | + assert_16_9_720p_min(env.logger(), env.console); |
| 120 | + LegendaryReset_Descriptor::Stats& stats = env.current_stats<LegendaryReset_Descriptor::Stats>(); |
| 121 | + |
| 122 | + /* |
| 123 | + Setup: |
| 124 | + Stand in front of encounter. (And save) |
| 125 | + Start the program in game. |
| 126 | + Your lead must not be shiny. |
| 127 | +
|
| 128 | + Settings: |
| 129 | + Text Speed fast |
| 130 | + Skip cutscene option? |
| 131 | +
|
| 132 | + Mewtwo, Articuno, Zapdos, Moltres, Snorlax, Electrode(?) |
| 133 | + Don't do it on the first Snorlax, otherwise have to sit through fuji tutorial |
| 134 | + */ |
| 135 | + |
| 136 | + while (true) { |
| 137 | + bool encounter_battle = run_battle(env, context); |
| 138 | + if (encounter_battle) { |
| 139 | + stats.shinies++; |
| 140 | + env.update_stats(); |
| 141 | + send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", env.console.video().snapshot(), true); |
| 142 | + break; |
| 143 | + } |
| 144 | + env.log("No shiny found. Resetting game."); |
| 145 | + send_program_status_notification( |
| 146 | + env, NOTIFICATION_STATUS_UPDATE, |
| 147 | + "No shiny found. Resetting game." |
| 148 | + ); |
| 149 | + |
| 150 | + //Reset game |
| 151 | + pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms); |
| 152 | + reset_game_from_home(env, env.console, context, 3000ms); |
| 153 | + context.wait_for_all_requests(); |
| 154 | + |
| 155 | + stats.resets++; |
| 156 | + env.update_stats(); |
| 157 | + } |
| 158 | + |
| 159 | + if (GO_HOME_WHEN_DONE) { |
| 160 | + pbf_press_button(context, BUTTON_HOME, 200ms, 1000ms); |
| 161 | + } |
| 162 | + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); |
| 163 | +} |
| 164 | + |
| 165 | + |
| 166 | +} |
| 167 | +} |
| 168 | +} |
0 commit comments