-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathPokemonSwSh_MaxLair_StrongBoss.cpp
More file actions
279 lines (241 loc) · 9.12 KB
/
PokemonSwSh_MaxLair_StrongBoss.cpp
File metadata and controls
279 lines (241 loc) · 9.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* Max Lair (Strong-Boss Mode)
*
* From: https://github.com/PokemonAutomation/
*
*/
#include "Common/Cpp/PrettyPrint.h"
#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Notifications/ProgramNotifications.h"
#include "CommonTools/StartupChecks/VideoResolutionCheck.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonSwSh/Options/PokemonSwSh_BallSelectOption.h"
#include "PokemonSwSh/Programs/PokemonSwSh_GameEntry.h"
#include "Program/PokemonSwSh_MaxLair_Run_Adventure.h"
#include "PokemonSwSh_MaxLair_StrongBoss.h"
//#include <iostream>
//using std::cout;
//using std::endl;
namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSwSh{
using namespace MaxLairInternal;
MaxLairStrongBoss_Descriptor::MaxLairStrongBoss_Descriptor()
: MultiSwitchProgramDescriptor(
"PokemonSwSh:MaxLair-StrongBoss",
STRING_POKEMON + " SwSh", "Max Lair - Strong Boss",
"Programs/PokemonSwSh/MaxLair-StrongBoss.html",
"Auto Max Lair 2.0 - Run Dynamax Adventures and intelligently reset to keep paths that have high win rates.",
ProgramControllerClass::StandardController_NoRestrictions,
FeedbackType::REQUIRED,
AllowCommandsWhenRunning::DISABLE_COMMANDS,
1, 4, 1
)
{}
std::unique_ptr<StatsTracker> MaxLairStrongBoss_Descriptor::make_stats() const{
return std::unique_ptr<StatsTracker>(new Stats());
}
class MaxLairStrongBoss_ConsoleOptions : public ConsoleSpecificOptions{
public:
MaxLairStrongBoss_ConsoleOptions(std::string label, const LanguageSet& languages, bool host)
: ConsoleSpecificOptions(std::move(label), languages, host)
, normal_ball(
"<b>Normal Ball:</b> Ball for catching non-boss " + STRING_POKEMON + ".",
LockMode::LOCK_WHILE_RUNNING,
"poke-ball"
)
, boss_ball(
"<b>Boss Ball:</b> Ball for catching the boss/legendary " + STRING_POKEMON + ".",
LockMode::LOCK_WHILE_RUNNING,
"poke-ball"
)
, actions_non_host(false, false)
, actions_host(
false, true,
CaughtScreenAction::RESET,
CaughtScreenAction::TAKE_NON_BOSS_SHINY_AND_CONTINUE,
CaughtScreenAction::STOP_PROGRAM
)
{
if (host){
actions_non_host.set_visibility(ConfigOptionState::HIDDEN);
}else{
actions_host.set_visibility(ConfigOptionState::ENABLED);
}
PA_ADD_OPTION(normal_ball);
PA_ADD_OPTION(boss_ball);
PA_ADD_OPTION(actions_non_host);
PA_ADD_OPTION(actions_host);
}
const CaughtScreenActionsOption& actions() const{
return is_host ? actions_host : actions_non_host;
}
virtual void set_host(bool is_host) override{
ConsoleSpecificOptions::set_host(is_host);
if (is_host){
actions_host.set_visibility(ConfigOptionState::ENABLED);
actions_non_host.set_visibility(ConfigOptionState::HIDDEN);
}else{
actions_host.set_visibility(ConfigOptionState::HIDDEN);
actions_non_host.set_visibility(ConfigOptionState::ENABLED);
}
}
PokemonBallSelectOption normal_ball;
PokemonBallSelectOption boss_ball;
CaughtScreenActionsOption actions_non_host;
CaughtScreenActionsOption actions_host;
};
class MaxLairStrongBoss_ConsoleFactory : public ConsoleSpecificOptionsFactory{
public:
virtual std::unique_ptr<ConsoleSpecificOptions> make(std::string label, const LanguageSet& languages, bool is_host) const override{
return std::unique_ptr<ConsoleSpecificOptions>(new MaxLairStrongBoss_ConsoleOptions(std::move(label), languages, is_host));
}
};
MaxLairStrongBoss::MaxLairStrongBoss()
: MultiSwitchProgramInstance({"Notifs", "LiveHost"})
, GO_HOME_WHEN_DONE(false)
, MIN_WIN_RATE(
"<b>Minimum Win Rate:</b><br>"
"Keep the path if the win rate stays above this ratio. This is done by resetting the host.",
LockMode::UNLOCK_WHILE_RUNNING,
0.75, 0, 1.0
)
, CONSOLES(MaxLairStrongBoss_ConsoleFactory())
, NOTIFICATION_STATUS("Status Update", true, false)
, NOTIFICATION_SHINY("Shiny Catch", true, true, ImageAttachmentMode::JPG, {"Notifs", "Showcase"})
, NOTIFICATIONS({
&HOSTING.NOTIFICATIONS.NOTIFICATION,
&NOTIFICATION_STATUS,
&NOTIFICATION_SHINY,
&NOTIFICATION_PROGRAM_FINISH,
&NOTIFICATION_ERROR_FATAL,
})
{
PA_ADD_OPTION(START_LOCATION);
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
PA_ADD_OPTION(MIN_WIN_RATE);
PA_ADD_OPTION(BOSS_SLOT);
PA_ADD_OPTION(CONSOLES);
PA_ADD_OPTION(HOSTING);
PA_ADD_OPTION(TOUCH_DATE_INTERVAL);
PA_ADD_OPTION(NOTIFICATIONS);
}
std::string MaxLairStrongBoss::check_validity() const{
std::string error = MultiSwitchProgramInstance::check_validity();
if (!error.empty()){
return error;
}
size_t active_consoles = CONSOLES.active_consoles();
error = CONSOLES.HOST.check_validity(active_consoles);
if (!error.empty()){
return error;
}
error = HOSTING.check_validity(active_consoles);
if (!error.empty()){
return error;
}
return std::string();
}
void MaxLairStrongBoss::update_active_consoles(size_t switch_count){
CONSOLES.set_active_consoles(switch_count);
}
class EndBattleDecider_StrongBoss : public EndBattleDecider{
public:
EndBattleDecider_StrongBoss(
Logger& logger,
const Consoles& consoles, size_t host_index,
const FloatingPointOption& min_win_ratio
)
: m_logger(logger)
, m_consoles(consoles)
, m_host_index(host_index)
, m_min_win_ratio(min_win_ratio)
{}
virtual const std::string& normal_ball(
size_t console_index
) const override{
return console(console_index).normal_ball.slug();
}
virtual const std::string& boss_ball(
size_t console_index, const std::string& boss_slug
) const override{
return console(console_index).boss_ball.slug();
}
virtual CaughtScreenAction end_adventure_action(
size_t console_index, const std::string& boss_slug,
const PathStats& path_stats,
bool any_shiny, bool boss_is_shiny
) const override{
const CaughtScreenActionsOption& actions = console(console_index).actions();
CaughtScreenAction action;
do{
if (boss_is_shiny){
action = actions.shiny_boss;
break;
}
if (any_shiny){
action = actions.shiny_nonboss;
break;
}
action = actions.no_shinies;
}while (false);
if (action != CaughtScreenAction::RESET || console_index != m_host_index){
return action;
}
double win_ratio = path_stats.win_ratio();
if (win_ratio >= m_min_win_ratio){
m_logger.log("Win Ratio = " + tostr_default(win_ratio) + ": Resetting to keep path.", COLOR_BLUE);
return CaughtScreenAction::RESET;
}else{
m_logger.log("Win Ratio = " + tostr_default(win_ratio) + ": Continuing to get new path.", COLOR_BLUE);
return CaughtScreenAction::TAKE_NON_BOSS_SHINY_AND_CONTINUE;
}
}
virtual bool stop_for_non_boss(const std::string& slug) const override {
return false;
}
private:
const MaxLairStrongBoss_ConsoleOptions& console(size_t index) const{
return static_cast<const MaxLairStrongBoss_ConsoleOptions&>(m_consoles[index]);
}
Logger& m_logger;
const Consoles& m_consoles;
size_t m_host_index;
const FloatingPointOption& m_min_win_ratio;
};
void MaxLairStrongBoss::program(MultiSwitchProgramEnvironment& env, CancellableScope& scope){
size_t host_index = CONSOLES.HOST.current_value();
if (host_index >= env.consoles.size()){
throw UserSetupError(env.logger(), "Invalid Host Switch");
}
env.run_in_parallel(scope, [&](ConsoleHandle& console, ProControllerContext& context){
assert_16_9_720p_min(console, console);
if (START_LOCATION.start_in_grip_menu()){
grip_menu_connect_go_home(context);
resume_game_no_interact(console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_FAST);
}else{
pbf_press_button(context, BUTTON_B, 40ms, 40ms);
}
});
EndBattleDecider_StrongBoss decider(
env.logger(),
CONSOLES, host_index,
MIN_WIN_RATE
);
loop_adventures(
env, scope, CONSOLES,
host_index, BOSS_SLOT.current_value(),
decider,
GO_HOME_WHEN_DONE,
HOSTING,
TOUCH_DATE_INTERVAL,
NOTIFICATION_STATUS,
NOTIFICATION_SHINY
);
env.update_stats();
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
}
}
}
}