Skip to content

Commit

Permalink
Merge pull request #375 from PokemonAutomation/main
Browse files Browse the repository at this point in the history
Cherrypick raid filter changes.
  • Loading branch information
Mysticial authored Oct 13, 2023
2 parents 22c8e88 + 7740ab9 commit d526282
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion SerialPrograms/Source/CommonFramework/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace PokemonAutomation{
const bool IS_BETA_VERSION = false;
const int PROGRAM_VERSION_MAJOR = 0;
const int PROGRAM_VERSION_MINOR = 42;
const int PROGRAM_VERSION_PATCH = 4;
const int PROGRAM_VERSION_PATCH = 5;

const std::string PROGRAM_VERSION_BASE =
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace NintendoSwitch{
namespace PokemonSV{


TeraRollFilter::TeraRollFilter()
TeraRollFilter::TeraRollFilter(uint8_t default_max_stars, bool enable_herb_filter)
: GroupOption("Opponent Filter", LockMode::UNLOCK_WHILE_RUNNING)
, EVENT_CHECK_MODE(
"<b>Event Tera Raid Action:</b><br>Choose how the program interacts with event/non-event raids."
Expand All @@ -42,9 +42,9 @@ TeraRollFilter::TeraRollFilter()
, MAX_STARS(
"<b>Max Stars:</b><br>Skip raids with more than this many stars.",
LockMode::UNLOCK_WHILE_RUNNING,
4, 1, 7
default_max_stars, 1, 7
)
, SKIP_HERBA(
, SKIP_NON_HERBA(
"<b>Skip Non-Herba Raids:</b><br>"
"Skip raids that don't have the possibility to reward all types of Herba Mystica. Enable this if you are searching for an herba raid.",
LockMode::UNLOCK_WHILE_RUNNING,
Expand All @@ -54,13 +54,24 @@ TeraRollFilter::TeraRollFilter()
PA_ADD_OPTION(EVENT_CHECK_MODE);
PA_ADD_OPTION(MIN_STARS);
PA_ADD_OPTION(MAX_STARS);
PA_ADD_OPTION(SKIP_HERBA);
if (enable_herb_filter){
PA_ADD_OPTION(SKIP_NON_HERBA);
}
}

void TeraRollFilter::start_program_check(Logger& logger) const{
std::string TeraRollFilter::check_validity() const{
if (MIN_STARS > MAX_STARS){
throw UserSetupError(logger, "Error in the settings, \"Min Stars\" is bigger than \"Max Stars\".");
return "\"Min Stars\" is bigger than \"Max Stars\".";
}
if (SKIP_NON_HERBA && MAX_STARS < 5){
return
"Setting \"Max Stars\" below 5 and \"Skip Herba\" to "
"true will never yield results because all herb raids are 5-star or higher.";
}
if (SKIP_NON_HERBA && EVENT_CHECK_MODE == EventCheckMode::CHECK_ONLY_EVENT){
return "\"Check only event raids\" and \"Skip Non-Herba Raids\" is incompatible because only non-event raids can have all herbs.";
}
return "";
}

TeraRollFilter::FilterResult TeraRollFilter::run_filter(
Expand Down Expand Up @@ -175,7 +186,7 @@ void TeraRollFilter::read_card(
console.log(log);
}
bool TeraRollFilter::check_herba(const std::string& pokemon_slug) const{
if (!SKIP_HERBA){
if (!SKIP_NON_HERBA){
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ struct TeraRaidData{

class TeraRollFilter : public GroupOption{
public:
TeraRollFilter();
TeraRollFilter(uint8_t default_max_stars, bool enable_herb_filter);

void start_program_check(Logger& logger) const;
virtual std::string check_validity() const override;

enum class FilterResult{
NO_RAID,
Expand Down Expand Up @@ -78,7 +78,7 @@ class TeraRollFilter : public GroupOption{
SimpleIntegerOption<uint8_t> MIN_STARS;
SimpleIntegerOption<uint8_t> MAX_STARS;

BooleanCheckBoxOption SKIP_HERBA;
BooleanCheckBoxOption SKIP_NON_HERBA;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ std::unique_ptr<StatsTracker> TeraRoller_Descriptor::make_stats() const{


TeraRoller::TeraRoller()
: CHECK_ONLY_FIRST(
: FILTER0(7, false)
, CHECK_ONLY_FIRST(
"<b>Check Only the First Pokédex Page:</b><br>Reduce time per reset at the expense of not checking repeated encounters.",
LockMode::UNLOCK_WHILE_RUNNING,
false
Expand All @@ -112,7 +113,7 @@ TeraRoller::TeraRoller()
&NOTIFICATION_ERROR_FATAL,
})
{
PA_ADD_OPTION(FILTER);
PA_ADD_OPTION(FILTER0);
PA_ADD_OPTION(CHECK_ONLY_FIRST);
PA_ADD_OPTION(PERIODIC_RESET);
PA_ADD_OPTION(NOTIFICATIONS);
Expand All @@ -124,11 +125,6 @@ void TeraRoller::program(SingleSwitchProgramEnvironment& env, BotBaseContext& co

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

FILTER.start_program_check(env.console);
if (FILTER.MIN_STARS > FILTER.MAX_STARS){
throw UserSetupError(env.console, "Error in the settings, \"Min Stars\" is bigger than \"Max Stars\".");
}

// Connect the controller
pbf_press_button(context, BUTTON_L, 10, 10);

Expand Down Expand Up @@ -159,7 +155,7 @@ void TeraRoller::program(SingleSwitchProgramEnvironment& env, BotBaseContext& co
}

TeraRaidData raid_data;
TeraRollFilter::FilterResult result = FILTER.run_filter(
TeraRollFilter::FilterResult result = FILTER0.run_filter(
env.program_info(), env.console, context,
raid_data
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TeraRoller : public SingleSwitchProgramInstance{
virtual void program(SingleSwitchProgramEnvironment& env, BotBaseContext& context) override;

private:
TeraRollFilter FILTER;
TeraRollFilter FILTER0;

BooleanCheckBoxOption CHECK_ONLY_FIRST;
SimpleIntegerOption<uint8_t> PERIODIC_RESET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ TeraSelfFarmer::TeraSelfFarmer()
PokemonNameReader::instance().languages(),
LockMode::UNLOCK_WHILE_RUNNING
)
, FILTER(4, true)
, PERIODIC_RESET(
"<b>Periodic Game Reset:</b><br>Reset the game after this many skips. This clears up the framerate bug.",
LockMode::UNLOCK_WHILE_RUNNING,
Expand Down Expand Up @@ -225,7 +226,7 @@ void TeraSelfFarmer::program(SingleSwitchProgramEnvironment& env, BotBaseContext
throw UserSetupError(env.console, "Error in the settings, \"Min Stars\" is bigger than \"Max Stars\".");
}

if (FILTER.SKIP_HERBA && FILTER.MAX_STARS < 5){
if (FILTER.SKIP_NON_HERBA && FILTER.MAX_STARS < 5){
throw UserSetupError(env.console, "Error in the settings, Skip Non-Herba Raids is checked but Max Stars is less than 5.");
}

Expand Down

0 comments on commit d526282

Please sign in to comment.