Skip to content

Commit 42976ae

Browse files
author
Gin
committed
write movement routine to reach Ansha from pokecenter
1 parent 548c9b8 commit 42976ae

File tree

7 files changed

+108
-14
lines changed

7 files changed

+108
-14
lines changed

SerialPrograms/Source/PokemonLZA/Programs/Farming/PokemonLZA_DonutMaker.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1414
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1515
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
16+
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
17+
#include "PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h"
1618
#include "Pokemon/Pokemon_Strings.h"
1719
#include "PokemonLZA/Programs/PokemonLZA_BasicNavigation.h"
1820
#include "PokemonLZA_DonutMaker.h"
@@ -72,6 +74,98 @@ DonutMaker::DonutMaker()
7274
// Return true if it should stop
7375
// Start the iteration at closest pokemon center
7476
bool donut_iteration(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
77+
bool zoom_to_max = false;
78+
open_map(env.console, context, zoom_to_max);
79+
// Move map cursor upwards a little bit
80+
pbf_move_left_joystick(context, 128, 64, 100ms, 200ms);
81+
// Press Y to load fast travel locaiton menu. The cursor should now points to Vert Pokemon Center
82+
pbf_press_button(context, BUTTON_Y, 125ms, 200ms);
83+
// Move one menu item up to select Hotel Z
84+
pbf_press_dpad(context, DPAD_UP, 125ms, 200ms);
85+
86+
OverworldPartySelectionWatcher overworld(COLOR_WHITE, &env.console.overlay());
87+
int ret = run_until<ProControllerContext>(
88+
env.console, context,
89+
[&](ProControllerContext& context){
90+
pbf_mash_button(context, BUTTON_A, Seconds(10));
91+
pbf_wait(context, Seconds(30));
92+
},
93+
{overworld}
94+
);
95+
if (ret != 0){
96+
OperationFailedException::fire(
97+
ErrorReport::SEND_ERROR_REPORT,
98+
"donut_maker(): Unable to find overworld after fast traveling from Vert Pokemon Cenetr after 30 sec.",
99+
env.console
100+
);
101+
}
102+
103+
ret = run_towards_gate_with_A_button(env.console, context, 128, 0, Seconds(5));
104+
if (ret == 1){
105+
if (run_towards_gate_with_A_button(env.console, context, 128, 0, Seconds(5)) != 0){
106+
OperationFailedException::fire(
107+
ErrorReport::SEND_ERROR_REPORT,
108+
"donut_maker(): Cannot reach Hotel Z gate after day/night change.",
109+
env.console
110+
);
111+
}
112+
} else if (ret != 0){
113+
OperationFailedException::fire(
114+
ErrorReport::SEND_ERROR_REPORT,
115+
"donut_maker(): Cannot reach Hotel Z gate after fast travel.",
116+
env.console
117+
);
118+
}
119+
120+
// Mash button A to enter the hotel.
121+
pbf_mash_button(context, BUTTON_A, Seconds(2));
122+
context.wait_for_all_requests();
123+
WallClock start_time = current_time();
124+
// We use 50s here to account for day night change
125+
wait_until_overworld(env.console, context, 50s);
126+
env.console.log("Detected overworld after entering zone.");
127+
WallClock end_time = current_time();
128+
const auto duration = end_time - start_time;
129+
// Due to day/night change may eating the mashing button A sequence, we may still be outside the hotel!
130+
if (duration >= 16s){
131+
// mash A again to make sure we are inside the hotel
132+
pbf_mash_button(context, BUTTON_A, Seconds(2));
133+
context.wait_for_all_requests();
134+
wait_until_overworld(env.console, context, 50s);
135+
}
136+
137+
// we are now inside the hotel
138+
139+
// Roll forward twice
140+
pbf_press_button(context, BUTTON_Y, 100ms, 1s);
141+
pbf_press_button(context, BUTTON_Y, 100ms, 1s);
142+
pbf_move_left_joystick(context, 0, 128, 500ms, 100ms);
143+
context.wait_for_all_requests();
144+
145+
146+
const ImageFloatBox button_A_box{0.3, 0.2, 0.4, 0.7};
147+
ButtonWatcher buttonA(COLOR_RED, ButtonType::ButtonA, button_A_box, &env.console.overlay());
148+
ret = wait_until(env.console, context, std::chrono::seconds(3), {buttonA});
149+
if (ret != 0){
150+
OperationFailedException::fire(
151+
ErrorReport::SEND_ERROR_REPORT,
152+
"donut_maker(): Unable to find button A facing Ansha.",
153+
env.console
154+
);
155+
}
156+
// press button A to start talking to Ansha
157+
pbf_press_button(context, BUTTON_A, 100ms, 200ms);
158+
context.wait_for_all_requests();
159+
FlatWhiteDialogWatcher white_dialog(COLOR_WHITE, &env.console.overlay());
160+
ret = wait_until(env.console, context, std::chrono::seconds(2), {white_dialog});
161+
if (ret != 0){
162+
OperationFailedException::fire(
163+
ErrorReport::SEND_ERROR_REPORT,
164+
"donut_maker(): Unable to detect white dialog after talking to Ansha.",
165+
env.console
166+
);
167+
}
168+
return true;
75169

76170
return false;
77171
}
@@ -82,6 +176,10 @@ void DonutMaker::program(SingleSwitchProgramEnvironment& env, ProControllerConte
82176

83177
assert_16_9_1080p_min(env.logger(), env.console);
84178

179+
// Mash button B to let Switch register the controller
180+
pbf_mash_button(context, BUTTON_B, 500ms);
181+
182+
85183
while(true){
86184
const bool should_stop = donut_iteration(env, context);
87185
stats.resets++;

SerialPrograms/Source/PokemonLZA/Programs/Farming/PokemonLZA_HyperspaceRewardReset.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ HyperspaceRewardReset::HyperspaceRewardReset()
6767
true
6868
)
6969
, TARGET_ITEMS("<b>Items:</b>")
70-
, GO_HOME_WHEN_DONE(true)
7170
, NOTIFICATION_REWARD_MATCH("Matching Reward", true, false, ImageAttachmentMode::JPG, { "Notifs" })
7271
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
7372
, NOTIFICATIONS({
@@ -79,7 +78,6 @@ HyperspaceRewardReset::HyperspaceRewardReset()
7978
{
8079
PA_ADD_OPTION(LANGUAGE);
8180
PA_ADD_OPTION(TARGET_ITEMS);
82-
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
8381
PA_ADD_OPTION(NOTIFICATIONS);
8482
}
8583

@@ -224,7 +222,7 @@ void HyperspaceRewardReset::program(SingleSwitchProgramEnvironment& env, ProCont
224222
}
225223

226224
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
227-
GO_HOME_WHEN_DONE.run_end_of_program(context);
225+
go_home(env.console, context);
228226
}
229227

230228
}

SerialPrograms/Source/PokemonLZA/Programs/Farming/PokemonLZA_HyperspaceRewardReset.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class HyperspaceRewardReset : public SingleSwitchProgramInstance{
3232
private:
3333
OCR::LanguageOCROption LANGUAGE;
3434
HyperspaceRewardTable TARGET_ITEMS;
35-
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
3635

3736
EventNotificationOption NOTIFICATION_REWARD_MATCH;
3837
EventNotificationOption NOTIFICATION_STATUS_UPDATE;

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ bool leave_zone_gate(ConsoleHandle& console, ProControllerContext& context){
542542
}
543543

544544

545-
int run_towards_wild_zone_gate(
545+
int run_towards_gate_with_A_button(
546546
ConsoleHandle& console, ProControllerContext& context,
547547
uint8_t run_direction_x, uint8_t run_direction_y,
548548
PokemonAutomation::Milliseconds run_time

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ double get_angle_between_facing_directions(double dir1, double dir2);
117117
// If the program mashes A after leaving the zone, it will stuck talking to the npcs.
118118
bool leave_zone_gate(ConsoleHandle& console, ProControllerContext& context);
119119

120-
// Run towards a wild zone until either button A is detected at specified box region,
120+
// Run towards a gate until either button A is detected at specified box region,
121121
// or day/night change happens. If day/night changes, it will wait until the transition
122122
// animation is done.
123123
// Return
124124
// - 0 if button A is detected
125125
// - 1 if day/night change happens
126126
// - -1 if it does not reach the gate in the end. Possible reasons are wrong run direction
127127
// or get stuck by terrain or obstacle on the way
128-
int run_towards_wild_zone_gate(
128+
int run_towards_gate_with_A_button(
129129
ConsoleHandle& console, ProControllerContext& context,
130130
uint8_t run_direction_x, uint8_t run_direction_y,
131131
Milliseconds run_time

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneCafe.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "CommonFramework/ProgramStats/StatsTracking.h"
1212
#include "CommonFramework/Notifications/ProgramNotifications.h"
1313
#include "CommonFramework/Globals.h"
14-
// #include "CommonFramework/Tools/DebugDumper.h"
1514
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1615
#include "CommonTools/Async/InferenceRoutines.h"
1716
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
@@ -178,7 +177,7 @@ void do_one_cafe_trip(
178177
break;
179178
}
180179

181-
int ret = run_towards_wild_zone_gate(env.console, context, move_x, move_y, Seconds(10));
180+
int ret = run_towards_gate_with_A_button(env.console, context, move_x, move_y, Seconds(10));
182181
switch (ret){
183182
case 0: // Found button A. Reached the gate.
184183
break;
@@ -196,7 +195,7 @@ void do_one_cafe_trip(
196195
env.console.overlay().add_log("Running Forward");
197196
}
198197
// Running forward or backward depends on character facing to go back to zone entrance
199-
ret = run_towards_wild_zone_gate(env.console, context, move_x, move_y, Seconds(10));
198+
ret = run_towards_gate_with_A_button(env.console, context, move_x, move_y, Seconds(10));
200199
if (ret != 0){
201200
stats.errors++;
202201
env.update_stats();

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void go_to_entrance(
179179
starting_direction = get_facing_direction(env.console, context);
180180
joystick_x = 145;
181181
}
182-
int ret = run_towards_wild_zone_gate(env.console, context, joystick_x, 0, 10s);
182+
int ret = run_towards_gate_with_A_button(env.console, context, joystick_x, 0, 10s);
183183
switch(ret){
184184
case 0: // detected button A. Reached gate
185185
break;
@@ -188,7 +188,7 @@ void go_to_entrance(
188188
get_angle_between_facing_directions(starting_direction, get_facing_direction(env.console, context)) > 2.5){
189189
joystick_x = 128; // we've already turned. Just need to go forward to enter the zone
190190
}
191-
ret = run_towards_wild_zone_gate(env.console, context, joystick_x, 0, 10s);
191+
ret = run_towards_gate_with_A_button(env.console, context, joystick_x, 0, 10s);
192192
if (ret != 0){
193193
OperationFailedException::fire(
194194
ErrorReport::SEND_ERROR_REPORT,
@@ -321,7 +321,7 @@ void leave_zone_and_reset_spawns(
321321

322322
const double starting_direction = get_facing_direction(env.console, context);
323323

324-
int ret = run_towards_wild_zone_gate(env.console, context, 128, 255, walk_time_in_zone);
324+
int ret = run_towards_gate_with_A_button(env.console, context, 128, 255, walk_time_in_zone);
325325
switch (ret){
326326
case 0: // Found button A. Reached the gate.
327327
break;
@@ -352,7 +352,7 @@ void leave_zone_and_reset_spawns(
352352
}
353353

354354
// Running forward or backward depends on character facing to go back to zone entrance
355-
ret = run_towards_wild_zone_gate(env.console, context, 128, joystick_y, walk_time_in_zone);
355+
ret = run_towards_gate_with_A_button(env.console, context, 128, joystick_y, walk_time_in_zone);
356356
if (ret != 0){
357357
stats.errors++;
358358
env.update_stats();

0 commit comments

Comments
 (0)