From 264623f40ac2a79fe7afd7818266a8f0f55ec2c2 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Mon, 13 Mar 2023 14:24:51 -0700 Subject: [PATCH] Shopsanity Affordable Logic Update (#2617) * Modified Affordable logic to select randomly from 10, 105, 205, and 505 depending on the selected wallet tier. Updated the tooltip to reflect. * Clarified logic in comments and variable names. * Streamlined affordable check for starter wallet. One more function comment. * More streamlining of affordable price generation, comment clarification. --- .../Enhancements/randomizer/3drando/shops.cpp | 44 +++++++++++-------- .../Enhancements/randomizer/randomizer.cpp | 6 +-- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/3drando/shops.cpp b/soh/soh/Enhancements/randomizer/3drando/shops.cpp index 1b4dbb28d..3cfaa01ad 100644 --- a/soh/soh/Enhancements/randomizer/3drando/shops.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/shops.cpp @@ -128,31 +128,39 @@ static constexpr std::array ShopPriceProbability= { 0.959992180, 0.968187000, 0.975495390, 0.981884488, 0.987344345, 0.991851853, 0.995389113, 0.997937921, 0.999481947, 1.000000000, }; -std::map affordableCaps = { - {RO_SHOPSANITY_PRICE_STARTER, 10}, - {RO_SHOPSANITY_PRICE_ADULT, 105}, - {RO_SHOPSANITY_PRICE_GIANT, 205}, - {RO_SHOPSANITY_PRICE_TYCOON, 505}, -}; - -// If affordable option is on, cap items at affordable price just above the max of the previous wallet tier -int CapPriceAffordable(int value, int cap) { - if (Settings::ShopsanityPricesAffordable.Is(true) && value > cap) - return cap; - return value; -} - // Generate random number from 5 to wallet max int GetPriceFromMax(int max) { - int temp = Random(1, max) * 5; // random range of 1 - wallet max / 5, where wallet max is the highest it goes as a multiple of 5 - return CapPriceAffordable(temp, affordableCaps.find(Settings::ShopsanityPrices.Value())->second); + return Random(1, max) * 5; // random range of 1 - wallet max / 5, where wallet max is the highest it goes as a multiple of 5 +} + +// Get random price out of available "affordable prices", or just return 10 if Starter wallet is selected (no need to randomly select +// from a single element) +int GetPriceAffordable() { + if (Settings::ShopsanityPrices.Is(RO_SHOPSANITY_PRICE_STARTER)) { + return 10; + } + + static const std::vector affordablePrices = { 10, 105, 205, 505 }; + std::vector priceList; + uint8_t maxElements = Settings::ShopsanityPrices.Value(); + for (int i = 0; i < maxElements; i++) { + priceList.push_back(affordablePrices.at(i)); + } + return RandomElement(priceList); } int GetRandomShopPrice() { + // If Affordable is enabled, no need to set randomizer max price + if (Settings::ShopsanityPricesAffordable.Is(true)) { + return GetPriceAffordable(); + } + + // max 0 means Balanced is selected, and thus shouldn't trigger GetPriceFromMax int max = 0; - if(Settings::ShopsanityPrices.Is(RO_SHOPSANITY_PRICE_STARTER)) {// check for xx wallet setting and set max amount as method for - max = 19; // 95/5 // setting true randomization + // check settings for a wallet tier selection and set max amount as method for setting true randomization + if(Settings::ShopsanityPrices.Is(RO_SHOPSANITY_PRICE_STARTER)) { + max = 19; // 95/5 } else if (Settings::ShopsanityPrices.Is(RO_SHOPSANITY_PRICE_ADULT)) { max = 40; // 200/5 diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index f3664c719..3e2cd3e60 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -3094,7 +3094,7 @@ void DrawRandoEditor(bool& open) { static const char* randoLinksPocket[4] = { "Dungeon Reward", "Advancement", "Anything", "Nothing" }; static const char* randoShuffleSongs[3] = { "Song Locations", "Dungeon Rewards", "Anywhere" }; static const char* randoShopsanity[7] = { "Off", "0 Items", "1 Item", "2 Items", "3 Items", "4 Items", "Random" }; - static const char* randoShopsanityPrices[6] = { "Balanced", "Starter Wallet", "Adult Wallet", "Giant's Wallet", "Tycoon's Wallet", "Affordable" }; + static const char* randoShopsanityPrices[5] = { "Balanced", "Starter Wallet", "Adult Wallet", "Giant's Wallet", "Tycoon's Wallet" }; static const char* randoTokensanity[4] = { "Off", "Dungeons", "Overworld", "All Tokens" }; static const char* randoShuffleScrubs[4] = { "Off", "Affordable", "Expensive", "Random Prices" }; static const char* randoShuffleMerchants[3] = { "Off", "On (no hints)", "On (with hints)" }; @@ -3729,8 +3729,8 @@ void DrawRandoEditor(bool& open) { UIWidgets::EnhancementCheckbox(Settings::ShopsanityPricesAffordable.GetName().c_str(), "gRandomizeShopsanityPricesAffordable", CVarGetInteger("gRandomizeShopsanityPrices", RO_SHOPSANITY_PRICE_BALANCED) == RO_SHOPSANITY_PRICE_BALANCED, "This can only apply to a wallet range."); - UIWidgets::InsertHelpHoverText("Cap item prices to a value just above the previous tier wallet's max value.\n" - "Affordable caps: starter = 10, adult = 105, giant = 205, tycoon = 505\n" + UIWidgets::InsertHelpHoverText("Random selection between the selected wallet tier's affordable price and the affordable prices of the preceding wallet tiers.\n\n" + "Affordable prices per tier: starter = 10, adult = 105, giant = 205, tycoon = 505\n\n" "Use this to enable wallet tier locking, but make shop items not as expensive as they could be."); }