Skip to content

Commit a1bb543

Browse files
committed
lgpe gift reset, feedback type for lgpe programs
1 parent 3be08a9 commit a1bb543

File tree

7 files changed

+250
-6
lines changed

7 files changed

+250
-6
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,8 @@ file(GLOB MAIN_SOURCES
13801380
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h
13811381
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp
13821382
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h
1383+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp
1384+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h
13831385
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp
13841386
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h
13851387
Source/PokemonLGPE/PokemonLGPE_Panels.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ SOURCES += \
677677
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
678678
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp \
679679
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp \
680+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.cpp \
680681
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.cpp \
681682
Source/PokemonLGPE/PokemonLGPE_Panels.cpp \
682683
Source/PokemonLGPE/PokemonLGPE_Settings.cpp \
@@ -1868,6 +1869,7 @@ HEADERS += \
18681869
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
18691870
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h \
18701871
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h \
1872+
Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_GiftReset.h \
18711873
Source/PokemonLGPE/Programs/PokemonLGPE_GameEntry.h \
18721874
Source/PokemonLGPE/PokemonLGPE_Panels.h \
18731875
Source/PokemonLGPE/PokemonLGPE_Settings.h \

SerialPrograms/Source/PokemonLGPE/PokemonLGPE_Panels.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "Programs/Farming/PokemonLGPE_DailyItemFarmer.h"
1313
#include "Programs/ShinyHunting/PokemonLGPE_AlolanTrade.h"
14+
#include "Programs/ShinyHunting/PokemonLGPE_GiftReset.h"
1415

1516
namespace PokemonAutomation{
1617
namespace NintendoSwitch{
@@ -31,6 +32,7 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
3132

3233
ret.emplace_back("---- Shiny Hunting ----");
3334
ret.emplace_back(make_single_switch_program<AlolanTrade_Descriptor, AlolanTrade>());
35+
ret.emplace_back(make_single_switch_program<GiftReset_Descriptor, GiftReset>());
3436

3537
return ret;
3638
}

SerialPrograms/Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DailyItemFarmer_Descriptor::DailyItemFarmer_Descriptor()
3333
Pokemon::STRING_POKEMON + " LGPE", "Daily Item Farmer",
3434
"",
3535
"Farm daily item respawns (ex. fossils) by date-skipping.",
36-
FeedbackType::NONE,
36+
FeedbackType::REQUIRED,
3737
AllowCommandsWhenRunning::DISABLE_COMMANDS,
3838
{ControllerFeature::NintendoSwitch_RightJoycon},
3939
FasterIfTickPrecise::NOT_FASTER

SerialPrograms/Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_AlolanTrade.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AlolanTrade_Descriptor::AlolanTrade_Descriptor()
2929
Pokemon::STRING_POKEMON + " LGPE", "Alolan Trade",
3030
"",
3131
"Shiny hunt Alolan forms by trading in-game.",
32-
FeedbackType::NONE,
32+
FeedbackType::REQUIRED,
3333
AllowCommandsWhenRunning::DISABLE_COMMANDS,
3434
{ControllerFeature::NintendoSwitch_RightJoycon},
3535
FasterIfTickPrecise::NOT_FASTER
@@ -136,19 +136,18 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
136136
/*
137137
WARNING: JOYCON TEST PROGRAM. Not well tested. Bare minimum in general.
138138
139-
Only works with Right joycon atm. Do not update right joycon. Decline the update before running this.
140-
141139
Right joycon required for home button (this means no on-switch screenshots).
142-
Also don't remap any of the buttons in the switch button mapping settings. Yet? Could use this to add Home and Screenshot.
140+
Also don't remap any of the buttons in the switch button mapping settings.
143141
144142
Preconditions:
145143
DO NOT have any Pokemon you want to keep in your boxes. Move them out to Home first.
146144
Favoriting a Pokemon does not prevent it from being traded.
147-
This must not be your first time doing the trade. (I've done all the trades, so I can't check first time trade behavior.)
145+
?This must not be your first time doing the trade? (I've done all the trades, so I can't check first time trade behavior.)
148146
149147
Setup:
150148
Catch the Kanto variant of the target. Put this number in NUM_TRADES.
151149
Stand in front of trade NPC.
150+
Save the game.
152151
Start the program in-game.
153152
154153
Future additions?:
@@ -230,6 +229,7 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
230229
env.update_stats();
231230
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true);
232231
shiny_found = true;
232+
//TODO: Favorite the shiny.
233233
}
234234
else {
235235
env.log("Not shiny.");
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/* LGPE Gift 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/PokemonLGPE_ShinySymbolDetector.h"
19+
#include "PokemonLGPE/Programs/PokemonLGPE_GameEntry.h"
20+
#include "PokemonLGPE_GiftReset.h"
21+
22+
namespace PokemonAutomation{
23+
namespace NintendoSwitch{
24+
namespace PokemonLGPE{
25+
26+
GiftReset_Descriptor::GiftReset_Descriptor()
27+
: SingleSwitchProgramDescriptor(
28+
"PokemonLGPE:GiftReset",
29+
Pokemon::STRING_POKEMON + " LGPE", "Gift Reset",
30+
"",
31+
"Shiny hunt gift Pokemon by resetting the game.",
32+
FeedbackType::REQUIRED,
33+
AllowCommandsWhenRunning::DISABLE_COMMANDS,
34+
{ControllerFeature::NintendoSwitch_RightJoycon},
35+
FasterIfTickPrecise::NOT_FASTER
36+
)
37+
{}
38+
39+
struct GiftReset_Descriptor::Stats : public StatsTracker{
40+
Stats()
41+
: resets(m_stats["Resets"])
42+
, shinies(m_stats["Shinies"])
43+
{
44+
m_display_order.emplace_back("Resets");
45+
m_display_order.emplace_back("Shinies");
46+
}
47+
std::atomic<uint64_t>& resets;
48+
std::atomic<uint64_t>& shinies;
49+
};
50+
std::unique_ptr<StatsTracker> GiftReset_Descriptor::make_stats() const{
51+
return std::unique_ptr<StatsTracker>(new Stats());
52+
}
53+
54+
GiftReset::GiftReset()
55+
: GO_HOME_WHEN_DONE(false)
56+
, NOTIFICATION_SHINY(
57+
"Shiny Found",
58+
true, true, ImageAttachmentMode::JPG,
59+
{"Notifs", "Showcase"}
60+
)
61+
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
62+
, NOTIFICATIONS({
63+
&NOTIFICATION_SHINY,
64+
&NOTIFICATION_STATUS_UPDATE,
65+
&NOTIFICATION_PROGRAM_FINISH,
66+
})
67+
{
68+
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
69+
PA_ADD_OPTION(NOTIFICATIONS);
70+
}
71+
72+
void GiftReset::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
73+
JoyconContext context(scope, env.console.controller<JoyconController>());
74+
assert_16_9_720p_min(env.logger(), env.console);
75+
GiftReset_Descriptor::Stats& stats = env.current_stats<GiftReset_Descriptor::Stats>();
76+
77+
/*
78+
Setup:
79+
Stand in front of trade NPC.
80+
Start the program in-game.
81+
82+
Must have 500yen for magikarp.
83+
Gift Pokemon: https://www.serebii.net/letsgopikachueevee/gift.shtml
84+
Tested with Magikarp on a new save. Should work with most of the others.
85+
Can always add a dropdown with target if it doesn't.
86+
Fossils will be handled in a different program.
87+
*/
88+
89+
bool shiny_found = false;
90+
while (!shiny_found) {
91+
//Purchase Magikarp
92+
BlackScreenOverWatcher gift_obtained(COLOR_RED);
93+
int ret = run_until<JoyconContext>(
94+
env.console, context,
95+
[](JoyconContext& context){
96+
pbf_mash_button(context, BUTTON_A, 20000ms);
97+
},
98+
{gift_obtained}
99+
);
100+
context.wait_for_all_requests();
101+
if (ret != 0){
102+
env.log("Failed to receive gift Pokemon.", COLOR_RED);
103+
OperationFailedException::fire(
104+
ErrorReport::SEND_ERROR_REPORT,
105+
"Failed to receive gift Pokemon.",
106+
env.console
107+
);
108+
}
109+
else {
110+
env.log("Received gift Pokemon.");
111+
}
112+
send_program_status_notification(
113+
env, NOTIFICATION_STATUS_UPDATE,
114+
"Received gift Pokemon."
115+
);
116+
117+
//Wait a bit.
118+
pbf_wait(context, 2500ms);
119+
context.wait_for_all_requests();
120+
121+
//Open menu, open party, open boxes
122+
env.log("Opening boxes.");
123+
pbf_press_button(context, BUTTON_X, 200ms, 500ms);
124+
pbf_press_button(context, BUTTON_A, 200ms, 1500ms);
125+
pbf_press_button(context, BUTTON_Y, 200ms, 2000ms);
126+
context.wait_for_all_requests();
127+
128+
//Sort by order caught
129+
env.log("Sorting by order caught.");
130+
pbf_press_button(context, BUTTON_Y, 200ms, 1000ms);
131+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
132+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
133+
context.wait_for_all_requests();
134+
135+
//Press left to go to last (most recent) Pokemon
136+
env.log("Opening summary of most recent Pokemon.");
137+
pbf_move_joystick(context, 0, 128, 100ms, 100ms);
138+
context.wait_for_all_requests();
139+
140+
//View summary - it takes a moment to load
141+
env.log("Viewing summary.");
142+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
143+
pbf_move_joystick(context, 128, 255, 100ms, 100ms);
144+
pbf_move_joystick(context, 128, 255, 100ms, 100ms);
145+
pbf_press_button(context, BUTTON_A, 200ms, 100ms);
146+
context.wait_for_all_requests();
147+
148+
pbf_wait(context, 5000ms);
149+
context.wait_for_all_requests();
150+
151+
//Now check for shinies. Check everything that was traded.
152+
VideoSnapshot screen = env.console.video().snapshot();
153+
ShinySymbolDetector shiny_checker(COLOR_YELLOW);
154+
bool check = shiny_checker.read(env.console.logger(), screen);
155+
156+
if (check) {
157+
env.log("Shiny detected!");
158+
stats.shinies++;
159+
env.update_stats();
160+
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", screen, true);
161+
shiny_found = true;
162+
}
163+
else {
164+
env.log("Not shiny. Resetting game.");
165+
send_program_status_notification(
166+
env, NOTIFICATION_STATUS_UPDATE,
167+
"Not shiny. Resetting game."
168+
);
169+
170+
//Reset game
171+
pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms);
172+
reset_game_from_home(env, env.console, context, 3000ms);
173+
context.wait_for_all_requests();
174+
175+
stats.resets++;
176+
env.update_stats();
177+
}
178+
}
179+
180+
if (GO_HOME_WHEN_DONE) {
181+
pbf_press_button(context, BUTTON_HOME, 200ms, 1000ms);
182+
}
183+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
184+
}
185+
186+
187+
}
188+
}
189+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* LGPE Gift Reset
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_GiftReset_H
8+
#define PokemonAutomation_PokemonLGPE_GiftReset_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 GiftReset_Descriptor : public SingleSwitchProgramDescriptor{
21+
public:
22+
GiftReset_Descriptor();
23+
struct Stats;
24+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
25+
};
26+
27+
class GiftReset : public SingleSwitchProgramInstance{
28+
public:
29+
GiftReset();
30+
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
31+
32+
private:
33+
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
34+
35+
EventNotificationOption NOTIFICATION_SHINY;
36+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
37+
EventNotificationsOption NOTIFICATIONS;
38+
};
39+
40+
41+
42+
43+
}
44+
}
45+
}
46+
#endif
47+
48+
49+

0 commit comments

Comments
 (0)