Skip to content

Commit 6c55f3a

Browse files
committed
LZA: add shiny hunt wild zone entrance
adjust wait time & fix reposition after shiny sound detected clang-format
1 parent f9f2324 commit 6c55f3a

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Programs/PokemonLZA_RestaurantFarmer.h"
1717
#include "Programs/PokemonLZA_ShinyHunt_BenchSit.h"
1818
#include "Programs/PokemonLZA_ShinyHunt_OverworldReset.h"
19+
#include "Programs/PokemonLZA_ShinyHunt_WildZoneEntrance.h"
1920
#include "Programs/TestPrograms/PokemonLZA_OverworldWatcher.h"
2021
#include "Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h"
2122
#include "Programs/TestPrograms/PokemonLZA_CheckBoxCellInfo.h"
@@ -44,6 +45,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
4445
ret.emplace_back("---- Shiny Hunting ----");
4546
ret.emplace_back(make_single_switch_program<ShinyHunt_BenchSit_Descriptor, ShinyHunt_BenchSit>());
4647
ret.emplace_back(make_single_switch_program<ShinyHunt_OverworldReset_Descriptor, ShinyHunt_OverworldReset>());
48+
ret.emplace_back(make_single_switch_program<ShinyHunt_WildZoneEntrance_Descriptor, ShinyHunt_WildZoneEntrance>());
4749

4850
if (PreloadSettings::instance().DEVELOPER_MODE){
4951
ret.emplace_back(make_single_switch_program<BeldumHunter_Descriptor, BeldumHunter>());
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/* Shiny Hunt - Wild Zone Entrance
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
8+
#include "CommonFramework/ProgramStats/StatsTracking.h"
9+
#include "CommonFramework/Notifications/ProgramNotifications.h"
10+
#include "CommonTools/Async/InferenceRoutines.h"
11+
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
12+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
13+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
14+
#include "Pokemon/Pokemon_Strings.h"
15+
#include "PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.h"
16+
#include "PokemonLZA/Inference/PokemonLZA_ButtonDetector.h"
17+
#include "PokemonLZA/Programs/PokemonLZA_BasicNavigation.h"
18+
#include "PokemonLZA_ShinyHunt_WildZoneEntrance.h"
19+
20+
namespace PokemonAutomation {
21+
namespace NintendoSwitch {
22+
namespace PokemonLZA {
23+
24+
using namespace Pokemon;
25+
26+
27+
ShinyHunt_WildZoneEntrance_Descriptor::ShinyHunt_WildZoneEntrance_Descriptor()
28+
: SingleSwitchProgramDescriptor("PokemonLZA:ShinyHunt-WildZoneEntrance", STRING_POKEMON + " LZA",
29+
"Shiny Hunt - Wild Zone Entrance",
30+
"Programs/PokemonLZA/ShinyHunt-WildZoneEntrance.html",
31+
"Shiny hunt by repeatedly entering Wild Zone from its entrance.",
32+
ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED,
33+
AllowCommandsWhenRunning::DISABLE_COMMANDS, {}) {}
34+
class ShinyHunt_WildZoneEntrance_Descriptor::Stats : public StatsTracker {
35+
public:
36+
Stats() : resets(m_stats["Wild Zone"]), shinies(m_stats["Shiny Sounds"]), errors(m_stats["Errors"]) {
37+
m_display_order.emplace_back("Wild Zone");
38+
m_display_order.emplace_back("Shiny Sounds");
39+
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
40+
41+
m_aliases["Shinies"] = "Shiny Sounds";
42+
m_aliases["Shinies Detected"] = "Shiny Sounds";
43+
}
44+
45+
std::atomic<uint64_t>& resets;
46+
std::atomic<uint64_t>& shinies;
47+
std::atomic<uint64_t>& errors;
48+
};
49+
std::unique_ptr<StatsTracker> ShinyHunt_WildZoneEntrance_Descriptor::make_stats() const {
50+
return std::unique_ptr<StatsTracker>(new Stats());
51+
}
52+
53+
54+
ShinyHunt_WildZoneEntrance::ShinyHunt_WildZoneEntrance()
55+
: SHINY_DETECTED("Shiny Detected", "", "2000 ms", ShinySoundDetectedAction::NOTIFY_ON_FIRST_ONLY),
56+
NOTIFICATION_STATUS("Status Update", true, false, std::chrono::seconds(3600)),
57+
NOTIFICATIONS({
58+
&NOTIFICATION_STATUS,
59+
&SHINY_DETECTED.NOTIFICATIONS,
60+
&NOTIFICATION_PROGRAM_FINISH,
61+
&NOTIFICATION_ERROR_RECOVERABLE,
62+
&NOTIFICATION_ERROR_FATAL,
63+
}) {
64+
PA_ADD_STATIC(SHINY_REQUIRES_AUDIO);
65+
PA_ADD_OPTION(SHINY_DETECTED);
66+
PA_ADD_OPTION(NOTIFICATIONS);
67+
}
68+
69+
70+
void run_to_gate(ConsoleHandle& console, ProControllerContext& context) {
71+
ButtonWatcher buttonA(COLOR_RED, ButtonType::ButtonA, {0, 0, 1, 1}, &console.overlay());
72+
int ret = run_until<ProControllerContext>(console, context,
73+
[](ProControllerContext& context) {
74+
for (int c = 0; c < 10; c++) {
75+
pbf_move_left_joystick(context, 128, 0, 800ms, 200ms);
76+
}
77+
},
78+
{{buttonA}});
79+
80+
switch (ret) {
81+
case 0:
82+
break;
83+
default:
84+
OperationFailedException::fire(ErrorReport::SEND_ERROR_REPORT,
85+
"run_to_gate(): Unable to detect entrance after 10 seconds.", console);
86+
}
87+
}
88+
89+
void enter_wild_zone_entrance(ConsoleHandle& console, ProControllerContext& context) {
90+
BlackScreenOverWatcher black_screen(COLOR_BLUE);
91+
int ret = run_until<ProControllerContext>(console, context,
92+
[&](ProControllerContext& context) {
93+
pbf_mash_button(context, BUTTON_B, 200ms); // dismiss menu if any
94+
run_to_gate(console, context);
95+
pbf_mash_button(context, BUTTON_A, 2000ms);
96+
pbf_move_left_joystick(context, 128, 0, 500ms, 200ms);
97+
context.wait_for_all_requests();
98+
pbf_press_button(context, BUTTON_PLUS, 100ms, 100ms); // open map
99+
},
100+
{{black_screen}});
101+
if (ret == 0) {
102+
console.log("[WildZoneEntrance] Detected day/night change after entering.");
103+
context.wait_for(std::chrono::milliseconds(2000));
104+
pbf_mash_button(context, BUTTON_B, 200ms); // dismiss menu if any
105+
pbf_press_button(context, BUTTON_PLUS, 100ms, 100ms); // open map again
106+
}
107+
pbf_mash_button(context, BUTTON_A, 800ms); // teleporting or just mashing button
108+
pbf_mash_button(context, BUTTON_B, 200ms); // in case need to dismiss map
109+
context.wait_for_all_requests();
110+
context.wait_for(std::chrono::milliseconds(4000)); // TODO: differ NS1 wait time from NS2
111+
}
112+
113+
void ShinyHunt_WildZoneEntrance::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) {
114+
ShinyHunt_WildZoneEntrance_Descriptor::Stats& stats =
115+
env.current_stats<ShinyHunt_WildZoneEntrance_Descriptor::Stats>();
116+
117+
uint8_t shiny_count = 0;
118+
119+
while (true) {
120+
float shiny_coefficient = 1.0;
121+
PokemonLA::ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool {
122+
// Warning: This callback will be run from a different thread than this function.
123+
shiny_count++;
124+
stats.shinies++;
125+
env.update_stats();
126+
shiny_coefficient = error_coefficient;
127+
return true;
128+
});
129+
130+
int ret = run_until<ProControllerContext>(env.console, context,
131+
[&](ProControllerContext& context) {
132+
while (true) {
133+
send_program_status_notification(env, NOTIFICATION_STATUS);
134+
stats.resets++;
135+
enter_wild_zone_entrance(env.console, context);
136+
env.update_stats();
137+
}
138+
},
139+
{{shiny_detector}});
140+
141+
// This should never happen.
142+
if (ret != 0) {
143+
continue;
144+
}
145+
146+
context.wait_for(std::chrono::milliseconds(1000));
147+
148+
// when shiny sound is detected, it's most likely happened inside the zone
149+
// now try to reset position
150+
pbf_mash_button(context, BUTTON_B, 200ms); // dismiss menu if any
151+
pbf_press_button(context, BUTTON_PLUS, 100ms, 100ms); // open map
152+
pbf_mash_button(context, BUTTON_A, 600ms); // teleporting or just mashing button
153+
pbf_mash_button(context, BUTTON_B, 200ms); // in case need to dismiss map
154+
155+
if (SHINY_DETECTED.on_shiny_sound(env, env.console, context, shiny_count, shiny_coefficient)) {
156+
break;
157+
}
158+
}
159+
160+
go_home(env.console, context);
161+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
162+
}
163+
164+
165+
} // namespace PokemonLZA
166+
} // namespace NintendoSwitch
167+
} // namespace PokemonAutomation
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Shiny Hunt - Wild Zone Entrance
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_ShinyHunt_WildZoneEntrance_H
8+
#define PokemonAutomation_PokemonLZA_ShinyHunt_WildZoneEntrance_H
9+
10+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
11+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
12+
#include "PokemonLA/Options/PokemonLA_ShinyDetectedAction.h"
13+
#include "PokemonLZA/Options/PokemonLZA_ShinyDetectedAction.h"
14+
15+
namespace PokemonAutomation {
16+
namespace NintendoSwitch {
17+
namespace PokemonLZA {
18+
19+
20+
class ShinyHunt_WildZoneEntrance_Descriptor : public SingleSwitchProgramDescriptor {
21+
public:
22+
ShinyHunt_WildZoneEntrance_Descriptor();
23+
24+
class Stats;
25+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
26+
};
27+
28+
29+
class ShinyHunt_WildZoneEntrance : public SingleSwitchProgramInstance {
30+
public:
31+
ShinyHunt_WildZoneEntrance();
32+
33+
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
34+
35+
private:
36+
PokemonLA::ShinyRequiresAudioText SHINY_REQUIRES_AUDIO;
37+
38+
ShinySoundDetectedActionOption SHINY_DETECTED;
39+
40+
EventNotificationOption NOTIFICATION_STATUS;
41+
EventNotificationsOption NOTIFICATIONS;
42+
};
43+
44+
45+
} // namespace PokemonLZA
46+
} // namespace NintendoSwitch
47+
} // namespace PokemonAutomation
48+
#endif

SerialPrograms/SourceFiles.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,8 @@ file(GLOB LIBRARY_SOURCES
15751575
Source/PokemonLZA/Programs/PokemonLZA_ShinyHunt_BenchSit.h
15761576
Source/PokemonLZA/Programs/PokemonLZA_ShinyHunt_OverworldReset.cpp
15771577
Source/PokemonLZA/Programs/PokemonLZA_ShinyHunt_OverworldReset.h
1578+
Source/PokemonLZA/Programs/PokemonLZA_ShinyHunt_WildZoneEntrance.cpp
1579+
Source/PokemonLZA/Programs/PokemonLZA_ShinyHunt_WildZoneEntrance.h
15781580
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_CheckBoxCellInfo.cpp
15791581
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_CheckBoxCellInfo.h
15801582
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.cpp

0 commit comments

Comments
 (0)