From dbb12d1241f680b49faf917ef333f871fae8ca13 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 3 Feb 2022 10:28:44 +0000 Subject: [PATCH] Add rounding of stack counts based on stack size --- AssortUpdater/Program.cs | 24 +++++++++++- AssortValidator.Common/Helpers/MathHelpers.cs | 38 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 AssortValidator.Common/Helpers/MathHelpers.cs diff --git a/AssortUpdater/Program.cs b/AssortUpdater/Program.cs index d50fffc..b5f5c25 100644 --- a/AssortUpdater/Program.cs +++ b/AssortUpdater/Program.cs @@ -39,7 +39,11 @@ class Program LoggingHelpers.LogInfo($"trader: {TraderHelper.GetTraderIdByName(trader.Key)}"); AssortMerger.ListDuplicatesInMergedAssorts(flatAssorts); - Assort unflattenedAssorts = AssortFlattener.UnFlatten(flatAssorts); + List roundedFlattenedAssorts = RoundFlatAssortStackCounts(flatAssorts); + Assort unflattenedAssorts = AssortFlattener.UnFlatten(roundedFlattenedAssorts); + + + JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort"); var questAssorts = QuestAssortGenerator.CreateQuestAssorts(trader.Key, traderQuestAssortUnlocks, flatAssorts); @@ -48,6 +52,24 @@ class Program } } + private static List RoundFlatAssortStackCounts(List flatAssorts) + { + foreach (var flatAssort in flatAssorts) + { + if (flatAssort.RawItem.upd.StackObjectsCount.HasValue) + { + var stackCount = flatAssort.RawItem.upd.StackObjectsCount; + if (stackCount > 49 && stackCount != 999999) + { + var numberSize = stackCount.Value.NumberSize(); + flatAssort.RawItem.upd.StackObjectsCount = stackCount.Value.Round(numberSize); + } + } + } + + return flatAssorts; + } + private static void LogQuestUnlocks(QuestAssorts questAssorts, Assort unflattenedAssorts) { foreach (var item in questAssorts.success) diff --git a/AssortValidator.Common/Helpers/MathHelpers.cs b/AssortValidator.Common/Helpers/MathHelpers.cs new file mode 100644 index 0000000..c31718c --- /dev/null +++ b/AssortValidator.Common/Helpers/MathHelpers.cs @@ -0,0 +1,38 @@ +using System; + +namespace AssortValidator.Common.Helpers +{ + public static class MathExtensions + { + public static int Round(this int i, int nearest) + { + if (nearest <= 0 || nearest % 10 != 0) + throw new ArgumentOutOfRangeException(nameof(nearest), "Must round to a positive multiple of 10"); + + return (i + (5 * nearest / 10)) / nearest * nearest; + } + + public static int NumberSize(this int i) + { + switch (i.ToString().Length) + { + case 1: + return 1; + case 2: + return 10; + case 3: + return 100; + case 4: + return 1000; + case 5: + return 10000; + case 6: + return 100000; + case 7: + return 1000000; + } + + return 10; + } + } +}