diff --git a/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h b/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h index 9ba4ba069b..08f40de7f4 100644 --- a/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h +++ b/SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h @@ -81,6 +81,13 @@ class WhiteDialogWatcher : public DetectorToFinder{ {} }; +class WhiteDialogOverWatcher : public DetectorToFinder{ +public: + WhiteDialogOverWatcher(Color color) + : DetectorToFinder("WhiteDialogOverWatcher", FinderType::GONE, std::chrono::milliseconds(250), color) + {} +}; + // Same as WhiteDialogDetector, but filter for the red arrow // Detect the red advancement arrow by filtering for DARK red. // There is red/pink color text for female npcs in non-japan versions diff --git a/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp b/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp index 75e23b0dbc..257575708d 100644 --- a/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp +++ b/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp @@ -599,6 +599,7 @@ bool EggRng::held_frame_check( } if (locked_in && !(definitely_hit_held_frame || possibly_hit_held_frame)){ + STARTING_POINT.set(EggProgramState::held_prep); OperationFailedException::fire( ErrorReport::SEND_ERROR_REPORT, "EggRng(): Missed held frame after saving. Restart the program after repeating the manual in-game setup.", diff --git a/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp b/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp index 4e3745f9be..a52f98a9a4 100644 --- a/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp +++ b/SerialPrograms/Source/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp @@ -806,25 +806,69 @@ void walk_from_pond_to_daycare_man(ConsoleHandle& console, ProControllerContext& void egg_pickup(ConsoleHandle& console, ProControllerContext& context){ console.log("Picking up egg..."); - WhiteDialogWatcher dialogue(COLOR_RED); + + // Clear the save dialogue, if it is open + WhiteDialogOverWatcher dialogue_cleared(COLOR_RED); context.wait_for_all_requests(); int ret = run_until( console, context, [](ProControllerContext& context) { - pbf_mash_button(context, BUTTON_A, 5000ms); + pbf_mash_button(context, BUTTON_B, 5000ms); + }, + { dialogue_cleared } + ); + if (ret < 0){ + OperationFailedException::fire( + ErrorReport::SEND_ERROR_REPORT, + "egg_pickup(): Failed to clear dialogue before talking to the daycare man.", + console + ); + } + + // Talk to the daycare man and wait for the egg prompt. + SelectionDialogWatcher egg_prompt(COLOR_RED); + context.wait_for_all_requests(); + ret = run_until( + console, context, + [](ProControllerContext& context) { + for (int i=0; i<12; i++){ + pbf_press_button(context, BUTTON_A, 200ms, 800ms); + } }, - { dialogue } + { egg_prompt } ); if (ret < 0){ OperationFailedException::fire( ErrorReport::SEND_ERROR_REPORT, - "egg_pickup(): Failed to initiate dialogue.", + "egg_pickup(): Failed to detect the egg selection dialogue.", console ); } + console.log("Egg selection dialogue detected. Taking the egg..."); + + // accept the egg + pbf_mash_button(context, BUTTON_A, 1000ms); + + // clear the rest of the dialogue + WhiteDialogOverWatcher dialogue_over(COLOR_RED); + context.wait_for_all_requests(); + ret = run_until( + console, context, + [](ProControllerContext& context) { + pbf_mash_button(context, BUTTON_B, 10000ms); + }, + { dialogue_over } + ); + if (ret < 0){ + OperationFailedException::fire( + ErrorReport::SEND_ERROR_REPORT, + "egg_pickup(): Failed to return to the overworld after taking the egg.", + console + ); + } + context.wait_for_all_requests(); - pbf_mash_button(context, BUTTON_A, 5000ms); - pbf_mash_button(context, BUTTON_B, 2500ms); + console.log("Egg picked up."); } bool walk_from_daycare_man_to_pond(ConsoleHandle& console, ProControllerContext& context){