|
| 1 | +/* Shiny Hunt - Shuttle Run |
| 2 | + * |
| 3 | + * From: https://github.com/PokemonAutomation/ |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#include "CommonFramework/ProgramStats/StatsTracking.h" |
| 8 | +#include "CommonFramework/Notifications/ProgramNotifications.h" |
| 9 | +#include "CommonTools/Async/InferenceRoutines.h" |
| 10 | +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" |
| 11 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" |
| 12 | +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" |
| 13 | +#include "Pokemon/Pokemon_Strings.h" |
| 14 | +#include "PokemonLZA_ShuttleRun.h" |
| 15 | + |
| 16 | +namespace PokemonAutomation { |
| 17 | +namespace NintendoSwitch { |
| 18 | +namespace PokemonLZA { |
| 19 | + |
| 20 | +using namespace Pokemon; |
| 21 | + |
| 22 | + |
| 23 | +ShinyHunt_ShuttleRun_Descriptor::ShinyHunt_ShuttleRun_Descriptor() |
| 24 | + : SingleSwitchProgramDescriptor( |
| 25 | + "PokemonLZA:ShinyHunt-ShuttleRun", STRING_POKEMON + " LZA", |
| 26 | + "Shuttle Run", |
| 27 | + "Programs/PokemonLZA/ShinyHunt-ShuttleRun.html", |
| 28 | + "Shiny hunt by repeatedly running back and forth between two points", |
| 29 | + ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, |
| 30 | + AllowCommandsWhenRunning::DISABLE_COMMANDS, {} |
| 31 | + ) |
| 32 | +{} |
| 33 | +class ShinyHunt_ShuttleRun_Descriptor::Stats : public StatsTracker{ |
| 34 | +public: |
| 35 | + Stats() |
| 36 | + : resets(m_stats["Rounds"]) |
| 37 | + , errors(m_stats["Errors"]) |
| 38 | + { |
| 39 | + m_display_order.emplace_back("Rounds"); |
| 40 | + m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO); |
| 41 | + } |
| 42 | + |
| 43 | + std::atomic<uint64_t>& resets; |
| 44 | + std::atomic<uint64_t>& errors; |
| 45 | +}; |
| 46 | +std::unique_ptr<StatsTracker> ShinyHunt_ShuttleRun_Descriptor::make_stats() const{ |
| 47 | + return std::unique_ptr<StatsTracker>(new Stats()); |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +ShinyHunt_ShuttleRun::ShinyHunt_ShuttleRun() |
| 52 | + : DURATION("<b>Duration:</b><br>Run the program this long.", LockMode::LOCK_WHILE_RUNNING, "1 h") |
| 53 | + // , RUN_FORWARD_DURATION("<b>Run Forward Duration</b><br>" |
| 54 | + // "Run forward and backward for this long each round trip.", LockMode::LOCK_WHILE_RUNNING, "5000 ms") |
| 55 | + , NOTIFICATION_STATUS("Status Update", true, false, std::chrono::seconds(3600)) |
| 56 | + , NOTIFICATIONS({ |
| 57 | + &NOTIFICATION_STATUS, |
| 58 | + &NOTIFICATION_PROGRAM_FINISH, |
| 59 | + &NOTIFICATION_ERROR_RECOVERABLE, |
| 60 | + &NOTIFICATION_ERROR_FATAL, |
| 61 | + }) |
| 62 | +{ |
| 63 | + PA_ADD_OPTION(DURATION); |
| 64 | + // PA_ADD_OPTION(RUN_FORWARD_DURATION); |
| 65 | + PA_ADD_OPTION(NOTIFICATIONS); |
| 66 | +} |
| 67 | + |
| 68 | +namespace { |
| 69 | + |
| 70 | +void hunt_loop(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Milliseconds duration){ |
| 71 | + context.wait_for_all_requests(); |
| 72 | + ssf_press_button(context, BUTTON_B, 0ms, 500ms, 0ms); |
| 73 | + pbf_move_left_joystick(context, 128, 0, duration, 0ms); |
| 74 | + pbf_move_left_joystick(context, 255, 128, 1300ms, 0ms); |
| 75 | + pbf_press_button(context, BUTTON_L, 100ms, 500ms); |
| 76 | + pbf_press_button(context, BUTTON_PLUS, 240ms, 80ms); // open map |
| 77 | + context.wait_for_all_requests(); |
| 78 | + pbf_wait(context, 500ms); |
| 79 | + pbf_press_button(context, BUTTON_Y, 100ms, 100ms); // select fly point |
| 80 | + pbf_mash_button(context, BUTTON_A, 1000ms); |
| 81 | + context.wait_for(std::chrono::milliseconds(4000)); |
| 82 | +} |
| 83 | +} // namespace |
| 84 | + |
| 85 | +void ShinyHunt_ShuttleRun::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ |
| 86 | + ShinyHunt_ShuttleRun_Descriptor::Stats& stats = |
| 87 | + env.current_stats<ShinyHunt_ShuttleRun_Descriptor::Stats>(); |
| 88 | + WallClock deadline = current_time() + DURATION.get(); |
| 89 | + Milliseconds duration = 8500ms; |
| 90 | + pbf_press_button(context, BUTTON_L, 100ms, 100ms); // connect |
| 91 | + do{ |
| 92 | + send_program_status_notification(env, NOTIFICATION_STATUS); |
| 93 | + stats.resets++; |
| 94 | + hunt_loop(env, context, duration); |
| 95 | + env.update_stats(); |
| 96 | + }while (current_time() < deadline); |
| 97 | + |
| 98 | + go_home(env.console, context); |
| 99 | + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); |
| 100 | +} |
| 101 | + |
| 102 | + |
| 103 | +} // namespace PokemonLZA |
| 104 | +} // namespace NintendoSwitch |
| 105 | +} // namespace PokemonAutomation |
0 commit comments