Skip to content

Commit dc89788

Browse files
committed
improve consistency of exit_battle()
1 parent ec97f7d commit dc89788

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

SerialPrograms/Source/PokemonFRLG/Programs/Farming/PokemonFRLG_PickupFarmer.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -389,26 +389,34 @@ void use_first_battle_move(SingleSwitchProgramEnvironment& env, ProControllerCon
389389

390390
bool exit_battle(SingleSwitchProgramEnvironment& env, ProControllerContext& context, BooleanCheckBoxOption& STOP_ON_MOVE_LEARN){
391391
BlackScreenWatcher battle_exited(COLOR_RED);
392+
BattleLearnDialogWatcher move_learn_select(COLOR_RED);
392393
context.wait_for_all_requests();
393394
env.log("Exiting battle.");
394395
int ret = run_until<ProControllerContext>(
395396
env.console, context,
396397
[](ProControllerContext& context) {
397-
pbf_mash_button(context, BUTTON_B, 15000ms);
398+
pbf_mash_button(context, BUTTON_B, 30000ms);
398399
},
399-
{ battle_exited }
400+
{ battle_exited, move_learn_select }
400401
);
401-
if (ret == 0) {
402+
if (ret == 0){
402403
pbf_wait(context, 500ms);
403404
context.wait_for_all_requests();
404405
env.log("Battle exited.");
405406
return false;
407+
}else if (ret == 1){
408+
env.log("Move learn detected.");
409+
if (STOP_ON_MOVE_LEARN) {
410+
return true;
411+
}
412+
}else{
413+
OperationFailedException::fire(
414+
ErrorReport::SEND_ERROR_REPORT,
415+
"Failed to exit battle within 30 seconds.",
416+
env.console
417+
);
406418
}
407419

408-
env.log("Move learn detected.");
409-
if (STOP_ON_MOVE_LEARN) {
410-
return true;
411-
}
412420
// there are two dialog selection boxes in a row
413421
// we need to decline the first one and accept the second one
414422
// the first one will occur after an Advance Battle Dialog
@@ -422,17 +430,20 @@ bool exit_battle(SingleSwitchProgramEnvironment& env, ProControllerContext& cont
422430
pbf_press_button(context, BUTTON_B, 200ms, 800ms);
423431
}
424432
},
425-
{ advance_dialog }
433+
{ battle_exited, advance_dialog }
426434
);
427-
if (ret < 0) {
435+
if (ret < 0){
428436
OperationFailedException::fire(
429437
ErrorReport::SEND_ERROR_REPORT,
430438
"Failed to detect dialog advance arrow within 20 seconds.",
431439
env.console
432440
);
441+
}else if (ret == 0){
442+
pbf_wait(context, 500ms);
443+
context.wait_for_all_requests();
444+
env.log("Battle exited.");
433445
}
434446

435-
BattleLearnDialogWatcher move_learn_select(COLOR_RED);
436447
context.wait_for_all_requests();
437448
deadline = current_time() + 10s;
438449
ret = run_until<ProControllerContext>(
@@ -442,14 +453,18 @@ bool exit_battle(SingleSwitchProgramEnvironment& env, ProControllerContext& cont
442453
pbf_press_button(context, BUTTON_B, 200ms, 1800ms);
443454
}
444455
},
445-
{ move_learn_select }
456+
{ battle_exited, move_learn_select }
446457
);
447-
if (ret < 0) {
458+
if (ret < 0){
448459
OperationFailedException::fire(
449460
ErrorReport::SEND_ERROR_REPORT,
450461
"Failed to detect learn move selection box within 10 seconds.",
451462
env.console
452463
);
464+
}else if (ret == 0){
465+
pbf_wait(context, 500ms);
466+
context.wait_for_all_requests();
467+
env.log("Battle exited.");
453468
}
454469
env.log("Detected YES/NO box for learning a move.");
455470

@@ -466,7 +481,7 @@ bool exit_battle(SingleSwitchProgramEnvironment& env, ProControllerContext& cont
466481
},
467482
{ battle_exited }
468483
);
469-
if (ret < 0) {
484+
if (ret < 0){
470485
OperationFailedException::fire(
471486
ErrorReport::SEND_ERROR_REPORT,
472487
"Failed to exit battle within 20 seconds.",

0 commit comments

Comments
 (0)