Skip to content

Commit 50d6611

Browse files
committed
partial working legendary reset, soundlistener fixes
1 parent 0896e03 commit 50d6611

File tree

7 files changed

+232
-5
lines changed

7 files changed

+232
-5
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,8 @@ file(GLOB MAIN_SOURCES
13891389
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.h
13901390
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp
13911391
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h
1392+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp
1393+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h
13921394
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp
13931395
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h
13941396
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ SOURCES += \
681681
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp \
682682
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.cpp \
683683
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp \
684+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp \
684685
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp \
685686
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp \
686687
Source/PokemonLGPE/PokemonLGPE_Panels.cpp \
@@ -1879,6 +1880,7 @@ HEADERS += \
18791880
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h \
18801881
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_FossilRevival.h \
18811882
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h \
1883+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h \
18821884
Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h \
18831885
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h \
18841886
Source/PokemonLGPE/PokemonLGPE_Panels.h \

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h"
1414
#include "Programs/ShinyHunting/PokemonLGPE_FossilRevival.h"
1515
#include "Programs/ShinyHunting/PokemonLGPE_GiftReset.h"
16+
#include "Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h"
1617

1718
#include "Programs/TestPrograms/PokemonLGPE_SoundListener.h"
1819

@@ -37,6 +38,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3738
ret.emplace_back(make_single_switch_program<AlolanTrade_Descriptor, AlolanTrade>());
3839
ret.emplace_back(make_single_switch_program<FossilRevival_Descriptor, FossilRevival>());
3940
ret.emplace_back(make_single_switch_program<GiftReset_Descriptor, GiftReset>());
41+
ret.emplace_back(make_single_switch_program<LegendaryReset_Descriptor, LegendaryReset>());
4042

4143
if (PreloadSettings::instance().DEVELOPER_MODE){
4244
ret.emplace_back("---- Developer Tools ----");
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/* LGPE Legendary Reset
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
8+
#include "CommonFramework/Notifications/ProgramNotifications.h"
9+
#include "CommonFramework/ProgramStats/StatsTracking.h"
10+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
11+
#include "CommonTools/Async/InferenceRoutines.h"
12+
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
13+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
14+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
15+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
16+
#include "Pokemon/Pokemon_Strings.h"
17+
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
18+
#include "PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h"
19+
#include "PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h"
20+
#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h"
21+
#include "PokemonLGPE_LegendaryReset.h"
22+
23+
namespace PokemonAutomation{
24+
namespace NintendoSwitch{
25+
namespace PokemonLGPE{
26+
27+
LegendaryReset_Descriptor::LegendaryReset_Descriptor()
28+
: SingleSwitchProgramDescriptor(
29+
"PokemonLGPE:LegendaryReset",
30+
Pokemon::STRING_POKEMON + " LGPE", "Legendary Reset",
31+
"ComputerControl/blob/master/Wiki/Programs/PokemonLGPE/LegendaryReset.md",
32+
"Shiny hunt Legendary Pokemon by resetting the game.",
33+
FeedbackType::VIDEO_AUDIO,
34+
AllowCommandsWhenRunning::DISABLE_COMMANDS,
35+
{ControllerFeature::NintendoSwitch_RightJoycon},
36+
FasterIfTickPrecise::NOT_FASTER
37+
)
38+
{}
39+
40+
struct LegendaryReset_Descriptor::Stats : public StatsTracker{
41+
Stats()
42+
: resets(m_stats["Resets"])
43+
, shinies(m_stats["Shinies"])
44+
{
45+
m_display_order.emplace_back("Resets");
46+
m_display_order.emplace_back("Shinies");
47+
}
48+
std::atomic<uint64_t>& resets;
49+
std::atomic<uint64_t>& shinies;
50+
};
51+
std::unique_ptr<StatsTracker> LegendaryReset_Descriptor::make_stats() const{
52+
return std::unique_ptr<StatsTracker>(new Stats());
53+
}
54+
55+
LegendaryReset::LegendaryReset()
56+
: GO_HOME_WHEN_DONE(true)
57+
, NOTIFICATION_SHINY(
58+
"Shiny Found",
59+
true, true, ImageAttachmentMode::JPG,
60+
{"Notifs", "Showcase"}
61+
)
62+
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
63+
, NOTIFICATIONS({
64+
&NOTIFICATION_SHINY,
65+
&NOTIFICATION_STATUS_UPDATE,
66+
&NOTIFICATION_PROGRAM_FINISH,
67+
})
68+
{
69+
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
70+
PA_ADD_OPTION(NOTIFICATIONS);
71+
}
72+
73+
bool LegendaryReset::run_battle(SingleSwitchProgramEnvironment& env, JoyconContext& context){
74+
float shiny_coefficient = 1.0;
75+
ShinySoundDetector shiny_detector(env.logger(), [&](float error_coefficient) -> bool{
76+
shiny_coefficient = error_coefficient;
77+
return true;
78+
});
79+
BattleMenuWatcher battle_started(COLOR_YELLOW);
80+
81+
env.log("Starting battle.");
82+
pbf_mash_button(context, BUTTON_A, 25000ms); //10000ms
83+
context.wait_for_all_requests();
84+
85+
int res = run_until<JoyconContext>(
86+
env.console, context,
87+
[&](JoyconContext& context) {
88+
int ret = wait_until(
89+
env.console, context,
90+
std::chrono::seconds(90),
91+
{{battle_started}}
92+
);
93+
if (ret == 0) {
94+
env.log("HP boxes detected.");
95+
} else {
96+
OperationFailedException::fire(
97+
ErrorReport::SEND_ERROR_REPORT,
98+
"run_battle(): Did not detect battle start.",
99+
env.console
100+
);
101+
}
102+
pbf_wait(context, 1000ms);
103+
context.wait_for_all_requests();
104+
},
105+
{{shiny_detector}}
106+
);
107+
shiny_detector.throw_if_no_sound();
108+
if (res == 0){
109+
env.log("Shiny detected!");
110+
return true;
111+
}
112+
env.log("Shiny not found.");
113+
114+
return false;
115+
}
116+
117+
void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
118+
JoyconContext context(scope, env.console.controller<JoyconController>());
119+
assert_16_9_720p_min(env.logger(), env.console);
120+
LegendaryReset_Descriptor::Stats& stats = env.current_stats<LegendaryReset_Descriptor::Stats>();
121+
122+
/*
123+
Setup:
124+
Stand in front of encounter. (And save)
125+
Start the program in game.
126+
Your lead must not be shiny.
127+
128+
Settings:
129+
Text Speed fast
130+
Skip cutscene option?
131+
132+
Mewtwo, Articuno, Zapdos, Moltres, Snorlax, Electrode(?)
133+
Don't do it on the first Snorlax, otherwise have to sit through fuji tutorial
134+
*/
135+
136+
while (true) {
137+
bool encounter_battle = run_battle(env, context);
138+
if (encounter_battle) {
139+
stats.shinies++;
140+
env.update_stats();
141+
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", env.console.video().snapshot(), true);
142+
break;
143+
}
144+
env.log("No shiny found. Resetting game.");
145+
send_program_status_notification(
146+
env, NOTIFICATION_STATUS_UPDATE,
147+
"No shiny found. Resetting game."
148+
);
149+
150+
//Reset game
151+
pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms);
152+
reset_game_from_home(env, env.console, context, 3000ms);
153+
context.wait_for_all_requests();
154+
155+
stats.resets++;
156+
env.update_stats();
157+
}
158+
159+
if (GO_HOME_WHEN_DONE) {
160+
pbf_press_button(context, BUTTON_HOME, 200ms, 1000ms);
161+
}
162+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
163+
}
164+
165+
166+
}
167+
}
168+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* LGPE Legendary Reset
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_LegendaryReset_H
8+
#define PokemonAutomation_PokemonLGPE_LegendaryReset_H
9+
10+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
11+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
12+
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
13+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
14+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
15+
16+
namespace PokemonAutomation{
17+
namespace NintendoSwitch{
18+
namespace PokemonLGPE{
19+
20+
class LegendaryReset_Descriptor : public SingleSwitchProgramDescriptor{
21+
public:
22+
LegendaryReset_Descriptor();
23+
struct Stats;
24+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
25+
};
26+
27+
class LegendaryReset : public SingleSwitchProgramInstance{
28+
public:
29+
LegendaryReset();
30+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
31+
32+
private:
33+
bool run_battle(SingleSwitchProgramEnvironment& env, JoyconContext& context);
34+
35+
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
36+
37+
EventNotificationOption NOTIFICATION_SHINY;
38+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
39+
EventNotificationsOption NOTIFICATIONS;
40+
};
41+
42+
43+
44+
45+
}
46+
}
47+
}
48+
#endif
49+
50+
51+

SerialPrograms/Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include "CommonTools/Audio/SpectrogramMatcher.h"
1919
#include "CommonTools/Async/InferenceSession.h"
2020
#include "Pokemon/Pokemon_Strings.h"
21+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
2122
#include "PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h"
2223
#include "PokemonLGPE_SoundListener.h"
2324

24-
2525
namespace PokemonAutomation{
2626
namespace NintendoSwitch{
2727
namespace PokemonLGPE{
@@ -35,7 +35,8 @@ SoundListener_Descriptor::SoundListener_Descriptor()
3535
"",
3636
"Test sound detectors listening to audio stream.",
3737
FeedbackType::REQUIRED, AllowCommandsWhenRunning::ENABLE_COMMANDS,
38-
{ControllerFeature::NintendoSwitch_RightJoycon}
38+
{ControllerFeature::NintendoSwitch_RightJoycon},
39+
FasterIfTickPrecise::NOT_FASTER
3940
)
4041
{}
4142

@@ -58,7 +59,9 @@ SoundListener::SoundListener()
5859
PA_ADD_OPTION(STOP_ON_DETECTED_SOUND);
5960
}
6061

61-
void SoundListener::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
62+
void SoundListener::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
63+
JoyconContext context(scope, env.console.controller<JoyconController>());
64+
6265
std::cout << "Running audio test program." << std::endl;
6366

6467
std::shared_ptr<AudioInferenceCallback> detector;

SerialPrograms/Source/PokemonLGPE/Programs/TestPrograms/PokemonLGPE_SoundListener.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class SoundListener_Descriptor : public SingleSwitchProgramDescriptor{
2727
class SoundListener : public SingleSwitchProgramInstance{
2828
public:
2929
SoundListener();
30-
31-
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
30+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
3231

3332
virtual void start_program_border_check(
3433
CancellableScope& scope,

0 commit comments

Comments
 (0)