Skip to content

Commit 56199c6

Browse files
authored
Claim Mystery Gift via Internet (#668)
* MysteryGift: add option for OBTAINING_METHOD. e.g. via Code vs via Internet * claim mystery gift via Internet
1 parent ec31863 commit 56199c6

File tree

2 files changed

+180
-17
lines changed

2 files changed

+180
-17
lines changed

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.cpp

Lines changed: 168 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ ClaimMysteryGift_Descriptor::ClaimMysteryGift_Descriptor()
5858

5959

6060
ClaimMysteryGift::~ClaimMysteryGift(){
61+
OBTAINING_METHOD.remove_listener(*this);
6162
STARTING_POINT.remove_listener(*this);
6263
}
6364

@@ -72,17 +73,28 @@ ClaimMysteryGift::ClaimMysteryGift()
7273
"<b>Starting point:",
7374
{
7475
{StartingPoint::NEW_GAME, "new-game", "New Game: Start after you have selected your username and character appearance"},
75-
{StartingPoint::IN_MYSTERY_GIFT, "in-mystery-gift", "Start in Mystery Gift window, with cursor on the “1” key."},
76-
{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."},
76+
{StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW, "in-mystery-gift-code-window", "Start in Mystery Gift code window, with cursor on the “1” key."},
77+
{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."},
7778
},
7879
LockMode::LOCK_WHILE_RUNNING,
7980
StartingPoint::NEW_GAME
8081
)
82+
, OBTAINING_METHOD(
83+
"<b>Method for obtaining mystery gift:",
84+
{
85+
// {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)."},
86+
{ObtainingMethod::VIA_INTERNET_NONE, "via-internet-one", "Via Internet: Go to the Mystery Gift \"Get via Internet\" screen. Don't claim anything."},
87+
{ObtainingMethod::VIA_CODE, "via-code", "Via Code: Get the mystery gift based on the code entered below."},
88+
},
89+
LockMode::LOCK_WHILE_RUNNING,
90+
ObtainingMethod::VIA_INTERNET_NONE
91+
)
8192
, MYSTERY_GIFT_NOTE{
82-
"Ensure you are logged into a Nintendo account. This account does NOT need to have a subscription to Nintendo Switch Online.<br>"
83-
"In the keyboard section below, you only need to adjust the option for Swtich 0. Ignore the options for the other Switches.<br>"
84-
"Refer to the documentation on github for more details."
93+
"Ensure you are logged into a Nintendo account. This account does NOT need to have a subscription to Nintendo Switch Online."
8594
}
95+
, MULTISWITCH_NOTE{
96+
"In the keyboard section below, you only need to adjust the option for Swtich 0. Ignore the options for the other Switches."
97+
}
8698
, CODE(
8799
"<b>Mystery Gift Code:</b><br>Mystery Gift code. (not case sensitive)<br>"
88100
"(Box is big so it's easy to land your mouse on.)",
@@ -101,8 +113,10 @@ ClaimMysteryGift::ClaimMysteryGift()
101113
{
102114

103115
PA_ADD_OPTION(LANGUAGE);
104-
PA_ADD_OPTION(STARTING_POINT);
105116
PA_ADD_OPTION(MYSTERY_GIFT_NOTE);
117+
PA_ADD_OPTION(STARTING_POINT);
118+
PA_ADD_OPTION(OBTAINING_METHOD);
119+
PA_ADD_OPTION(MULTISWITCH_NOTE);
106120
PA_ADD_OPTION(CODE);
107121
PA_ADD_OPTION(SETTINGS);
108122
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
@@ -111,12 +125,28 @@ ClaimMysteryGift::ClaimMysteryGift()
111125

112126
ClaimMysteryGift::on_config_value_changed(this);
113127

128+
OBTAINING_METHOD.add_listener(*this);
114129
STARTING_POINT.add_listener(*this);
115130
}
116131

117132
void ClaimMysteryGift::on_config_value_changed(void* object){
133+
if (STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW){
134+
OBTAINING_METHOD.set_visibility(ConfigOptionState::HIDDEN);
135+
}else{
136+
OBTAINING_METHOD.set_visibility(ConfigOptionState::ENABLED);
137+
}
118138

119139

140+
if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
141+
MULTISWITCH_NOTE.set_visibility(ConfigOptionState::ENABLED);
142+
CODE.set_visibility(ConfigOptionState::ENABLED);
143+
SETTINGS.set_visibility(ConfigOptionState::ENABLED);
144+
}else{
145+
MULTISWITCH_NOTE.set_visibility(ConfigOptionState::HIDDEN);
146+
CODE.set_visibility(ConfigOptionState::HIDDEN);
147+
SETTINGS.set_visibility(ConfigOptionState::HIDDEN);
148+
}
149+
120150
}
121151

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

139169
}
140170

141-
void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
171+
void ClaimMysteryGift::enter_mystery_gift_via_internet_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
172+
env.console.log("Save game, then try to enter the mystery gift via internet window.", COLOR_YELLOW);
173+
save_game_from_menu_or_overworld(env.program_info(), env.console, context, false);
174+
175+
size_t max_attempts = 5;
176+
for (size_t i = 0; i < max_attempts; i++){
177+
enter_menu_from_overworld(env.program_info(), env.console, context, menu_index);
178+
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
179+
pbf_press_dpad(context, DPAD_UP, 20, 105);
180+
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
181+
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
182+
try {
183+
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG});
184+
}catch(OperationFailedException&){
185+
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);
186+
reset_game(env.program_info(), env.console, context);
187+
continue;
188+
}
189+
190+
return;
191+
}
192+
193+
OperationFailedException::fire(
194+
ErrorReport::SEND_ERROR_REPORT,
195+
"enter_mystery_gift_code_window(): Failed to reach Mystery Gift code window after several attempts.",
196+
env.console
197+
);
198+
}
199+
200+
201+
// void ClaimMysteryGift::claim_internet_mystery_gift(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
202+
// env.log("Claim Mystery Gifts via Internet.");
203+
// context.wait_for_all_requests();
204+
// ImageFloatBox box{0.256326, 0.099804, 0.044004, 0.616438};
205+
// GradientArrowWatcher arrow(COLOR_RED, GradientArrowType::RIGHT, box);
206+
// int ret = wait_until(
207+
// env.console, context,
208+
// Milliseconds(10 * 1000),
209+
// { arrow }
210+
// );
211+
// if (ret == 0){
212+
// env.console.log("Gradient arrow detected.");
213+
// }else{
214+
// OperationFailedException::fire(
215+
// ErrorReport::SEND_ERROR_REPORT,
216+
// "Failed to detect gradient arrow. We might not be in the Mystery Gift via Internet screen.",
217+
// env.console
218+
// );
219+
// }
220+
221+
// std::vector<double> y_position_seen;
222+
// // determine how many mystery gifts are available to claim
223+
// while(true){
224+
// context.wait_for_all_requests();
225+
// ImageFloatBox result_box;
226+
// arrow.detect(result_box, console.video().snapshot());
227+
// double current_y_pos = result_box.y;
228+
// bool seen = false;
229+
// for (double y_pos : y_position_seen){
230+
// // if difference is less than 0.02, then it's the same
231+
// if (std::abs(current_y_pos - y_pos) < 0.02){
232+
// seen = true;
233+
// break;
234+
// }
235+
// }
236+
// if (!seen){
237+
// y_position_seen.emplace_back(current_y_pos);
238+
// }else{
239+
// pbf_press_dpad(context, DPAD_DOWN, 160ms, 320ms);
240+
// }
241+
// }
242+
243+
// while(true){
244+
// context.wait_for_all_requests();
245+
// ImageFloatBox result_box;
246+
// arrow.detect(result_box, console.video().snapshot());
247+
// double y_pos = result_box.y;
248+
249+
// pbf_press_dpad(context, DPAD_DOWN, 160ms, 320ms);
250+
// // collect the mystery gift. Press A until you see the Gradient arrow again.
251+
// ret = run_until<ProControllerContext>(
252+
// env.console, context,
253+
// [&](ProControllerContext& context){
254+
// for (size_t i = 0; i < 40; i++){
255+
// pbf_press_button(context, BUTTON_A, 160ms, 1000ms);
256+
// }
257+
// },
258+
// arrow
259+
// );
260+
// if (ret < 0){
261+
// OperationFailedException::fire(
262+
// ErrorReport::SEND_ERROR_REPORT,
263+
// "Failed to detect gradient arrow. We might not be in the Mystery Gift via Internet screen.",
264+
// env.console
265+
// );
266+
// }
267+
268+
// }
269+
270+
271+
// }
272+
273+
void ClaimMysteryGift::enter_mystery_gift_code_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
142274
env.console.log("Save game, then try to enter the mystery gift window.", COLOR_YELLOW);
143275
save_game_from_menu_or_overworld(env.program_info(), env.console, context, false);
144276

@@ -154,7 +286,7 @@ void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment&
154286
try {
155287
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG});
156288
}catch(OperationFailedException&){
157-
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);
289+
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);
158290
reset_game(env.program_info(), env.console, context);
159291
continue;
160292
}
@@ -199,7 +331,7 @@ void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment&
199331
{key1_selected}
200332
);
201333
if (ret < 0){ // failed to detect Key 1 being highlighted. Reset game and re-try
202-
env.console.log("enter_mystery_gift_window: Failed to detect the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW);
334+
env.console.log("enter_mystery_gift_code_window: Failed to detect the Mystery Gift code window. Reset game and re-try.", COLOR_YELLOW);
203335
reset_game(env.program_info(), env.console, context);
204336
continue;
205337
}
@@ -210,7 +342,7 @@ void ClaimMysteryGift::enter_mystery_gift_window(SingleSwitchProgramEnvironment&
210342

211343
OperationFailedException::fire(
212344
ErrorReport::SEND_ERROR_REPORT,
213-
"enter_mystery_gift_window(): Failed to reach Mystery Gift screen after several attempts.",
345+
"enter_mystery_gift_code_window(): Failed to reach Mystery Gift code window after several attempts.",
214346
env.console
215347
);
216348
}
@@ -241,13 +373,34 @@ void ClaimMysteryGift::program(SingleSwitchProgramEnvironment& env, ProControlle
241373
if (STARTING_POINT == StartingPoint::NEW_GAME){
242374
run_autostory_until_pokeportal_unlocked(env, context);
243375
env.console.log("Done Autostory portion. Pokeportal should now be unlocked.");
244-
enter_mystery_gift_window(env, context, 2);
245-
enter_mystery_gift_code(env, context);
246-
}else if(STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT){
376+
if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
377+
enter_mystery_gift_code_window(env, context, 2);
378+
enter_mystery_gift_code(env, context);
379+
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ALL){
380+
// enter_mystery_gift_via_internet_window(env, context, 2);
381+
// claim_internet_mystery_gift(env, context);
382+
383+
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_NONE){
384+
enter_mystery_gift_via_internet_window(env, context, 2);
385+
386+
}
387+
388+
}else if(STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW){
389+
// only claim the mystery gift via code. not via internet
247390
enter_mystery_gift_code(env, context);
391+
248392
}else if (STARTING_POINT == StartingPoint::DONE_TUTORIAL){
249-
enter_mystery_gift_window(env, context, 3);
250-
enter_mystery_gift_code(env, context);
393+
394+
if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
395+
enter_mystery_gift_code_window(env, context, 3);
396+
enter_mystery_gift_code(env, context);
397+
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ALL){
398+
// enter_mystery_gift_via_internet_window(env, context, 3);
399+
400+
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_NONE){
401+
enter_mystery_gift_via_internet_window(env, context, 3);
402+
403+
}
251404
}else{
252405
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown STARTING_POINT.");
253406
}

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class ClaimMysteryGift : public SingleSwitchProgramInstance, public ConfigOption
4040
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
4141

4242
void run_autostory_until_pokeportal_unlocked(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
43-
void enter_mystery_gift_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
43+
void enter_mystery_gift_via_internet_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
44+
void claim_internet_mystery_gift(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
45+
void enter_mystery_gift_code_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
4446
void enter_mystery_gift_code(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
4547

4648
private:
@@ -54,12 +56,20 @@ class ClaimMysteryGift : public SingleSwitchProgramInstance, public ConfigOption
5456

5557
enum class StartingPoint{
5658
NEW_GAME,
57-
IN_MYSTERY_GIFT,
59+
IN_MYSTERY_GIFT_CODE_WINDOW,
5860
DONE_TUTORIAL,
5961
};
6062

63+
enum class ObtainingMethod{
64+
VIA_INTERNET_ALL,
65+
VIA_INTERNET_NONE,
66+
VIA_CODE,
67+
};
68+
6169
EnumDropdownOption<StartingPoint> STARTING_POINT;
70+
EnumDropdownOption<ObtainingMethod> OBTAINING_METHOD;
6271
StaticTextOption MYSTERY_GIFT_NOTE;
72+
StaticTextOption MULTISWITCH_NOTE;
6373
TextEditOption CODE;
6474
FastCodeEntrySettingsOption SETTINGS;
6575

0 commit comments

Comments
 (0)