1414#include " NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1515#include " Pokemon/Pokemon_Strings.h"
1616#include " PokemonSwSh/PokemonSwSh_Settings.h"
17+ #include " PokemonSwSh/Inference/PokemonSwSh_DialogTriangleDetector.h"
18+ #include " PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.h"
19+ #include " PokemonSwSh/Inference/PokemonSwSh_DialogBoxDetector.h"
20+ #include " PokemonSwSh/Inference/PokemonSwSh_ReceivePokemonDetector.h"
1721#include " PokemonSwSh/Programs/PokemonSwSh_GameEntry.h"
1822#include " PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_Entrance.h"
1923#include " PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_Notifications.h"
@@ -35,23 +39,79 @@ StateMachineAction mash_A_to_entrance(
3539 VideoStream& stream, ProControllerContext& context,
3640 const ImageViewRGB32& entrance
3741){
38- EntranceDetector entrance_detector (entrance);
42+ WallClock start = current_time ();
43+ while (true ){
44+ if (current_time () - start > std::chrono::seconds (60 )){
45+ stream.log (" Unable to find entrance after 60 seconds." , COLOR_RED);
46+ runtime.session_stats .add_error ();
47+ dump_image (stream.logger (), MODULE_NAME, stream.video (), " FailedToDetectEntrance" );
48+ return StateMachineAction::RESET_RECOVER;
49+ }
50+
51+ EntranceDetector entrance_detector (entrance);
52+ SelectionArrowFinder prompt (stream.overlay (), {0.362689 , 0.282828 , 0.625000 , 0.580808 });
53+ DialogTriangleDetector triangle (stream.logger (), stream.overlay (), true );
54+ BlackDialogBoxDetector dialog (true );
55+ ReceivePokemonDetector receive (true );
56+
57+ context.wait_for_all_requests ();
58+ int ret = wait_until (
59+ stream, context,
60+ std::chrono::seconds (10 ),
61+ {
62+ entrance_detector,
63+ prompt,
64+ triangle,
65+ dialog,
66+ receive,
67+ },
68+ INFERENCE_RATE
69+ );
70+ context.wait_for (std::chrono::milliseconds (100 ));
71+ switch (ret){
72+ case 0 :
73+ stream.log (" Detected entrance." );
74+ return StateMachineAction::KEEP_GOING;
75+ case 1 :
76+ stream.log (" Detected prompt." );
77+ pbf_press_button (context, BUTTON_A, 80ms, 320ms);
78+ break ;
79+ case 2 :
80+ stream.log (" Detected dialog triangle." );
81+ pbf_press_button (context, BUTTON_B, 80ms, 320ms);
82+ break ;
83+ case 3 :
84+ stream.log (" Detected dialog box." );
85+ pbf_press_button (context, BUTTON_B, 80ms, 320ms);
86+ break ;
87+ case 4 :
88+ stream.log (" Detected receive " + Pokemon::STRING_POKEMON + " ." );
89+ pbf_press_button (context, BUTTON_B, 80ms, 320ms);
90+ break ;
91+ default :
92+ stream.log (" No recognized state after 10 seconds." , COLOR_RED);
93+ pbf_press_button (context, BUTTON_B, 80ms, 320ms);
94+ pbf_press_button (context, BUTTON_X, 80ms, 320ms); // In case we landed in the nickname menu.
95+ }
96+ }
3997
40- int result = run_until<ProControllerContext>(
98+ EntranceDetector entrance_detector (entrance);
99+ int ret = run_until<ProControllerContext>(
41100 stream, context,
42- [&](ProControllerContext& context){
43- pbf_mash_button (context, BUTTON_A, 60 * TICKS_PER_SECOND);
101+ [](ProControllerContext& context){
102+ for (size_t c = 0 ; c < 60 ; c++){
103+ pbf_press_button (context, BUTTON_B, 80ms, 920ms);
104+ }
44105 },
45- {{entrance_detector}},
46- INFERENCE_RATE
106+ {entrance_detector}
47107 );
48-
49- if (result < 0 ){
50- stream.log (" Failed to detect entrance." , COLOR_RED);
108+ if (ret < 0 ){
109+ stream.log (" Unable to find entrance after 60 seconds." , COLOR_RED);
51110 runtime.session_stats .add_error ();
52111 dump_image (stream.logger (), MODULE_NAME, stream.video (), " FailedToDetectEntrance" );
53112 return StateMachineAction::RESET_RECOVER;
54113 }
114+
55115 return StateMachineAction::KEEP_GOING;
56116}
57117
0 commit comments