Skip to content

Commit 3e02fa8

Browse files
committed
LZA: add program for hunting zone 19
1 parent c8a5c44 commit 3e02fa8

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-0
lines changed

SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Programs/ShinyHunting/PokemonLZA_AutoFossil.h"
3232
#include "Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.h"
3333
#include "Programs/ShinyHunting/PokemonLZA_Zone11Alpha.h"
34+
#include "Programs/ShinyHunting/PokemonLZA_Zone19Runner.h"
3435

3536
// Non-Shiny Hunting
3637
#include "Programs/NonShinyHunting/PokemonLZA_StatsReset.h"
@@ -79,6 +80,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
7980
ret.emplace_back(make_single_switch_program<AutoFossil_Descriptor, AutoFossil>());
8081
if (IS_BETA_VERSION){
8182
ret.emplace_back(make_single_switch_program<ShinyHunt_Zone11Alpha_Descriptor, ShinyHunt_Zone11Alpha>());
83+
ret.emplace_back(make_single_switch_program<ShinyHunt_Zone19Runner_Descriptor, ShinyHunt_Zone19Runner>());
8284
}
8385
if (PreloadSettings::instance().DEVELOPER_MODE){
8486
ret.emplace_back(make_single_switch_program<BeldumHunter_Descriptor, BeldumHunter>());
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/* Shiny Hunt - Zone 19 Runner
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 "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
15+
#include "Pokemon/Pokemon_Strings.h"
16+
#include "PokemonLZA/Inference/PokemonLZA_ButtonDetector.h"
17+
#include "PokemonLZA/Programs/PokemonLZA_BasicNavigation.h"
18+
#include "PokemonLZA_Zone19Runner.h"
19+
20+
namespace PokemonAutomation {
21+
namespace NintendoSwitch {
22+
namespace PokemonLZA {
23+
24+
using namespace Pokemon;
25+
26+
27+
ShinyHunt_Zone19Runner_Descriptor::ShinyHunt_Zone19Runner_Descriptor()
28+
: SingleSwitchProgramDescriptor(
29+
"PokemonLZA:ShinyHunt-Zone19Runner", STRING_POKEMON + " LZA",
30+
"Wild Zone 19 Runner",
31+
"Programs/PokemonLZA/ShinyHunt-Zone19Runner.html",
32+
"Shiny hunt by repeatedly running outside of Wild Zone 19",
33+
ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED,
34+
AllowCommandsWhenRunning::DISABLE_COMMANDS, {}
35+
)
36+
{}
37+
class ShinyHunt_Zone19Runner_Descriptor::Stats : public StatsTracker{
38+
public:
39+
Stats()
40+
: resets(m_stats["Rounds"])
41+
, day_changes(m_stats["Day/Night Changes"])
42+
, errors(m_stats["Errors"])
43+
{
44+
m_display_order.emplace_back("Rounds");
45+
m_display_order.emplace_back("Day/Night Changes");
46+
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
47+
}
48+
49+
std::atomic<uint64_t>& resets;
50+
std::atomic<uint64_t>& day_changes;
51+
std::atomic<uint64_t>& errors;
52+
};
53+
std::unique_ptr<StatsTracker> ShinyHunt_Zone19Runner_Descriptor::make_stats() const{
54+
return std::unique_ptr<StatsTracker>(new Stats());
55+
}
56+
57+
58+
ShinyHunt_Zone19Runner::ShinyHunt_Zone19Runner()
59+
: DURATION("<b>duration:</b><br>Run the program this long.", LockMode::LOCK_WHILE_RUNNING, "1 h")
60+
, NOTIFICATION_STATUS("Status Update", true, false, std::chrono::seconds(3600))
61+
, NOTIFICATIONS({
62+
&NOTIFICATION_STATUS,
63+
&NOTIFICATION_PROGRAM_FINISH,
64+
&NOTIFICATION_ERROR_RECOVERABLE,
65+
&NOTIFICATION_ERROR_FATAL,
66+
})
67+
{
68+
PA_ADD_OPTION(DURATION);
69+
PA_ADD_OPTION(NOTIFICATIONS);
70+
}
71+
72+
namespace {
73+
74+
void fly_back_to_zone_entrance(ConsoleHandle& console, ProControllerContext& context){
75+
open_map(console, context, true);
76+
context.wait_for_all_requests();
77+
pbf_move_left_joystick(context, 0, 128, 100ms, 100ms); // TODO: inference
78+
fly_from_map(console, context);
79+
}
80+
81+
void fly_back_to_zone_entrance_after_day_night_change(ConsoleHandle& console, ProControllerContext& context){
82+
open_map(console, context, true);
83+
context.wait_for_all_requests();
84+
pbf_move_left_joystick(context, 0, 128, 100ms, 100ms); // TODO: inference
85+
if (fly_from_map(console, context) == FastTravelState::NOT_AT_FLY_SPOT) {
86+
pbf_move_left_joystick(context, 128, 255, 100ms, 100ms); // TODO: inference
87+
fly_from_map(console, context);
88+
}
89+
}
90+
91+
void hunt_zone_loop(
92+
SingleSwitchProgramEnvironment& env,
93+
ProControllerContext& context
94+
){
95+
ShinyHunt_Zone19Runner_Descriptor::Stats& stats = env.current_stats<ShinyHunt_Zone19Runner_Descriptor::Stats>();
96+
context.wait_for_all_requests();
97+
98+
BlackScreenOverWatcher black_screen(COLOR_BLUE);
99+
int ret = run_until<ProControllerContext>(
100+
env.console, context,
101+
[&](ProControllerContext& context){
102+
ssf_press_button(context, BUTTON_B, 0ms, 500ms, 0ms);
103+
pbf_move_left_joystick(context, 0, 80, 6500ms, 0ms);
104+
},
105+
{{black_screen}}
106+
);
107+
if (ret == 0){
108+
env.console.log("[Zone19Runner] Detected day/night change");
109+
stats.day_changes++;
110+
context.wait_for(std::chrono::milliseconds(2000));
111+
fly_back_to_zone_entrance_after_day_night_change(env.console, context);
112+
} else {
113+
fly_back_to_zone_entrance(env.console, context);
114+
}
115+
context.wait_for(std::chrono::milliseconds(1000));
116+
}
117+
} // namespace
118+
119+
void ShinyHunt_Zone19Runner::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
120+
ShinyHunt_Zone19Runner_Descriptor::Stats& stats =
121+
env.current_stats<ShinyHunt_Zone19Runner_Descriptor::Stats>();
122+
WallClock deadline = current_time() + DURATION.get();
123+
pbf_press_button(context, BUTTON_L, 100ms, 100ms); // connect
124+
do{
125+
send_program_status_notification(env, NOTIFICATION_STATUS);
126+
stats.resets++;
127+
hunt_zone_loop(env, context);
128+
env.update_stats();
129+
}while (current_time() < deadline);
130+
131+
go_home(env.console, context);
132+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
133+
}
134+
135+
136+
} // namespace PokemonLZA
137+
} // namespace NintendoSwitch
138+
} // namespace PokemonAutomation
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Shiny Hunt - Zone 19 Runner
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_Zone19_Runner_H
8+
#define PokemonAutomation_PokemonLZA_Zone19_Runner_H
9+
10+
#include "Common/Cpp/Options/TimeDurationOption.h"
11+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
12+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
13+
14+
namespace PokemonAutomation {
15+
namespace NintendoSwitch {
16+
namespace PokemonLZA {
17+
18+
19+
class ShinyHunt_Zone19Runner_Descriptor : public SingleSwitchProgramDescriptor {
20+
public:
21+
ShinyHunt_Zone19Runner_Descriptor();
22+
23+
class Stats;
24+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
25+
};
26+
27+
28+
class ShinyHunt_Zone19Runner : public SingleSwitchProgramInstance {
29+
public:
30+
ShinyHunt_Zone19Runner();
31+
32+
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override;
33+
34+
private:
35+
MillisecondsOption DURATION;
36+
EventNotificationOption NOTIFICATION_STATUS;
37+
EventNotificationsOption NOTIFICATIONS;
38+
};
39+
40+
41+
} // namespace PokemonLZA
42+
} // namespace NintendoSwitch
43+
} // namespace PokemonAutomation
44+
#endif

SerialPrograms/SourceFiles.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,8 @@ file(GLOB LIBRARY_SOURCES
16291629
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.h
16301630
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone11Alpha.cpp
16311631
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone11Alpha.h
1632+
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone19Runner.cpp
1633+
Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_Zone19Runner.h
16321634
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.cpp
16331635
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h
16341636
Source/PokemonLZA/Programs/TestPrograms/PokemonLZA_OverworldWatcher.cpp

0 commit comments

Comments
 (0)