Skip to content

Commit 6599616

Browse files
kichithewolfGin890
authored andcommitted
use new light blue dialog detection
1 parent e3dcad1 commit 6599616

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

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

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -85,61 +85,61 @@ HyperspaceRewardReset::HyperspaceRewardReset()
8585

8686
void HyperspaceRewardReset::talk_to_trainer(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
8787
HyperspaceRewardReset_Descriptor::Stats& stats = env.current_stats<HyperspaceRewardReset_Descriptor::Stats>();
88-
context.wait_for_all_requests();
89-
90-
env.log("Looking for A button.");
91-
ButtonWatcher buttonA_watcher(
92-
COLOR_WHITE,
93-
ButtonType::ButtonA,
94-
{0.1, 0.1, 0.8, 0.8},
95-
&env.console.overlay()
96-
);
97-
int ret = wait_until(
98-
env.console, context,
99-
10s,
100-
{
101-
buttonA_watcher,
102-
}
103-
);
104-
if (ret == 0) {
105-
env.log("Detected A button.");
106-
pbf_press_button(context, BUTTON_A, 80ms, 40ms);
107-
}
108-
else {
109-
stats.errors++;
110-
env.update_stats();
111-
OperationFailedException::fire(
112-
ErrorReport::SEND_ERROR_REPORT,
113-
"talk_to_trainer(): Failed to detect A button.",
114-
env.console
88+
89+
bool exit = false;
90+
while (!exit){
91+
context.wait_for_all_requests();
92+
93+
ButtonWatcher buttonA_watcher(
94+
COLOR_WHITE,
95+
ButtonType::ButtonA,
96+
{0.1, 0.1, 0.8, 0.8},
97+
&env.console.overlay()
11598
);
116-
}
117-
context.wait_for_all_requests();
118-
119-
BlueDialogWatcher blue_dialog_watcher(COLOR_BLUE, &env.console.overlay());
120-
env.log("Pressing A until item received dialog.");
121-
//First dialog box varies by trainer (hologram, regular, etc.)
122-
int ret_blue = run_until<ProControllerContext>(
123-
env.console, context,
124-
[](ProControllerContext& context){
125-
for (int i = 0; i < 20; i++) {
126-
pbf_press_button(context, BUTTON_A, 80ms, 100ms);
127-
pbf_wait(context, 1000ms);
128-
context.wait_for_all_requests();
99+
//First dialog box varies by trainer (hologram, regular, etc.)
100+
BlueDialogWatcher blue_dialog_watcher(COLOR_BLUE, &env.console.overlay()); //Item received (not the big box)
101+
FlatWhiteDialogWatcher white_dialog_watcher(COLOR_WHITE, &env.console.overlay()); //Non-hologram
102+
LightBlueDialogWatcher light_blue_dialog_watcher(COLOR_WHITE, &env.console.overlay()); //hologram
103+
104+
int ret = wait_until(
105+
env.console, context,
106+
10s,
107+
{
108+
buttonA_watcher,
109+
blue_dialog_watcher,
110+
white_dialog_watcher,
111+
light_blue_dialog_watcher,
129112
}
130-
},
131-
{ blue_dialog_watcher }
132-
);
133-
if (ret_blue != 0){
134-
stats.errors++;
135-
env.update_stats();
136-
OperationFailedException::fire(
137-
ErrorReport::SEND_ERROR_REPORT,
138-
"talk_to_trainer(): Failed to detect blue item received dialog after 20 A presses.",
139-
env.console
140113
);
114+
context.wait_for(100ms);
115+
116+
switch (ret){
117+
case 0:
118+
env.log("Detected A button.");
119+
pbf_press_button(context, BUTTON_A, 80ms, 40ms);
120+
continue;
121+
case 1:
122+
env.log("Detected item received dialog.");
123+
exit = true;
124+
break;
125+
case 2:
126+
env.log("Detected white dialog.");
127+
pbf_press_button(context, BUTTON_A, 80ms, 40ms);
128+
continue;
129+
case 3:
130+
env.log("Detected light blue dialog.");
131+
pbf_press_button(context, BUTTON_A, 80ms, 40ms);
132+
continue;
133+
default:
134+
stats.errors++;
135+
env.update_stats();
136+
OperationFailedException::fire(
137+
ErrorReport::SEND_ERROR_REPORT,
138+
"talk_to_trainer(): Failed to detect blue item received dialog.",
139+
env.console
140+
);
141+
}
141142
}
142-
context.wait_for_all_requests();
143143
}
144144

145145
//Check reward and notify if it matches filters

0 commit comments

Comments
 (0)