Skip to content

Commit

Permalink
Enforce herb compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Sep 22, 2023
1 parent 86e278d commit 00eb5b5
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ SandwichRecipe SandwichMakerOption::get_premade_sandwich_recipe(BaseRecipe base,
}

SandwichMakerOption::~SandwichMakerOption() {
HERBA_TWO.remove_listener(*this);
HERBA_ONE.remove_listener(*this);
TYPE.remove_listener(*this);
BASE_RECIPE.remove_listener(*this);
}

Expand Down Expand Up @@ -419,6 +422,7 @@ SandwichMakerOption::SandwichMakerOption(OCR::LanguageOCROption* language_option
LockWhileRunning::LOCKED,
HerbaSelection::salty_herba_mystica
)
, HERB_INCOMPATIBILITY_WARNING("")
, SANDWICH_INGREDIENTS("<b>Custom Sandwich:</b><br>Make a sandwich from the selected ingredients.<br>You must have at least one ingredient and one condiment, and no more than six ingredients and four condiments.")
{
if (m_language_owner){
Expand All @@ -429,36 +433,109 @@ SandwichMakerOption::SandwichMakerOption(OCR::LanguageOCROption* language_option
PA_ADD_OPTION(PARADOX);
PA_ADD_OPTION(HERBA_ONE);
PA_ADD_OPTION(HERBA_TWO);
PA_ADD_OPTION(HERB_INCOMPATIBILITY_WARNING);
PA_ADD_OPTION(SANDWICH_INGREDIENTS);

HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN);

SandwichMakerOption::value_changed();
BASE_RECIPE.add_listener(*this);

TYPE.add_listener(*this);
HERBA_ONE.add_listener(*this);
HERBA_TWO.add_listener(*this);
}

void SandwichMakerOption::value_changed() {
if (BASE_RECIPE == BaseRecipe::custom) {
void SandwichMakerOption::value_changed(){
if (BASE_RECIPE == BaseRecipe::custom){
SANDWICH_INGREDIENTS.set_visibility(ConfigOptionState::ENABLED);
HERBA_ONE.set_visibility(ConfigOptionState::DISABLED);
HERBA_TWO.set_visibility(ConfigOptionState::DISABLED);
HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN);
TYPE.set_visibility(ConfigOptionState::DISABLED); //to prevent the options moving around
PARADOX.set_visibility(ConfigOptionState::HIDDEN);
}
else if (two_herba_required(BASE_RECIPE)) { //shiny, huge, tiny
}else if (two_herba_required(BASE_RECIPE)){ //shiny, huge, tiny
SANDWICH_INGREDIENTS.set_visibility(ConfigOptionState::DISABLED);
HERBA_ONE.set_visibility(ConfigOptionState::ENABLED);
HERBA_TWO.set_visibility(ConfigOptionState::ENABLED);

std::string herb_error;
do{
if (BASE_RECIPE != BaseRecipe::shiny){
break;
}
herb_error = check_herb_compatibility(HERBA_ONE, HERBA_TWO, TYPE);
}while (false);

if (herb_error.empty()){
HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN);
}else{
HERB_INCOMPATIBILITY_WARNING.set_text("<font color=\"red\">" + herb_error + "</font>");
HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::ENABLED);
}
TYPE.set_visibility(ConfigOptionState::ENABLED);
PARADOX.set_visibility(ConfigOptionState::HIDDEN);
}
else { //other
}else{ //other
SANDWICH_INGREDIENTS.set_visibility(ConfigOptionState::DISABLED);
HERBA_ONE.set_visibility(ConfigOptionState::DISABLED);
HERBA_TWO.set_visibility(ConfigOptionState::DISABLED);
TYPE.set_visibility(ConfigOptionState::HIDDEN);
HERB_INCOMPATIBILITY_WARNING.set_visibility(ConfigOptionState::HIDDEN);
PARADOX.set_visibility(ConfigOptionState::ENABLED);
}
}
std::string SandwichMakerOption::check_validity() const{
if (!two_herba_required(BASE_RECIPE)){
return "";
}
if (BASE_RECIPE != BaseRecipe::shiny){
return "";
}
return check_herb_compatibility(HERBA_ONE, HERBA_TWO, TYPE);
}

std::string SandwichMakerOption::check_herb_compatibility(HerbaSelection herb1, HerbaSelection herb2, PokemonType type) const{
if ((herb1 == HerbaSelection::sweet_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica) ||
(herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::sweet_herba_mystica)
){
return "1x Sweet and 1x Sour herb are incompatible for all types.";
}
if (herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica){
return "2x Sour herbs are incompatible for all types.";
}
if (herb1 == HerbaSelection::sweet_herba_mystica && herb2 == HerbaSelection::sweet_herba_mystica &&
type == PokemonType::bug
){
return "2x Sweet herbs are incompatible with bug type.";
}
if ((herb1 == HerbaSelection::salty_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica) ||
(herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::salty_herba_mystica)
){
static const std::set<PokemonType> TYPES{
PokemonType::flying,
PokemonType::ground,
PokemonType::rock,
PokemonType::ice,
};
if (TYPES.contains(type)){
return "1x Salty and 1x Sour herb are incompatible with flying, ground, rock, and ice.";
}
}
if ((herb1 == HerbaSelection::bitter_herba_mystica && herb2 == HerbaSelection::sour_herba_mystica) ||
(herb1 == HerbaSelection::sour_herba_mystica && herb2 == HerbaSelection::bitter_herba_mystica)
){
static const std::set<PokemonType> TYPES{
PokemonType::fighting,
PokemonType::bug,
PokemonType::fairy,
};
if (TYPES.contains(type)){
return "1x Sour and 1x Bitter herb are incompatible with fighting, bug, and fairy.";
}
}

return "";
}



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef PokemonAutomation_PokemonSV_SandwichMakerOption_H
#define PokemonAutomation_PokemonSV_SandwichMakerOption_H

#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/GroupOption.h"
#include "Common/Cpp/Options/EnumDropdownOption.h"
//#include "PokemonSV/Resources/PokemonSV_Ingredients.h"
Expand Down Expand Up @@ -245,12 +246,15 @@ class SandwichMakerOption : public GroupOption, private ConfigOption::Listener {
EnumDropdownOption<ParadoxRecipe> PARADOX;
EnumDropdownOption<HerbaSelection> HERBA_ONE;
EnumDropdownOption<HerbaSelection> HERBA_TWO;
StaticTextOption HERB_INCOMPATIBILITY_WARNING;
SandwichIngredientsTable SANDWICH_INGREDIENTS;

private:
SandwichMakerOption(OCR::LanguageOCROption* language_option);
virtual void value_changed();
virtual void value_changed() override;
virtual std::string check_validity() const override;

std::string check_herb_compatibility(HerbaSelection herb1, HerbaSelection herb2, PokemonType type) const;
};

}
Expand Down

0 comments on commit 00eb5b5

Please sign in to comment.