Skip to content

Commit c7da6d7

Browse files
committed
Make TeraMultiFarmer work for one-catch mons if joiner has already caught.
1 parent 51e6943 commit c7da6d7

File tree

5 files changed

+62
-20
lines changed

5 files changed

+62
-20
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,14 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
279279
BotBaseContext context(scope, console.botbase());
280280
VideoOverlaySet overlays(overlay);
281281

282-
282+
#if 0
283283
PokemonSwSh::MaxLairInternal::PokemonSwapMenuReader reader(console, overlay, Language::English);
284284

285285
ImageRGB32 image("20241221-123730238930.png");
286286

287287
double hp[4];
288288
reader.read_hp(image, hp);
289+
#endif
289290

290291
// reader.read_opponent_in_summary(logger, image);
291292

@@ -340,7 +341,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
340341
);
341342
#endif
342343

343-
#if 0
344+
#if 1
344345
VideoSnapshot image = feed.snapshot();
345346
// ImageRGB32 image("screenshot-20241124-135028529403.png");
346347

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ bool DateReader::detect(const ImageViewRGB32& screen) const{
112112

113113
return true;
114114
}
115+
#if 0
115116
int8_t DateReader::read_hours(Logger& logger, const ImageViewRGB32& screen) const{
116117
if (!detect(screen)){
117118
return -1;
@@ -158,7 +159,9 @@ int8_t DateReader::read_hours(Logger& logger, const ImageViewRGB32& screen) cons
158159
}
159160
return (int8_t)hours;
160161
}
162+
161163
}
164+
#endif
162165

163166

164167
void DateReader::set_hours(
@@ -187,7 +190,9 @@ void DateReader::set_hours(
187190

188191
// Read the hour.
189192
VideoSnapshot snapshot = console.video().snapshot();
190-
int8_t current_hour = read_hours(console.logger(), snapshot);
193+
// int8_t current_hour = read_hours(console, snapshot);
194+
int8_t current_hour = read_date(console, snapshot).second.hour;
195+
191196
if (current_hour < 0){
192197
throw_and_log<FatalProgramException>(
193198
console, ErrorReport::SEND_ERROR_REPORT,

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class DateReader : public StaticScreenDetector{
3939

4040
// Read the hours (0 - 23) while on the date change window.
4141
// Returns -1 if unable to read.
42-
int8_t read_hours(Logger& logger, const ImageViewRGB32& screen) const;
42+
// int8_t read_hours(Logger& logger, std::shared_ptr<const ImageRGB32> screen) const;
4343

4444
void set_hours(
4545
const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context,

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraMultiFarmer.cpp

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include "PokemonSV_AutoHostLobbyWaiter.h"
3232
#include "PokemonSV_TeraMultiFarmer.h"
3333

34+
//#include <iostream>
35+
//using std::cout;
36+
//using std::endl;
37+
3438
namespace PokemonAutomation{
3539
namespace NintendoSwitch{
3640
namespace PokemonSV{
@@ -322,44 +326,68 @@ void TeraMultiFarmer::join_lobby(
322326

323327
TeraMultiFarmer_Descriptor::Stats& stats = env.current_stats<TeraMultiFarmer_Descriptor::Stats>();
324328

325-
for (size_t attempts = 0;; attempts++){
329+
// cout << "Joining Lobby" << endl;
330+
331+
bool seen_code_entry = false;
332+
bool seen_dialog = false;
333+
size_t attempts = 0;
334+
while (true){
326335
if (attempts >= 3){
327336
OperationFailedException::fire(
328337
console, ErrorReport::SEND_ERROR_REPORT,
329338
"Failed to join lobby 3 times."
330339
);
331340
}
332341

333-
enter_code(console, context, FastCodeEntrySettings(), normalized_code, false);
334-
342+
CodeEntryWatcher code_entry(COLOR_GREEN);
335343
TeraLobbyWatcher lobby(console.logger(), env.realtime_dispatcher(), COLOR_RED);
336-
AdvanceDialogWatcher wrong_code(COLOR_YELLOW);
337-
CodeEntryWatcher incomplete_code(COLOR_GREEN);
344+
AdvanceDialogWatcher dialog(COLOR_YELLOW, std::chrono::seconds(2));
345+
TeraRaidSearchWatcher raid_search(COLOR_CYAN);
338346
context.wait_for_all_requests();
339347
context.wait_for(std::chrono::seconds(3));
340348
int ret = wait_until(
341349
console, context, std::chrono::seconds(60),
342350
{
343-
{lobby, std::chrono::milliseconds(500)},
344-
wrong_code,
345-
incomplete_code,
351+
code_entry,
352+
lobby,
353+
dialog,
354+
raid_search,
346355
}
347356
);
348357
switch (ret){
349358
case 0:
359+
console.log("Detected code entry.", COLOR_RED);
360+
if (seen_code_entry){
361+
console.log("Failed to enter code! Backing out and trying again...", COLOR_RED);
362+
stats.m_errors++;
363+
attempts++;
364+
pbf_press_button(context, BUTTON_X, 20, 480);
365+
enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE);
366+
seen_code_entry = false;
367+
continue;
368+
}
369+
seen_code_entry = true;
370+
enter_code(console, context, FastCodeEntrySettings(), normalized_code, false);
371+
context.wait_for(std::chrono::seconds(1));
372+
continue;
373+
case 1:
350374
console.log("Entered raid lobby!");
351-
pbf_mash_button(context, BUTTON_A, 125);
375+
pbf_mash_button(context, BUTTON_A, 5 * TICKS_PER_SECOND);
352376
break;
353-
case 1:
354-
console.log("Wrong code! Backing out and trying again...", COLOR_RED);
355-
stats.m_errors++;
377+
case 2:
378+
console.log("Detected dialog...", COLOR_ORANGE);
379+
seen_dialog = true;
356380
pbf_press_button(context, BUTTON_B, 20, 230);
357-
enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE);
358381
continue;
359-
case 2:
360-
console.log("Failed to enter code! Backing out and trying again...", COLOR_RED);
382+
case 3:
383+
if (!seen_dialog){
384+
context.wait_for(std::chrono::seconds(1));
385+
continue;
386+
}
387+
console.log("Wrong code! Backing out and trying again...", COLOR_RED);
361388
stats.m_errors++;
362-
pbf_press_button(context, BUTTON_X, 20, 230);
389+
attempts++;
390+
// pbf_press_button(context, BUTTON_B, 20, 230);
363391
enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE);
364392
continue;
365393
default:

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraRoutines.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ void open_hosting_lobby(
139139
recovery_mode = true;
140140
}
141141

142+
// AdvanceDialogWatcher dialog(COLOR_GREEN);
142143
TeraCardWatcher card_detector(COLOR_YELLOW);
143144
TeraLobbyWatcher lobby(console.logger(), env.realtime_dispatcher(), COLOR_BLUE);
144145
context.wait_for_all_requests();
@@ -147,6 +148,7 @@ void open_hosting_lobby(
147148
std::chrono::seconds(30),
148149
{
149150
overworld,
151+
// dialog,
150152
card_detector,
151153
{lobby, std::chrono::milliseconds(500)}
152154
}
@@ -163,6 +165,12 @@ void open_hosting_lobby(
163165
);
164166
}
165167
continue;
168+
#if 0
169+
case 1:
170+
console.log("Detect possible uncatchable dialog...", COLOR_ORANGE);
171+
pbf_press_button(context, BUTTON_B, 20, 230);
172+
continue;
173+
#endif
166174
case 1:
167175
console.log("Detected Tera card.");
168176
if (mode != HostingMode::LOCAL){

0 commit comments

Comments
 (0)