Skip to content

Commit 4f4c49e

Browse files
committed
claim mystery gift via Internet
1 parent 8322437 commit 4f4c49e

File tree

2 files changed

+117
-8
lines changed

2 files changed

+117
-8
lines changed

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

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ ClaimMysteryGift::ClaimMysteryGift()
7474
{
7575
{StartingPoint::NEW_GAME, "new-game", "New Game: Start after you have selected your username and character appearance"},
7676
{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. But with all menus closed. Tutorial must be completed. You need to be outside, where you can use Pokeportal."},
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."},
7878
},
7979
LockMode::LOCK_WHILE_RUNNING,
8080
StartingPoint::NEW_GAME
8181
)
8282
, OBTAINING_METHOD(
8383
"<b>Method for obtaining mystery gift:",
8484
{
85-
{ObtainingMethod::VIA_INTERNET_ALL, "via-internet-all", "Via Internet: Get all mystery gifts from the \"Via internet\" screen."},
86-
{ObtainingMethod::VIA_INTERNET_ONE, "via-internet-one", "Via Internet: Get only the top mystery gift from the \"Via internet\" screen."},
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."},
8787
{ObtainingMethod::VIA_CODE, "via-code", "Via Code: Get the mystery gift based on the code entered below."},
8888
},
8989
LockMode::LOCK_WHILE_RUNNING,
90-
ObtainingMethod::VIA_INTERNET_ALL
90+
ObtainingMethod::VIA_INTERNET_NONE
9191
)
9292
, MYSTERY_GIFT_NOTE{
9393
"Ensure you are logged into a Nintendo account. This account does NOT need to have a subscription to Nintendo Switch Online."
@@ -168,6 +168,108 @@ void ClaimMysteryGift::enter_mystery_gift_code(SingleSwitchProgramEnvironment& e
168168

169169
}
170170

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+
171273
void ClaimMysteryGift::enter_mystery_gift_code_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index){
172274
env.console.log("Save game, then try to enter the mystery gift window.", COLOR_YELLOW);
173275
save_game_from_menu_or_overworld(env.program_info(), env.console, context, false);
@@ -275,23 +377,28 @@ void ClaimMysteryGift::program(SingleSwitchProgramEnvironment& env, ProControlle
275377
enter_mystery_gift_code_window(env, context, 2);
276378
enter_mystery_gift_code(env, context);
277379
}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);
278382

279-
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ONE){
383+
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_NONE){
384+
enter_mystery_gift_via_internet_window(env, context, 2);
280385

281386
}
282387

283388
}else if(STARTING_POINT == StartingPoint::IN_MYSTERY_GIFT_CODE_WINDOW){
284389
// only claim the mystery gift via code. not via internet
285390
enter_mystery_gift_code(env, context);
286-
391+
287392
}else if (STARTING_POINT == StartingPoint::DONE_TUTORIAL){
288393

289394
if (OBTAINING_METHOD == ObtainingMethod::VIA_CODE){
290395
enter_mystery_gift_code_window(env, context, 3);
291396
enter_mystery_gift_code(env, context);
292397
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ALL){
398+
// enter_mystery_gift_via_internet_window(env, context, 3);
293399

294-
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_ONE){
400+
}else if(OBTAINING_METHOD == ObtainingMethod::VIA_INTERNET_NONE){
401+
enter_mystery_gift_via_internet_window(env, context, 3);
295402

296403
}
297404
}else{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ 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_via_internet_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
44+
void claim_internet_mystery_gift(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
4345
void enter_mystery_gift_code_window(SingleSwitchProgramEnvironment& env, ProControllerContext& context, int menu_index);
4446
void enter_mystery_gift_code(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
4547

@@ -60,7 +62,7 @@ class ClaimMysteryGift : public SingleSwitchProgramInstance, public ConfigOption
6062

6163
enum class ObtainingMethod{
6264
VIA_INTERNET_ALL,
63-
VIA_INTERNET_ONE,
65+
VIA_INTERNET_NONE,
6466
VIA_CODE,
6567
};
6668

0 commit comments

Comments
 (0)