|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | #include "CommonFramework/Exceptions/OperationFailedException.h" |
| 10 | +#include "CommonFramework/VideoPipeline/VideoFeed.h" |
10 | 11 | #include "CommonTools/Random.h" |
11 | 12 | #include "CommonTools/Async/InferenceRoutines.h" |
12 | 13 | #include "CommonTools/StartupChecks/StartProgramChecks.h" |
@@ -306,15 +307,15 @@ bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, boo |
306 | 307 | shiny_coefficient = error_coefficient; |
307 | 308 | return true; |
308 | 309 | }); |
309 | | - AdvanceBattleDialogWatcher legendary_appeared(COLOR_YELLOW); |
310 | | - |
| 310 | + AdvanceBattleDialogWatcher battle_dialog(COLOR_YELLOW); |
| 311 | + |
311 | 312 | int res = run_until<ProControllerContext>( |
312 | 313 | console, context, |
313 | 314 | [&](ProControllerContext& context){ |
314 | 315 | int ret = wait_until( |
315 | 316 | console, context, |
316 | 317 | std::chrono::seconds(30), //More than enough time for shiny sound |
317 | | - {{legendary_appeared}} |
| 318 | + {{battle_dialog}} |
318 | 319 | ); |
319 | 320 | if (ret == 0){ |
320 | 321 | console.log("Battle Advance arrow detected."); |
@@ -366,24 +367,42 @@ bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, boo |
366 | 367 | //Send out lead, no shiny detection needed. (Or wanted.) |
367 | 368 | BattleMenuWatcher battle_menu(COLOR_RED); |
368 | 369 | console.log("Sending out lead Pokemon."); |
369 | | - pbf_press_button(context, BUTTON_A, 320ms, 320ms); |
| 370 | + WallClock start = current_time(); |
| 371 | + |
| 372 | + while (true){ |
| 373 | + if (current_time() - start > 60s){ |
| 374 | + OperationFailedException::fire( |
| 375 | + ErrorReport::SEND_ERROR_REPORT, |
| 376 | + "handle_encounter(): No battle menu detected after sixty seconds.", |
| 377 | + console |
| 378 | + ); |
| 379 | + } |
| 380 | + pbf_press_button(context, BUTTON_B, 320ms, 320ms); |
370 | 381 |
|
371 | | - int ret = wait_until( |
372 | | - console, context, |
373 | | - std::chrono::seconds(15), |
374 | | - { {battle_menu} } |
375 | | - ); |
376 | | - if (ret == 0){ |
377 | | - console.log("Battle menu detecteed!"); |
378 | | - }else{ |
379 | | - OperationFailedException::fire( |
380 | | - ErrorReport::SEND_ERROR_REPORT, |
381 | | - "handle_encounter(): Did not detect battle menu.", |
382 | | - console |
| 382 | + int ret = wait_until( |
| 383 | + console, context, |
| 384 | + std::chrono::seconds(15), |
| 385 | + { {battle_menu, battle_dialog} } |
383 | 386 | ); |
| 387 | + |
| 388 | + switch (ret){ |
| 389 | + case 0: |
| 390 | + console.log("Battle menu detecteed!"); |
| 391 | + break; |
| 392 | + case 1: |
| 393 | + console.log("Battle Advance arrow detected. This is likely due to an ability triggering at the start of battle."); |
| 394 | + pbf_press_button(context, BUTTON_B, 320ms, 320ms); |
| 395 | + context.wait_for_all_requests(); |
| 396 | + continue; |
| 397 | + default: |
| 398 | + console.log("Did not detect battle menu or battle dialog."); |
| 399 | + continue; |
| 400 | + } |
| 401 | + |
| 402 | + pbf_wait(context, 1000ms); |
| 403 | + context.wait_for_all_requests(); |
| 404 | + break; |
384 | 405 | } |
385 | | - pbf_wait(context, 1000ms); |
386 | | - context.wait_for_all_requests(); |
387 | 406 | } |
388 | 407 |
|
389 | 408 | return false; |
|
0 commit comments