Skip to content

Commit ac3195e

Browse files
authored
Frlg gift fixes (#1112)
* retry A press * FRLG tests, adjust dialog detectors * arrow color adjustment * Update PokemonFRLG_GiftReset.cpp * shiny symbol test (no adjustments) * black border check * fix white dialog detection * tick precise not required, take video, audio warn
1 parent ab07fde commit ac3195e

15 files changed

Lines changed: 206 additions & 23 deletions

SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ bool WhiteDialogDetector::detect(const ImageViewRGB32& screen){
3939
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
4040
ImageViewRGB32 top_image = extract_box_reference(screen, m_top_box);
4141
ImageViewRGB32 bottom_image = extract_box_reference(screen, m_bottom_box);
42-
if (is_solid(right_image, { 0.25, 0.38, 0.369 })
43-
&& is_solid(top_image, { 0.25, 0.38, 0.369 })
44-
&& is_solid(bottom_image, { 0.25, 0.38, 0.369 })
42+
if (is_white(right_image)
43+
&& is_white(top_image)
44+
&& is_white(bottom_image)
4545
){
4646
return true;
4747
}
@@ -66,7 +66,7 @@ bool AdvanceWhiteDialogDetector::detect(const ImageViewRGB32& screen){
6666
//Filter out background
6767
ImageRGB32 filtered_region = filter_rgb32_range(
6868
extract_box_reference(screen, m_dialog_box),
69-
combine_rgb(185, 0, 1), combine_rgb(255, 32, 33), Color(0), replace_color_within_range
69+
combine_rgb(164, 0, 0), combine_rgb(255, 114, 87), Color(0), replace_color_within_range
7070
);
7171
ImageStats stats = image_stats(filtered_region);
7272

@@ -81,11 +81,11 @@ bool AdvanceWhiteDialogDetector::detect(const ImageViewRGB32& screen){
8181
ImageViewRGB32 top_image = extract_box_reference(screen, m_top_box);
8282
ImageViewRGB32 bottom_image = extract_box_reference(screen, m_bottom_box);
8383

84-
if (is_solid(right_image, { 0.25, 0.38, 0.369 })
85-
&& is_solid(top_image, { 0.25, 0.38, 0.369 })
86-
&& is_solid(bottom_image, { 0.25, 0.38, 0.369 })
87-
&& (stats.average.r > stats.average.b + 200)
88-
&& (stats.average.r > stats.average.g + 200)
84+
if (is_white(right_image)
85+
&& is_white(top_image)
86+
&& is_white(bottom_image)
87+
&& (stats.average.r > stats.average.b + 180)
88+
&& (stats.average.r > stats.average.g + 180)
8989
)
9090
{
9191
return true;
@@ -110,10 +110,10 @@ bool SelectionDialogDetector::detect(const ImageViewRGB32& screen){
110110
ImageViewRGB32 top_image = extract_box_reference(screen, m_top_box);
111111
ImageViewRGB32 bottom_image = extract_box_reference(screen, m_bottom_box);
112112
ImageViewRGB32 selection_image = extract_box_reference(screen, m_selection_box);
113-
if (is_solid(right_image, { 0.25, 0.38, 0.369 })
114-
&& is_solid(top_image, { 0.25, 0.38, 0.369 })
115-
&& is_solid(bottom_image, { 0.25, 0.38, 0.369 })
116-
&& is_solid(selection_image, { 0.25, 0.38, 0.369 })
113+
if (is_white(right_image)
114+
&& is_white(top_image)
115+
&& is_white(bottom_image)
116+
&& is_white(selection_image)
117117
){
118118
return true;
119119
}
@@ -189,7 +189,7 @@ bool AdvanceBattleDialogDetector::detect(const ImageViewRGB32& screen){
189189
//Filter out background
190190
ImageRGB32 filtered_region = filter_rgb32_range(
191191
extract_box_reference(screen, m_dialog_box),
192-
combine_rgb(185, 0, 1), combine_rgb(255, 32, 33), Color(0), replace_color_within_range
192+
combine_rgb(164, 0, 0), combine_rgb(255, 114, 87), Color(0), replace_color_within_range
193193
);
194194
ImageStats stats = image_stats(filtered_region);
195195

@@ -205,8 +205,8 @@ bool AdvanceBattleDialogDetector::detect(const ImageViewRGB32& screen){
205205

206206
if (is_solid(dialog_top_image, { 0.176, 0.357, 0.467 })
207207
&& is_solid(dialog_right_image, { 0.176, 0.357, 0.467 })
208-
&& (stats.average.r > stats.average.b + 200)
209-
&& (stats.average.r > stats.average.g + 200)
208+
&& (stats.average.r > stats.average.b + 180)
209+
&& (stats.average.r > stats.average.g + 180)
210210
)
211211
{
212212
return true;

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "CommonTools/Random.h"
1111
#include "CommonTools/Async/InferenceRoutines.h"
1212
#include "CommonTools/VisualDetectors/BlackScreenDetector.h"
13+
#include "CommonTools/StartupChecks/StartProgramChecks.h"
14+
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
1315
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1416
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
1517
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
@@ -333,6 +335,18 @@ void flee_battle(ConsoleHandle& console, ProControllerContext& context){
333335
}
334336
}
335337

338+
void home_black_border_check(ConsoleHandle& console, ProControllerContext& context){
339+
console.log("Going to home to check for black border.");
340+
go_home(console, context);
341+
ensure_at_home(console, context);
342+
context.wait_for_all_requests();
343+
StartProgramChecks::check_border(console);
344+
console.log("Returning to game.");
345+
resume_game_from_home(console, context);
346+
context.wait_for_all_requests();
347+
console.log("Entered game.");
348+
}
349+
336350

337351
}
338352
}

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ bool handle_encounter(ConsoleHandle& console, ProControllerContext& context, boo
3636
// Run from battle. Cursor must start on the FIGHT button. Assumes fleeing will always work. (Smoke Ball)
3737
void flee_battle(ConsoleHandle& console, ProControllerContext& context);
3838

39+
// Go to home to check that scaling is 100%. Then resume game.
40+
void home_black_border_check(ConsoleHandle& console, ProControllerContext& context);
41+
3942
}
4043
}
4144
}

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_GiftReset.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ GiftReset_Descriptor::GiftReset_Descriptor()
3030
Pokemon::STRING_POKEMON + " FRLG", "Gift Reset",
3131
"Programs/PokemonFRLG/GiftReset.html",
3232
"Soft reset for a shiny gift Pokemon.",
33-
ProgramControllerClass::StandardController_RequiresPrecision,
33+
ProgramControllerClass::StandardController_NoRestrictions,
3434
FeedbackType::REQUIRED,
3535
AllowCommandsWhenRunning::DISABLE_COMMANDS
3636
)
@@ -67,6 +67,7 @@ GiftReset::GiftReset()
6767
LockMode::LOCK_WHILE_RUNNING,
6868
Target::starters
6969
)
70+
, TAKE_VIDEO("<b>Take Video:</b><br>Record a video when the shiny is found.", LockMode::UNLOCK_WHILE_RUNNING, true)
7071
, GO_HOME_WHEN_DONE(true)
7172
, NOTIFICATION_SHINY(
7273
"Shiny found",
@@ -81,6 +82,7 @@ GiftReset::GiftReset()
8182
})
8283
{
8384
PA_ADD_OPTION(TARGET);
85+
PA_ADD_OPTION(TAKE_VIDEO);
8486
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
8587
PA_ADD_OPTION(NOTIFICATIONS);
8688
}
@@ -100,8 +102,33 @@ void GiftReset::obtain_pokemon(SingleSwitchProgramEnvironment& env, ProControlle
100102
*/
101103

102104
env.log("Obtaining Pokemon.");
103-
pbf_press_button(context, BUTTON_A, 320ms, 640ms);
104-
105+
if (TARGET == Target::starters) {
106+
AdvanceWhiteDialogWatcher adv_white_start(COLOR_RED);
107+
int rets = run_until<ProControllerContext>(
108+
env.console, context,
109+
[](ProControllerContext& context) {
110+
for (int i = 0; i < 10; i++) {
111+
pbf_press_button(context, BUTTON_A, 320ms, 640ms);
112+
pbf_wait(context, 2000ms);
113+
context.wait_for_all_requests();
114+
}
115+
},
116+
{ adv_white_start }
117+
);
118+
context.wait_for_all_requests();
119+
if (rets < 0) {
120+
env.update_stats();
121+
env.log("obtain_pokemon(): Unable to start starter dialog after 10 attempts.", COLOR_RED);
122+
OperationFailedException::fire(
123+
ErrorReport::SEND_ERROR_REPORT,
124+
"obtain_pokemon(): Unable to start starter dialog after 10 attempts.",
125+
env.console
126+
);
127+
}
128+
env.log("Initial A press completed.");
129+
} else {
130+
pbf_press_button(context, BUTTON_A, 320ms, 640ms);
131+
}
105132
bool seen_selection_arrow = false;
106133
//bool seen_nickname_arrow = false;
107134
while (true){
@@ -310,6 +337,8 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
310337

311338
GiftReset_Descriptor::Stats& stats = env.current_stats<GiftReset_Descriptor::Stats>();
312339

340+
home_black_border_check(env.console, context);
341+
313342
/*
314343
* Settings: Text Speed fast. Default borders.
315344
* Setup: 5 pokemon in your party. None for starter. Stand in front of the pokemon. Save the game.
@@ -346,6 +375,9 @@ void GiftReset::program(SingleSwitchProgramEnvironment& env, ProControllerContex
346375
screen,
347376
true
348377
);
378+
if (TAKE_VIDEO){
379+
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 0ms);
380+
}
349381
break;
350382
}else{
351383
env.log("Pokemon is not shiny.");

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_GiftReset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef PokemonAutomation_PokemonFRLG_GiftReset_H
88
#define PokemonAutomation_PokemonFRLG_GiftReset_H
99

10+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
1011
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1112
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1213
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
@@ -47,6 +48,8 @@ class GiftReset : public SingleSwitchProgramInstance{
4748
};
4849
EnumDropdownOption<Target> TARGET;
4950

51+
BooleanCheckBoxOption TAKE_VIDEO;
52+
5053
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
5154

5255
EventNotificationOption NOTIFICATION_SHINY;

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_LegendaryReset.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LegendaryReset_Descriptor::LegendaryReset_Descriptor()
2929
Pokemon::STRING_POKEMON + " FRLG", "Legendary Reset",
3030
"Programs/PokemonFRLG/LegendaryReset.html",
3131
"Shiny hunt legendary Pokemon using soft resets.",
32-
ProgramControllerClass::StandardController_RequiresPrecision,
32+
ProgramControllerClass::StandardController_NoRestrictions,
3333
FeedbackType::REQUIRED,
3434
AllowCommandsWhenRunning::DISABLE_COMMANDS
3535
)
@@ -59,6 +59,7 @@ LegendaryReset::LegendaryReset()
5959
LockMode::LOCK_WHILE_RUNNING,
6060
false
6161
)
62+
, TAKE_VIDEO("<b>Take Video:</b><br>Record a video when the shiny is found.", LockMode::UNLOCK_WHILE_RUNNING, true)
6263
, GO_HOME_WHEN_DONE(true)
6364
, NOTIFICATION_SHINY(
6465
"Shiny found",
@@ -72,14 +73,18 @@ LegendaryReset::LegendaryReset()
7273
&NOTIFICATION_PROGRAM_FINISH,
7374
})
7475
{
76+
PA_ADD_STATIC(SHINY_REQUIRES_AUDIO);
7577
PA_ADD_OPTION(WALK_UP);
78+
PA_ADD_OPTION(TAKE_VIDEO);
7679
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
7780
PA_ADD_OPTION(NOTIFICATIONS);
7881
}
7982

8083
void LegendaryReset::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
8184
LegendaryReset_Descriptor::Stats& stats = env.current_stats<LegendaryReset_Descriptor::Stats>();
8285

86+
home_black_border_check(env.console, context);
87+
8388
/*
8489
* Settings: Text Speed fast. Default borders. Audio required.
8590
* Setup: Stand in front of target. Save the game.
@@ -138,6 +143,9 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, ProControllerC
138143
env.console.video().snapshot(),
139144
true
140145
);
146+
if (TAKE_VIDEO){
147+
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 0ms);
148+
}
141149
break;
142150
}
143151

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_LegendaryReset.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
1313
#include "Common/Cpp/Options/EnumDropdownOption.h"
1414
#include "Common/Cpp/Options/SimpleIntegerOption.h"
15+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
16+
#include "PokemonLA/Options/PokemonLA_ShinyDetectedAction.h"
1517

1618
namespace PokemonAutomation{
1719
namespace NintendoSwitch{
@@ -35,7 +37,10 @@ class LegendaryReset : public SingleSwitchProgramInstance{
3537
) override{}
3638

3739
private:
40+
PokemonLA::ShinyRequiresAudioText SHINY_REQUIRES_AUDIO;
41+
3842
BooleanCheckBoxOption WALK_UP;
43+
BooleanCheckBoxOption TAKE_VIDEO;
3944

4045
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
4146

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_LegendaryRunAway.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LegendaryRunAway_Descriptor::LegendaryRunAway_Descriptor()
3030
Pokemon::STRING_POKEMON + " FRLG", "Legendary Run Away",
3131
"Programs/PokemonFRLG/LegendaryRunAway.html",
3232
"Shiny hunt legendary Pokemon using the run away method.",
33-
ProgramControllerClass::StandardController_RequiresPrecision,
33+
ProgramControllerClass::StandardController_NoRestrictions,
3434
FeedbackType::REQUIRED,
3535
AllowCommandsWhenRunning::DISABLE_COMMANDS
3636
)
@@ -64,6 +64,7 @@ LegendaryRunAway::LegendaryRunAway()
6464
LockMode::LOCK_WHILE_RUNNING,
6565
Target::hooh
6666
)
67+
, TAKE_VIDEO("<b>Take Video:</b><br>Record a video when the shiny is found.", LockMode::UNLOCK_WHILE_RUNNING, true)
6768
, GO_HOME_WHEN_DONE(true)
6869
, NOTIFICATION_SHINY(
6970
"Shiny found",
@@ -100,7 +101,9 @@ LegendaryRunAway::LegendaryRunAway()
100101
"550 ms"
101102
)
102103
{
104+
PA_ADD_STATIC(SHINY_REQUIRES_AUDIO);
103105
PA_ADD_OPTION(TARGET);
106+
PA_ADD_OPTION(TAKE_VIDEO);
104107
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
105108
PA_ADD_OPTION(NOTIFICATIONS);
106109
PA_ADD_STATIC(m_advanced_options);
@@ -243,6 +246,8 @@ void LegendaryRunAway::reset_lugia(SingleSwitchProgramEnvironment& env, ProContr
243246
void LegendaryRunAway::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
244247
LegendaryRunAway_Descriptor::Stats& stats = env.current_stats<LegendaryRunAway_Descriptor::Stats>();
245248

249+
home_black_border_check(env.console, context);
250+
246251
/*
247252
* Settings: Text Speed fast. Default borders. Battle animations off. Audio required.
248253
* Smoke Ball or fast pokemon required.
@@ -264,7 +269,17 @@ void LegendaryRunAway::program(SingleSwitchProgramEnvironment& env, ProControlle
264269
if (legendary_shiny){
265270
stats.shinies++;
266271
env.update_stats();
267-
send_program_notification(env, NOTIFICATION_SHINY, COLOR_YELLOW, "Shiny found!", {}, "", env.console.video().snapshot(), true);
272+
send_program_notification(env,
273+
NOTIFICATION_SHINY,
274+
COLOR_YELLOW,
275+
"Shiny found!",
276+
{}, "",
277+
env.console.video().snapshot(),
278+
true
279+
);
280+
if (TAKE_VIDEO){
281+
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 0ms);
282+
}
268283
break;
269284
}
270285
env.log("No shiny found.");

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_LegendaryRunAway.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "Common/Cpp/Options/EnumDropdownOption.h"
1515
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1616
#include "Common/Cpp/Options/TimeDurationOption.h"
17+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
18+
#include "PokemonLA/Options/PokemonLA_ShinyDetectedAction.h"
1719

1820
namespace PokemonAutomation{
1921
namespace NintendoSwitch{
@@ -46,6 +48,9 @@ class LegendaryRunAway : public SingleSwitchProgramInstance{
4648
void reset_hooh(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
4749
void reset_lugia(SingleSwitchProgramEnvironment& env, ProControllerContext& context);
4850

51+
PokemonLA::ShinyRequiresAudioText SHINY_REQUIRES_AUDIO;
52+
BooleanCheckBoxOption TAKE_VIDEO;
53+
4954
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
5055

5156
EventNotificationOption NOTIFICATION_SHINY;

SerialPrograms/Source/PokemonFRLG/Programs/ShinyHunting/PokemonFRLG_PrizeCornerReset.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PrizeCornerReset_Descriptor::PrizeCornerReset_Descriptor()
3131
Pokemon::STRING_POKEMON + " FRLG", "Prize Corner Reset",
3232
"Programs/PokemonFRLG/PrizeCornerReset.html",
3333
"Redeem and soft reset for a shiny Game Corner prize.",
34-
ProgramControllerClass::StandardController_RequiresPrecision,
34+
ProgramControllerClass::StandardController_NoRestrictions,
3535
FeedbackType::REQUIRED,
3636
AllowCommandsWhenRunning::DISABLE_COMMANDS
3737
)
@@ -68,6 +68,7 @@ PrizeCornerReset::PrizeCornerReset()
6868
LockMode::LOCK_WHILE_RUNNING,
6969
0
7070
)
71+
, TAKE_VIDEO("<b>Take Video:</b><br>Record a video when the shiny is found.", LockMode::UNLOCK_WHILE_RUNNING, true)
7172
, GO_HOME_WHEN_DONE(true)
7273
, NOTIFICATION_SHINY(
7374
"Shiny found",
@@ -82,6 +83,7 @@ PrizeCornerReset::PrizeCornerReset()
8283
})
8384
{
8485
PA_ADD_OPTION(SLOT);
86+
PA_ADD_OPTION(TAKE_VIDEO);
8587
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
8688
PA_ADD_OPTION(NOTIFICATIONS);
8789
}
@@ -136,6 +138,8 @@ void PrizeCornerReset::obtain_prize(SingleSwitchProgramEnvironment& env, ProCont
136138
void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
137139
PrizeCornerReset_Descriptor::Stats& stats = env.current_stats<PrizeCornerReset_Descriptor::Stats>();
138140

141+
home_black_border_check(env.console, context);
142+
139143
/*
140144
* Settings: Text Speed fast. Default borders.
141145
* Setup: Have a party of 5. Stand in front of the prize redemption. Save game. Move cursor back to top.
@@ -165,6 +169,9 @@ void PrizeCornerReset::program(SingleSwitchProgramEnvironment& env, ProControlle
165169
screen,
166170
true
167171
);
172+
if (TAKE_VIDEO){
173+
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 0ms);
174+
}
168175
break;
169176
}else{
170177
env.log("Prize is not shiny.");

0 commit comments

Comments
 (0)