@@ -78,6 +78,8 @@ LegendaryReset::LegendaryReset()
7878 &NOTIFICATION_SHINY,
7979 &NOTIFICATION_STATUS_UPDATE,
8080 &NOTIFICATION_PROGRAM_FINISH,
81+ &NOTIFICATION_ERROR_RECOVERABLE,
82+ &NOTIFICATION_ERROR_FATAL,
8183 })
8284{
8385 PA_ADD_OPTION (TARGET);
@@ -166,28 +168,47 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableSco
166168 Don't do it on the first Snorlax, otherwise have to sit through fuji tutorial
167169 */
168170
171+ size_t consecutive_failures = 0 ;
172+
169173 while (true ) {
170- bool encounter_battle = run_encounter (env, context);
171- if (encounter_battle) {
172- stats.shinies ++;
173- env.update_stats ();
174- send_program_notification (env, NOTIFICATION_SHINY, COLOR_YELLOW, " Shiny found!" , {}, " " , env.console .video ().snapshot (), true );
175- break ;
174+ env.update_stats ();
175+
176+ if (consecutive_failures >= 3 ){
177+ OperationFailedException::fire (
178+ ErrorReport::SEND_ERROR_REPORT,
179+ " Failed 3 times in the row." ,
180+ env.console
181+ );
176182 }
177- env.log (" No shiny found. Resetting game." );
178- send_program_status_notification (
179- env, NOTIFICATION_STATUS_UPDATE,
180- " No shiny found. Resetting game."
181- );
182- context.wait_for_all_requests ();
183+
184+ try {
185+ bool encounter_battle = run_encounter (env, context);
186+ if (encounter_battle) {
187+ stats.shinies ++;
188+ env.update_stats ();
189+ send_program_notification (env, NOTIFICATION_SHINY, COLOR_YELLOW, " Shiny found!" , {}, " " , env.console .video ().snapshot (), true );
190+ break ;
191+ }
192+
193+ env.log (" No shiny found. Resetting game." );
194+ send_program_status_notification (
195+ env, NOTIFICATION_STATUS_UPDATE,
196+ " No shiny found. Resetting game."
197+ );
198+ context.wait_for_all_requests ();
199+ }catch (OperationFailedException& e){
200+ e.send_notification (env, NOTIFICATION_ERROR_RECOVERABLE);
201+ consecutive_failures++;
202+ continue ;
203+ }
204+ consecutive_failures = 0 ;
183205
184206 // Reset game
185207 pbf_press_button (context, BUTTON_HOME, 200ms, 2000ms);
186208 reset_game_from_home (env, env.console , context, 3000ms);
187209 context.wait_for_all_requests ();
188210
189211 stats.resets ++;
190- env.update_stats ();
191212 }
192213 // Shiny found, complete the battle
193214 WallClock start = current_time ();
0 commit comments