Skip to content

Commit

Permalink
- Change Traveling Merchant to always sell a location regardless of s…
Browse files Browse the repository at this point in the history
…tock size, if there are items remaining for today
  • Loading branch information
agilbert1412 committed Feb 21, 2023
1 parent 5338bc8 commit 5dc39c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using StardewArchipelago.Archipelago;
using StardewModdingAPI;
using StardewValley;
Expand Down Expand Up @@ -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<ISalable>();

foreach (var (item, prices) in __result)
Expand All @@ -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);
Expand All @@ -127,28 +128,45 @@ 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);
var requiredAPItemToSeeMerchantToday = string.Format(AP_MERCHANT_DAYS, dayOfWeek);
return _archipelago.HasReceivedItem(requiredAPItemToSeeMerchantToday, out playerName);
}

private static void AddApStock(ref Dictionary<ISalable, int[]> currentStock, Random random)
private static void AddApStock(ref Dictionary<ISalable, int[]> 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<string>();
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});
}
Expand Down
2 changes: 1 addition & 1 deletion StardewArchipelago/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 5dc39c3

Please sign in to comment.