Skip to content

Commit 1366992

Browse files
committed
Update PokemonLZA_InPlaceCatcher.cpp
1 parent a092e0a commit 1366992

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

SerialPrograms/Source/PokemonLZA/Programs/Farming/PokemonLZA_InPlaceCatcher.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1414
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
1515
#include "Pokemon/Pokemon_Strings.h"
16+
#include "PokemonLZA/Inference/PokemonLZA_DialogDetector.h"
1617
#include "PokemonLZA/Inference/PokemonLZA_DayNightChangeDetector.h"
1718
#include "PokemonLZA/Inference/PokemonLZA_AlertEyeDetector.h"
1819
#include "PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h"
1920
#include "PokemonLZA/Inference/Battles/PokemonLZA_MoveEffectivenessSymbol.h"
21+
#include "PokemonLZA/Programs/PokemonLZA_GameEntry.h"
2022
#include "PokemonLZA/Programs/PokemonLZA_TrainerBattle.h"
2123
#include "PokemonLZA_InPlaceCatcher.h"
2224

@@ -34,7 +36,8 @@ InPlaceCatcher_Descriptor::InPlaceCatcher_Descriptor()
3436
Pokemon::STRING_POKEMON + " LZA", "In-Place Catcher",
3537
"Programs/PokemonLZA/InPlaceCatcher.html",
3638
"Stand in one spot and catch everything that spawns nearby. "
37-
"Useful for filling up your boxes.",
39+
"Useful for filling up your boxes for the purpose of running Floette "
40+
"stats reset or to mass transfer " + Pokemon::STRING_POKEMON + " between saves via Box Trade.",
3841
ProgramControllerClass::StandardController_NoRestrictions,
3942
FeedbackType::REQUIRED,
4043
AllowCommandsWhenRunning::DISABLE_COMMANDS
@@ -48,17 +51,20 @@ class InPlaceCatcher_Descriptor::Stats : public StatsTracker{
4851
: balls_thrown(m_stats["Balls Thrown"])
4952
, attacks_fired(m_stats["Attacks Launched"])
5053
, day_changes(m_stats["Day/Night Changes"])
54+
, deaths(m_stats["Day/Night Changes"])
5155
, errors(m_stats["Errors"])
5256
{
5357
m_display_order.emplace_back("Balls Thrown");
5458
m_display_order.emplace_back("Attacks Launched");
5559
m_display_order.emplace_back("Day/Night Changes");
60+
m_display_order.emplace_back("Deaths", HIDDEN_IF_ZERO);
5661
m_display_order.emplace_back("Errors", HIDDEN_IF_ZERO);
5762
}
5863

5964
std::atomic<uint64_t>& balls_thrown;
6065
std::atomic<uint64_t>& attacks_fired;
6166
std::atomic<uint64_t>& day_changes;
67+
std::atomic<uint64_t>& deaths;
6268
std::atomic<uint64_t>& errors;
6369
};
6470
std::unique_ptr<StatsTracker> InPlaceCatcher_Descriptor::make_stats() const{
@@ -121,12 +127,15 @@ void InPlaceCatcher::program(SingleSwitchProgramEnvironment& env, ProControllerC
121127
{attack_tracker}
122128
);
123129

130+
WallClock last_attack = WallClock::min();
124131
while (stats.balls_thrown.load(std::memory_order_relaxed) < MAX_BALLS){
125132
env.update_stats();
126133
send_program_status_notification(env, NOTIFICATION_STATUS_UPDATE);
127134

128135
MoveEffectivenessSymbolWatcher battle_menu(COLOR_RED, &env.console.overlay(), 100ms);
129136
DayNightChangeWatcher day_night(COLOR_RED);
137+
BlueDialogWatcher dialog(COLOR_BLUE, &env.console.overlay());
138+
130139
context.wait_for_all_requests();
131140

132141
int ret = run_until<ProControllerContext>(
@@ -145,20 +154,27 @@ void InPlaceCatcher::program(SingleSwitchProgramEnvironment& env, ProControllerC
145154
{
146155
battle_menu,
147156
day_night,
157+
dialog,
148158
}
149159
);
150160
context.wait_for(100ms);
151161

152162
switch (ret){
153163
case 0:
154164
break;
155-
case 1:{
165+
case 1:
156166
day_night_handler(env, context);
157167
continue;
158-
}
168+
case 2:
169+
env.log("You died... Resetting game.", COLOR_RED);
170+
stats.deaths++;
171+
env.update_stats();
172+
go_home(env.console, context);
173+
reset_game_from_home(env, env.console, context);
174+
continue;
159175
}
160176

161-
if (!attack_tracker.currently_active()){
177+
if (!attack_tracker.currently_active() || last_attack + 5000ms > current_time()){
162178
env.log("Detected battle menu. Throwing ball...", COLOR_BLUE);
163179
pbf_press_button(
164180
context,
@@ -176,6 +192,7 @@ void InPlaceCatcher::program(SingleSwitchProgramEnvironment& env, ProControllerC
176192

177193
TrainerBattleState state;
178194
if (state.attempt_one_attack(env, env.console, context, true, false, false)){
195+
last_attack = current_time();
179196
stats.attacks_fired++;
180197
env.update_stats();
181198
pbf_wait(context, 2000ms);

0 commit comments

Comments
 (0)