Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Jan 31, 2025
2 parents e239334 + 3024d1f commit bdcf8ea
Show file tree
Hide file tree
Showing 7 changed files with 410 additions and 2 deletions.
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonRSE/Inference/PokemonRSE_ShinyNumberDetector.h
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.cpp
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.cpp
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.h
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.cpp
Source/PokemonRSE/Programs/ShinyHunting/PokemonRSE_StarterReset.h
Source/PokemonRSE/Programs/TestPrograms/PokemonRSE_SoundListener.cpp
Expand Down
108 changes: 108 additions & 0 deletions SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
#include "PokemonRSE/Inference/Dialogs/PokemonRSE_DialogDetector.h"
#include "PokemonRSE/Inference/Sounds/PokemonRSE_ShinySoundDetector.h"
#include "PokemonRSE/PokemonRSE_Settings.h"
#include "PokemonRSE_Navigation.h"

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

void flee_battle(VideoStream& stream, SwitchControllerContext& context) {
stream.log("Navigate to Run.");
pbf_press_dpad(context, DPAD_RIGHT, 20, 20);
pbf_press_dpad(context, DPAD_DOWN, 20, 20);
pbf_press_button(context, BUTTON_A, 20, 40);

AdvanceBattleDialogWatcher ran_away(COLOR_YELLOW);
int ret2 = wait_until(
stream, context,
std::chrono::seconds(5),
{{ran_away}}
);
if (ret2 == 0) {
stream.log("Running away...");
} else {
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"handle_encounter(): Unable to navigate to flee button.",
stream
);
}

pbf_press_button(context, BUTTON_A, 40, 40);
BlackScreenOverWatcher battle_over(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
int ret3 = wait_until(
stream, context,
std::chrono::seconds(5),
{{battle_over}}
);
if (ret3 == 0) {
stream.log("Ran from battle.");
} else {
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"handle_encounter(): Unable to flee from battle.",
stream
);
}
}

bool handle_encounter(VideoStream& stream, SwitchControllerContext& context) {
float shiny_coefficient = 1.0;
ShinySoundDetector shiny_detector(stream.logger(), [&](float error_coefficient) -> bool{
shiny_coefficient = error_coefficient;
return true;
});
AdvanceBattleDialogWatcher legendary_appeared(COLOR_YELLOW);

stream.log("Starting battle.");
pbf_mash_button(context, BUTTON_A, 540);
context.wait_for_all_requests();

int res = run_until<SwitchControllerContext>(
stream, context,
[&](SwitchControllerContext& context) {
int ret = wait_until(
stream, context,
std::chrono::seconds(30),
{{legendary_appeared}}
);
if (ret == 0) {
stream.log("Advance arrow detected.");
} else {
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"handle_encounter(): Did not detect battle start.",
stream
);
}
pbf_wait(context, 125);
context.wait_for_all_requests();
},
{{shiny_detector}}
);
shiny_detector.throw_if_no_sound();
if (res == 0){
stream.log("Shiny detected!");
return true;
}
stream.log("Shiny not found.");

//Send out lead, no shiny detection needed.
BattleMenuWatcher battle_menu(COLOR_RED);
stream.log("Sending out lead Pokemon.");
pbf_press_button(context, BUTTON_A, 40, 40);

int ret = wait_until(
stream, context,
std::chrono::seconds(15),
{{battle_menu}}
);
if (ret == 0) {
stream.log("Battle menu detecteed!");
} else {
OperationFailedException::fire(
ErrorReport::SEND_ERROR_REPORT,
"handle_encounter(): Did not detect battle menu.",
stream
);
}
pbf_wait(context, 125);
context.wait_for_all_requests();

return false;
}


}
}
Expand Down
7 changes: 7 additions & 0 deletions SerialPrograms/Source/PokemonRSE/PokemonRSE_Navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ namespace PokemonRSE{
// For now this assumes no dry battery.
void soft_reset(const ProgramInfo& info, VideoStream& stream, SwitchControllerContext &context);

// Run from battle. Cursor must start on the FIGHT button. Assumes fleeing will always work. (Smoke Ball)
void flee_battle(VideoStream& stream, SwitchControllerContext& context);

// After press A/walking up to enter a battle, run this handle the battle start and to check if opponent is shiny.
// Use flee_battle or soft_reset after this, depending on game.
bool handle_encounter(VideoStream& stream, SwitchControllerContext& context);


}
}
Expand Down
7 changes: 6 additions & 1 deletion SerialPrograms/Source/PokemonRSE/PokemonRSE_Panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "PokemonRSE_Settings.h"

#include "Programs/ShinyHunting/PokemonRSE_AudioStarterReset.h"
#include "Programs/ShinyHunting/PokemonRSE_ShinyHunt-Deoxys.h"

#include "Programs/ShinyHunting/PokemonRSE_StarterReset.h"
#include "Programs/TestPrograms/PokemonRSE_SoundListener.h"

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

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

ret.emplace_back("---- Shiny Hunting ----");
ret.emplace_back("---- Shiny Hunting (Ruby/Sapphire) ----");
ret.emplace_back(make_single_switch_program<AudioStarterReset_Descriptor, AudioStarterReset>());

ret.emplace_back("---- Shiny Hunting (Emerald) ----");
ret.emplace_back(make_single_switch_program<ShinyHuntDeoxys_Descriptor, ShinyHuntDeoxys>());


if (PreloadSettings::instance().DEVELOPER_MODE){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace PokemonRSE{
AudioStarterReset_Descriptor::AudioStarterReset_Descriptor()
: SingleSwitchProgramDescriptor(
"PokemonRSE:AudioStarterReset",
Pokemon::STRING_POKEMON + " RSE", "Starter Reset (Ruby/Sapphire)",
Pokemon::STRING_POKEMON + " RSE", "Starter Reset",
"ComputerControl/blob/master/Wiki/Programs/PokemonRSE/AudioStarterReset.md",
"Soft reset for a shiny starter. Ruby and Sapphire only.",
FeedbackType::VIDEO_AUDIO,
Expand Down
Loading

0 comments on commit bdcf8ea

Please sign in to comment.