Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ AutoStory::AutoStory()
}

void AutoStory::on_config_value_changed(void* object){
ConfigOptionState state = (STARTPOINT_TUTORIAL.index() <= 1)
ConfigOptionState state = (STARTPOINT_TUTORIAL.index() <= 1 && STORY_SECTION == StorySection::TUTORIAL)
? ConfigOptionState::ENABLED
: ConfigOptionState::HIDDEN;
STARTERCHOICE.set_visibility(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,52 +556,47 @@ void config_option(ProControllerContext& context, int change_option_value){
pbf_press_dpad(context, DPAD_DOWN, 15, 20);
}

void swap_starter_moves(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, Language language){
WallClock start = current_time();
while (true){
if (current_time() - start > std::chrono::minutes(3)){
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"swap_starter_moves(): Failed to swap the starter moves after 3 minutes.",
stream
);
}
// start in the overworld
press_Bs_to_back_to_overworld(info, stream, context);

// open menu, select your starter
enter_menu_from_overworld(info, stream, context, 0, MenuSide::LEFT);
void swap_starter_moves(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Language language){
const ProgramInfo& info = env.program_info();
VideoStream& stream = env.console;

// enter Pokemon summary screen
pbf_press_button(context, BUTTON_A, 20, 5 * TICKS_PER_SECOND);
pbf_press_dpad(context, DPAD_RIGHT, 15, 1 * TICKS_PER_SECOND);
pbf_press_button(context, BUTTON_Y, 20, 40);
// start in the overworld
press_Bs_to_back_to_overworld(info, stream, context);

// select move 1
pbf_press_button(context, BUTTON_A, 20, 40);
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
// extra button presses to avoid drops
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
// open menu, select your starter
enter_menu_from_overworld(info, stream, context, 0, MenuSide::LEFT);

// select move 3. swap move 1 and move 3.
pbf_press_button(context, BUTTON_A, 20, 40);
// enter Pokemon summary screen
pbf_press_button(context, BUTTON_A, 20, 5 * TICKS_PER_SECOND);
pbf_press_dpad(context, DPAD_RIGHT, 15, 1 * TICKS_PER_SECOND);
pbf_press_button(context, BUTTON_Y, 20, 40);

// confirm that Ember/Leafage/Water Gun is in slot 1
context.wait_for_all_requests();
VideoSnapshot screen = stream.video().snapshot();
PokemonMovesReader reader(language);
std::string top_move = reader.read_move(stream.logger(), screen, 0);
stream.log("Current top move: " + top_move);
if (top_move != "ember" && top_move != "leafage" && top_move != "water-gun"){
stream.log("Failed to swap moves. Re-try.");
continue;
}
// select move 1
pbf_press_button(context, BUTTON_A, 20, 40);
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
// extra button presses to avoid drops
pbf_press_dpad(context, DPAD_DOWN, 15, 40);
pbf_press_dpad(context, DPAD_DOWN, 15, 40);

// select move 3. swap move 1 and move 3.
pbf_press_button(context, BUTTON_A, 20, 40);

break;
}
// confirm that Ember/Leafage/Water Gun is in slot 1
context.wait_for_all_requests();
VideoSnapshot screen = stream.video().snapshot();
PokemonMovesReader reader(language);
std::string top_move = reader.read_move(stream.logger(), screen, 0);
stream.log("Current top move: " + top_move);
if (top_move != "ember" && top_move != "leafage" && top_move != "water-gun"){
stream.log("Failed to swap moves.");
OperationFailedException exception(
ErrorReport::SEND_ERROR_REPORT,
"swap_starter_moves: Failed to swap moves.\n" + language_warning(language),
stream
);
exception.send_recoverable_notification(env);
}

}

Expand Down Expand Up @@ -1220,6 +1215,85 @@ void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProController

}

void checkpoint_reattempt_loop(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context,
EventNotificationOption& notif_status_update,
AutoStoryStats& stats,
std::function<void(size_t attempt_number)>&& action
){
size_t max_attempts = 100;
for (size_t i = 0;;i++){
try{
if (i==0){
checkpoint_save(env, context, notif_status_update, stats);
}

context.wait_for_all_requests();
action(i);

break;
}catch(OperationFailedException& e){
if (i > max_attempts){
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"Autostory checkpoint failed " + std::to_string(max_attempts) + " times.\n"
"Make sure you selected the correct Start Point, and your character is in the exactly correct starting position."
"Also, make sure you have set the correct Language.\n" + e.message(),
env.console
);
}
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}

}

void checkpoint_reattempt_loop_tutorial(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context,
EventNotificationOption& notif_status_update,
AutoStoryStats& stats,
std::function<void(size_t attempt_number)>&& action
){
size_t max_attempts = 100;
for (size_t i = 0;;i++){
try{
if(i==0){
save_game_tutorial(env.program_info(), env.console, context);
stats.m_checkpoint++;
env.update_stats();
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
}

context.wait_for_all_requests();
action(i);

break;
}catch(OperationFailedException& e){
if (i > max_attempts){
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"Autostory checkpoint failed " + std::to_string(max_attempts) + " times.\n"
"Make sure you selected the correct Start Point, and your character is in the exactly correct starting position."
"Also, make sure you have set the correct Language.\n" + e.message(),
env.console
);
}
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}
}




}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void overworld_navigation(const ProgramInfo& info, VideoStream& stream, ProContr
void config_option(ProControllerContext& context, int change_option_value);

// enter menu and swap the first and third moves for your starter
void swap_starter_moves(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, Language language);
void swap_starter_moves(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Language language);

// run the given `action`. if detect a battle, stop the action, and throw exception
void do_action_and_monitor_for_battles(
Expand Down Expand Up @@ -337,6 +337,27 @@ void move_cursor_towards_flypoint_and_go_there(

void check_num_sunflora_found(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int expected_number);

// run given action, with max_attempts number of attempts
// save prior to first attempt
// throw exception if we try to exceed max_attempts.
void checkpoint_reattempt_loop(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context,
EventNotificationOption& notif_status_update,
AutoStoryStats& stats,
std::function<void(size_t attempt_number)>&& action
);

void checkpoint_reattempt_loop_tutorial(
SingleSwitchProgramEnvironment& env,
ProControllerContext& context,
EventNotificationOption& notif_status_update,
AutoStoryStats& stats,
std::function<void(size_t attempt_number)>&& action
);



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,17 @@ void checkpoint_01(
AutoStoryStats& stats,
Language language
){
bool first_attempt = true;
while (true){
try{
if(first_attempt){
save_game_tutorial(env.program_info(), env.console, context);
stats.m_checkpoint++;
env.update_stats();
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
}
checkpoint_reattempt_loop_tutorial(env, context, notif_status_update, stats,
[&](size_t attempt_number){

context.wait_for_all_requests();
// set settings
enter_menu_from_overworld(env.program_info(), env.console, context, 0, MenuSide::RIGHT, false);
change_settings(env, context, language, first_attempt);
change_settings(env, context, language, attempt_number==0);
pbf_mash_button(context, BUTTON_B, 2 * TICKS_PER_SECOND);
context.wait_for_all_requests();

break;
}catch(OperationFailedException&){
// (void)e;
first_attempt = false;
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}
});
}

void checkpoint_02(
Expand All @@ -111,16 +94,8 @@ void checkpoint_02(
EventNotificationOption& notif_status_update,
AutoStoryStats& stats
){
bool first_attempt = true;
while (true){
try{
if(first_attempt){
save_game_tutorial(env.program_info(), env.console, context);
stats.m_checkpoint++;
env.update_stats();
send_program_status_notification(env, notif_status_update, "Saved at checkpoint.");
first_attempt = false;
}
checkpoint_reattempt_loop_tutorial(env, context, notif_status_update, stats,
[&](size_t attempt_number){

context.wait_for_all_requests();
env.console.log("Go downstairs, get stopped by Skwovet");
Expand Down Expand Up @@ -184,15 +159,7 @@ void checkpoint_02(
open_map_from_overworld(env.program_info(), env.console, context, true);
leave_phone_to_overworld(env.program_info(), env.console, context);

break;
}catch(OperationFailedException&){
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}
});
}

void checkpoint_03(
Expand All @@ -203,13 +170,8 @@ void checkpoint_03(
Language language,
StarterChoice starter_choice
){
bool first_attempt = true;
while (true){
try{
if (first_attempt){
checkpoint_save(env, context, notif_status_update, stats);
first_attempt = false;
}
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
[&](size_t attempt_number){

context.wait_for_all_requests();
DirectionDetector direction;
Expand Down Expand Up @@ -274,19 +236,12 @@ void checkpoint_03(
clear_tutorial(env.console, context);

env.console.log("Change move order.");
swap_starter_moves(env.program_info(), env.console, context, language);
leave_box_system_to_overworld(env.program_info(), env.console, context);
swap_starter_moves(env, context, language);
press_Bs_to_back_to_overworld(env.program_info(), env.console, context);

break;
}catch(OperationFailedException&){
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}

);

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,8 @@ void checkpoint_04(
EventNotificationOption& notif_status_update,
AutoStoryStats& stats
){
bool first_attempt = true;
while (true){
try{
if (first_attempt){
checkpoint_save(env, context, notif_status_update, stats);
first_attempt = false;
}
checkpoint_reattempt_loop(env, context, notif_status_update, stats,
[&](size_t attempt_number){
context.wait_for_all_requests();

DirectionDetector direction;
Expand All @@ -92,15 +87,8 @@ void checkpoint_04(
context.wait_for_all_requests();
env.console.log("Finished battle.");

break;
}catch(OperationFailedException&){
context.wait_for_all_requests();
env.console.log("Resetting from checkpoint.");
reset_game(env.program_info(), env.console, context);
stats.m_reset++;
env.update_stats();
}
}
);

}

Expand Down
Loading