1010#include " CommonTools/Async/InferenceRoutines.h"
1111#include " CommonTools/VisualDetectors/BlackScreenDetector.h"
1212#include " NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
13+ #include " NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1314#include " PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h"
1415#include " PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h"
1516#include " PokemonRSE/PokemonRSE_Settings.h"
@@ -20,11 +21,11 @@ namespace NintendoSwitch{
2021namespace PokemonRSE {
2122
2223
23- void soft_reset (const ProgramInfo& info, VideoStream& stream, ProControllerContext & context){
24+ void soft_reset (const ProgramInfo& info, VideoStream& stream, SwitchControllerContext & context){
2425 // A + B + Select + Start
2526 pbf_press_button (context, BUTTON_B | BUTTON_Y | BUTTON_MINUS | BUTTON_PLUS, 10 , 180 );
2627
27- pbf_mash_button (context, BUTTON_PLUS, GameSettings::instance ().START_BUTTON_MASH0 );
28+ pbf_mash_button (context, BUTTON_PLUS, GameSettings::instance ().START_BUTTON_MASH );
2829 context.wait_for_all_requests ();
2930
3031 pbf_press_button (context, BUTTON_A, 20 , 40 );
@@ -33,8 +34,8 @@ void soft_reset(const ProgramInfo& info, VideoStream& stream, ProControllerConte
3334 BlackScreenOverWatcher detector (COLOR_RED, {0.282 , 0.064 , 0.448 , 0.871 });
3435 int ret = wait_until (
3536 stream, context,
36- GameSettings::instance ().ENTER_GAME_WAIT0 ,
37- {detector}
37+ std::chrono::milliseconds ( GameSettings::instance ().ENTER_GAME_WAIT * ( 1000 / TICKS_PER_SECOND)) ,
38+ {{ detector} }
3839 );
3940 if (ret == 0 ){
4041 stream.log (" Entered game!" );
@@ -49,7 +50,7 @@ void soft_reset(const ProgramInfo& info, VideoStream& stream, ProControllerConte
4950 context.wait_for_all_requests ();
5051}
5152
52- void flee_battle (VideoStream& stream, ProControllerContext & context) {
53+ void flee_battle (VideoStream& stream, SwitchControllerContext & context) {
5354 stream.log (" Navigate to Run." );
5455 pbf_press_dpad (context, DPAD_RIGHT, 20 , 20 );
5556 pbf_press_dpad (context, DPAD_DOWN, 20 , 20 );
@@ -89,7 +90,7 @@ void flee_battle(VideoStream& stream, ProControllerContext& context) {
8990 }
9091}
9192
92- bool handle_encounter (VideoStream& stream, ProControllerContext & context) {
93+ bool handle_encounter (VideoStream& stream, SwitchControllerContext & context, bool send_out_lead ) {
9394 float shiny_coefficient = 1.0 ;
9495 ShinySoundDetector shiny_detector (stream.logger (), [&](float error_coefficient) -> bool {
9596 shiny_coefficient = error_coefficient;
@@ -101,9 +102,9 @@ bool handle_encounter(VideoStream& stream, ProControllerContext& context) {
101102 pbf_mash_button (context, BUTTON_A, 540 );
102103 context.wait_for_all_requests ();
103104
104- int res = run_until<ProControllerContext >(
105+ int res = run_until<SwitchControllerContext >(
105106 stream, context,
106- [&](ProControllerContext & context) {
107+ [&](SwitchControllerContext & context) {
107108 int ret = wait_until (
108109 stream, context,
109110 std::chrono::seconds (30 ),
@@ -130,27 +131,30 @@ bool handle_encounter(VideoStream& stream, ProControllerContext& context) {
130131 }
131132 stream.log (" Shiny not found." );
132133
133- // Send out lead, no shiny detection needed.
134- BattleMenuWatcher battle_menu (COLOR_RED);
135- stream.log (" Sending out lead Pokemon." );
136- pbf_press_button (context, BUTTON_A, 40 , 40 );
134+ if (send_out_lead) {
135+ // Send out lead, no shiny detection needed.
136+ BattleMenuWatcher battle_menu (COLOR_RED);
137+ stream.log (" Sending out lead Pokemon." );
138+ pbf_press_button (context, BUTTON_A, 40 , 40 );
137139
138- int ret = wait_until (
139- stream, context,
140- std::chrono::seconds (15 ),
141- {{battle_menu}}
142- );
143- if (ret == 0 ) {
144- stream.log (" Battle menu detecteed!" );
145- } else {
146- OperationFailedException::fire (
147- ErrorReport::SEND_ERROR_REPORT,
148- " handle_encounter(): Did not detect battle menu." ,
149- stream
140+ int ret = wait_until (
141+ stream, context,
142+ std::chrono::seconds (15 ),
143+ { {battle_menu} }
150144 );
145+ if (ret == 0 ) {
146+ stream.log (" Battle menu detecteed!" );
147+ }
148+ else {
149+ OperationFailedException::fire (
150+ ErrorReport::SEND_ERROR_REPORT,
151+ " handle_encounter(): Did not detect battle menu." ,
152+ stream
153+ );
154+ }
155+ pbf_wait (context, 125 );
156+ context.wait_for_all_requests ();
151157 }
152- pbf_wait (context, 125 );
153- context.wait_for_all_requests ();
154158
155159 return false ;
156160}
0 commit comments