-
Notifications
You must be signed in to change notification settings - Fork 81
LZA: add program for hunting at wildzone entrance #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
14865b5
cmake: update tesseract & lept
naussika 20af7ef
cmake: tidy up opencv for macOS/Linux
naussika 7780141
cmake: unmark tesseract&lept as required
naussika a9be649
LZA: add shiny hunt wild zone entrance
naussika be237f6
only detect shiny sound at most once
naussika 4cdb2d6
walk_in_zone duration as an option
naussika aa8a26a
move into shiny hunting folder
naussika f4e8193
warn use if shiny detection options set to notify all
naussika File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| /* Shiny Hunt - Wild Zone Entrance | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include "CommonFramework/Exceptions/OperationFailedException.h" | ||
| #include "CommonFramework/ProgramStats/StatsTracking.h" | ||
| #include "CommonFramework/Notifications/ProgramNotifications.h" | ||
| #include "CommonTools/Async/InferenceRoutines.h" | ||
| #include "CommonTools/VisualDetectors/BlackScreenDetector.h" | ||
| #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" | ||
| #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" | ||
| #include "Pokemon/Pokemon_Strings.h" | ||
| #include "PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.h" | ||
| #include "PokemonLZA/Inference/PokemonLZA_ButtonDetector.h" | ||
| #include "PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" | ||
| #include "PokemonLZA_WildZoneEntrance.h" | ||
|
|
||
| namespace PokemonAutomation { | ||
| namespace NintendoSwitch { | ||
| namespace PokemonLZA { | ||
|
|
||
| using namespace Pokemon; | ||
|
|
||
|
|
||
| ShinyHunt_WildZoneEntrance_Descriptor::ShinyHunt_WildZoneEntrance_Descriptor() | ||
| : SingleSwitchProgramDescriptor("PokemonLZA:ShinyHunt-WildZoneEntrance", STRING_POKEMON + " LZA", | ||
| "Shiny Hunt - Wild Zone Entrance", | ||
| "Programs/PokemonLZA/ShinyHunt-WildZoneEntrance.html", | ||
| "Shiny hunt by repeatedly entering Wild Zone from its entrance.", | ||
| ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, | ||
| AllowCommandsWhenRunning::DISABLE_COMMANDS, {}) {} | ||
| class ShinyHunt_WildZoneEntrance_Descriptor::Stats : public StatsTracker { | ||
| public: | ||
| Stats() : resets(m_stats["Wild Zone"]), shinies(m_stats["Shiny Sounds"]), errors(m_stats["Errors"]) { | ||
| m_display_order.emplace_back("Wild Zone"); | ||
| m_display_order.emplace_back("Shiny Sounds"); | ||
| m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO); | ||
|
|
||
| m_aliases["Shinies"] = "Shiny Sounds"; | ||
| m_aliases["Shinies Detected"] = "Shiny Sounds"; | ||
| } | ||
|
|
||
| std::atomic<uint64_t>& resets; | ||
| std::atomic<uint64_t>& shinies; | ||
| std::atomic<uint64_t>& errors; | ||
| }; | ||
| std::unique_ptr<StatsTracker> ShinyHunt_WildZoneEntrance_Descriptor::make_stats() const { | ||
| return std::unique_ptr<StatsTracker>(new Stats()); | ||
| } | ||
|
|
||
|
|
||
| ShinyHunt_WildZoneEntrance::ShinyHunt_WildZoneEntrance() | ||
| : WALK_IN_ZONE("<b>WALK IN ZONE:</b><br>Walk this long in the zone after passing through the gate.", | ||
| LockMode::UNLOCK_WHILE_RUNNING, "500 ms"), | ||
| SHINY_DETECTED("Shiny Detected", "", "2000 ms", ShinySoundDetectedAction::NOTIFY_ON_FIRST_ONLY), | ||
| NOTIFICATION_STATUS("Status Update", true, false, std::chrono::seconds(3600)), | ||
| NOTIFICATIONS({ | ||
| &NOTIFICATION_STATUS, | ||
| &SHINY_DETECTED.NOTIFICATIONS, | ||
| &NOTIFICATION_PROGRAM_FINISH, | ||
| &NOTIFICATION_ERROR_RECOVERABLE, | ||
| &NOTIFICATION_ERROR_FATAL, | ||
| }) { | ||
| PA_ADD_STATIC(SHINY_REQUIRES_AUDIO); | ||
| PA_ADD_OPTION(WALK_IN_ZONE); | ||
| PA_ADD_OPTION(SHINY_DETECTED); | ||
| PA_ADD_OPTION(NOTIFICATIONS); | ||
| } | ||
|
|
||
|
|
||
| void run_to_gate(ConsoleHandle& console, ProControllerContext& context) { | ||
| ButtonWatcher buttonA(COLOR_RED, ButtonType::ButtonA, {0, 0, 1, 1}, &console.overlay()); | ||
| int ret = run_until<ProControllerContext>(console, context, | ||
| [](ProControllerContext& context) { | ||
| for (int c = 0; c < 10; c++) { | ||
| pbf_move_left_joystick(context, 128, 0, 800ms, 200ms); | ||
| } | ||
| }, | ||
| {{buttonA}}); | ||
|
|
||
| switch (ret) { | ||
| case 0: | ||
| break; | ||
| default: | ||
| OperationFailedException::fire(ErrorReport::SEND_ERROR_REPORT, | ||
| "run_to_gate(): Unable to detect entrance after 10 seconds.", console); | ||
| } | ||
| } | ||
|
|
||
| void enter_wild_zone_entrance(ConsoleHandle& console, ProControllerContext& context, Milliseconds walk_in_zone) { | ||
| BlackScreenOverWatcher black_screen(COLOR_BLUE); | ||
| int ret = run_until<ProControllerContext>(console, context, | ||
| [&](ProControllerContext& context) { | ||
| pbf_mash_button(context, BUTTON_B, 200ms); // dismiss menu if any | ||
| run_to_gate(console, context); | ||
| pbf_mash_button(context, BUTTON_A, 2000ms); | ||
| pbf_move_left_joystick(context, 128, 0, walk_in_zone, 200ms); | ||
| context.wait_for_all_requests(); | ||
| pbf_press_button(context, BUTTON_PLUS, 100ms, 100ms); // open map | ||
| }, | ||
| {{black_screen}}); | ||
| if (ret == 0) { | ||
| console.log("[WildZoneEntrance] Detected day/night change after entering."); | ||
| context.wait_for(std::chrono::milliseconds(2000)); | ||
| pbf_mash_button(context, BUTTON_B, 200ms); // dismiss menu if any | ||
| pbf_press_button(context, BUTTON_PLUS, 100ms, 100ms); // open map again | ||
| } | ||
| pbf_mash_button(context, BUTTON_A, 800ms); // teleporting or just mashing button | ||
| pbf_mash_button(context, BUTTON_B, 200ms); // in case need to dismiss map | ||
| context.wait_for_all_requests(); | ||
| context.wait_for(std::chrono::milliseconds(4000)); // TODO: differ NS1 wait time from NS2 | ||
| } | ||
|
|
||
| void ShinyHunt_WildZoneEntrance::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) { | ||
| ShinyHunt_WildZoneEntrance_Descriptor::Stats& stats = | ||
| env.current_stats<ShinyHunt_WildZoneEntrance_Descriptor::Stats>(); | ||
|
|
||
| if (SHINY_DETECTED.ACTION == ShinySoundDetectedAction::NOTIFY_ON_ALL) { | ||
| throw UserSetupError(env.console, "Shiny would be detected/notified at most once. Choose one of the other 2 options"); | ||
| } | ||
|
|
||
| uint8_t shiny_count = 0; | ||
|
|
||
| { // first run with shiny detection | ||
| float shiny_coefficient = 1.0; | ||
| PokemonLA::ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool { | ||
| // Warning: This callback will be run from a different thread than this function. | ||
| shiny_count++; | ||
| stats.shinies++; | ||
| env.update_stats(); | ||
| shiny_coefficient = error_coefficient; | ||
| return true; | ||
| }); | ||
|
|
||
| run_until<ProControllerContext>(env.console, context, | ||
| [&](ProControllerContext& context) { | ||
| while (true) { | ||
| send_program_status_notification(env, NOTIFICATION_STATUS); | ||
| stats.resets++; | ||
| enter_wild_zone_entrance(env.console, context, WALK_IN_ZONE); | ||
| env.update_stats(); | ||
| } | ||
| }, | ||
| {{shiny_detector}}); | ||
|
|
||
| context.wait_for(std::chrono::milliseconds(1000)); | ||
|
|
||
| // when shiny sound is detected, it's most likely happened inside the zone | ||
| // now try to reset position | ||
| pbf_mash_button(context, BUTTON_B, 200ms); // dismiss menu if any | ||
| pbf_press_button(context, BUTTON_PLUS, 100ms, 100ms); // open map | ||
| pbf_mash_button(context, BUTTON_A, 600ms); // teleporting or just mashing button | ||
| pbf_mash_button(context, BUTTON_B, 200ms); // in case need to dismiss map | ||
|
|
||
| SHINY_DETECTED.on_shiny_sound(env, env.console, context, shiny_count, shiny_coefficient); | ||
| } | ||
|
|
||
| // continue with shiny sound detection is pointless | ||
| if (SHINY_DETECTED.ACTION != ShinySoundDetectedAction::STOP_PROGRAM) { | ||
| while (true) { | ||
| send_program_status_notification(env, NOTIFICATION_STATUS); | ||
| stats.resets++; | ||
| enter_wild_zone_entrance(env.console, context, WALK_IN_ZONE); | ||
| env.update_stats(); | ||
| } | ||
| } | ||
|
|
||
| go_home(env.console, context); | ||
| send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); | ||
| } | ||
|
|
||
|
|
||
| } // namespace PokemonLZA | ||
| } // namespace NintendoSwitch | ||
| } // namespace PokemonAutomation |
49 changes: 49 additions & 0 deletions
49
SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* Shiny Hunt - Wild Zone Entrance | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_PokemonLZA_WildZoneEntrance_H | ||
| #define PokemonAutomation_PokemonLZA_WildZoneEntrance_H | ||
|
|
||
| #include "CommonFramework/Notifications/EventNotificationsTable.h" | ||
| #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" | ||
| #include "PokemonLA/Options/PokemonLA_ShinyDetectedAction.h" | ||
| #include "PokemonLZA/Options/PokemonLZA_ShinyDetectedAction.h" | ||
|
|
||
| namespace PokemonAutomation { | ||
| namespace NintendoSwitch { | ||
| namespace PokemonLZA { | ||
|
|
||
|
|
||
| class ShinyHunt_WildZoneEntrance_Descriptor : public SingleSwitchProgramDescriptor { | ||
| public: | ||
| ShinyHunt_WildZoneEntrance_Descriptor(); | ||
|
|
||
| class Stats; | ||
| virtual std::unique_ptr<StatsTracker> make_stats() const override; | ||
| }; | ||
|
|
||
|
|
||
| class ShinyHunt_WildZoneEntrance : public SingleSwitchProgramInstance { | ||
| public: | ||
| ShinyHunt_WildZoneEntrance(); | ||
|
|
||
| virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; | ||
|
|
||
| private: | ||
| PokemonLA::ShinyRequiresAudioText SHINY_REQUIRES_AUDIO; | ||
| MillisecondsOption WALK_IN_ZONE; | ||
|
|
||
| ShinySoundDetectedActionOption SHINY_DETECTED; | ||
|
|
||
| EventNotificationOption NOTIFICATION_STATUS; | ||
| EventNotificationsOption NOTIFICATIONS; | ||
| }; | ||
|
|
||
|
|
||
| } // namespace PokemonLZA | ||
| } // namespace NintendoSwitch | ||
| } // namespace PokemonAutomation | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is the same as #774 I guess it will need to be merged in and rebase before ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya i'll do a rebase later