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 @@ -58,6 +58,7 @@ ClaimMysteryGift_Descriptor::ClaimMysteryGift_Descriptor()


ClaimMysteryGift::~ClaimMysteryGift(){
OBTAINING_METHOD.remove_listener(*this);
STARTING_POINT.remove_listener(*this);
}

Expand All @@ -72,17 +73,28 @@ ClaimMysteryGift::ClaimMysteryGift()
"<b>Starting point:",
{
{StartingPoint::NEW_GAME, "new-game", "New Game: Start after you have selected your username and character appearance"},
{StartingPoint::IN_MYSTERY_GIFT, "in-mystery-gift", "Start in Mystery Gift window, with cursor on the “1” key."},
{StartingPoint::DONE_TUTORIAL, "done-tutorial", "Start in game. But with all menus closed. Tutorial must be completed. You need to be outside, where you can use Pokeportal."},
{StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW, "in-mystery-gift-code-window", "Start in Mystery Gift code window, with cursor on the “1” key."},
{StartingPoint::DONE_TUTORIAL, "done-tutorial", "Start in game. Tutorial must be completed. All menus closed. Disconnected from internet. You need to be outside, where you can use Pokeportal."},
},
LockMode::LOCK_WHILE_RUNNING,
StartingPoint::NEW_GAME
)
, OBTAINING_METHOD(
"<b>Method for obtaining mystery gift:",
{
// {ObtainingMethod::VIA_INTERNET_ALL, "via-internet-all", "Via Internet: Get all mystery gifts from the \"Get via Internet\" screen (except for the Mythical Pecha Berry)."},
{ObtainingMethod::VIA_INTERNET_NONE, "via-internet-one", "Via Internet: Go to the Mystery Gift \"Get via Internet\" screen. Don't claim anything."},
{ObtainingMethod::VIA_CODE, "via-code", "Via Code: Get the mystery gift based on the code entered below."},
},
LockMode::LOCK_WHILE_RUNNING,
ObtainingMethod::VIA_INTERNET_NONE
)
, MYSTERY_GIFT_NOTE{
"Ensure you are logged into a Nintendo account. This account does NOT need to have a subscription to Nintendo Switch Online.<br>"
"In the keyboard section below, you only need to adjust the option for Swtich 0. Ignore the options for the other Switches.<br>"
"Refer to the documentation on github for more details."
"Ensure you are logged into a Nintendo account. This account does NOT need to have a subscription to Nintendo Switch Online."
}
, MULTISWITCH_NOTE{
"In the keyboard section below, you only need to adjust the option for Swtich 0. Ignore the options for the other Switches."
}
, CODE(
"<b>Mystery Gift Code:</b><br>Mystery Gift code. (not case sensitive)<br>"
"(Box is big so it's easy to land your mouse on.)",
Expand All @@ -101,8 +113,10 @@ ClaimMysteryGift::ClaimMysteryGift()
{

PA_ADD_OPTION(LANGUAGE);
PA_ADD_OPTION(STARTING_POINT);
PA_ADD_OPTION(MYSTERY_GIFT_NOTE);
PA_ADD_OPTION(STARTING_POINT);
PA_ADD_OPTION(OBTAINING_METHOD);
PA_ADD_OPTION(MULTISWITCH_NOTE);
PA_ADD_OPTION(CODE);
PA_ADD_OPTION(SETTINGS);
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
Expand All @@ -111,12 +125,28 @@ ClaimMysteryGift::ClaimMysteryGift()

ClaimMysteryGift::on_config_value_changed(this);

OBTAINING_METHOD.add_listener(*this);
STARTING_POINT.add_listener(*this);
}

void ClaimMysteryGift::on_config_value_changed(void* object){
if (STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW){
OBTAINING_METHOD.set_visibility(ConfigOptionState::HIDDEN);
}else{
OBTAINING_METHOD.set_visibility(ConfigOptionState::ENABLED);
}


if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
MULTISWITCH_NOTE.set_visibility(ConfigOptionState::ENABLED);
CODE.set_visibility(ConfigOptionState::ENABLED);
SETTINGS.set_visibility(ConfigOptionState::ENABLED);
}else{
MULTISWITCH_NOTE.set_visibility(ConfigOptionState::HIDDEN);
CODE.set_visibility(ConfigOptionState::HIDDEN);
SETTINGS.set_visibility(ConfigOptionState::HIDDEN);
}

}

void ClaimMysteryGift::enter_mystery_gift_code(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
Expand All @@ -138,7 +168,109 @@ void ClaimMysteryGift::enter_mystery_gift_code(SingleSwitchProgramEnvironment& e

}

void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
void ClaimMysteryGift::enter_mystery_gift_via_internet_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
env.console.log("Save game, then try to enter the mystery gift via internet window.", COLOR_YELLOW);
save_game_from_menu_or_overworld(env.program_info(), env.console, context, false);

size_t max_attempts = 5;
for (size_t i = 0; i < max_attempts; i++){
enter_menu_from_overworld(env.program_info(), env.console, context, menu_index);
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
pbf_press_dpad(context, DPAD_UP, 20, 105);
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
try {
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG});
}catch(OperationFailedException&){
env.console.log("enter_mystery_gift_via_internet_window: Failed to detect the dialog that leads to the Mystery Gift code window. Reset game and re-try.", COLOR_YELLOW);
reset_game(env.program_info(), env.console, context);
continue;
}

return;
}

OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"enter_mystery_gift_code_window(): Failed to reach Mystery Gift code window after several attempts.",
env.console
);
}


// void ClaimMysteryGift::claim_internet_mystery_gift(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
// env.log("Claim Mystery Gifts via Internet.");
// context.wait_for_all_requests();
// ImageFloatBox box{0.256326, 0.099804, 0.044004, 0.616438};
// GradientArrowWatcher arrow(COLOR_RED, GradientArrowType::RIGHT, box);
// int ret = wait_until(
// env.console, context,
// Milliseconds(10 * 1000),
// { arrow }
// );
// if (ret == 0){
// env.console.log("Gradient arrow detected.");
// }else{
// OperationFailedException::fire(
// ErrorReport::SEND_ERROR_REPORT,
// "Failed to detect gradient arrow. We might not be in the Mystery Gift via Internet screen.",
// env.console
// );
// }

// std::vector<double> y_position_seen;
// // determine how many mystery gifts are available to claim
// while(true){
// context.wait_for_all_requests();
// ImageFloatBox result_box;
// arrow.detect(result_box, console.video().snapshot());
// double current_y_pos = result_box.y;
// bool seen = false;
// for (double y_pos : y_position_seen){
// // if difference is less than 0.02, then it's the same
// if (std::abs(current_y_pos - y_pos) < 0.02){
// seen = true;
// break;
// }
// }
// if (!seen){
// y_position_seen.emplace_back(current_y_pos);
// }else{
// pbf_press_dpad(context, DPAD_DOWN, 160ms, 320ms);
// }
// }

// while(true){
// context.wait_for_all_requests();
// ImageFloatBox result_box;
// arrow.detect(result_box, console.video().snapshot());
// double y_pos = result_box.y;

// pbf_press_dpad(context, DPAD_DOWN, 160ms, 320ms);
// // collect the mystery gift. Press A until you see the Gradient arrow again.
// ret = run_until<ProControllerContext>(
// env.console, context,
// [&](ProControllerContext& context){
// for (size_t i = 0; i < 40; i++){
// pbf_press_button(context, BUTTON_A, 160ms, 1000ms);
// }
// },
// arrow
// );
// if (ret < 0){
// OperationFailedException::fire(
// ErrorReport::SEND_ERROR_REPORT,
// "Failed to detect gradient arrow. We might not be in the Mystery Gift via Internet screen.",
// env.console
// );
// }

// }


// }

void ClaimMysteryGift::enter_mystery_gift_code_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
env.console.log("Save game, then try to enter the mystery gift window.", COLOR_YELLOW);
save_game_from_menu_or_overworld(env.program_info(), env.console, context, false);

Expand All @@ -154,7 +286,7 @@ void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment&
try {
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG});
}catch(OperationFailedException&){
env.console.log("enter_mystery_gift_window: Failed to detect the dialog that leads to the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW);
env.console.log("enter_mystery_gift_code_window: Failed to detect the dialog that leads to the Mystery Gift code window. Reset game and re-try.", COLOR_YELLOW);
reset_game(env.program_info(), env.console, context);
continue;
}
Expand Down Expand Up @@ -199,7 +331,7 @@ void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment&
{key1_selected}
);
if (ret < 0){ // failed to detect Key 1 being highlighted. Reset game and re-try
env.console.log("enter_mystery_gift_window: Failed to detect the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW);
env.console.log("enter_mystery_gift_code_window: Failed to detect the Mystery Gift code window. Reset game and re-try.", COLOR_YELLOW);
reset_game(env.program_info(), env.console, context);
continue;
}
Expand All @@ -210,7 +342,7 @@ void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment&

OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"enter_mystery_gift_window(): Failed to reach Mystery Gift screen after several attempts.",
"enter_mystery_gift_code_window(): Failed to reach Mystery Gift code window after several attempts.",
env.console
);
}
Expand Down Expand Up @@ -241,13 +373,34 @@ void ClaimMysteryGift::program(SingleSwitchProgramEnvironment& env, ProControlle
if (STARTING_POINT == StartingPoint::NEW_GAME){
run_autostory_until_pokeportal_unlocked(env, context);
env.console.log("Done Autostory portion. Pokeportal should now be unlocked.");
enter_mystery_gift_window(env, context, 2);
enter_mystery_gift_code(env, context);
}else if(STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT){
if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
enter_mystery_gift_code_window(env, context, 2);
enter_mystery_gift_code(env, context);
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ALL){
// enter_mystery_gift_via_internet_window(env, context, 2);
// claim_internet_mystery_gift(env, context);

}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_NONE){
enter_mystery_gift_via_internet_window(env, context, 2);

}

}else if(STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW){
// only claim the mystery gift via code. not via internet
enter_mystery_gift_code(env, context);

}else if (STARTING_POINT == StartingPoint::DONE_TUTORIAL){
enter_mystery_gift_window(env, context, 3);
enter_mystery_gift_code(env, context);

if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
enter_mystery_gift_code_window(env, context, 3);
enter_mystery_gift_code(env, context);
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ALL){
// enter_mystery_gift_via_internet_window(env, context, 3);

}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_NONE){
enter_mystery_gift_via_internet_window(env, context, 3);

}
}else{
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown STARTING_POINT.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class ClaimMysteryGift : public SingleSwitchProgramInstance, public ConfigOption
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;

void run_autostory_until_pokeportal_unlocked(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
void enter_mystery_gift_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
void enter_mystery_gift_via_internet_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
void claim_internet_mystery_gift(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
void enter_mystery_gift_code_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
void enter_mystery_gift_code(SingleSwitchProgramEnvironment& env, ProControllerContext& context);

private:
Expand All @@ -54,12 +56,20 @@ class ClaimMysteryGift : public SingleSwitchProgramInstance, public ConfigOption

enum class StartingPoint{
NEW_GAME,
IN_MYSTERY_GIFT,
IN_MYSTERY_GIFT_CODE_WINDOW,
DONE_TUTORIAL,
};

enum class ObtainingMethod{
VIA_INTERNET_ALL,
VIA_INTERNET_NONE,
VIA_CODE,
};

EnumDropdownOption<StartingPoint> STARTING_POINT;
EnumDropdownOption<ObtainingMethod> OBTAINING_METHOD;
StaticTextOption MYSTERY_GIFT_NOTE;
StaticTextOption MULTISWITCH_NOTE;
TextEditOption CODE;
FastCodeEntrySettingsOption SETTINGS;

Expand Down