Skip to content

Commit 0123ffa

Browse files
committed
working reset sequence, adjust alolantrade timings
1 parent bc004d1 commit 0123ffa

File tree

6 files changed

+57
-34
lines changed

6 files changed

+57
-34
lines changed

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ void close_game(VideoStream& stream, JoyconContext& context){
8080
// regardless of whether the game is initially open or closed.
8181

8282
// if game initially open. | if game initially closed
83-
pbf_mash_button(context, BUTTON_X, 800ms); // - Close game. | - does nothing
83+
pbf_mash_button(context, BUTTON_X, 800ms); // - Close game. | - does nothing
8484
pbf_move_joystick(context, 128, 255, 100ms, 10ms); // - Does nothing. | - moves selector away from the closed game to avoid opening it.
8585
pbf_move_joystick(context, 128, 255, 100ms, 10ms); // - Does nothing. | - Press Down a second time in case we drop one.
86-
pbf_mash_button(context, BUTTON_A, 400ms); // - Confirm close game. | - opens an app on the home screen (e.g. Online)
86+
pbf_mash_button(context, BUTTON_A, 400ms); // - Confirm close game. | - opens an app on the home screen (e.g. Online)
8787
// - Does nothing. | - goes back to home screen.
8888
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
8989
context.wait_for_all_requests();

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ GameSettings::GameSettings()
2727
LockMode::LOCK_WHILE_RUNNING,
2828
"1000 ms"
2929
)
30-
, LOAD_REGION_TIMEOUT0(
31-
"<b>Load Region Timeout:</b><br>Wait at most this long to enter a region before giving up.",
32-
LockMode::LOCK_WHILE_RUNNING,
33-
"30 s"
34-
)
3530
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
3631
, START_GAME_MASH0(
3732
"<b>1. Start Game Mash:</b><br>Mash A for this long to start the game.",
@@ -41,15 +36,15 @@ GameSettings::GameSettings()
4136
, START_GAME_WAIT1(
4237
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
4338
LockMode::LOCK_WHILE_RUNNING,
44-
"40 s"
39+
"20 s"
4540
)
4641
, ENTER_GAME_MASH0(
4742
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
4843
LockMode::LOCK_WHILE_RUNNING,
49-
"5000 ms"
44+
"5 s"
5045
)
5146
, ENTER_GAME_WAIT0(
52-
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
47+
"<b>4. Enter Game Wait:</b><br>Wait this long for the opening animations to finish.",
5348
LockMode::LOCK_WHILE_RUNNING,
5449
"15 s"
5550
)
@@ -58,7 +53,6 @@ GameSettings::GameSettings()
5853

5954
PA_ADD_STATIC(m_menu_navigation);
6055
PA_ADD_OPTION(GAME_TO_HOME_DELAY0);
61-
PA_ADD_OPTION(LOAD_REGION_TIMEOUT0);
6256

6357
PA_ADD_STATIC(m_start_game_timings);
6458
PA_ADD_OPTION(START_GAME_MASH0);

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class GameSettings : public BatchOption{
2626

2727
SectionDividerOption m_menu_navigation;
2828
MillisecondsOption GAME_TO_HOME_DELAY0;
29-
MillisecondsOption LOAD_REGION_TIMEOUT0;
3029

3130
SectionDividerOption m_start_game_timings;
3231
MillisecondsOption START_GAME_MASH0;

SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1414
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.h"
1515
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
16+
#include "NintendoSwitch/Inference/NintendoSwitch_DetectHome.h"
1617
#include "PokemonLGPE/PokemonLGPE_Settings.h"
1718
#include "PokemonLGPE_GameEntry.h"
1819

@@ -34,6 +35,13 @@ bool reset_game_to_gamemenu(
3435
ConsoleSettings::instance().START_GAME_REQUIRES_INTERNET ||
3536
tolerate_update_menu
3637
){
38+
//Handle Right Joycon attempting to update
39+
//If no update, this will open the All Software menu
40+
//The active game will be closed from there
41+
//pbf_move_joystick(context, 0, 128, 100ms, 10ms);
42+
//pbf_move_joystick(context, 0, 128, 100ms, 10ms);
43+
//pbf_press_button(context, BUTTON_A, 100ms, 10ms);
44+
3745
close_game(stream, context);
3846
start_game_from_home(
3947
stream,
@@ -55,17 +63,47 @@ bool gamemenu_to_ingame(
5563
VideoStream& stream, JoyconContext& context,
5664
Milliseconds mash_duration, Milliseconds enter_game_timeout
5765
){
58-
stream.log("Mashing A to enter game...");
59-
BlackScreenOverWatcher detector(COLOR_RED, {0.2, 0.2, 0.6, 0.6});
66+
//Includes choosing the controller.
67+
//Controllers are disconnected? on selection screen so make sure to mash.
68+
stream.log("Mashing A to enter game and select controller...");
6069
pbf_mash_button(context, BUTTON_A, mash_duration);
6170
context.wait_for_all_requests();
71+
72+
//White screen, Pikachu/Eevee running across the screen.
73+
//Mash A at then end.
74+
BlackScreenOverWatcher detector(COLOR_RED, {0.2, 0.2, 0.6, 0.6});
6275
stream.log("Waiting to enter game...");
63-
int ret = wait_until(
76+
int ret = run_until<JoyconContext>(
6477
stream, context,
65-
std::chrono::milliseconds(enter_game_timeout * (1000 / TICKS_PER_SECOND)),
66-
{{detector}}
78+
[&enter_game_timeout](JoyconContext& context){
79+
pbf_wait(context, enter_game_timeout);
80+
pbf_press_button(context, BUTTON_A, 400ms, 10ms);
81+
pbf_wait(context, 5000ms);
82+
},
83+
{detector}
6784
);
85+
context.wait_for_all_requests();
6886
if (ret == 0){
87+
stream.log("At continue screen.");
88+
}else{
89+
stream.log("Timed out waiting to enter game and select continue.", COLOR_RED);
90+
return false;
91+
}
92+
pbf_wait(context, 1000ms);
93+
context.wait_for_all_requests();
94+
95+
//Continue your adventure.
96+
BlackScreenOverWatcher detector2(COLOR_YELLOW, {0.2, 0.2, 0.6, 0.6});
97+
int ret2 = run_until<JoyconContext>(
98+
stream, context,
99+
[](JoyconContext& context){
100+
pbf_press_button(context, BUTTON_A, 400ms, 10ms);
101+
pbf_wait(context, 5000ms);
102+
},
103+
{detector2}
104+
);
105+
context.wait_for_all_requests();
106+
if (ret2 == 0){
69107
stream.log("Entered game!");
70108
return true;
71109
}else{

SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool gamemenu_to_ingame(
3737
bool reset_game_from_home(
3838
ProgramEnvironment& env, VideoStream& stream, JoyconContext& context,
3939
bool tolerate_update_menu,
40-
uint16_t post_wait_time = 125
40+
Milliseconds post_wait_time = 125ms
4141
);
4242

4343

SerialPrograms/Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Pokemon/Pokemon_Strings.h"
1717
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
1818
#include "PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h"
19+
#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h"
1920
#include "PokemonLGPE_AlolanTrade.h"
2021

2122
namespace PokemonAutomation{
@@ -192,8 +193,8 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
192193
//Open menu, open party, open boxes
193194
env.log("Opening boxes.");
194195
pbf_press_button(context, BUTTON_X, 200ms, 500ms);
195-
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
196-
pbf_press_button(context, BUTTON_Y, 200ms, 1500ms);
196+
pbf_press_button(context, BUTTON_A, 200ms, 1500ms);
197+
pbf_press_button(context, BUTTON_Y, 200ms, 2000ms);
197198
context.wait_for_all_requests();
198199

199200
//Sort by order caught
@@ -240,31 +241,22 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
240241
pbf_press_button(context, BUTTON_X, 0ms, 1000ms);
241242
context.wait_for_all_requests();
242243
}
243-
/*
244+
244245
if (!shiny_found) {
245246
env.log("Out of Pokemon to trade and no shiny found. Resetting game.");
246247
send_program_status_notification(
247248
env, NOTIFICATION_STATUS_UPDATE,
248249
"Out of Pokemon to trade and no shiny found. Resetting game."
249250
);
250251

251-
//TODO: Need to make proper GameEntry eventually
252-
//Thankfully, Joycon is upright after going to home.
253-
//Go to home and close game
254-
pbf_press_button(context, BUTTON_HOME, 200ms, 3000ms);
255-
pbf_press_button(context, BUTTON_X, 200ms, 200ms);
256-
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
257-
258-
//TODO:
259-
//joycon context->pro controller context?
260-
start_game_from_home(env.console, context, true, 0, 0, std::chrono::milliseconds(2000));
252+
//Reset game
253+
pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms);
254+
reset_game_from_home(env, env.console, context, true, 3000ms);
255+
context.wait_for_all_requests();
261256

262257
stats.resets++;
263258
env.update_stats();
264259
}
265-
*/
266-
//Break for now since resetting the game doesn't work.
267-
//break;
268260
}
269261

270262
if (GO_HOME_WHEN_DONE) {

0 commit comments

Comments
 (0)