Skip to content

Commit a82ceef

Browse files
committed
Add WIP bench shiny hunt.
1 parent 88e8388 commit a82ceef

File tree

13 files changed

+457
-24
lines changed

13 files changed

+457
-24
lines changed

SerialPrograms/Source/PanelLists.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ ProgramSelect::ProgramSelect(QWidget& parent, PanelHolder& holder)
5454
add(std::make_unique<NintendoSwitch::PokemonSV::PanelListFactory>());
5555

5656
add(std::make_unique<NintendoSwitch::PokemonLZA::PanelListFactory>());
57-
add(std::make_unique<NintendoSwitch::PokemonRSE::PanelListFactory>());
57+
if (PreloadSettings::instance().DEVELOPER_MODE){
58+
add(std::make_unique<NintendoSwitch::PokemonRSE::PanelListFactory>());
59+
}
5860

5961
add(std::make_unique<NintendoSwitch::ZeldaTotK::PanelListFactory>());
6062

SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ GameSettings::GameSettings()
3939
)
4040
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
4141
, START_GAME_WAIT0(
42-
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
42+
"<b>Start Game Wait:</b><br>Wait this long for the game to load.",
4343
LockMode::LOCK_WHILE_RUNNING,
4444
"300 s"
4545
)
4646
, ENTER_GAME_MASH0(
47-
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
47+
"<b>Enter Game Mash:</b><br>Mash A for this long to enter the game.",
4848
LockMode::LOCK_WHILE_RUNNING,
4949
"5000 ms"
5050
)
5151
, ENTER_GAME_WAIT0(
52-
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
52+
"<b>Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
5353
LockMode::LOCK_WHILE_RUNNING,
5454
"300 s"
5555
)

SerialPrograms/Source/PokemonLA/PokemonLA_Settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ GameSettings::GameSettings()
4040
)
4141
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
4242
, START_GAME_WAIT1(
43-
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
43+
"<b>Start Game Wait:</b><br>Wait this long for the game to load.",
4444
LockMode::LOCK_WHILE_RUNNING,
4545
"40 s"
4646
)
4747
, ENTER_GAME_MASH0(
48-
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
48+
"<b>Enter Game Mash:</b><br>Mash A for this long to enter the game.",
4949
LockMode::LOCK_WHILE_RUNNING,
5050
"5000 ms"
5151
)
5252
, ENTER_GAME_WAIT0(
53-
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
53+
"<b>Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
5454
LockMode::LOCK_WHILE_RUNNING,
5555
"15 s"
5656
)

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ GameSettings::GameSettings()
2929
)
3030
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
3131
, START_GAME_WAIT1(
32-
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
32+
"<b>Start Game Wait:</b><br>Wait this long for the game to load.",
3333
LockMode::LOCK_WHILE_RUNNING,
3434
"20 s"
3535
)
3636
, ENTER_GAME_MASH0(
37-
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
37+
"<b>Enter Game Mash:</b><br>Mash A for this long to enter the game.",
3838
LockMode::LOCK_WHILE_RUNNING,
3939
"5 s"
4040
)
4141
, ENTER_GAME_WAIT0(
42-
"<b>4. Enter Game Wait:</b><br>Wait this long for the opening animations to finish.",
42+
"<b>Enter Game Wait:</b><br>Wait this long for the opening animations to finish.",
4343
LockMode::LOCK_WHILE_RUNNING,
4444
"15 s"
4545
)
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* Shiny Detected Action
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Exceptions.h"
8+
#include "CommonFramework/Notifications/ProgramNotifications.h"
9+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
10+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
11+
#include "Pokemon/Pokemon_Notification.h"
12+
#include "PokemonLZA_ShinyDetectedAction.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonLZA{
17+
18+
19+
20+
ShinyDetectedActionOption::ShinyDetectedActionOption(
21+
std::string label, std::string description,
22+
std::string default_delay,
23+
ShinyDetectedActionType default_action
24+
)
25+
: GroupOption(std::move(label), LockMode::UNLOCK_WHILE_RUNNING)
26+
, DESCRIPTION(std::move(description))
27+
, ACTION(
28+
"<b>Action:</b>",
29+
{
30+
{ShinyDetectedActionType::IGNORE, "ignore", "Ignore the shiny. Do not stop the program."},
31+
{ShinyDetectedActionType::STOP_PROGRAM, "stop", "Stop program and go Home."},
32+
{ShinyDetectedActionType::STOP_AFTER_COUNT, "stop-count", "Stop program only after X shinies are found."},
33+
},
34+
LockMode::UNLOCK_WHILE_RUNNING,
35+
default_action
36+
)
37+
, MAX_COUNT(
38+
"<b>Max Detections:</b><br>"
39+
"Stop the program after this many shinies are detected.",
40+
LockMode::UNLOCK_WHILE_RUNNING,
41+
10
42+
)
43+
, TAKE_VIDEO(
44+
"<b>Take Video:</b>",
45+
LockMode::UNLOCK_WHILE_RUNNING,
46+
true
47+
)
48+
, SCREENSHOT_DELAY(
49+
"<b>Screenshot Delay:</b><br>"
50+
"Wait this long before taking a screenshot + video of the shiny.<br>"
51+
"Set to zero to skip this. Don't set this too large or the shiny may run away!",
52+
LockMode::UNLOCK_WHILE_RUNNING,
53+
std::move(default_delay)
54+
)
55+
, NOTIFICATIONS(
56+
this->label(),
57+
true, true,
58+
ImageAttachmentMode::JPG,
59+
{"Notifs", "Showcase"}
60+
)
61+
{
62+
if (!DESCRIPTION.text().empty()){
63+
PA_ADD_OPTION(DESCRIPTION);
64+
}
65+
PA_ADD_OPTION(ACTION);
66+
PA_ADD_OPTION(MAX_COUNT);
67+
PA_ADD_OPTION(TAKE_VIDEO);
68+
PA_ADD_OPTION(SCREENSHOT_DELAY);
69+
70+
on_config_value_changed(this);
71+
72+
ACTION.add_listener(*this);
73+
}
74+
ShinyDetectedActionOption::~ShinyDetectedActionOption(){
75+
ACTION.remove_listener(*this);
76+
}
77+
void ShinyDetectedActionOption::on_config_value_changed(void* object){
78+
MAX_COUNT.set_visibility(
79+
ACTION == ShinyDetectedActionType::STOP_AFTER_COUNT
80+
? ConfigOptionState::ENABLED
81+
: ConfigOptionState::HIDDEN
82+
);
83+
}
84+
85+
bool ShinyDetectedActionOption::stop_on_shiny(uint8_t current_count) const{
86+
switch (ACTION){
87+
case ShinyDetectedActionType::IGNORE:
88+
return false;
89+
case ShinyDetectedActionType::STOP_PROGRAM:
90+
return true;
91+
case ShinyDetectedActionType::STOP_AFTER_COUNT:
92+
return current_count >= MAX_COUNT;
93+
default:
94+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid shiny action enum type.");
95+
}
96+
}
97+
98+
99+
100+
101+
102+
103+
104+
105+
bool on_shiny_sound(
106+
ProgramEnvironment& env, VideoStream& stream, ProControllerContext& context,
107+
ShinyDetectedActionOption& options,
108+
uint8_t current_count,
109+
float error_coefficient
110+
){
111+
{
112+
std::ostringstream ss;
113+
ss << "Detected Shiny Sound! (error coefficient = " << error_coefficient << ")";
114+
stream.log(ss.str(), COLOR_BLUE);
115+
}
116+
117+
if (options.TAKE_VIDEO){
118+
context.wait_for(options.SCREENSHOT_DELAY);
119+
pbf_press_button(context, BUTTON_CAPTURE, 2 * TICKS_PER_SECOND, 0);
120+
}
121+
122+
std::vector<std::pair<std::string, std::string>> embeds;
123+
124+
{
125+
std::ostringstream ss;
126+
ss << "Error Coefficient: ";
127+
ss << error_coefficient;
128+
ss << "\n(Shiny may not be visible on the screen.)";
129+
embeds.emplace_back("Detection Results:", ss.str());
130+
}
131+
132+
send_program_notification(
133+
env, options.NOTIFICATIONS,
134+
Pokemon::COLOR_STAR_SHINY,
135+
"Detected Shiny Sound",
136+
embeds, "",
137+
stream.video().snapshot(), true
138+
);
139+
140+
return options.stop_on_shiny(current_count);
141+
}
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
}
161+
}
162+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* Shiny Detected Action
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_ShinyDetectedAction_H
8+
#define PokemonAutomation_PokemonLZA_ShinyDetectedAction_H
9+
10+
#include "Common/Cpp/Options/GroupOption.h"
11+
#include "Common/Cpp/Options/StaticTextOption.h"
12+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
13+
#include "Common/Cpp/Options//TimeDurationOption.h"
14+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
15+
#include "CommonFramework/Notifications/EventNotificationOption.h"
16+
#include "CommonFramework/Tools/VideoStream.h"
17+
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
18+
19+
namespace PokemonAutomation{
20+
class ProgramEnvironment;
21+
namespace NintendoSwitch{
22+
namespace PokemonLZA{
23+
24+
25+
enum class ShinyDetectedActionType{
26+
IGNORE,
27+
STOP_PROGRAM,
28+
STOP_AFTER_COUNT,
29+
};
30+
31+
32+
class ShinyDetectedActionOption : public GroupOption, public ConfigOption::Listener{
33+
public:
34+
~ShinyDetectedActionOption();
35+
ShinyDetectedActionOption(
36+
std::string label, std::string description,
37+
std::string default_delay,
38+
ShinyDetectedActionType default_action = ShinyDetectedActionType::STOP_AFTER_COUNT
39+
);
40+
41+
bool stop_on_shiny(uint8_t current_count) const;
42+
43+
virtual void on_config_value_changed(void* object) override;
44+
45+
StaticTextOption DESCRIPTION;
46+
EnumDropdownOption<ShinyDetectedActionType> ACTION;
47+
SimpleIntegerOption<uint8_t> MAX_COUNT;
48+
BooleanCheckBoxOption TAKE_VIDEO;
49+
MillisecondsOption SCREENSHOT_DELAY;
50+
EventNotificationOption NOTIFICATIONS;
51+
};
52+
53+
54+
55+
bool on_shiny_sound(
56+
ProgramEnvironment& env, VideoStream& stream, ProControllerContext& context,
57+
ShinyDetectedActionOption& options,
58+
uint8_t current_count,
59+
float error_coefficient
60+
);
61+
62+
63+
64+
65+
}
66+
}
67+
}
68+
#endif

SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
#include "PokemonLZA_Settings.h"
1212

13-
#include "Programs/PokemonLZA_RestaurantFarmer.h"
1413
#include "Programs/PokemonLZA_ClothingBuyer.h"
14+
#include "Programs/PokemonLZA_RestaurantFarmer.h"
15+
#include "Programs/PokemonLZA_ShinyHunt_Bench.h"
1516
#include "Programs/TestPrograms/PokemonLZA_OverworldWatcher.h"
1617

1718
namespace PokemonAutomation{
@@ -31,8 +32,13 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3132
ret.emplace_back(make_settings<GameSettings_Descriptor, GameSettingsPanel>());
3233

3334
ret.emplace_back("---- General ----");
34-
ret.emplace_back(make_single_switch_program<RestaurantFarmer_Descriptor, RestaurantFarmer>());
3535
ret.emplace_back(make_single_switch_program<ClothingBuyer_Descriptor, ClothingBuyer>());
36+
ret.emplace_back(make_single_switch_program<RestaurantFarmer_Descriptor, RestaurantFarmer>());
37+
38+
if (PreloadSettings::instance().DEVELOPER_MODE){
39+
ret.emplace_back("---- Shiny Hunting ----");
40+
ret.emplace_back(make_single_switch_program<ShinyHunt_Bench_Descriptor, ShinyHunt_Bench>());
41+
}
3642

3743

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

SerialPrograms/Source/PokemonLZA/PokemonLZA_Settings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ GameSettings::GameSettings()
2424
, m_general("<font size=4><b>General Settings:</b></font>")
2525
, m_start_game_timings("<font size=4><b>Start Game Timings:</b></font>")
2626
, START_GAME_WAIT(
27-
"<b>2. Start Game Wait:</b><br>Wait this long for the game to load.",
27+
"<b>Start Game Wait:</b><br>Wait this long for the game to load.",
2828
LockMode::LOCK_WHILE_RUNNING,
2929
"40 s"
3030
)
3131
, ENTER_GAME_MASH(
32-
"<b>3. Enter Game Mash:</b><br>Mash A for this long to enter the game.",
32+
"<b>Enter Game Mash:</b><br>Mash A for this long to enter the game.",
3333
LockMode::LOCK_WHILE_RUNNING,
3434
"5000 ms"
3535
)
3636
, ENTER_GAME_WAIT(
37-
"<b>4. Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
37+
"<b>Enter Game Wait:</b><br>Wait this long for the game to enter the overworld.",
3838
LockMode::LOCK_WHILE_RUNNING,
3939
"15 s"
4040
)

0 commit comments

Comments
 (0)