@@ -140,51 +140,56 @@ bool read_battle_menu(
140140 if (health[3 ].hp >= 0 ) state.players [3 ].health = health[3 ];
141141
142142
143- // Enter move selection to read PP.
144- pbf_press_button (context, BUTTON_A, 10 , TICKS_PER_SECOND);
145- context.wait_for_all_requests ();
146-
147-
148- // Clear move blocked status.
149- player.move_blocked [0 ] = false ;
150- player.move_blocked [1 ] = false ;
151- player.move_blocked [2 ] = false ;
152- player.move_blocked [3 ] = false ;
153-
154-
155- screen = stream.video ().snapshot ();
143+ for (size_t attempts = 0 ; attempts < 5 ; attempts++){
144+ // Enter move selection to read PP.
145+ pbf_press_button (context, BUTTON_A, 10 , TICKS_PER_SECOND);
146+ context.wait_for_all_requests ();
156147
157- int8_t pp[4 ] = {-1 , -1 , -1 , -1 };
158- reader.read_own_pp (stream.logger (), screen, pp);
159- player.pp [0 ] = pp[0 ];
160- player.pp [1 ] = pp[1 ];
161- player.pp [2 ] = pp[2 ];
162- player.pp [3 ] = pp[3 ];
163148
164- player.can_dmax = reader.can_dmax (screen);
149+ // Clear move blocked status.
150+ player.move_blocked [0 ] = false ;
151+ player.move_blocked [1 ] = false ;
152+ player.move_blocked [2 ] = false ;
153+ player.move_blocked [3 ] = false ;
154+
155+ screen = stream.video ().snapshot ();
156+
157+ int8_t pp[4 ] = {-1 , -1 , -1 , -1 };
158+ reader.read_own_pp (stream.logger (), screen, pp);
159+ player.pp [0 ] = pp[0 ];
160+ player.pp [1 ] = pp[1 ];
161+ player.pp [2 ] = pp[2 ];
162+ player.pp [3 ] = pp[3 ];
163+
164+ player.can_dmax = reader.can_dmax (screen);
165+
166+ // Read move slot.
167+ // int8_t move_slot = arrow_finder.get_slot();
168+ int8_t move_slot = arrow_finder.detect (screen);
169+ if (move_slot < 0 ){
170+ stream.log (" Unable to detect move slot." , COLOR_RED);
171+ // dump_image(stream.logger(), MODULE_NAME, "MoveSlot", screen);
172+ // pbf_press_button(context, BUTTON_A, 10, TICKS_PER_SECOND);
173+ // pbf_press_dpad(context, DPAD_RIGHT, 2 * TICKS_PER_SECOND, 0);
174+ // pbf_press_dpad(context, DPAD_UP, 2 * TICKS_PER_SECOND, 0);
175+ // move_slot = 0;
176+ pbf_mash_button (context, BUTTON_B, 1 * TICKS_PER_SECOND);
177+ continue ;
178+ }else {
179+ stream.log (" Current Move Slot: " + std::to_string (move_slot), COLOR_BLUE);
180+ }
181+ if (move_slot != state.move_slot ){
182+ stream.log (
183+ " Move Slot Mismatch: Expected = " + std::to_string (state.move_slot ) + " , Actual = " + std::to_string (move_slot),
184+ COLOR_RED
185+ );
186+ }
187+ state.move_slot = move_slot;
165188
166- // Read move slot.
167- // int8_t move_slot = arrow_finder.get_slot();
168- int8_t move_slot = arrow_finder.detect (screen);
169- if (move_slot < 0 ){
170- stream.log (" Unable to detect move slot." , COLOR_RED);
171- dump_image (stream.logger (), MODULE_NAME, " MoveSlot" , screen);
172- pbf_press_button (context, BUTTON_A, 10 , TICKS_PER_SECOND);
173- pbf_press_dpad (context, DPAD_RIGHT, 2 * TICKS_PER_SECOND, 0 );
174- pbf_press_dpad (context, DPAD_UP, 2 * TICKS_PER_SECOND, 0 );
175- move_slot = 0 ;
176- }else {
177- stream.log (" Current Move Slot: " + std::to_string (move_slot), COLOR_BLUE);
178- }
179- if (move_slot != state.move_slot ){
180- stream.log (
181- " Move Slot Mismatch: Expected = " + std::to_string (state.move_slot ) + " , Actual = " + std::to_string (move_slot),
182- COLOR_RED
183- );
189+ return true ;
184190 }
185- state.move_slot = move_slot;
186191
187- // inference.stop( );
192+ dump_image (stream. logger (), MODULE_NAME, " MoveSlot " , screen );
188193 return true ;
189194}
190195
0 commit comments