Skip to content

Commit bdd4617

Browse files
authored
Fix extra dialogue issue in handle_encounter (#1296)
1 parent d358a42 commit bdd4617

1 file changed

Lines changed: 37 additions & 18 deletions

File tree

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "CommonFramework/Exceptions/OperationFailedException.h"
10+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1011
#include "CommonTools/Random.h"
1112
#include "CommonTools/Async/InferenceRoutines.h"
1213
#include "CommonTools/StartupChecks/StartProgramChecks.h"
@@ -306,15 +307,15 @@ bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, boo
306307
shiny_coefficient = error_coefficient;
307308
return true;
308309
});
309-
AdvanceBattleDialogWatcher legendary_appeared(COLOR_YELLOW);
310-
310+
AdvanceBattleDialogWatcher battle_dialog(COLOR_YELLOW);
311+
311312
int res = run_until<ProControllerContext>(
312313
console, context,
313314
[&](ProControllerContext& context){
314315
int ret = wait_until(
315316
console, context,
316317
std::chrono::seconds(30), //More than enough time for shiny sound
317-
{{legendary_appeared}}
318+
{{battle_dialog}}
318319
);
319320
if (ret == 0){
320321
console.log("Battle Advance arrow detected.");
@@ -366,24 +367,42 @@ bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, boo
366367
//Send out lead, no shiny detection needed. (Or wanted.)
367368
BattleMenuWatcher battle_menu(COLOR_RED);
368369
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);
370381

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} }
383386
);
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;
384405
}
385-
pbf_wait(context, 1000ms);
386-
context.wait_for_all_requests();
387406
}
388407

389408
return false;

0 commit comments

Comments
 (0)