@@ -81,13 +81,13 @@ LegendaryReset::LegendaryReset()
8181 PA_ADD_OPTION (NOTIFICATIONS);
8282}
8383
84- bool LegendaryReset::run_battle (SingleSwitchProgramEnvironment& env, JoyconContext& context){
84+ bool LegendaryReset::run_encounter (SingleSwitchProgramEnvironment& env, JoyconContext& context){
8585 float shiny_coefficient = 1.0 ;
8686 ShinySoundDetector shiny_detector (env.logger (), [&](float error_coefficient) -> bool {
8787 shiny_coefficient = error_coefficient;
8888 return true ;
8989 });
90- BattleArrowWatcher battle_started (COLOR_YELLOW);
90+ BattleArrowWatcher battle_started (COLOR_YELLOW, { 0.546 , 0.863 , 0.045 , 0.068 } );
9191
9292 env.log (" Starting battle." );
9393 switch (TARGET) {
@@ -146,14 +146,15 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableSco
146146
147147 Settings:
148148 Text Speed fast
149- Skip cutscene option?
149+ Skip cutscene On
150+ Skip move animation On
150151
151152 Mewtwo, Articuno, Zapdos, Moltres, Snorlax, Electrode(?)
152153 Don't do it on the first Snorlax, otherwise have to sit through fuji tutorial
153154 */
154155
155156 while (true ) {
156- bool encounter_battle = run_battle (env, context);
157+ bool encounter_battle = run_encounter (env, context);
157158 if (encounter_battle) {
158159 stats.shinies ++;
159160 env.update_stats ();
@@ -174,6 +175,59 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableSco
174175 stats.resets ++;
175176 env.update_stats ();
176177 }
178+ // Shiny found, complete the battle
179+ WallClock start = current_time ();
180+ BattleArrowWatcher catching_started (COLOR_RED, {0.005 , 0.662 , 0.049 , 0.069 });
181+ int res = run_until<JoyconContext>(
182+ env.console , context,
183+ [&](JoyconContext& context) {
184+ while (true ){
185+ if (current_time () - start > std::chrono::minutes (5 )){
186+ env.log (" Timed out during battle after 5 minutes." , COLOR_RED);
187+ OperationFailedException::fire (
188+ ErrorReport::SEND_ERROR_REPORT,
189+ " Timed out during battle after 5 minutes." ,
190+ env.console
191+ );
192+ }
193+ BattleArrowWatcher battle_menu (COLOR_YELLOW, {0.546 , 0.863 , 0.045 , 0.068 });
194+ context.wait_for_all_requests ();
195+
196+ int ret = wait_until (
197+ env.console , context,
198+ std::chrono::seconds (30 ),
199+ { battle_menu }
200+ );
201+ switch (ret){
202+ case 0 :
203+ env.log (" Detected battle menu. Mashing A to attack." );
204+ pbf_mash_button (context, BUTTON_A, 3000ms);
205+ context.wait_for_all_requests ();
206+ break ;
207+ default :
208+ env.log (" Timed out during battle. Stuck, crashed, or took more than 30 seconds for a turn." , COLOR_RED);
209+ OperationFailedException::fire (
210+ ErrorReport::SEND_ERROR_REPORT,
211+ " Timed out during battle. Stuck, crashed, or took more than 30 seconds for a turn." ,
212+ env.console
213+ );
214+ }
215+ }
216+ },
217+ {{catching_started}}
218+ );
219+ switch (res){
220+ case 0 :
221+ env.log (" Catching menu detected." );
222+ break ;
223+ default :
224+ OperationFailedException::fire (
225+ ErrorReport::SEND_ERROR_REPORT,
226+ " Failed to detect catching menu." ,
227+ env.console
228+ );
229+ break ;
230+ }
177231
178232 if (GO_HOME_WHEN_DONE) {
179233 pbf_press_button (context, BUTTON_HOME, 200ms, 1000ms);
0 commit comments