1- /* Berry Buyer
1+ /* Stall Buyer
22 *
33 * From: https://github.com/PokemonAutomation/
44 *
1414#include " PokemonLZA/Inference/PokemonLZA_ButtonDetector.h"
1515#include " PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h"
1616#include " PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
17- #include " PokemonLZA_BerryBuyer .h"
17+ #include " PokemonLZA_StallBuyer .h"
1818
1919namespace PokemonAutomation {
2020namespace NintendoSwitch {
2121namespace PokemonLZA {
2222
2323using namespace Pokemon ;
2424
25- BerryBuyer_Descriptor::BerryBuyer_Descriptor ()
25+ StallBuyer_Descriptor::StallBuyer_Descriptor ()
2626 : SingleSwitchProgramDescriptor(
27- " PokemonLZA:BerryBuyer " ,
28- STRING_POKEMON + " LZA" , " Berry Buyer" ,
29- " Programs/PokemonLZA/BerryBuyer .html" ,
30- " Buy EV reducing berries from stall." ,
27+ " PokemonLZA:StallBuyer " ,
28+ STRING_POKEMON + " LZA" , " Stall Buyer" ,
29+ " Programs/PokemonLZA/StallBuyer .html" ,
30+ " Buy berries or mints from stall." ,
3131 ProgramControllerClass::StandardController_NoRestrictions,
3232 FeedbackType::REQUIRED,
3333 AllowCommandsWhenRunning::DISABLE_COMMANDS
3434 )
3535{}
3636
37- class BerryBuyer_Descriptor ::Stats : public StatsTracker{
37+ class StallBuyer_Descriptor ::Stats : public StatsTracker{
3838public:
3939 Stats ()
4040 : purchases(m_stats[" Purchases" ])
@@ -47,27 +47,33 @@ class BerryBuyer_Descriptor::Stats : public StatsTracker{
4747 std::atomic<uint64_t >& purchases;
4848 std::atomic<uint64_t >& errors;
4949};
50- std::unique_ptr<StatsTracker> BerryBuyer_Descriptor ::make_stats () const {
50+ std::unique_ptr<StatsTracker> StallBuyer_Descriptor ::make_stats () const {
5151 return std::unique_ptr<StatsTracker>(new Stats ());
5252}
5353
5454
55- BerryBuyer::BerryBuyer ()
56- : BERRY_TYPE (
57- " <b>Berry to Purchase:</b>" ,
55+ StallBuyer::StallBuyer ()
56+ : ITEM_POSITION (
57+ " <b>Item Position to Purchase:</b>" ,
5858 {
59- {BerryType::POMEG, " pomeg" , " Pomeg (HP)" },
60- {BerryType::KELPSY, " kelpsy" , " Kelpsy (Attack)" },
61- {BerryType::QUALOT, " qualot" , " Qualot (Defence)" },
62- {BerryType::HONDEW, " hondew" , " Hondew (Special Attack)" },
63- {BerryType::GREPA, " grepa" , " Grepa (Special Defence)" },
64- {BerryType::TAMATO, " tamato" , " Tamato (Speed)" },
59+ {ItemPosition::FirstItem, " FirstItem" , " First Item" },
60+ {ItemPosition::SecondItem, " SecondItem" , " Second Item" },
61+ {ItemPosition::ThirdItem, " ThirdItem" , " Third Item" },
62+ {ItemPosition::FourthItem, " FourthItem" , " Fourth Item" },
63+ {ItemPosition::FifthItem, " FifthItem" , " Fifth Item" },
64+ {ItemPosition::SixthItem, " SixthItem" , " Sixth Item" },
65+ {ItemPosition::SeventhItem, " SeventhItem" , " Seventh Item" },
6566 },
6667 LockMode::LOCK_WHILE_RUNNING,
67- BerryType::POMEG
68+ ItemPosition::FirstItem
69+ )
70+ , NUM_ITEM(
71+ " <b>Number of available items in the stall:</b><br>Number of available items in the stall." ,
72+ LockMode::LOCK_WHILE_RUNNING,
73+ 6 , 2 , 7
6874 )
6975 , NUM_PURCHASE(
70- " <b>Number to Purchase:</b><br>The number of berries you want to purchase." ,
76+ " <b>Number to Purchase:</b><br>The number of items you want to purchase." ,
7177 LockMode::LOCK_WHILE_RUNNING,
7278 100 , 1 , 999
7379 )
@@ -79,15 +85,35 @@ BerryBuyer::BerryBuyer()
7985 &NOTIFICATION_ERROR_FATAL,
8086 })
8187{
82- PA_ADD_OPTION (BERRY_TYPE);
88+ PA_ADD_OPTION (ITEM_POSITION);
89+ PA_ADD_OPTION (NUM_ITEM);
8390 PA_ADD_OPTION (NUM_PURCHASE);
8491 PA_ADD_OPTION (GO_HOME_WHEN_DONE);
8592 PA_ADD_OPTION (NOTIFICATIONS);
8693}
8794
88- void BerryBuyer::program (SingleSwitchProgramEnvironment& env, ProControllerContext& context){
89- BerryBuyer_Descriptor::Stats& stats = env.current_stats <BerryBuyer_Descriptor::Stats>();
95+ std::pair<DpadPosition, int > compute_needed_inputs (int item_position, int num_item){
96+ int down_presses = item_position;
97+ int up_presses = num_item - item_position + 1 ;
98+
99+ if (down_presses <= up_presses){
100+ return { DPAD_DOWN, down_presses };
101+ }else {
102+ return { DPAD_UP, up_presses };
103+ }
104+ }
105+
106+ void StallBuyer::program (SingleSwitchProgramEnvironment& env, ProControllerContext& context){
107+ StallBuyer_Descriptor::Stats& stats = env.current_stats <StallBuyer_Descriptor::Stats>();
90108 assert_16_9_720p_min (env.logger (), env.console );
109+ int item_position = static_cast <int >(ITEM_POSITION.get ());
110+ if (item_position >= NUM_ITEM){
111+ throw UserSetupError (
112+ env.logger (),
113+ " Item position to purchase must be less than or equal to number of available items in the stall."
114+ );
115+ }
116+
91117 while (true ) {
92118 context.wait_for_all_requests ();
93119
@@ -100,12 +126,12 @@ void BerryBuyer::program(SingleSwitchProgramEnvironment& env, ProControllerConte
100126 SelectionArrowWatcher select (
101127 COLOR_YELLOW, &env.console .overlay (),
102128 SelectionArrowType::RIGHT,
103- {0.715 , 0.235 , 0.045 , 0.080 }
129+ {0.715 , 0.165 , 0.045 , 0.440 }
104130 );
105131 SelectionArrowWatcher confirm (
106132 COLOR_YELLOW, &env.console .overlay (),
107133 SelectionArrowType::RIGHT,
108- {0.715 , 0.600 , 0.045 , 0.080 }
134+ {0.665 , 0.600 , 0.145 , 0.080 }
109135 );
110136 FlatWhiteDialogWatcher dialog (COLOR_RED, &env.console .overlay ());
111137
@@ -121,29 +147,17 @@ void BerryBuyer::program(SingleSwitchProgramEnvironment& env, ProControllerConte
121147 );
122148 context.wait_for (100ms);
123149
150+ auto [direction, presses] = compute_needed_inputs (item_position, NUM_ITEM);
124151 switch (ret){
125152 case 0 :
126153 env.log (" Detected A button." );
127154 pbf_press_button (context, BUTTON_A, 160ms, 80ms);
128155 continue ;
129156
130157 case 1 :
131- env.log (" Detected berry selection screen." );
132- switch (BERRY_TYPE){
133- case BerryType::HONDEW:
134- pbf_press_dpad (context, DPAD_DOWN, 160ms, 80ms);
135- case BerryType::QUALOT:
136- pbf_press_dpad (context, DPAD_DOWN, 160ms, 80ms);
137- case BerryType::KELPSY:
138- pbf_press_dpad (context, DPAD_DOWN, 160ms, 80ms);
139- case BerryType::POMEG:
140- break ;
141- case BerryType::GREPA:
142- pbf_press_dpad (context, DPAD_UP, 160ms, 80ms);
143- case BerryType::TAMATO:
144- pbf_press_dpad (context, DPAD_UP, 160ms, 80ms);
145- pbf_press_dpad (context, DPAD_UP, 160ms, 80ms);
146- break ;
158+ env.log (" Detected item selection screen." );
159+ for (int i = 0 ; i < presses; i++){
160+ pbf_press_dpad (context, direction, 160ms, 80ms);
147161 }
148162 pbf_press_button (context, BUTTON_A, 160ms, 80ms);
149163 continue ;
0 commit comments