Skip to content

Commit 8888716

Browse files
jw098fyex
authored andcommitted
segments 17 and 18 (PokemonAutomation#515)
1 parent c8d0cb0 commit 8888716

File tree

6 files changed

+676
-0
lines changed

6 files changed

+676
-0
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,10 @@ file(GLOB MAIN_SOURCES
14781478
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_15.h
14791479
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_16.cpp
14801480
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_16.h
1481+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_17.cpp
1482+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_17.h
1483+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_18.cpp
1484+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_18.h
14811485
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp
14821486
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h
14831487
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ SOURCES += \
737737
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.cpp \
738738
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_15.cpp \
739739
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_16.cpp \
740+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_17.cpp \
741+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_18.cpp \
740742
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.cpp \
741743
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.cpp \
742744
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.cpp \
@@ -1853,6 +1855,8 @@ HEADERS += \
18531855
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_14.h \
18541856
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_15.h \
18551857
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_16.h \
1858+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_17.h \
1859+
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory_Segment_18.h \
18561860
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStory.h \
18571861
Source/PokemonSV/Programs/AutoStory/PokemonSV_AutoStoryTools.h \
18581862
Source/PokemonSV/Programs/AutoStory/PokemonSV_MenuOption.h \
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/* AutoStory
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "CommonFramework/GlobalSettingsPanel.h"
8+
#include "CommonFramework/Exceptions/FatalProgramException.h"
9+
#include "CommonFramework/Exceptions/OperationFailedException.h"
10+
#include "CommonFramework/InferenceInfra/InferenceRoutines.h"
11+
#include "CommonFramework/Notifications/ProgramNotifications.h"
12+
#include "CommonFramework/Tools/StatsTracking.h"
13+
#include "CommonFramework/Tools/VideoResolutionCheck.h"
14+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
15+
#include "Pokemon/Pokemon_Strings.h"
16+
#include "PokemonSwSh/Inference/PokemonSwSh_IvJudgeReader.h"
17+
#include "PokemonSV/Programs/PokemonSV_GameEntry.h"
18+
#include "PokemonSV/Programs/PokemonSV_SaveGame.h"
19+
#include "PokemonSV/Inference/Overworld/PokemonSV_DirectionDetector.h"
20+
#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
21+
#include "PokemonSV_AutoStoryTools.h"
22+
#include "PokemonSV_AutoStory_Segment_17.h"
23+
24+
//#include <iostream>
25+
//using std::cout;
26+
//using std::endl;
27+
//#include <unordered_map>
28+
//#include <algorithm>
29+
30+
namespace PokemonAutomation{
31+
namespace NintendoSwitch{
32+
namespace PokemonSV{
33+
34+
using namespace Pokemon;
35+
36+
37+
38+
39+
std::string AutoStory_Segment_17::name() const{
40+
return "13.2: Cascarrafa Gym (Water): Gym challenge and Gym battle";
41+
}
42+
43+
std::string AutoStory_Segment_17::start_text() const{
44+
return "Start: Received Kofu's wallet. At Porto Marinada Pokecenter.";
45+
}
46+
47+
std::string AutoStory_Segment_17::end_text() const{
48+
return "End: Defeated Cascarrafa Gym (Water). At Cascarrafa Gym.";
49+
}
50+
51+
void AutoStory_Segment_17::run_segment(SingleSwitchProgramEnvironment& env, BotBaseContext& context, AutoStoryOptions options) const{
52+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
53+
54+
context.wait_for_all_requests();
55+
env.console.overlay().add_log("Start Segment 13.2: Cascarrafa Gym (Water): Gym battle", COLOR_ORANGE);
56+
57+
checkpoint_37(env, context, options.notif_status_update);
58+
checkpoint_38(env, context, options.notif_status_update);
59+
60+
context.wait_for_all_requests();
61+
env.console.log("End Segment 13.2: Cascarrafa Gym (Water): Gym battle", COLOR_GREEN);
62+
stats.m_segment++;
63+
env.update_stats();
64+
65+
}
66+
67+
68+
void checkpoint_37(
69+
SingleSwitchProgramEnvironment& env,
70+
BotBaseContext& context,
71+
EventNotificationOption& notif_status_update
72+
){
73+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
74+
bool first_attempt = true;
75+
while (true){
76+
try{
77+
if (first_attempt){
78+
checkpoint_save(env, context, notif_status_update);
79+
first_attempt = false;
80+
}
81+
context.wait_for_all_requests();
82+
DirectionDetector direction;
83+
do_action_and_monitor_for_battles(env.program_info(), env.console, context,
84+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
85+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 0, 255, 50);
86+
87+
// section 1
88+
direction.change_direction(env.program_info(), env.console, context, 1.606);
89+
pbf_move_left_joystick(context, 128, 0, 200, 100);
90+
91+
get_on_ride(env.program_info(), env.console, context);
92+
93+
// section 2
94+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_OLD_MARKER);
95+
});
96+
97+
overworld_navigation(env.program_info(), env.console, context,
98+
NavigationStopCondition::STOP_MARKER, NavigationMovementMode::DIRECTIONAL_ONLY,
99+
128, 0, 30, 10, false);
100+
// section 3. set marker to shop/Kofu
101+
realign_player(env.program_info(), env.console, context, PlayerRealignMode::REALIGN_NEW_MARKER, 0, 140, 27);
102+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 20);
103+
104+
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
105+
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW});
106+
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
107+
108+
109+
break;
110+
}catch (...){
111+
context.wait_for_all_requests();
112+
env.console.log("Resetting from checkpoint.");
113+
reset_game(env.program_info(), env.console, context);
114+
stats.m_reset++;
115+
env.update_stats();
116+
}
117+
}
118+
119+
}
120+
121+
void checkpoint_38(
122+
SingleSwitchProgramEnvironment& env,
123+
BotBaseContext& context,
124+
EventNotificationOption& notif_status_update
125+
){
126+
AutoStoryStats& stats = env.current_stats<AutoStoryStats>();
127+
bool first_attempt = true;
128+
while (true){
129+
try{
130+
if (first_attempt){
131+
checkpoint_save(env, context, notif_status_update);
132+
first_attempt = false;
133+
}
134+
context.wait_for_all_requests();
135+
move_cursor_towards_flypoint_and_go_there(env.program_info(), env.console, context, {ZoomChange::KEEP_ZOOM, 255, 180, 170});
136+
DirectionDetector direction;
137+
do_action_and_monitor_for_battles(env.program_info(), env.console, context,
138+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
139+
direction.change_direction(env.program_info(), env.console, context, 0.3491);
140+
pbf_move_left_joystick(context, 128, 0, 400, 100);
141+
direction.change_direction(env.program_info(), env.console, context, 5.075911);
142+
pbf_move_left_joystick(context, 128, 0, 525, 100);
143+
});
144+
145+
direction.change_direction(env.program_info(), env.console, context, 3.771252);
146+
get_on_ride(env.program_info(), env.console, context);
147+
// walk towards elevator
148+
pbf_move_left_joystick(context, 128, 0, 700, 100);
149+
// jump to ensure you get on elevator
150+
pbf_controller_state(context, BUTTON_B, DPAD_NONE, 128, 0, 128, 128, 200);
151+
pbf_wait(context, 3 * TICKS_PER_SECOND);
152+
// wait for overworld to reappear after stepping off elevator
153+
wait_for_overworld(env.program_info(), env.console, context, 30);
154+
155+
pbf_move_left_joystick(context, 128, 0, 120, 100);
156+
157+
direction.change_direction(env.program_info(), env.console, context, 5.11);
158+
pbf_move_left_joystick(context, 128, 0, 1600, 100);
159+
direction.change_direction(env.program_info(), env.console, context, 3.2245);
160+
161+
162+
handle_when_stationary_in_overworld(env.program_info(), env.console, context,
163+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
164+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 18);
165+
},
166+
[&](const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context){
167+
pbf_move_left_joystick(context, 255, 0, 100, 50);
168+
pbf_move_left_joystick(context, 0, 0, 100, 50);
169+
}
170+
);
171+
// talk to Nemona
172+
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
173+
174+
// talk to reception. Battle Kofu
175+
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
176+
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
177+
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
178+
mash_button_till_overworld(env.console, context, BUTTON_A, 360);
179+
180+
break;
181+
}catch (...){
182+
context.wait_for_all_requests();
183+
env.console.log("Resetting from checkpoint.");
184+
reset_game(env.program_info(), env.console, context);
185+
stats.m_reset++;
186+
env.update_stats();
187+
}
188+
}
189+
190+
}
191+
192+
193+
}
194+
}
195+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Autostory
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonSV_AutoStory_Segment_17_H
8+
#define PokemonAutomation_PokemonSV_AutoStory_Segment_17_H
9+
10+
#include <functional>
11+
#include "Common/Cpp/Options/EnumDropdownOption.h"
12+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
13+
#include "CommonFramework/Options/LanguageOCROption.h"
14+
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
15+
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
16+
#include "PokemonSV/Programs/PokemonSV_Navigation.h"
17+
#include "PokemonSV_AutoStoryTools.h"
18+
19+
namespace PokemonAutomation{
20+
namespace NintendoSwitch{
21+
namespace PokemonSV{
22+
23+
class AutoStory_Segment_17 : public AutoStory_Segment{
24+
public:
25+
virtual std::string name() const override;
26+
virtual std::string start_text() const override;
27+
virtual std::string end_text() const override;
28+
virtual void run_segment(
29+
SingleSwitchProgramEnvironment& env,
30+
BotBaseContext& context,
31+
AutoStoryOptions options) const override;
32+
};
33+
34+
35+
// start: At Porto Marinada Pokecenter.
36+
// end: Won auction at Porto Marinada, passed Gym challenge.
37+
void checkpoint_37(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update);
38+
39+
// start: Won auction at Porto Marinada, passed Gym challenge.
40+
// end: Defeat Cascarrafa Gym
41+
void checkpoint_38(SingleSwitchProgramEnvironment& env, BotBaseContext& context, EventNotificationOption& notif_status_update);
42+
43+
44+
45+
}
46+
}
47+
}
48+
#endif

0 commit comments

Comments
 (0)