Skip to content

Commit

Permalink
Item Printer Auto mode (#462)
Browse files Browse the repository at this point in the history
* update item printer database and table, to allow for Item printer Simple mode

* add Item printer simple mode

* run item printer based on the prizes and quantities obtained

* fixed bug with Item printer skipping prints after material farming

* update logic for when to run material farmer

* rename simple mode to auto mode

* update defaults for item printer auto mode

* remove print statements

* fix indentation
  • Loading branch information
jw098 authored Sep 1, 2024
1 parent 88569dd commit 2f17b07
Show file tree
Hide file tree
Showing 8 changed files with 708 additions and 256 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ enum class PrebuiltOptions{
};
const EnumDatabase<PrebuiltOptions>& PrebuiltOptions_Database();

const EnumDatabase<PrebuiltOptions>& PrebuiltOptions_AutoMode_Database();

const EnumDatabase<PrebuiltOptions>& PrebuiltOptions_Simple_Database2();


struct ItemPrinterEnumOption{
int64_t seed;
PrebuiltOptions enum_value;
ItemPrinterJobs jobs;
uint16_t quantity_obtained; // quantity obtained from the given seed, with given number of print jobs (ususally 5 print), with bonus active
};
const ItemPrinterEnumOption& option_lookup_by_enum(PrebuiltOptions enum_value);
const ItemPrinterEnumOption* option_lookup_by_seed(int64_t seed);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,45 @@ class ItemPrinterRNG : public SingleSwitchProgramInstance, public ConfigOption::


private:
enum class MaterialFarmerTrigger{
FIXED_NUM_PRINT_JOBS,
MINIMUM_HAPPINY_DUST,
};

enum class ItemPrinterMode{
AUTO_MODE,
STANDARD_MODE
};

virtual void value_changed(void* object) override;

bool overlapping_bonus();

void run_item_printer_rng_automode(SingleSwitchProgramEnvironment& env, BotBaseContext& context, ItemPrinterRNG_Descriptor::Stats& stats);

void run_item_printer_rng(SingleSwitchProgramEnvironment& env, BotBaseContext& context, ItemPrinterRNG_Descriptor::Stats& stats);

void run_print_at_date(
std::vector<ItemPrinterRngRowSnapshot> desired_print_table(
ItemPrinter::PrebuiltOptions desired_item,
uint16_t quantity_to_print
);

// return Ball bonus or item bonus, based on the desired_item
// if the desired_item is a type of ball, return Ball Bonus, else return Item Bonus
ItemPrinter::PrebuiltOptions get_bonus_type(ItemPrinter::PrebuiltOptions desired_item);

int16_t check_obtained_quantity(std::map<std::string, uint16_t> obtained_prizes, std::string desired_slug);

// move from item printer to material farming, run material farmer, then
// return to item printer
void run_material_farming_then_return_to_item_printer(
SingleSwitchProgramEnvironment& env,
BotBaseContext& context,
ItemPrinterRNG_Descriptor::Stats& stats,
MaterialFarmerOptions& material_farmer_options
);

ItemPrinterPrizeResult run_print_at_date(
SingleSwitchProgramEnvironment& env, BotBaseContext& context,
const DateTime& date, ItemPrinterJobs jobs
);
Expand Down Expand Up @@ -73,8 +105,10 @@ class ItemPrinterRNG : public SingleSwitchProgramInstance, public ConfigOption::
const std::array<std::string, 10>& expected_result
);

uint32_t calc_num_jobs_with_happiny_dust(
SingleSwitchProgramEnvironment& env, BotBaseContext& context
uint32_t calc_num_jobs_using_happiny_dust(
SingleSwitchProgramEnvironment& env,
BotBaseContext& context,
uint16_t min_happiny_dust
);

uint32_t check_num_happiny_dust(
Expand All @@ -84,9 +118,10 @@ class ItemPrinterRNG : public SingleSwitchProgramInstance, public ConfigOption::
private:
OCR::LanguageOCROption LANGUAGE;
SimpleIntegerOption<uint16_t> NUM_ITEM_PRINTER_ROUNDS;
// StaticTextOption AFTER_ITEM_PRINTER_DONE_EXPLANATION;

StaticTextOption OVERLAPPING_BONUS_WARNING;
EnumDropdownOption<ItemPrinterMode> MODE;
ItemPrinterDesiredItemTable TABLE1;
ItemPrinterRngTable TABLE0;

SimpleIntegerOption<uint16_t> DELAY_MILLIS;
Expand All @@ -95,14 +130,6 @@ class ItemPrinterRNG : public SingleSwitchProgramInstance, public ConfigOption::
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
BooleanCheckBoxOption FIX_TIME_WHEN_DONE;

// BooleanCheckBoxOption AUTO_MATERIAL_FARMING;
// SimpleIntegerOption<uint16_t> NUM_ROUNDS_OF_ITEM_PRINTER_TO_MATERIAL_FARM;

// StaticTextOption MATERIAL_FARMER_DISABLED_EXPLANATION;
enum class MaterialFarmerTrigger{
FIXED_NUM_PRINT_JOBS,
MINIMUM_HAPPINY_DUST,
};
EnumDropdownOption<MaterialFarmerTrigger> MATERIAL_FARMER_TRIGGER;
SimpleIntegerOption<uint16_t> MATERIAL_FARMER_FIXED_NUM_JOBS;
SimpleIntegerOption<uint16_t> MIN_HAPPINY_DUST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,77 @@ std::vector<std::unique_ptr<EditableTableRow>> ItemPrinterRngTable::make_default
}



ItemPrinterDesiredItemRow::ItemPrinterDesiredItemRow(EditableTableOption& parent_table)
: EditableTableRow(parent_table)
, desired_item(
ItemPrinter::PrebuiltOptions_AutoMode_Database(),
LockMode::UNLOCK_WHILE_RUNNING,
ItemPrinter::PrebuiltOptions::ABILITY_PATCH
)
, desired_quantity(
"",
LockMode::UNLOCK_WHILE_RUNNING,
999, 1, 999
)
{
PA_ADD_OPTION(desired_item);
PA_ADD_OPTION(desired_quantity);

}

ItemPrinterDesiredItemRow::ItemPrinterDesiredItemRow(
EditableTableOption& parent_table,
ItemPrinter::PrebuiltOptions item, uint16_t quantity
)
: ItemPrinterDesiredItemRow(parent_table)
{
desired_item.set(item);
desired_quantity.set(quantity);
}

ItemPrinterDesiredItemRowSnapshot ItemPrinterDesiredItemRow::snapshot() const{

return ItemPrinterDesiredItemRowSnapshot{desired_item, desired_quantity};
}


std::unique_ptr<EditableTableRow> ItemPrinterDesiredItemRow::clone() const{
std::unique_ptr<ItemPrinterDesiredItemRow> ret(new ItemPrinterDesiredItemRow(parent()));
ret->desired_item.set(desired_item);
ret->desired_quantity.set(desired_quantity);
return ret;
}


void ItemPrinterDesiredItemRow::value_changed(void* object){

}

ItemPrinterDesiredItemTable::ItemPrinterDesiredItemTable(std::string label)
: EditableTableOption_t<ItemPrinterDesiredItemRow>(
std::move(label),
LockMode::LOCK_WHILE_RUNNING
)
{
// Need to do this separately because this prematurely accesses the table.
set_default(make_defaults());
restore_defaults();
}
std::vector<std::string> ItemPrinterDesiredItemTable::make_header() const{
return std::vector<std::string>{
"Desired Item",
"Quantity",
};
}
std::vector<std::unique_ptr<EditableTableRow>> ItemPrinterDesiredItemTable::make_defaults(){
std::vector<std::unique_ptr<EditableTableRow>> ret;
ret.emplace_back(std::make_unique<ItemPrinterDesiredItemRow>(*this, ItemPrinter::PrebuiltOptions::ABILITY_PATCH, 999));
ret.emplace_back(std::make_unique<ItemPrinterDesiredItemRow>(*this, ItemPrinter::PrebuiltOptions::EXP_CANDY, 999));
return ret;
}


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Common/Cpp/Options/EnumDropdownOption.h"
#include "Common/Cpp/Options/DateOption.h"
#include "Common/Cpp/Options/EditableTableOption.h"
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "PokemonSV_ItemPrinterTools.h"
#include "PokemonSV_ItemPrinterDatabase.h"

Expand Down Expand Up @@ -60,6 +61,41 @@ class ItemPrinterRngTable : public EditableTableOption_t<ItemPrinterRngRow>{
friend class ItemPrinterRngRow;
};

struct ItemPrinterDesiredItemRowSnapshot{
ItemPrinter::PrebuiltOptions item;
uint16_t quantity;
};

class ItemPrinterDesiredItemRow : public EditableTableRow, public ConfigOption::Listener{
public:

ItemPrinterDesiredItemRow(EditableTableOption& parent_table);

ItemPrinterDesiredItemRow(
EditableTableOption& parent_table,
ItemPrinter::PrebuiltOptions item, uint16_t quantity
);

ItemPrinterDesiredItemRowSnapshot snapshot() const;

virtual std::unique_ptr<EditableTableRow> clone() const override;
virtual void value_changed(void* object) override;

public:
EnumDropdownCell<ItemPrinter::PrebuiltOptions> desired_item;
SimpleIntegerOption<uint16_t> desired_quantity;

};

class ItemPrinterDesiredItemTable : public EditableTableOption_t<ItemPrinterDesiredItemRow>{
public:
ItemPrinterDesiredItemTable(std::string label);
virtual std::vector<std::string> make_header() const override;
std::vector<std::unique_ptr<EditableTableRow>> make_defaults();

friend class ItemPrinterDesiredItemRow;
};



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ void item_printer_start_print(
}
}
}
std::array<std::string, 10> item_printer_finish_print(
ItemPrinterPrizeResult item_printer_finish_print(
AsyncDispatcher& dispatcher,
ConsoleHandle& console, BotBaseContext& context,
Language language
){
console.log("Finishing print...");
bool print_finished = false;

std::array<std::string, 10> ret;
ItemPrinterPrizeResult prize_result;
while (true){
AdvanceDialogWatcher dialog(COLOR_YELLOW);
WhiteButtonWatcher material(COLOR_GREEN, WhiteButton::ButtonX, {0.63, 0.93, 0.17, 0.06});
Expand All @@ -100,7 +100,7 @@ std::array<std::string, 10> item_printer_finish_print(
switch (ret_print_end){
case 0: // material
console.log("Material selection screen detected.");
return ret;
return prize_result;
case 1: // handle
case 2: // dialog
pbf_press_button(context, BUTTON_A, 20, 105);
Expand All @@ -116,7 +116,9 @@ std::array<std::string, 10> item_printer_finish_print(
VideoOverlaySet overlays(console.overlay());
reader.make_overlays(overlays);
auto snapshot = console.video().snapshot();
ret = reader.read_prizes(console.logger(), dispatcher, snapshot);
std::array<std::string, 10> prizes = reader.read_prizes(console.logger(), dispatcher, snapshot);
std::array<int16_t, 10> quantities = reader.read_quantity(console.logger(), dispatcher, snapshot);
prize_result = {prizes, quantities};
// static int c = 0;
// snapshot->save("test-" + std::to_string(c) + ".png");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ enum class ItemPrinterJobs{
};
const EnumDatabase<ItemPrinterJobs>& ItemPrinterJobs_Database();

struct ItemPrinterPrizeResult{
std::array<std::string, 10> prizes;
std::array<int16_t, 10> quantities;
};


void item_printer_start_print(
AsyncDispatcher& dispatcher,
ConsoleHandle& console, BotBaseContext& context,
Language language, ItemPrinterJobs jobs
);
std::array<std::string, 10> item_printer_finish_print(
ItemPrinterPrizeResult item_printer_finish_print(
AsyncDispatcher& dispatcher,
ConsoleHandle& console, BotBaseContext& context,
Language language
Expand Down

0 comments on commit 2f17b07

Please sign in to comment.