Skip to content

Commit 41a2894

Browse files
authored
Lucky Egg Farmer fix program finished notification (#1186)
1 parent 1f2d00e commit 41a2894

2 files changed

Lines changed: 99 additions & 75 deletions

File tree

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

Lines changed: 84 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,92 @@ bool LuckyEggFarmer::check_for_lucky_egg(ConsoleHandle& console, ProControllerCo
376376
return false;
377377
}
378378

379+
bool LuckyEggFarmer::run_safari_zone(SingleSwitchProgramEnvironment& env, ProControllerContext& context) {
380+
LuckyEggFarmer_Descriptor::Stats& stats = env.current_stats<LuckyEggFarmer_Descriptor::Stats>();
381+
382+
int chancy_count = 0;
383+
int balls_left = 30;
384+
385+
while (chancy_count < 4) {
386+
if (!find_encounter(env, context)) {
387+
return false;
388+
}
389+
390+
bool encounter_shiny = handle_encounter(env.console, context, true);
391+
if (encounter_shiny) {
392+
stats.shinies++;
393+
env.update_stats();
394+
send_program_notification(
395+
env,
396+
NOTIFICATION_SHINY,
397+
COLOR_YELLOW,
398+
"Shiny found!",
399+
{}, "",
400+
env.console.video().snapshot(),
401+
true
402+
);
403+
if (TAKE_VIDEO) {
404+
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 0ms);
405+
}
406+
return true;
407+
}
408+
409+
if (!is_chansey(env, context)) {
410+
continue;
411+
}
412+
413+
bool caught = attempt_catch(env, context, balls_left);
414+
415+
if (caught) {
416+
stats.chanseys++;
417+
env.update_stats();
418+
chancy_count++;
419+
}
420+
421+
pbf_wait(context, 500ms);
422+
context.wait_for_all_requests();
423+
424+
WhiteDialogDetector dialog(COLOR_RED);
425+
bool in_safari_zone_building = dialog.detect(env.console.video().snapshot());
426+
427+
if (balls_left <= 0) {
428+
in_safari_zone_building = true;
429+
}
430+
431+
if (in_safari_zone_building && !caught) {
432+
return false;
433+
}
434+
435+
if (in_safari_zone_building) {
436+
pbf_mash_button(context, BUTTON_B, 500ms);
437+
context.wait_for_all_requests();
438+
}
439+
440+
if (caught) {
441+
if (check_for_lucky_egg(env.console, context, in_safari_zone_building)) {
442+
env.log("Lucky Egg found!");
443+
stats.eggs++;
444+
env.update_stats();
445+
return true;
446+
}
447+
env.log("Lucky Egg not found. Continuing to farm...");
448+
pbf_mash_button(context, BUTTON_B, 1500ms);
449+
context.wait_for_all_requests();
450+
}
451+
452+
if (balls_left <= 0) {
453+
env.log("Out of Safari balls. Resetting...");
454+
return false;
455+
}
456+
}
457+
458+
return false;
459+
}
460+
379461
void LuckyEggFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
380462

381463
home_black_border_check(env.console, context);
382464

383-
LuckyEggFarmer_Descriptor::Stats& stats = env.current_stats<LuckyEggFarmer_Descriptor::Stats>();
384465
DeferredStopButtonOption::ResetOnExit reset_on_exit(STOP_AFTER_CURRENT);
385466

386467
while (true){
@@ -431,80 +512,8 @@ void LuckyEggFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerC
431512

432513
swap_lead_pokemon(env.console, context);
433514

434-
int chancy_count = 0;
435-
int balls_left = 30;
436-
437-
while (chancy_count < 4) {
438-
if (!find_encounter(env, context)) {
439-
break;
440-
}
441-
442-
bool encounter_shiny = handle_encounter(env.console, context, true);
443-
if (encounter_shiny) {
444-
stats.shinies++;
445-
env.update_stats();
446-
send_program_notification(
447-
env,
448-
NOTIFICATION_SHINY,
449-
COLOR_YELLOW,
450-
"Shiny found!",
451-
{}, "",
452-
env.console.video().snapshot(),
453-
true
454-
);
455-
if (TAKE_VIDEO) {
456-
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 0ms);
457-
}
458-
return;
459-
}
460-
461-
if (!is_chansey(env, context)) {
462-
continue;
463-
}
464-
465-
bool caught = attempt_catch(env, context, balls_left);
466-
467-
if (caught){
468-
stats.chanseys++;
469-
env.update_stats();
470-
chancy_count++;
471-
}
472-
473-
pbf_wait(context, 500ms);
474-
context.wait_for_all_requests();
475-
476-
WhiteDialogDetector dialog(COLOR_RED);
477-
bool in_safari_zone_building = dialog.detect(env.console.video().snapshot());
478-
479-
if (balls_left <= 0) {
480-
in_safari_zone_building = true;
481-
}
482-
483-
if (in_safari_zone_building && !caught) {
484-
break;
485-
}
486-
487-
if (in_safari_zone_building) {
488-
pbf_mash_button(context, BUTTON_B, 500ms);
489-
context.wait_for_all_requests();
490-
}
491-
492-
if (caught) {
493-
if (check_for_lucky_egg(env.console, context, in_safari_zone_building)) {
494-
env.log("Lucky Egg found!");
495-
stats.eggs++;
496-
env.update_stats();
497-
return;
498-
}
499-
env.log("Lucky Egg not found. Continuing to farm...");
500-
pbf_mash_button(context, BUTTON_B, 1500ms);
501-
context.wait_for_all_requests();
502-
}
503-
504-
if (balls_left <= 0) {
505-
env.log("Out of Safari balls. Resetting...");
506-
break;
507-
}
515+
if (run_safari_zone(env, context)) {
516+
break;
508517
}
509518

510519
soft_reset(env.console, context);

SerialPrograms/Source/PokemonFRLG/Programs/Farming/PokemonFRLG_LuckyEggFarmer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,27 @@ class LuckyEggFarmer : public SingleSwitchProgramInstance {
3838

3939
private:
4040

41+
// After exiting the safari zone building navigate to grass with Chansey.
42+
// Currently only supports running. Should add Surf option...
4143
bool navigate_to_chansey(ConsoleHandle& console, ProControllerContext& context);
44+
// Swap first and second pokemon.
45+
// First pokemon used to avoid encounters on the route to Chansey. Second pokemon used to improve encounter rates.
4246
void swap_lead_pokemon(ConsoleHandle& console, ProControllerContext& context);
47+
// Reads wild encounter name and returns true if Chansey
4348
bool is_chansey(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
49+
// Handles the encounter logic. Attempts to spin in place. Resets position to the top right corner of grass.
50+
// Returns true if transition to battle detected.
4451
bool find_encounter(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
52+
// Handles the catch logic. Should be updated to throw bait for better catch rates.
53+
// Returns true if catch successful. Returns in the overworld.
4554
bool attempt_catch(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int& balls_left);
55+
// Opens the party menu from a given overworld location (safari zone, or the main safari zone building)
56+
// Checks the last four party slots for held items. Returns true if item detected.
4657
bool check_for_lucky_egg(ConsoleHandle& console, ProControllerContext& context, bool returned_to_building);
58+
// Handles the main loop once we are in the grass ready to search for a Chansey.
59+
// Returns true if a stop condition is met (lucky egg or shiny found).
60+
// Returns false if we need to soft reset (out of safari balls, out of steps, caught a full party of Chansey).
61+
bool run_safari_zone(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
4762

4863
OCR::LanguageOCROption LANGUAGE;
4964

0 commit comments

Comments
 (0)