Skip to content

Commit 27f7570

Browse files
author
Gin
committed
writing bag movement for 3-seg
1 parent 253b571 commit 27f7570

File tree

5 files changed

+222
-18
lines changed

5 files changed

+222
-18
lines changed

SerialPrograms/Source/PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace PokemonSV{
2121
bool is_summary_color(const ImageStats& stats);
2222

2323

24-
24+
// Detect pokemon status summary page
2525
class PokemonSummaryDetector : public StaticScreenDetector{
2626
public:
2727
PokemonSummaryDetector(Color color = COLOR_RED);

SerialPrograms/Source/PokemonSV/Programs/FormHunting/PokemonSV_ThreeSegmentDudunsparceFinder.cpp

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#include "CommonFramework/Exceptions/OperationFailedException.h"
1010
#include "CommonFramework/Notifications/ProgramNotifications.h"
1111
#include "CommonFramework/ProgramStats/StatsTracking.h"
12+
#include "CommonTools/Async/InferenceRoutines.h"
1213
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
1314
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1415
#include "Pokemon/Pokemon_Strings.h"
16+
#include "PokemonSV/Inference/PokemonSV_PokemonSummaryReader.h"
1517
#include "PokemonSV/Programs/Boxes/PokemonSV_BoxRoutines.h"
1618
#include "PokemonSV/Programs/PokemonSV_MenuNavigation.h"
1719
#include "PokemonSV_ThreeSegmentDudunsparceFinder.h"
@@ -85,11 +87,91 @@ void ThreeSegmentDudunsparceFinder::check_one_column(SingleSwitchProgramEnvironm
8587
}
8688

8789
load_one_column_to_party(env, env.console, context, NOTIFICATION_ERROR_FATAL, column_index, HAS_CLONE_RIDE_POKEMON);
88-
const int menu_index = 0;
90+
const int empty_party_slots = check_empty_slots_in_party(env.program_info(), env.console, context);
91+
if (empty_party_slots == 5){
92+
env.log("Empty column");
93+
env.console.overlay().add_log("Empty column");
94+
return;
95+
}
96+
const int num_pokemon_in_party = 6 - empty_party_slots;
97+
const int menu_index = -1;
8998
// go to bag from box system
90-
enter_menu_from_box_system(env.program_info(), env.console, context, menu_index, MenuSide::RIGHT);
99+
enter_menu_from_box_system(env.program_info(), env.console, context, menu_index);
100+
enter_bag_from_menu(env.program_info(), env.console, context);
101+
// move cursor to the "Other Items" tab
102+
for (size_t c = 0; c < 4; c++){
103+
pbf_press_dpad(context, DPAD_RIGHT, 20, 105);
104+
}
91105
context.wait_for_all_requests();
92-
// BagWatcher bag_detector(BagWatcher::FinderType::PRESENT, COLOR_GREEN);
106+
// move to candies:
107+
108+
// Exp M: 3k exp points. from Tera Raid Battles (2★, 3★, 4★)
109+
// Exp L: 10k exp points. from Tera Raid Battles (4★, 5★, 6★, 7★)
110+
// Exp XL: 30k exp points. from Tera Raid Battles (5★, 6★, 7★)
111+
112+
// - 3 exp L to go to lv 31 from lv 1
113+
// - 4 Exp L to go to lv 34 from lv 1
114+
// - 11 exp M to go to lv 32 from lv 1
115+
// - 1 exp M to go from lv 32 to lv 33
116+
117+
// so total 12 exp M per dunsparce. 12 * 30 = 360 exp M
118+
// or 3 expl L + 2 exp M per dunsparce. 90 exp M and 60 exp M
119+
// or 1 exp XL + 2 exp M per dunsparce. 30 exp XL and 60 exp M
120+
121+
// go down 5 to go to candy XL
122+
for (size_t c = 0; c < 5; c++){
123+
pbf_press_dpad(context, DPAD_DOWN, 20, 105);
124+
}
125+
// press A to bring up sub menu: "Use this item", "Give to Pokemon", "Cancel"
126+
pbf_press_button(context, BUTTON_A, 20, 105);
127+
// press A again to select "Use this item"
128+
pbf_press_button(context, BUTTON_A, 20, 105);
129+
// now the cursor is on the first pokemon
130+
const int starting_pokemon_in_party = HAS_CLONE_RIDE_POKEMON ? 2 : 1;
131+
for (int i_pokemon = starting_pokemon_in_party; i_pokemon < num_pokemon_in_party; i_pokemon++){
132+
// go down to the target pokemon
133+
for (int c = 0; c < i_pokemon; c++){
134+
pbf_press_dpad(context, DPAD_DOWN, 20, 105);
135+
}
136+
// select the pokemon. This will open up the item count "x1"
137+
pbf_press_button(context, BUTTON_A, 20, 105);
138+
// press A again to apply the x1 candy XL to the pokemon
139+
pbf_press_button(context, BUTTON_A, 20, 105);
140+
// wait for some more time to let the level up animation finish
141+
pbf_wait(context, Seconds(1));
142+
// press A to clear the "dudunsparce grew up to lv 31" message box
143+
pbf_press_button(context, BUTTON_A, 20, 105);
144+
}
145+
146+
// leave bag and move to menu, enter the first dunsparce's sub-menu
147+
enter_menu_from_bag(env.program_info(), env.console, context, starting_pokemon_in_party, MenuSide::LEFT);
148+
// press A again to go into pokemon status summary screen
149+
pbf_press_button(context, BUTTON_A, 20, 105);
150+
// wait until we are in pokemon status summary screen
151+
PokemonSummaryWatcher summary_watcher;
152+
int ret = wait_until(
153+
env.console, context,
154+
Seconds(3),
155+
{summary_watcher}
156+
);
157+
if (ret < 0){
158+
throw_and_log<FatalProgramException>(
159+
env.console, ErrorReport::NO_ERROR_REPORT,
160+
"ThreeSegmentDudunsparceFinder::check_one_column(): No pokemon status summary screen found.",
161+
env.console
162+
);
163+
}
164+
// move to the moves screen
165+
pbf_press_dpad(context, DPAD_RIGHT, 20, 105);
166+
167+
for (int i_pokemon = starting_pokemon_in_party; i_pokemon < num_pokemon_in_party; i_pokemon++){
168+
// press A to open submenu "Remember moves", "Forget a move", "Use TMs to learn moves", "Quit"
169+
pbf_press_button(context, BUTTON_A, 20, 105);
170+
// press A to select "Remember moves"
171+
pbf_press_button(context, BUTTON_A, 20, 105);
172+
// wait until Remember Move list to appear
173+
// XXX
174+
}
93175
}
94176

95177
void ThreeSegmentDudunsparceFinder::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_MenuNavigation.cpp

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@
1414
#include "PokemonSV/PokemonSV_Settings.h"
1515
#include "PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
1616
#include "PokemonSV/Inference/Map/PokemonSV_MapDetector.h"
17-
#include "PokemonSV/Inference/Map/PokemonSV_MapMenuDetector.h"
18-
#include "PokemonSV/Inference/Map/PokemonSV_MapPokeCenterIconDetector.h"
19-
#include "PokemonSV/Inference/Picnics/PokemonSV_PicnicDetector.h"
17+
#include "PokemonSV/Inference/PokemonSV_BagDetector.h"
2018
#include "PokemonSV/Inference/PokemonSV_MainMenuDetector.h"
21-
#include "PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h"
2219
#include "PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h"
2320
#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
2421
#include "PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
25-
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"
2622
#include "PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h"
2723
#include "PokemonSV_ConnectToInternet.h"
2824
#include "PokemonSV_MenuNavigation.h"
@@ -533,25 +529,24 @@ void enter_menu_from_box_system(const ProgramInfo& info, VideoStream& stream, Pr
533529
[](ProControllerContext& context){
534530
// repeatedly pressing B and waiting for three seconds
535531
for (int i = 0; i < 10; i++){
536-
pbf_press_button(context, BUTTON_B, 20, 3 * TICKS_PER_SECOND);
532+
pbf_press_button(context, BUTTON_B, 200ms, 3s);
537533
}
538534
},
539535
{main_menu}
540536
);
541-
context.wait_for(std::chrono::milliseconds(100));
542537

543538
const bool fast_mode = false;
544539
switch (ret){
545540
case 0:
546-
stream.log("Detected main menu.");
541+
stream.log("Detected main menu when going from box system to menu");
547542
if (menu_index == -1){
548543
return;
549544
}
550545
success = main_menu.move_cursor(info, stream, context, side, menu_index, fast_mode);
551546
if (success == false){
552547
OperationFailedException::fire(
553548
ErrorReport::SEND_ERROR_REPORT,
554-
"enter_menu_from_overworld(): Cannot move menu cursor to specified menu.",
549+
"enter_menu_from_box_system(): Cannot move menu cursor to specified menu.",
555550
stream
556551
);
557552
}
@@ -560,13 +555,129 @@ void enter_menu_from_box_system(const ProgramInfo& info, VideoStream& stream, Pr
560555
default:
561556
OperationFailedException::fire(
562557
ErrorReport::SEND_ERROR_REPORT,
563-
"enter_menu_from_overworld(): No recognized state after 30 seconds.",
558+
"enter_menu_from_box_system(): No recognized state after 30 seconds.",
564559
stream
565560
);
566561
}
567562
}
568563
}
569564

565+
566+
void enter_menu_from_bag(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
567+
int menu_index,
568+
MenuSide side
569+
){
570+
WallClock start = current_time();
571+
bool success = false;
572+
573+
while (true){
574+
if (current_time() - start > std::chrono::seconds(20)){
575+
OperationFailedException::fire(
576+
ErrorReport::SEND_ERROR_REPORT,
577+
"enter_menu_from_bag(): Failed to enter specified menu after 20 seconds.",
578+
stream
579+
);
580+
}
581+
582+
MainMenuWatcher main_menu(COLOR_RED);
583+
BagWatcher bag_watcher(BagWatcher::FinderType::PRESENT, COLOR_RED);
584+
context.wait_for_all_requests();
585+
586+
int ret = run_until<ProControllerContext>(
587+
stream, context,
588+
[](ProControllerContext& context){
589+
// repeatedly pressing B and waiting for three seconds
590+
for (int i = 0; i < 10; i++){
591+
pbf_press_button(context, BUTTON_B, 200ms, 3s);
592+
}
593+
},
594+
{main_menu, bag_watcher}
595+
);
596+
597+
const bool fast_mode = false;
598+
switch (ret){
599+
case 0:
600+
stream.log("Detected main menu when going from box system to menu");
601+
if (menu_index == -1){
602+
return;
603+
}
604+
success = main_menu.move_cursor(info, stream, context, side, menu_index, fast_mode);
605+
if (success == false){
606+
OperationFailedException::fire(
607+
ErrorReport::SEND_ERROR_REPORT,
608+
"enter_menu_from_bag(): Cannot move menu cursor to specified menu.",
609+
stream
610+
);
611+
}
612+
pbf_press_button(context, BUTTON_A, 20, 105);
613+
return;
614+
case 1:
615+
stream.log("still on bag.");
616+
pbf_press_button(context, BUTTON_B, 20, 105);
617+
continue;
618+
default:
619+
OperationFailedException::fire(
620+
ErrorReport::SEND_ERROR_REPORT,
621+
"enter_menu_from_bag(): No recognized state after 30 seconds.",
622+
stream
623+
);
624+
}
625+
}
626+
}
627+
628+
629+
void enter_bag_from_menu(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
630+
WallClock start = current_time();
631+
bool success = false;
632+
stream.log("Entering bag from menu");
633+
634+
while (true){
635+
if (current_time() - start > std::chrono::seconds(20)){
636+
OperationFailedException::fire(
637+
ErrorReport::SEND_ERROR_REPORT,
638+
"enter_bag_from_menu(): Failed to enter specified menu after 20 seconds.",
639+
stream
640+
);
641+
}
642+
643+
MainMenuWatcher main_menu(COLOR_RED);
644+
BagWatcher bag_watcher(BagWatcher::FinderType::PRESENT, COLOR_RED);
645+
context.wait_for_all_requests();
646+
647+
int ret = wait_until(
648+
stream, context,
649+
Seconds(5),
650+
{main_menu, bag_watcher}
651+
);
652+
653+
const bool fast_mode = false;
654+
switch (ret){
655+
case 0:
656+
stream.log("Detected main menu.");
657+
success = main_menu.move_cursor(info, stream, context, MenuSide::RIGHT, 0, fast_mode);
658+
if (success == false){
659+
OperationFailedException::fire(
660+
ErrorReport::SEND_ERROR_REPORT,
661+
"enter_bag_from_menu(): Cannot move menu cursor to specified menu.",
662+
stream
663+
);
664+
}
665+
pbf_press_button(context, BUTTON_A, 20, 105);
666+
continue;
667+
case 1:
668+
stream.overlay().add_log("Enter bag");
669+
return;
670+
default:
671+
OperationFailedException::fire(
672+
ErrorReport::SEND_ERROR_REPORT,
673+
"enter_bag_from_menu(): No recognized state after 30 seconds.",
674+
stream
675+
);
676+
}
677+
}
678+
}
679+
680+
570681
void press_button_until_gradient_arrow(
571682
const ProgramInfo& info,
572683
VideoStream& stream,

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_MenuNavigation.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "CommonFramework/Tools/VideoStream.h"
1313
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
1414
#include "PokemonSV/Inference/PokemonSV_MainMenuDetector.h"
15-
#include "PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h"
15+
1616

1717
namespace PokemonAutomation{
1818
struct ProgramInfo;
@@ -68,13 +68,25 @@ void enter_menu_from_overworld(const ProgramInfo& info, VideoStream& stream, Pro
6868
bool has_minimap = true
6969
);
7070

71-
// enter menu and move the cursor to the given side and index, then press the A button (without wait for A button to press)
71+
// enter menu from box system and move the cursor to the given side and index, then press the A button (without wait for A
72+
// button to press)
7273
// if menu_index is -1, return once the menu is detected.
7374
void enter_menu_from_box_system(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
7475
int menu_index,
75-
MenuSide side = MenuSide::RIGHT
76+
MenuSide side = MenuSide::NONE
7677
);
7778

79+
// enter menu from bag and move the cursor to the given side and index, then press the A button (without wait for A
80+
// button to press)
81+
// if menu_index is -1, return once the menu is detected.
82+
void enter_menu_from_bag(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
83+
int menu_index,
84+
MenuSide side = MenuSide::NONE
85+
);
86+
87+
// enter bag from any place on the main menu
88+
void enter_bag_from_menu(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context);
89+
7890
// press given button until gradient arrow appears in given box_area_to_check.
7991
void press_button_until_gradient_arrow(
8092
const ProgramInfo& info,

SerialPrograms/Source/PokemonSV/Programs/PokemonSV_WorldNavigation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "PokemonSV/Inference/Picnics/PokemonSV_PicnicDetector.h"
2020
#include "PokemonSV/Inference/PokemonSV_MainMenuDetector.h"
2121
#include "PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h"
22-
#include "PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h"
2322
#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
2423
#include "PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
2524
#include "PokemonSV/Inference/PokemonSV_TutorialDetector.h"

0 commit comments

Comments
 (0)