Skip to content

Commit

Permalink
Make TeraMultiFarmer work for one-catch mons if joiner has already ca…
Browse files Browse the repository at this point in the history
…ught.
  • Loading branch information
Mysticial committed Dec 22, 2024
1 parent 51e6943 commit c7da6d7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,14 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
BotBaseContext context(scope, console.botbase());
VideoOverlaySet overlays(overlay);


#if 0
PokemonSwSh::MaxLairInternal::PokemonSwapMenuReader reader(console, overlay, Language::English);

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

double hp[4];
reader.read_hp(image, hp);
#endif

// reader.read_opponent_in_summary(logger, image);

Expand Down Expand Up @@ -340,7 +341,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
);
#endif

#if 0
#if 1
VideoSnapshot image = feed.snapshot();
// ImageRGB32 image("screenshot-20241124-135028529403.png");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ bool DateReader::detect(const ImageViewRGB32& screen) const{

return true;
}
#if 0
int8_t DateReader::read_hours(Logger& logger, const ImageViewRGB32& screen) const{
if (!detect(screen)){
return -1;
Expand Down Expand Up @@ -158,7 +159,9 @@ int8_t DateReader::read_hours(Logger& logger, const ImageViewRGB32& screen) cons
}
return (int8_t)hours;
}

}
#endif


void DateReader::set_hours(
Expand Down Expand Up @@ -187,7 +190,9 @@ void DateReader::set_hours(

// Read the hour.
VideoSnapshot snapshot = console.video().snapshot();
int8_t current_hour = read_hours(console.logger(), snapshot);
// int8_t current_hour = read_hours(console, snapshot);
int8_t current_hour = read_date(console, snapshot).second.hour;

if (current_hour < 0){
throw_and_log<FatalProgramException>(
console, ErrorReport::SEND_ERROR_REPORT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DateReader : public StaticScreenDetector{

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

void set_hours(
const ProgramInfo& info, ConsoleHandle& console, BotBaseContext& context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "PokemonSV_AutoHostLobbyWaiter.h"
#include "PokemonSV_TeraMultiFarmer.h"

//#include <iostream>
//using std::cout;
//using std::endl;

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSV{
Expand Down Expand Up @@ -322,44 +326,68 @@ void TeraMultiFarmer::join_lobby(

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

for (size_t attempts = 0;; attempts++){
// cout << "Joining Lobby" << endl;

bool seen_code_entry = false;
bool seen_dialog = false;
size_t attempts = 0;
while (true){
if (attempts >= 3){
OperationFailedException::fire(
console, ErrorReport::SEND_ERROR_REPORT,
"Failed to join lobby 3 times."
);
}

enter_code(console, context, FastCodeEntrySettings(), normalized_code, false);

CodeEntryWatcher code_entry(COLOR_GREEN);
TeraLobbyWatcher lobby(console.logger(), env.realtime_dispatcher(), COLOR_RED);
AdvanceDialogWatcher wrong_code(COLOR_YELLOW);
CodeEntryWatcher incomplete_code(COLOR_GREEN);
AdvanceDialogWatcher dialog(COLOR_YELLOW, std::chrono::seconds(2));
TeraRaidSearchWatcher raid_search(COLOR_CYAN);
context.wait_for_all_requests();
context.wait_for(std::chrono::seconds(3));
int ret = wait_until(
console, context, std::chrono::seconds(60),
{
{lobby, std::chrono::milliseconds(500)},
wrong_code,
incomplete_code,
code_entry,
lobby,
dialog,
raid_search,
}
);
switch (ret){
case 0:
console.log("Detected code entry.", COLOR_RED);
if (seen_code_entry){
console.log("Failed to enter code! Backing out and trying again...", COLOR_RED);
stats.m_errors++;
attempts++;
pbf_press_button(context, BUTTON_X, 20, 480);
enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE);
seen_code_entry = false;
continue;
}
seen_code_entry = true;
enter_code(console, context, FastCodeEntrySettings(), normalized_code, false);
context.wait_for(std::chrono::seconds(1));
continue;
case 1:
console.log("Entered raid lobby!");
pbf_mash_button(context, BUTTON_A, 125);
pbf_mash_button(context, BUTTON_A, 5 * TICKS_PER_SECOND);
break;
case 1:
console.log("Wrong code! Backing out and trying again...", COLOR_RED);
stats.m_errors++;
case 2:
console.log("Detected dialog...", COLOR_ORANGE);
seen_dialog = true;
pbf_press_button(context, BUTTON_B, 20, 230);
enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE);
continue;
case 2:
console.log("Failed to enter code! Backing out and trying again...", COLOR_RED);
case 3:
if (!seen_dialog){
context.wait_for(std::chrono::seconds(1));
continue;
}
console.log("Wrong code! Backing out and trying again...", COLOR_RED);
stats.m_errors++;
pbf_press_button(context, BUTTON_X, 20, 230);
attempts++;
// pbf_press_button(context, BUTTON_B, 20, 230);
enter_tera_search(env.program_info(), console, context, HOSTING_MODE == Mode::HOST_ONLINE);
continue;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void open_hosting_lobby(
recovery_mode = true;
}

// AdvanceDialogWatcher dialog(COLOR_GREEN);
TeraCardWatcher card_detector(COLOR_YELLOW);
TeraLobbyWatcher lobby(console.logger(), env.realtime_dispatcher(), COLOR_BLUE);
context.wait_for_all_requests();
Expand All @@ -147,6 +148,7 @@ void open_hosting_lobby(
std::chrono::seconds(30),
{
overworld,
// dialog,
card_detector,
{lobby, std::chrono::milliseconds(500)}
}
Expand All @@ -163,6 +165,12 @@ void open_hosting_lobby(
);
}
continue;
#if 0
case 1:
console.log("Detect possible uncatchable dialog...", COLOR_ORANGE);
pbf_press_button(context, BUTTON_B, 20, 230);
continue;
#endif
case 1:
console.log("Detected Tera card.");
if (mode != HostingMode::LOCAL){
Expand Down

0 comments on commit c7da6d7

Please sign in to comment.