From 5dc39c37634472040425ed2851bd1a5e69063dcc Mon Sep 17 00:00:00 2001 From: Alex Gilbert Date: Tue, 21 Feb 2023 15:37:16 -0500 Subject: [PATCH] - Change Traveling Merchant to always sell a location regardless of stock size, if there are items remaining for today --- .../TravelingMerchantInjections.cs | 36 ++++++++++++++----- StardewArchipelago/manifest.json | 2 +- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/StardewArchipelago/Locations/CodeInjections/TravelingMerchantInjections.cs b/StardewArchipelago/Locations/CodeInjections/TravelingMerchantInjections.cs index 560b5a5f3..95d7824f7 100644 --- a/StardewArchipelago/Locations/CodeInjections/TravelingMerchantInjections.cs +++ b/StardewArchipelago/Locations/CodeInjections/TravelingMerchantInjections.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using StardewArchipelago.Archipelago; using StardewModdingAPI; using StardewValley; @@ -99,8 +100,6 @@ public static void GenerateLocalTravelingMerchantStock_APStock_Postfix(int seed, var random = new Random(seed); - AddApStock(ref __result, random); - var itemsToRemove = new List(); foreach (var (item, prices) in __result) @@ -110,9 +109,11 @@ public static void GenerateLocalTravelingMerchantStock_APStock_Postfix(int seed, itemsToRemove.Add(item); } - prices[0] = (int)Math.Round(prices[0] * priceMultiplier, MidpointRounding.ToEven); + prices[0] = ModifyPrice(prices[0], priceMultiplier); } + AddApStock(ref __result, random, priceMultiplier); + foreach (var itemToRemove in itemsToRemove) { __result.Remove(itemToRemove); @@ -127,6 +128,11 @@ public static void GenerateLocalTravelingMerchantStock_APStock_Postfix(int seed, } } + private static int ModifyPrice(int price, double priceMultiplier) + { + return (int)Math.Round(price * priceMultiplier, MidpointRounding.ToEven); + } + private static bool IsTravelingMerchantDay(int dayOfMonth, out string playerName) { var dayOfWeek = GetDayOfWeekName(dayOfMonth); @@ -134,21 +140,33 @@ private static bool IsTravelingMerchantDay(int dayOfMonth, out string playerName return _archipelago.HasReceivedItem(requiredAPItemToSeeMerchantToday, out playerName); } - private static void AddApStock(ref Dictionary currentStock, Random random) + private static void AddApStock(ref Dictionary currentStock, Random random, double priceMultiplier) { var dayOfWeek = GetDayOfWeekName(Game1.dayOfMonth); - var chosenApItem = random.Next(0, 3) + 1; - var apLocationName = string.Format(AP_MERCHANT_LOCATION, dayOfWeek, chosenApItem); + var apItems = new List(); + for (var i = 1; i < 4; i++) + { + var apLocationName = string.Format(AP_MERCHANT_LOCATION, dayOfWeek, i); - if (_locationChecker.IsLocationChecked(apLocationName)) + if (_locationChecker.IsLocationChecked(apLocationName)) + { + continue; + } + + apItems.Add(apLocationName); + } + + if (!apItems.Any()) { return; } + var chosenApItem = apItems[random.Next(0, apItems.Count)]; + var scamName = _merchantApItemNames[random.Next(0, _merchantApItemNames.Length)]; var apLocation = - new PurchaseableArchipelagoLocation(scamName, apLocationName, _locationChecker, _archipelago); - var price = _merchantPrices[random.Next(0, _merchantPrices.Length)]; + new PurchaseableArchipelagoLocation(scamName, chosenApItem, _locationChecker, _archipelago); + var price = ModifyPrice(_merchantPrices[random.Next(0, _merchantPrices.Length)], priceMultiplier); currentStock.Add(apLocation, new []{price, 1}); } diff --git a/StardewArchipelago/manifest.json b/StardewArchipelago/manifest.json index 86819a3c9..5429dbebf 100644 --- a/StardewArchipelago/manifest.json +++ b/StardewArchipelago/manifest.json @@ -1,7 +1,7 @@ { "Name": "StardewArchipelago", "Author": "Kaito Kid", - "Version": "2.2.0", + "Version": "2.2.1", "Description": "Stardew Valley Randomizer for Archipelago", "UniqueID": "KaitoKid.StardewArchipelago", "EntryDll": "StardewArchipelago.dll",