diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_InPlaceCatcher.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_InPlaceCatcher.cpp index 4d6f3a1097..8849f1f925 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_InPlaceCatcher.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_InPlaceCatcher.cpp @@ -10,7 +10,6 @@ //#include "CommonTools/Async/InferenceSession.h" #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" -#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.h" @@ -20,6 +19,7 @@ #include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "VideoGames/PokemonLZA/Inference/Battles/PokemonLZA_MoveEffectivenessSymbol.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h" #include "PokemonLZA_InPlaceCatcher.h" @@ -167,13 +167,7 @@ void InPlaceCatcher::run( env.console, context, [](ProControllerContext& context){ while (true){ - for (int c = 0; c < 10; c++){ - ssf_press_right_joystick(context, {-0.5, 0}, 0ms, 1000ms, 0ms); - ssf_press_dpad(context, DpadPosition::DPAD_UP, 0ms, 160ms, 160ms); - pbf_mash_button(context, BUTTON_ZL, 1000ms); - pbf_press_button(context, BUTTON_ZL, 500ms, 0ms); - } - pbf_press_button(context, BUTTON_L, 160ms, 160ms); + sweep_camera_for_lock_on(context, /*camera_x=*/-0.5, /*rounds=*/10); } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.cpp new file mode 100644 index 0000000000..4247396e4b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.cpp @@ -0,0 +1,47 @@ +/* Lock-On Sweep + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "VideoGames/PokemonLZA/Inference/Battles/PokemonLZA_MoveEffectivenessSymbol.h" +#include "PokemonLZA_LockOnSweep.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono; + + +void sweep_camera_for_lock_on(ProControllerContext& context, double camera_x, int rounds){ + for (int c = 0; c < rounds; c++){ + ssf_press_right_joystick(context, {camera_x, 0}, /*delay=*/0ms, /*hold=*/1000ms, /*cool=*/0ms); + ssf_press_dpad(context, DpadPosition::DPAD_UP, /*delay=*/0ms, /*hold=*/160ms, /*cool=*/160ms); + pbf_mash_button(context, BUTTON_ZL, /*duration=*/1000ms); + pbf_press_button(context, BUTTON_ZL, /*hold=*/500ms, /*release=*/0ms); + } + pbf_press_button(context, BUTTON_L, /*hold=*/160ms, /*release=*/160ms); +} + +bool lock_on_by_sweep(ConsoleHandle& console, ProControllerContext& context, double camera_x, int rounds){ + MoveEffectivenessSymbolWatcher battle_menu(COLOR_RED, &console.overlay(), /*hold_duration=*/100ms); + context.wait_for_all_requests(); + int ret = run_until( + console, context, + [&](ProControllerContext& context){ + sweep_camera_for_lock_on(context, camera_x, rounds); + }, + {battle_menu} + ); + context.wait_for_all_requests(); + return ret == 0; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.h new file mode 100644 index 0000000000..9d67dac7d3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.h @@ -0,0 +1,33 @@ +/* Lock-On Sweep + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_LockOnSweep_H +#define PokemonAutomation_PokemonLZA_LockOnSweep_H + +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Sweep the camera to lock on to a wild pokemon: `rounds` rounds of turning the camera with +// the right stick at `camera_x` (negative turns left) for 1 s, D-pad up, then mashing ZL +// for 1 s and holding it for 0.5 s. Then press L to put the camera back behind the player. +// This only presses buttons. Run it with a MoveEffectivenessSymbolWatcher to stop at a lock-on. +void sweep_camera_for_lock_on(ProControllerContext& context, double camera_x, int rounds); + +// Run sweep_camera_for_lock_on() until the battle menu's move effectiveness symbols show, +// which means ZL has locked on to a wild pokemon. +// Return true if locked on, false if the whole sweep ended without a lock-on. +bool lock_on_by_sweep(ConsoleHandle& console, ProControllerContext& context, double camera_x, int rounds); + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index adc3c5cbd3..3075048538 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2270,6 +2270,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h Source/VideoGames/PokemonLZA/Programs/PokemonLZA_HyperspaceNavigation.cpp Source/VideoGames/PokemonLZA/Programs/PokemonLZA_HyperspaceNavigation.h + Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.cpp + Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.h Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MegaShardFarmer.cpp Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MegaShardFarmer.h Source/VideoGames/PokemonLZA/Programs/PokemonLZA_MenuNavigation.cpp