Skip to content

Commit 8805cd0

Browse files
committed
Fix the flying trial farmer for ESP32.
1 parent 830a40e commit 8805cd0

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

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

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,52 @@ FlyingTrialFarmer::FlyingTrialFarmer()
114114

115115

116116
bool FlyingTrialFarmer::run_rewards(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
117-
bool trial_failed = true;
117+
// Wait until a dialog shows up.
118+
{
119+
DialogBoxWatcher dialog(COLOR_GREEN, true);
120+
int ret = wait_until(
121+
env.console, context,
122+
std::chrono::seconds(120),
123+
{dialog}
124+
);
125+
if (ret != 0){
126+
OperationFailedException::fire(
127+
ErrorReport::SEND_ERROR_REPORT,
128+
"End of trial not detected after 2 minutes.",
129+
env.console
130+
);
131+
}
132+
env.log("Detected end of trial.");
133+
}
134+
135+
bool trial_passed = false;
118136
while (true){
119-
DialogBoxWatcher dialog(COLOR_GREEN, true, std::chrono::milliseconds(250), DialogType::DIALOG_BLACK);
120137
OverworldWatcher overworld(env.console, COLOR_CYAN);
138+
DialogBoxWatcher dialog_white(COLOR_GREEN, true, std::chrono::milliseconds(250), DialogType::DIALOG_WHITE);
139+
DialogBoxWatcher dialog_black(COLOR_GREEN, true, std::chrono::milliseconds(250), DialogType::DIALOG_BLACK);
121140
context.wait_for_all_requests();
122141

123-
int ret_finish = run_until<ProControllerContext>(
142+
int ret_finish = wait_until(
124143
env.console, context,
125-
[](ProControllerContext& context){
126-
pbf_mash_button(context, BUTTON_B, 10000);
127-
},
128-
{ dialog, overworld }
144+
std::chrono::seconds(80),
145+
{
146+
overworld,
147+
dialog_white,
148+
dialog_black
149+
}
129150
);
130151
context.wait_for_all_requests();
131152

132153
switch (ret_finish){
133-
case 0: // dialog
134-
trial_failed = false;
154+
case 0: // overworld
155+
return trial_passed;
156+
case 1: // white dialog
157+
pbf_press_button(context, BUTTON_B, 160ms, 0ms);
158+
continue;
159+
case 2: // black dialog
160+
pbf_press_button(context, BUTTON_B, 160ms, 0ms);
161+
trial_passed = true;
135162
continue;
136-
case 1: // overworld
137-
return trial_failed;
138163
default:
139164
OperationFailedException::fire(
140165
ErrorReport::SEND_ERROR_REPORT,
@@ -216,6 +241,7 @@ void FlyingTrialFarmer::program(SingleSwitchProgramEnvironment& env, ProControll
216241
pbf_wait(context, 9 * TICKS_PER_SECOND);
217242
break;
218243
case FlightPath::BACK_ENTRY_SOFT_TURN:
244+
#if 0
219245
if (env.console.controller().controller_type() == ControllerType::NintendoSwitch_WirelessProController){
220246
pbf_wait(context, Milliseconds(3000));
221247
pbf_move_left_joystick(context, 180, get_final_y_axis(-108), Milliseconds(1005), Milliseconds(0));
@@ -227,17 +253,17 @@ void FlyingTrialFarmer::program(SingleSwitchProgramEnvironment& env, ProControll
227253
pbf_move_left_joystick(context, 205, get_final_y_axis( 30), Milliseconds(735), Milliseconds(0));
228254
pbf_wait(context, Milliseconds(9000));
229255
}else{
230-
pbf_wait(context, 3 * TICKS_PER_SECOND);
231-
pbf_move_left_joystick(context, 180, get_final_y_axis(-108), 1 * TICKS_PER_SECOND, 0);
232-
pbf_wait(context, 2 * TICKS_PER_SECOND);
233-
pbf_move_left_joystick(context, 40, get_final_y_axis( -78), 240, 0);
234-
pbf_wait(context, 1 * TICKS_PER_SECOND);
235-
pbf_move_left_joystick(context, 110, get_final_y_axis( -78), 2 * TICKS_PER_SECOND, 0);
236-
pbf_wait(context, 14 * TICKS_PER_SECOND);
237-
pbf_move_left_joystick(context, 205, get_final_y_axis( 37), 160, 0);
238-
pbf_wait(context, 9 * TICKS_PER_SECOND);
239-
}
240-
256+
#endif
257+
pbf_wait(context, 3000ms);
258+
pbf_move_left_joystick(context, 180, get_final_y_axis(-108), 1000ms, 0ms);
259+
pbf_wait(context, 2000ms);
260+
pbf_move_left_joystick(context, 40, get_final_y_axis( -78), 1920ms, 0ms);
261+
pbf_wait(context, 1000ms);
262+
pbf_move_left_joystick(context, 110, get_final_y_axis( -78), 2000ms, 0ms);
263+
pbf_wait(context, 14000ms);
264+
pbf_move_left_joystick(context, 205, get_final_y_axis( 37), 1280ms, 0ms);
265+
pbf_wait(context, 9000ms);
266+
// }
241267
break;
242268
case FlightPath::BACK_ENTRY_HARD_TURN:
243269
pbf_wait(context, 3 * TICKS_PER_SECOND);
@@ -253,7 +279,7 @@ void FlyingTrialFarmer::program(SingleSwitchProgramEnvironment& env, ProControll
253279
}
254280
}
255281

256-
if (!run_rewards(env, context)){
282+
if (run_rewards(env, context)){
257283
stats.m_success++;
258284
}else{
259285
stats.m_fail++;

0 commit comments

Comments
 (0)