@@ -59,8 +59,8 @@ std::unique_ptr<StatsTracker> AlolanTrade_Descriptor::make_stats() const{
5959AlolanTrade::AlolanTrade ()
6060 : NUM_TRADES(
6161 " <b>Number of Pokemon to trade:</b>" ,
62- LockMode::UNLOCK_WHILE_RUNNING ,
63- 30
62+ LockMode::LOCK_WHILE_RUNNING ,
63+ 30 , 1
6464 )
6565 , GO_HOME_WHEN_DONE(false )
6666 , NOTIFICATION_SHINY(
@@ -76,7 +76,7 @@ AlolanTrade::AlolanTrade()
7676 })
7777{
7878 PA_ADD_OPTION (NUM_TRADES);
79- // PA_ADD_OPTION(GO_HOME_WHEN_DONE);
79+ PA_ADD_OPTION (GO_HOME_WHEN_DONE);
8080 PA_ADD_OPTION (NOTIFICATIONS);
8181}
8282
@@ -89,12 +89,13 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
8989 WARNING: JOYCON TEST PROGRAM. Not well tested. Minimum infra to get this running. Bare minimum in general.
9090 Use at your own risk, it won't skip update checks and the like.
9191 FLASH RIGHT JOYCON. YOU NEED RIGHT JOYCON. YOU NEED THE HOME BUTTON. (this means no on-switch screenshots)
92- Also don't remap any of the buttons in the switch button mapping settings. Yet?
92+ Also don't remap any of the buttons in the switch button mapping settings. Yet? Could use this to add Home and Screenshot.
9393
9494 Preconditions:
9595 DO NOT have any Pokemon you want to keep in your boxes. Move them out to Home first.
9696 Favoriting a Pokemon does not prevent it from being traded.
9797 This must not be your first time doing the trade. (I've done all the trades, can't check first time trade behavior.)
98+ In your boxes, sort by ORDER CAUGHT
9899
99100 Setup:
100101 Catch the Kanto variant of the target.
@@ -111,26 +112,6 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
111112 get rid of all this blindly mashing A in general...so need everything really.
112113 */
113114
114- // to check pokemon in menu boxes - not used
115- // Open menu - always defaults to center (Party)
116- /* Menu:
117- Play with Partner
118- Pokedex - Bag - Party - Communicate - Save
119- (Press Y for options)
120-
121- sort boxes by recently caught and press left to get to most recent pokemon
122- */
123-
124- /*
125- pbf_press_button(context, BUTTON_A, 200ms, 2000ms);
126- pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms);
127- pbf_move_joystick(context, 128, 0, 100ms, 100ms);
128- pbf_move_joystick(context, 128, 0, 100ms, 100ms);
129- pbf_move_joystick(context, 255, 128, 100ms, 100ms);
130- pbf_move_joystick(context, 128, 0, 100ms, 100ms);
131- pbf_press_button(context, BUTTON_X, 200ms, 2000ms);
132- */
133-
134115 bool shiny_found = false ;
135116 while (!shiny_found) {
136117 // Run trades
@@ -160,7 +141,7 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
160141 }
161142
162143 // Wait for trade to complete.
163- BlackScreenOverWatcher trade_completed (COLOR_RED );
144+ BlackScreenOverWatcher trade_completed (COLOR_YELLOW );
164145 int ret2 = wait_until (
165146 env.console , context,
166147 std::chrono::seconds (120 ),
@@ -179,36 +160,104 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
179160 env.log (" Trade completed." );
180161 }
181162
182- // After black screen fade is done, a summary will appear.
183- // pbf_wait(context, 250);
163+ // Summary will appear the first time you trade in a session(?) Close that as well.
164+ // Exit menu and dialog.
165+ pbf_mash_button (context, BUTTON_B, 3000ms);
184166 context.wait_for_all_requests ();
185167
168+ stats.trades ++;
169+ env.update_stats ();
170+ }
171+
172+ // to check pokemon in menu boxes
173+ // Open menu - always defaults to center (Party)
174+ /* Menu:
175+ Play with Partner
176+ Pokedex - Bag - Party - Communicate - Save (these all have a colored line under when selected)
177+ (Press Y for options)
178+
179+ sort boxes by recently caught and press left to get to most recent pokemon
180+ */
181+
182+ // Wait a bit.
183+ pbf_press_button (context, BUTTON_X, 0ms, 2500ms);
184+ context.wait_for_all_requests ();
185+
186+ // Open menu, open party, open boxes
187+ env.log (" Opening boxes." );
188+ pbf_press_button (context, BUTTON_X, 200ms, 500ms);
189+ pbf_press_button (context, BUTTON_A, 200ms, 1000ms);
190+ pbf_press_button (context, BUTTON_Y, 200ms, 1500ms);
191+ context.wait_for_all_requests ();
192+
193+ // Sort by order caught
194+ env.log (" Sorting by order caught." );
195+ pbf_press_button (context, BUTTON_Y, 200ms, 1000ms);
196+ pbf_press_button (context, BUTTON_A, 200ms, 1000ms);
197+ pbf_press_button (context, BUTTON_A, 200ms, 1000ms);
198+ context.wait_for_all_requests ();
199+
200+ // Press left to go to last (most recent) Pokemon
201+ env.log (" Opening summary of most recent Pokemon." );
202+ pbf_move_joystick (context, 0 , 128 , 100ms, 100ms);
203+ context.wait_for_all_requests ();
204+
205+ // View summary - it takes a moment to load, wait is below
206+ pbf_press_button (context, BUTTON_A, 200ms, 1000ms);
207+ pbf_move_joystick (context, 128 , 255 , 100ms, 100ms);
208+ pbf_move_joystick (context, 128 , 255 , 100ms, 100ms);
209+ pbf_press_button (context, BUTTON_A, 200ms, 100ms);
210+ context.wait_for_all_requests ();
211+
212+ // Wait.
213+ pbf_press_button (context, BUTTON_X, 0ms, 5000ms);
214+ context.wait_for_all_requests ();
215+
216+ // Now check for shinies. Check everything that was traded.
217+ for (uint16_t i = 0 ; i < NUM_TRADES; i++) {
186218 VideoSnapshot screen = env.console .video ().snapshot ();
187219 ShinySymbolDetector shiny_checker (COLOR_YELLOW);
188- shiny_found = shiny_checker.read (env.console .logger (), screen);
220+ bool check = shiny_checker.read (env.console .logger (), screen);
189221
190- if (shiny_found ) {
222+ if (check ) {
191223 env.log (" Shiny detected!" );
192224 stats.shinies ++;
225+ env.update_stats ();
193226 send_program_status_notification (env, NOTIFICATION_SHINY, " Shiny found!" , screen, true );
194- break ;
227+ shiny_found = true ;
195228 }
196229 else {
197230 env.log (" Not shiny." );
198- stats.trades ++;
199231 }
232+
233+ // Move left, check next.
234+ pbf_move_joystick (context, 0 , 128 , 100ms, 100ms);
235+ pbf_press_button (context, BUTTON_X, 0ms, 2000ms);
236+ context.wait_for_all_requests ();
200237 }
201238
202239 if (!shiny_found) {
203- // Go to home, reset game
204- // How to handle sideways joycons vs in-game? What if a set is paired?
205- // Set as-is for now - I only have one ESP32, don't know how we're handling multiple joycons w/our usual home functions
240+ // TODO? Check if home button even exists before attempting to reset.
241+ // This way, if on left joycon, stop the program and alert the user.
206242
207243 env.log (" Out of Pokemon to trade. Resetting game." );
208244 send_program_status_notification (
209245 env, NOTIFICATION_STATUS_UPDATE,
210246 " Out of Pokemon to trade. Resetting game."
211247 );
248+
249+ // TODO: Need to make proper GameEntry eventually
250+ // Thankfully, Joycon is upright after going to home.
251+ // Go to home and close game
252+ pbf_press_button (context, BUTTON_HOME, 200ms, 3000ms);
253+ pbf_press_button (context, BUTTON_X, 200ms, 1000ms);
254+ pbf_press_button (context, BUTTON_A, 200ms, 1000ms);
255+
256+ // Enter game from home
257+ // break;
258+
259+ stats.resets ++;
260+ env.update_stats ();
212261 }
213262 }
214263
0 commit comments