Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down Expand Up @@ -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);
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProControllerContext>(
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
Original file line number Diff line number Diff line change
@@ -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);

Check warning on line 27 in SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_LockOnSweep.h

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

style: 'lock_on_by_sweep' is used only in its own .cpp; test through the public function, or keep it in the .cpp's anonymous namespace (ignore if a later PR in the stack calls it) (user review on fork #590)


} // namespace PokemonLZA
} // namespace NintendoSwitch
} // namespace PokemonAutomation
#endif
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down