@@ -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+
379461void 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);
0 commit comments