Skip to content

Commit 3424527

Browse files
committed
Update to new controller changes
1 parent 43b314c commit 3424527

File tree

3 files changed

+76
-49
lines changed

3 files changed

+76
-49
lines changed

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_DailyHighlightRNG.cpp

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* From: https://github.com/PokemonAutomation/Arduino-Source
44
*
5-
* Based on Anubis' findings: https://docs.google.com/spreadsheets/u/0/d/1pNYtCJKRh_efX9LvzjCiA-0n2lGSFnVmSWwmPzgSOMw/htmlview
5+
* Based on Anubis' findings: https://docs.google.com/spreadsheets/u/0/d/1pNYtCJKRh_efX9LvzjCiA-0n2lGSFnVmSWwmPzgSOMw
66
*
77
*/
88

@@ -11,13 +11,15 @@
1111
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
1212
#include "CommonFramework/Exceptions/OperationFailedException.h"
1313
#include "CommonFramework/Notifications/ProgramNotifications.h"
14+
#include "CommonFramework/ProgramStats/StatsTracking.h"
1415
#include "CommonFramework/VideoPipeline/VideoFeed.h"
15-
#include "CommonFramework/Tools/StatsTracking.h"
16+
#include "CommonTools/Async/InferenceRoutines.h"
1617
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
18+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1719
#include "Pokemon/Pokemon_Strings.h"
1820
#include "PokemonSwSh/PokemonSwSh_Settings.h"
1921
#include "PokemonSwSh/Commands/PokemonSwSh_Commands_DateSpam.h"
20-
#include "PokemonSwSh/Inference/PokemonSwSh_DialogTriangleDetector.h"
22+
#include "PokemonSwSh/Inference/PokemonSwSh_DialogBoxDetector.h"
2123
#include "PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.h"
2224
#include "PokemonSwSh/Programs/PokemonSwSh_MenuNavigation.h"
2325
#include "PokemonSwSh/Programs/RNG/PokemonSwSh_BasicRNG.h"
@@ -44,7 +46,8 @@ DailyHighlightRNG_Descriptor::DailyHighlightRNG_Descriptor()
4446
"Perform RNG manipulation to get rare items from the daily highlight trader.",
4547
FeedbackType::REQUIRED,
4648
AllowCommandsWhenRunning::DISABLE_COMMANDS,
47-
PABotBaseLevel::PABOTBASE_12KB
49+
{ControllerFeature::NintendoSwitch_ProController},
50+
FasterIfTickPrecise::MUCH_FASTER
4851
)
4952
{}
5053

@@ -94,6 +97,11 @@ DailyHighlightRNG::DailyHighlightRNG()
9497
, m_advanced_options(
9598
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
9699
)
100+
, MOVE_TIME("Move time:", LockMode::LOCK_WHILE_RUNNING, "1280 ms")
101+
, LEFT_X("Left X:", LockMode::LOCK_WHILE_RUNNING, 207)
102+
, LEFT_Y("Left Y:", LockMode::LOCK_WHILE_RUNNING, 1)
103+
, RIGHT_X("Right X:", LockMode::LOCK_WHILE_RUNNING, 127)
104+
, RIGHT_Y("Right Y:", LockMode::LOCK_WHILE_RUNNING, 127)
97105
, MAX_UNKNOWN_ADVANCES(
98106
"<b>Max Unknown advances:</b><br>How many advances to check when updating the rng state.",
99107
LockMode::LOCK_WHILE_RUNNING,
@@ -102,12 +110,12 @@ DailyHighlightRNG::DailyHighlightRNG()
102110
, ADVANCE_PRESS_DURATION(
103111
"<b>Advance Press Duration:</b><br>Hold the button down for this long to advance once.",
104112
LockMode::LOCK_WHILE_RUNNING,
105-
10
113+
"80 ms"
106114
)
107115
, ADVANCE_RELEASE_DURATION(
108116
"<b>Advance Release Duration:</b><br>After releasing the button, wait this long before pressing it again.",
109117
LockMode::LOCK_WHILE_RUNNING,
110-
10
118+
"80 ms"
111119
)
112120
, SAVE_SCREENSHOTS(
113121
"<b>Save Debug Screenshots:</b>",
@@ -129,39 +137,50 @@ DailyHighlightRNG::DailyHighlightRNG()
129137
PA_ADD_OPTION(NOTIFICATIONS);
130138

131139
PA_ADD_STATIC(m_advanced_options);
140+
PA_ADD_OPTION(MOVE_TIME);
141+
PA_ADD_OPTION(LEFT_X);
142+
PA_ADD_OPTION(LEFT_Y);
143+
PA_ADD_OPTION(RIGHT_X);
144+
PA_ADD_OPTION(RIGHT_Y);
132145
PA_ADD_OPTION(MAX_UNKNOWN_ADVANCES);
133146
PA_ADD_OPTION(ADVANCE_PRESS_DURATION);
134147
PA_ADD_OPTION(ADVANCE_RELEASE_DURATION);
135148
PA_ADD_OPTION(SAVE_SCREENSHOTS);
136149
PA_ADD_OPTION(LOG_VALUES);
137150
}
138151

139-
void DailyHighlightRNG::move_to_trader(SingleSwitchProgramEnvironment& env, BotBaseContext& context) {
140-
pbf_move_left_joystick(context, 207, 1, 160, 10); // Magic numbers to barely reach the trader
141-
pbf_press_button(context, BUTTON_A, 20, 20);
152+
void DailyHighlightRNG::move_to_trader(SingleSwitchProgramEnvironment& env, ProControllerContext& context) {
153+
pbf_move_right_joystick(context, LEFT_X, LEFT_Y, MOVE_TIME, Milliseconds(80)); // TODO: remove/combine with left stick
154+
pbf_move_left_joystick(context, RIGHT_X, RIGHT_Y, MOVE_TIME, Milliseconds(80));
155+
156+
157+
pbf_press_button(context, BUTTON_A, Milliseconds(160), Milliseconds(160));
142158

143159
//Check if NPC was reached
144-
DialogTriangleDetector dialog_detector(env.console, ImageFloatBox(0.465, 0.195, 0.054, 0.57));
160+
//DialogTriangleDetector dialog_detector(env.console, ImageFloatBox(0.465, 0.195, 0.054, 0.57));
161+
VideoOverlaySet boxes(env.console);
162+
BlackDialogBoxDetector dialog_detector(true);
145163
dialog_detector.make_overlays(boxes);
146164

147165
int ret = wait_until(env.console, context, Milliseconds(3000), { dialog_detector });
148166
if (ret < 0) {
149167
OperationFailedException::fire(
150-
env.console, ErrorReport::SEND_ERROR_REPORT,
151-
"Failed to talk to the trader."
168+
ErrorReport::SEND_ERROR_REPORT,
169+
"Failed to talk to the trader.",
170+
env.console
152171
);
153172
}
154173
}
155174

156-
void DailyHighlightRNG::navigate_to_party(SingleSwitchProgramEnvironment& env, BotBaseContext& context){
157-
pbf_mash_button(context, BUTTON_B, 2 * TICKS_PER_SECOND); // exit dialog
158-
pbf_press_button(context, BUTTON_X, 10, GameSettings::instance().OVERWORLD_TO_MENU_DELAY);
175+
void DailyHighlightRNG::navigate_to_party(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
176+
pbf_mash_button(context, BUTTON_B, Milliseconds(2000)); // exit dialog
177+
pbf_press_button(context, BUTTON_X, Milliseconds(80), GameSettings::instance().OVERWORLD_TO_MENU_DELAY0);
159178
navigate_to_menu_app(env, env.console, context, 1, NOTIFICATION_ERROR_RECOVERABLE); // TODO: try-catch-block + error recovery
160-
pbf_press_button(context, BUTTON_A, 10, 3*TICKS_PER_SECOND);
179+
pbf_press_button(context, BUTTON_A, Milliseconds(80), Milliseconds(3000));
161180
context.wait_for_all_requests();
162181
}
163182

164-
uint8_t DailyHighlightRNG::calibrate_num_npc_from_party(SingleSwitchProgramEnvironment& env, BotBaseContext& context, Pokemon::Xoroshiro128Plus& rng){
183+
uint8_t DailyHighlightRNG::calibrate_num_npc_from_party(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Pokemon::Xoroshiro128Plus& rng){
165184
// TODO: implement
166185
return 2; // Usually either 1 or 2 -> higher numbers suggest bad npc state
167186
}
@@ -204,50 +223,50 @@ size_t DailyHighlightRNG::calculate_target(SingleSwitchProgramEnvironment& env,
204223
return advances;
205224
}
206225

207-
void DailyHighlightRNG::leave_to_overworld_and_interact(SingleSwitchProgramEnvironment& env, BotBaseContext& context, bool buy_highlight) {
226+
void DailyHighlightRNG::leave_to_overworld_and_interact(SingleSwitchProgramEnvironment& env, ProControllerContext& context, bool buy_highlight) {
208227
// Close menu
209-
pbf_press_button(context, BUTTON_B, 2 * TICKS_PER_SECOND, 5);
210-
pbf_press_button(context, BUTTON_B, 10, 70);
228+
pbf_press_button(context, BUTTON_B, Milliseconds(2000), Milliseconds(40));
229+
pbf_press_button(context, BUTTON_B, Milliseconds(80), Milliseconds(560));
211230

212231
// Quickly interact
213-
pbf_press_button(context, BUTTON_A, 30, 30);
214-
pbf_wait(context, 2*TICKS_PER_SECOND);
232+
pbf_press_button(context, BUTTON_A, Milliseconds(240), Milliseconds(240));
233+
pbf_wait(context, Milliseconds(2000));
215234

216235
// TODO: check if interaction worked -> see move_to_trader()
217236

218237
// Buy highlight
219238
if (buy_highlight) {
220-
pbf_press_button(context, BUTTON_ZL, 10, 40);
221-
pbf_press_dpad(context, DPAD_DOWN, 10, 10);
222-
pbf_mash_button(context, BUTTON_ZL, 400);
239+
pbf_press_button(context, BUTTON_ZL, Milliseconds(80), Milliseconds(360));
240+
pbf_press_dpad(context, DPAD_DOWN, Milliseconds(80), Milliseconds(80));
241+
pbf_mash_button(context, BUTTON_ZL, Milliseconds(3200));
223242
}
224243

225244
// Leave dialog
226-
pbf_mash_button(context, BUTTON_B, 6 * TICKS_PER_SECOND);
245+
pbf_mash_button(context, BUTTON_B, Milliseconds(6000));
227246
}
228247

229-
void DailyHighlightRNG::recover_from_wrong_state(SingleSwitchProgramEnvironment& env, BotBaseContext& context) {
248+
void DailyHighlightRNG::recover_from_wrong_state(SingleSwitchProgramEnvironment& env, ProControllerContext& context) {
230249
// Mash the B button to exit potential menus or dialog boxes
231-
pbf_mash_button(context, BUTTON_B, 30 * TICKS_PER_SECOND);
250+
pbf_mash_button(context, BUTTON_B, Seconds(30));
232251

233252
// Open map
234-
pbf_press_button(context, BUTTON_X, 20, GameSettings::instance().OVERWORLD_TO_MENU_DELAY);
253+
pbf_press_button(context, BUTTON_X, Milliseconds(160), GameSettings::instance().OVERWORLD_TO_MENU_DELAY0);
235254
navigate_to_menu_app(env, env.console, context, 5, NOTIFICATION_ERROR_RECOVERABLE);
236255

237256
// Fly to Snowslide Slope
238-
pbf_move_left_joystick(context, 200, 210, 20, 20);
239-
pbf_mash_button(context, BUTTON_A, 1 * TICKS_PER_SECOND);
257+
pbf_move_left_joystick(context, 200, 210, Milliseconds(160), Milliseconds(160));
258+
pbf_mash_button(context, BUTTON_A, Milliseconds(1000));
240259
}
241260

242261

243-
void DailyHighlightRNG::advance_date(SingleSwitchProgramEnvironment& env, BotBaseContext& context, uint8_t& year) {
244-
pbf_press_button(context, BUTTON_HOME, 10, GameSettings::instance().GAME_TO_HOME_DELAY_FAST);
262+
void DailyHighlightRNG::advance_date(SingleSwitchProgramEnvironment& env, ProControllerContext& context, uint8_t& year) {
263+
pbf_press_button(context, BUTTON_HOME, Milliseconds(80), GameSettings::instance().GAME_TO_HOME_DELAY_SAFE0);
245264
home_roll_date_enter_game_autorollback(env.console, context, year);
246265
//resume_game_from_home(env.console, context, false);
247266
}
248267

249268

250-
void DailyHighlightRNG::program(SingleSwitchProgramEnvironment& env, BotBaseContext& context){
269+
void DailyHighlightRNG::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
251270
DailyHighlightRNG_Descriptor::Stats& stats = env.current_stats<DailyHighlightRNG_Descriptor::Stats>();
252271
env.update_stats();
253272

@@ -260,7 +279,7 @@ void DailyHighlightRNG::program(SingleSwitchProgramEnvironment& env, BotBaseCont
260279
grip_menu_connect_go_home(context);
261280
}
262281
else {
263-
pbf_press_button(context, BUTTON_B, 5, 5);
282+
pbf_press_button(context, BUTTON_B, Milliseconds(40), Milliseconds(40));
264283
}
265284

266285
Xoroshiro128Plus rng(0, 0);
@@ -303,8 +322,9 @@ void DailyHighlightRNG::program(SingleSwitchProgramEnvironment& env, BotBaseCont
303322
state_errors++;
304323
if (state_errors >= 3){
305324
OperationFailedException::fire(
306-
env.console, ErrorReport::SEND_ERROR_REPORT,
307-
"Detected invalid RNG state three times in a row."
325+
ErrorReport::SEND_ERROR_REPORT,
326+
"Detected invalid RNG state three times in a row.",
327+
env.console
308328
);
309329
}
310330
VideoSnapshot screen = env.console.video().snapshot();

SerialPrograms/Source/PokemonSwSh/Programs/RNG/PokemonSwSh_DailyHighlightRNG.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
1313
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1414
#include "Common/Cpp/Options/StaticTextOption.h"
15+
#include "Common/Cpp/Options/TimeDurationOption.h"
1516
#include "CommonFramework/Notifications/EventNotificationsTable.h"
16-
#include "CommonFramework/Options/LanguageOCROption.h"
17-
#include "CommonFramework/Options/StringSelectTableOption.h"
17+
#include "CommonTools/Options/LanguageOCROption.h"
18+
#include "CommonTools/Options/StringSelectTableOption.h"
1819
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
1920
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
2021
#include "Pokemon/Pokemon_Xoroshiro128Plus.h"
@@ -38,7 +39,7 @@ class DailyHighlightRNG : public SingleSwitchProgramInstance{
3839
public:
3940
DailyHighlightRNG();
4041

41-
virtual void program(SingleSwitchProgramEnvironment& env, BotBaseContext& context) override;
42+
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
4243

4344
private:
4445
StartInGripOrGameOption START_LOCATION;
@@ -50,19 +51,25 @@ class DailyHighlightRNG : public SingleSwitchProgramInstance{
5051
EventNotificationsOption NOTIFICATIONS;
5152

5253
SectionDividerOption m_advanced_options;
54+
MillisecondsOption MOVE_TIME;
55+
SimpleIntegerOption<uint8_t> LEFT_X;
56+
SimpleIntegerOption<uint8_t> LEFT_Y;
57+
SimpleIntegerOption<uint8_t> RIGHT_X;
58+
SimpleIntegerOption<uint8_t> RIGHT_Y;
59+
5360
SimpleIntegerOption<uint32_t> MAX_UNKNOWN_ADVANCES;
54-
SimpleIntegerOption<uint16_t> ADVANCE_PRESS_DURATION;
55-
SimpleIntegerOption<uint16_t> ADVANCE_RELEASE_DURATION;
61+
MillisecondsOption ADVANCE_PRESS_DURATION;
62+
MillisecondsOption ADVANCE_RELEASE_DURATION;
5663
BooleanCheckBoxOption SAVE_SCREENSHOTS;
5764
BooleanCheckBoxOption LOG_VALUES;
5865

59-
void move_to_trader(SingleSwitchProgramEnvironment& env, BotBaseContext& context);
60-
uint8_t calibrate_num_npc_from_party(SingleSwitchProgramEnvironment& env, BotBaseContext& context, Pokemon::Xoroshiro128Plus& rng);
61-
void navigate_to_party(SingleSwitchProgramEnvironment& env, BotBaseContext& context);
66+
void move_to_trader(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
67+
uint8_t calibrate_num_npc_from_party(SingleSwitchProgramEnvironment& env, ProControllerContext& context, Pokemon::Xoroshiro128Plus& rng);
68+
void navigate_to_party(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
6269
size_t calculate_target(SingleSwitchProgramEnvironment& env, Pokemon::Xoroshiro128PlusState state, uint8_t num_npcs, std::vector<std::string> wanted_highlights);
63-
void leave_to_overworld_and_interact(SingleSwitchProgramEnvironment& env, BotBaseContext& context, bool buy_highlight);
64-
void recover_from_wrong_state(SingleSwitchProgramEnvironment& env, BotBaseContext& context);
65-
void advance_date(SingleSwitchProgramEnvironment& env, BotBaseContext& context, uint8_t& year);
70+
void leave_to_overworld_and_interact(SingleSwitchProgramEnvironment& env, ProControllerContext& context, bool buy_highlight);
71+
void recover_from_wrong_state(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
72+
void advance_date(SingleSwitchProgramEnvironment& env, ProControllerContext& context, uint8_t& year);
6673
};
6774

6875

SerialPrograms/Source/PokemonSwSh/Resources/PokemonSwSh_DailyHighlightDatabase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define PokemonAutomation_PokemonSwSh_DailyHighlightDatabase_H
99

1010
#include <map>
11-
#include "CommonFramework/Options/StringSelectOption.h"
11+
#include "CommonTools/Options/StringSelectOption.h"
1212

1313
namespace PokemonAutomation {
1414
namespace NintendoSwitch {

0 commit comments

Comments
 (0)