Skip to content

Commit 4bf5931

Browse files
committed
working audio starter detection
1 parent 59beefa commit 4bf5931

File tree

5 files changed

+58
-55
lines changed

5 files changed

+58
-55
lines changed

SerialPrograms/Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool BattleDialogDetector::detect(const ImageViewRGB32& screen) const{
5959

6060

6161
BattleMenuDetector::BattleMenuDetector(Color color)
62-
: m_left_box(0.155, 0.727, 0.015, 0.168)
62+
: m_left_box(0.439, 0.717, 0.021, 0.192)
6363
, m_right_box(0.821, 0.725, 0.030, 0.181)
6464
{}
6565
void BattleMenuDetector::make_overlays(VideoOverlaySet& items) const{

SerialPrograms/Source/PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class BattleDialogWatcher : public DetectorToFinder<BattleDialogDetector>{
6464

6565

6666
// Battle menu is up when it is white on the right and teal on the left
67+
// For emerald the test is more flush to the left, so we target the right of the battle menu box
6768
class BattleMenuDetector : public StaticScreenDetector{
6869
public:
6970
BattleMenuDetector(Color color);

SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3333
//ret.emplace_back("---- General ----");
3434

3535
ret.emplace_back("---- Shiny Hunting ----");
36-
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>());
3736
ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());
3837

3938

4039
if (PreloadSettings::instance().DEVELOPER_MODE){
40+
ret.emplace_back("---- Test ----");
41+
ret.emplace_back(make_single_switch_program<StarterReset_Descriptor, StarterReset>());
42+
4143
ret.emplace_back("---- Developer Tools ----");
4244
ret.emplace_back(make_single_switch_program<SoundListener_Descriptor, SoundListener>());
4345
}

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "CommonFramework/Notifications/ProgramNotifications.h"
1111
#include "CommonFramework/Tools/VideoResolutionCheck.h"
1212
#include "CommonFramework/Tools/StatsTracking.h"
13+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1314
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1415
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1516
#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h"
@@ -62,26 +63,14 @@ AudioStarterReset::AudioStarterReset()
6263
LockMode::LOCK_WHILE_RUNNING,
6364
Target::treecko
6465
)
65-
, POOCH_WAIT(
66-
"<b>Battle start wait:</b><br>Time for battle to start and for Poochyena to appear. Make sure to add extra time in case the Poochyena is shiny.",
67-
LockMode::LOCK_WHILE_RUNNING,
68-
TICKS_PER_SECOND,
69-
"6 * TICKS_PER_SECOND"
70-
)
71-
, STARTER_WAIT(
72-
"<b>Send out starter wait:</b><br>After pressing A to send out your selected starter, wait this long for the animation. Make sure to add extra time in case it is shiny.",
73-
LockMode::LOCK_WHILE_RUNNING,
74-
TICKS_PER_SECOND,
75-
"6 * TICKS_PER_SECOND"
76-
)
7766
, NOTIFICATION_SHINY_POOCH(
7867
"Shiny Poochyena",
79-
false, false,
68+
false, false, ImageAttachmentMode::JPG,
8069
{"Notifs"}
8170
)
8271
, NOTIFICATION_SHINY_STARTER(
8372
"Shiny Starter",
84-
true, false,
73+
true, true, ImageAttachmentMode::JPG,
8574
{"Notifs", "Showcase"}
8675
)
8776
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
@@ -116,8 +105,9 @@ void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseCont
116105

117106
bool shiny_starter = false;
118107
while (!shiny_starter) {
119-
108+
float shiny_coefficient = 1.0;
120109
ShinySoundDetector pooch_detector(env.console, [&](float error_coefficient) -> bool{
110+
shiny_coefficient = error_coefficient;
121111
return true;
122112
});
123113

@@ -143,71 +133,84 @@ void AudioStarterReset::program(SingleSwitchProgramEnvironment& env, BotBaseCont
143133
}
144134
pbf_mash_button(context, BUTTON_A, 540);
145135
context.wait_for_all_requests();
146-
env.log("Starter selected. Checking for shiny Poochyena.");
147136

137+
env.log("Starter selected. Checking for shiny Poochyena.");
148138
AdvanceDialogWatcher pooch_appeared(COLOR_YELLOW);
139+
149140
int res = run_until(
150141
env.console, context,
151142
[&](BotBaseContext& context) {
152143
int ret = wait_until(
153144
env.console, context,
154145
std::chrono::seconds(20),
155-
{{pooch_detector}}
146+
{{pooch_appeared}}
156147
);
157-
pooch_detector.throw_if_no_sound();
158-
if (ret == 0){
159-
env.log("Shiny Poochyena detected!");
160-
stats.poochyena++;
161-
send_program_status_notification(env, NOTIFICATION_SHINY_POOCH, "Shiny Poochyena found.");
162-
}
163-
else {
164-
env.log("Poochyena is not shiny.");
148+
if (ret == 0) {
149+
env.log("Advance arrow detected.");
165150
}
151+
pbf_wait(context, 125);
152+
context.wait_for_all_requests();
166153
},
167-
{{pooch_appeared}}
154+
{{pooch_detector}}
168155
);
169-
if (res == 0) {
170-
env.log("Advance arrow detected. Pressing A.");
171-
} //res != if pooch is shiny
156+
pooch_detector.throw_if_no_sound();
157+
if (res == 0){
158+
env.log("Shiny Poochyena detected!");
159+
stats.poochyena++;
160+
env.update_stats();
161+
send_program_status_notification(env, NOTIFICATION_SHINY_POOCH, "Shiny Poochyena found.", env.console.video().snapshot(), false);
162+
}
163+
else {
164+
env.log("Poochyena is not shiny.");
165+
}
166+
context.wait_for_all_requests();
172167

168+
float shiny_coefficient2 = 1.0;
173169
ShinySoundDetector starter_detector(env.console, [&](float error_coefficient) -> bool{
170+
shiny_coefficient2 = error_coefficient;
174171
return true;
175172
});
176173

177-
//Press A to send out your selected starter
178-
env.log("Sending out selected starter.");
179-
pbf_press_button(context, BUTTON_A, 40, 40);
180-
181-
int ret2 = run_until(
174+
BattleMenuWatcher battle_menu(COLOR_RED);
175+
int res2 = run_until(
182176
env.console, context,
183-
[&](BotBaseContext& context){
184-
env.log("Wait for starter to come out.");
185-
pbf_wait(context, STARTER_WAIT);
177+
[&](BotBaseContext& context) {
178+
env.log("Sending out selected starter.");
179+
pbf_press_button(context, BUTTON_A, 40, 40);
180+
181+
int ret = wait_until(
182+
env.console, context,
183+
std::chrono::seconds(20),
184+
{{battle_menu}}
185+
);
186+
if (ret == 0) {
187+
env.log("Battle menu detecteed!");
188+
}
189+
pbf_wait(context, 125);
186190
context.wait_for_all_requests();
187191
},
188192
{{starter_detector}}
189193
);
190194
starter_detector.throw_if_no_sound();
191-
if (ret2 == 0){
195+
context.wait_for_all_requests();
196+
if (res2 == 0){
192197
env.log("Shiny starter detected!");
193198
stats.shinystarter++;
194-
195-
send_program_status_notification(env, NOTIFICATION_SHINY_STARTER, "Shiny starter found!");
196-
199+
env.update_stats();
200+
send_program_status_notification(env, NOTIFICATION_SHINY_STARTER, "Shiny starter found!", env.console.video().snapshot(), true);
197201
shiny_starter = true;
198-
break;
199202
}
200203
else {
201204
env.log("Starter is not shiny.");
205+
env.log("Soft resetting.");
206+
send_program_status_notification(
207+
env, NOTIFICATION_STATUS_UPDATE,
208+
"Soft resetting."
209+
);
210+
soft_reset(env.program_info(), env.console, context);
211+
stats.resets++;
212+
env.update_stats();
202213
}
203-
204-
env.log("Soft resetting.");
205-
send_program_status_notification(
206-
env, NOTIFICATION_STATUS_UPDATE,
207-
"Soft resetting."
208-
);
209-
soft_reset(env.program_info(), env.console, context);
210-
stats.resets++;
211214
}
212215

213216
//if system set to nintendo switch, have go home when done option?

SerialPrograms/Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class AudioStarterReset : public SingleSwitchProgramInstance{
3636
};
3737
EnumDropdownOption<Target> TARGET;
3838

39-
TimeExpressionOption<uint16_t> POOCH_WAIT;
40-
TimeExpressionOption<uint16_t> STARTER_WAIT;
41-
4239
EventNotificationOption NOTIFICATION_SHINY_POOCH;
4340
EventNotificationOption NOTIFICATION_SHINY_STARTER;
4441
EventNotificationOption NOTIFICATION_STATUS_UPDATE;

0 commit comments

Comments
 (0)