Skip to content

Commit bdcf8ea

Browse files
committed
2 parents e239334 + 3024d1f commit bdcf8ea

File tree

7 files changed

+410
-2
lines changed

7 files changed

+410
-2
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,8 @@ file(GLOB MAIN_SOURCES
13241324
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h
13251325
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp
13261326
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h
1327+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.cpp
1328+
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.h
13271329
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp
13281330
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h
13291331
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.cpp

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
1212
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1313
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
14+
#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h"
15+
#include "PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h"
1416
#include "PokemonRSE/PokemonRSE_Settings.h"
1517
#include "PokemonRSE_Navigation.h"
1618

@@ -48,6 +50,112 @@ void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerCo
4850
context.wait_for_all_requests();
4951
}
5052

53+
void flee_battle(VideoStream& stream, SwitchControllerContext& context) {
54+
stream.log("Navigate to Run.");
55+
pbf_press_dpad(context, DPAD_RIGHT, 20, 20);
56+
pbf_press_dpad(context, DPAD_DOWN, 20, 20);
57+
pbf_press_button(context, BUTTON_A, 20, 40);
58+
59+
AdvanceBattleDialogWatcher ran_away(COLOR_YELLOW);
60+
int ret2 = wait_until(
61+
stream, context,
62+
std::chrono::seconds(5),
63+
{{ran_away}}
64+
);
65+
if (ret2 == 0) {
66+
stream.log("Running away...");
67+
} else {
68+
OperationFailedException::fire(
69+
ErrorReport::SEND_ERROR_REPORT,
70+
"handle_encounter(): Unable to navigate to flee button.",
71+
stream
72+
);
73+
}
74+
75+
pbf_press_button(context, BUTTON_A, 40, 40);
76+
BlackScreenOverWatcher battle_over(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
77+
int ret3 = wait_until(
78+
stream, context,
79+
std::chrono::seconds(5),
80+
{{battle_over}}
81+
);
82+
if (ret3 == 0) {
83+
stream.log("Ran from battle.");
84+
} else {
85+
OperationFailedException::fire(
86+
ErrorReport::SEND_ERROR_REPORT,
87+
"handle_encounter(): Unable to flee from battle.",
88+
stream
89+
);
90+
}
91+
}
92+
93+
bool handle_encounter(VideoStream& stream, SwitchControllerContext& context) {
94+
float shiny_coefficient = 1.0;
95+
ShinySoundDetector shiny_detector(stream.logger(), [&](float error_coefficient) -> bool{
96+
shiny_coefficient = error_coefficient;
97+
return true;
98+
});
99+
AdvanceBattleDialogWatcher legendary_appeared(COLOR_YELLOW);
100+
101+
stream.log("Starting battle.");
102+
pbf_mash_button(context, BUTTON_A, 540);
103+
context.wait_for_all_requests();
104+
105+
int res = run_until<SwitchControllerContext>(
106+
stream, context,
107+
[&](SwitchControllerContext& context) {
108+
int ret = wait_until(
109+
stream, context,
110+
std::chrono::seconds(30),
111+
{{legendary_appeared}}
112+
);
113+
if (ret == 0) {
114+
stream.log("Advance arrow detected.");
115+
} else {
116+
OperationFailedException::fire(
117+
ErrorReport::SEND_ERROR_REPORT,
118+
"handle_encounter(): Did not detect battle start.",
119+
stream
120+
);
121+
}
122+
pbf_wait(context, 125);
123+
context.wait_for_all_requests();
124+
},
125+
{{shiny_detector}}
126+
);
127+
shiny_detector.throw_if_no_sound();
128+
if (res == 0){
129+
stream.log("Shiny detected!");
130+
return true;
131+
}
132+
stream.log("Shiny not found.");
133+
134+
//Send out lead, no shiny detection needed.
135+
BattleMenuWatcher battle_menu(COLOR_RED);
136+
stream.log("Sending out lead Pokemon.");
137+
pbf_press_button(context, BUTTON_A, 40, 40);
138+
139+
int ret = wait_until(
140+
stream, context,
141+
std::chrono::seconds(15),
142+
{{battle_menu}}
143+
);
144+
if (ret == 0) {
145+
stream.log("Battle menu detecteed!");
146+
} else {
147+
OperationFailedException::fire(
148+
ErrorReport::SEND_ERROR_REPORT,
149+
"handle_encounter(): Did not detect battle menu.",
150+
stream
151+
);
152+
}
153+
pbf_wait(context, 125);
154+
context.wait_for_all_requests();
155+
156+
return false;
157+
}
158+
51159

52160
}
53161
}

SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ namespace PokemonRSE{
2222
// For now this assumes no dry battery.
2323
void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext &context);
2424

25+
// Run from battle. Cursor must start on the FIGHT button. Assumes fleeing will always work. (Smoke Ball)
26+
void flee_battle(VideoStream& stream, SwitchControllerContext& context);
27+
28+
// After press A/walking up to enter a battle, run this handle the battle start and to check if opponent is shiny.
29+
// Use flee_battle or soft_reset after this, depending on game.
30+
bool handle_encounter(VideoStream& stream, SwitchControllerContext& context);
31+
2532

2633
}
2734
}

SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "PokemonRSE_Settings.h"
1212

1313
#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
14+
#include "Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.h"
15+
1416
#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
1517
#include "Programs/TestPrograms/PokemonRSE_SoundListener.h"
1618

@@ -32,8 +34,11 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3234

3335
//ret.emplace_back("---- General ----");
3436

35-
ret.emplace_back("---- Shiny Hunting ----");
37+
ret.emplace_back("---- Shiny Hunting (Ruby/Sapphire) ----");
3638
ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());
39+
40+
ret.emplace_back("---- Shiny Hunting (Emerald) ----");
41+
ret.emplace_back(make_single_switch_program<ShinyHuntDeoxys_Descriptor, ShinyHuntDeoxys>());
3742

3843

3944
if (PreloadSettings::instance().DEVELOPER_MODE){

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace PokemonRSE{
2323
AudioStarterReset_Descriptor::AudioStarterReset_Descriptor()
2424
: SingleSwitchProgramDescriptor(
2525
"PokemonRSE:AudioStarterReset",
26-
Pokemon::STRING_POKEMON + " RSE", "Starter Reset (Ruby/Sapphire)",
26+
Pokemon::STRING_POKEMON + " RSE", "Starter Reset",
2727
"ComputerControl/blob/master/Wiki/Programs/PokemonRSE/AudioStarterReset.md",
2828
"Soft reset for a shiny starter. Ruby and Sapphire only.",
2929
FeedbackType::VIDEO_AUDIO,

0 commit comments

Comments
 (0)