Skip to content

Commit 2b84ea9

Browse files
committed
Fix BDSP box trade.
1 parent abde37b commit 2b84ea9

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

SerialPrograms/Source/PokemonBDSP/Programs/Trading/PokemonBDSP_TradeRoutines.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,40 @@ void trade_current_pokemon(
4141
VideoSnapshot box_image = console.video().snapshot();
4242
ImageMatchWatcher box_detector(std::move(box_image.frame), {0.02, 0.10, 0.15, 0.80}, 50);
4343

44-
{
45-
pbf_press_button(context, BUTTON_ZL, 20, 0);
44+
pbf_press_button(context, BUTTON_ZL, 20, 0);
45+
46+
while (true){
4647
context.wait_for_all_requests();
47-
SelectionArrowFinder detector(console, {0.50, 0.58, 0.40, 0.10}, COLOR_RED);
48+
SelectionArrowFinder detector0(console, {0.50, 0.58, 0.40, 0.10}, COLOR_RED);
49+
SelectionArrowFinder detector1(console, {0.50, 0.52, 0.40, 0.10}, COLOR_RED);
4850
int ret = wait_until(
49-
console, context, std::chrono::seconds(120),
50-
{{detector}}
51+
console, context, std::chrono::seconds(20),
52+
{detector0, detector1}
5153
);
5254
if (ret < 0){
53-
stats.m_errors++;
54-
tracker.report_unrecoverable_error(console, "Failed to detect trade select prompt after 2 minutes.");
5555
}
56-
console.log("Detected trade prompt.");
57-
context.wait_for(std::chrono::milliseconds(100));
58-
tracker.check_unrecoverable_error(console);
59-
}
60-
{
61-
pbf_press_button(context, BUTTON_ZL, 20, 0);
62-
context.wait_for_all_requests();
63-
SelectionArrowFinder detector(console, {0.50, 0.52, 0.40, 0.10}, COLOR_RED);
64-
int ret = wait_until(
65-
console, context, std::chrono::seconds(10),
66-
{{detector}}
67-
);
68-
if (ret < 0){
56+
switch (ret){
57+
case 0:
58+
console.log("Detected trade prompt.");
59+
context.wait_for(std::chrono::milliseconds(100));
60+
tracker.check_unrecoverable_error(console);
61+
pbf_press_button(context, BUTTON_ZL, 20, 0);
62+
continue;
63+
case 1:
64+
console.log("Detected trade confirm prompt.");
65+
context.wait_for(std::chrono::milliseconds(100));
66+
tracker.check_unrecoverable_error(console);
67+
pbf_press_button(context, BUTTON_ZL, 20, 0);
68+
break;
69+
default:
6970
stats.m_errors++;
70-
tracker.report_unrecoverable_error(console, "Failed to detect trade confirm prompt after 10 seconds.");
71+
tracker.report_unrecoverable_error(console, "Failed to detect a prompt after 20 minutes.");
7172
}
72-
console.log("Detected trade confirm prompt.");
73-
context.wait_for(std::chrono::milliseconds(100));
74-
tracker.check_unrecoverable_error(console);
73+
break;
7574
}
7675

7776
// Start trade.
78-
pbf_press_button(context, BUTTON_ZL, 20, 0);
77+
// pbf_press_button(context, BUTTON_ZL, 20, 0);
7978

8079
// Wait for black screen.
8180
{

0 commit comments

Comments
 (0)