@@ -33,18 +33,40 @@ void run_away(
3333 VideoStream& stream, ProControllerContext& context,
3434 Milliseconds exit_battle_time
3535){
36+ pbf_press_dpad (context, DPAD_UP, 10 , 0 );
37+ pbf_press_button (context, BUTTON_A, 250ms, 750ms);
38+
3639 BlackScreenOverWatcher black_screen_detector;
37- run_until<ProControllerContext>(
38- stream, context,
39- [exit_battle_time](ProControllerContext& context){
40- pbf_press_dpad (context, DPAD_UP, 10 , 0 );
41- pbf_mash_button (context, BUTTON_A, 1000ms);
42- if (exit_battle_time > 1000ms){
43- pbf_mash_button (context, BUTTON_B, exit_battle_time - 1000ms);
40+ StandardBattleMenuWatcher battle_menu (false , COLOR_GREEN);
41+ while (true ){
42+ context.wait_for_all_requests ();
43+ int ret = run_until<ProControllerContext>(
44+ stream, context,
45+ [exit_battle_time](ProControllerContext& context){
46+ pbf_mash_button (context, BUTTON_B, exit_battle_time);
47+ },
48+ {
49+ black_screen_detector,
50+ battle_menu,
4451 }
45- },
46- {{black_screen_detector}}
47- );
52+ );
53+ switch (ret){
54+ case 0 :
55+ context->logger ().log (" Detected end of battle!" );
56+ return ;
57+ case 1 :
58+ context->logger ().log (" Detected unexpected battle menu!" , COLOR_RED);
59+ pbf_press_dpad (context, DPAD_DOWN, 3000ms, 0ms);
60+ pbf_press_button (context, BUTTON_A, 80ms, 0ms);
61+ continue ;
62+ default :
63+ throw OperationFailedException (
64+ ErrorReport::SEND_ERROR_REPORT,
65+ " Unable to run away. Are you stuck in the battle?" ,
66+ stream
67+ );
68+ }
69+ }
4870}
4971
5072
@@ -82,10 +104,7 @@ void StandardEncounterHandler::run_away_and_update_stats(
82104 // Read the name.
83105 const std::set<std::string>* candidates_ptr = encounter.candidates ();
84106
85- // Initiate the run-away.
86- pbf_press_dpad (m_context, DPAD_UP, 10 , 0 );
87- pbf_mash_button (m_context, BUTTON_A, 60 );
88- m_context.wait_for_all_requests ();
107+ run_away (m_stream, m_context, exit_battle_time);
89108
90109 update_frequencies (encounter);
91110
@@ -101,21 +120,6 @@ void StandardEncounterHandler::run_away_and_update_stats(
101120 result.get_best_screenshot (),
102121 &m_frequencies
103122 );
104-
105- BlackScreenOverWatcher black_screen_detector;
106- int ret = run_until<ProControllerContext>(
107- m_stream, m_context,
108- [exit_battle_time](ProControllerContext& context){
109- pbf_mash_button (context, BUTTON_A, 1000ms);
110- if (exit_battle_time > 1000ms){
111- pbf_mash_button (context, BUTTON_B, exit_battle_time - 1000ms);
112- }
113- },
114- {{black_screen_detector}}
115- );
116- if (ret < 0 ){
117- m_stream.log (" Timed out waiting for end of battle. Are you stuck in the battle?" , COLOR_RED);
118- }
119123}
120124
121125
0 commit comments