Add rounding of stack counts based on stack size

This commit is contained in:
Chomp 2022-02-03 10:28:44 +00:00
parent b8bcb4ab62
commit dbb12d1241
2 changed files with 61 additions and 1 deletions

View File

@ -39,7 +39,11 @@ class Program
LoggingHelpers.LogInfo($"trader: {TraderHelper.GetTraderIdByName(trader.Key)}"); LoggingHelpers.LogInfo($"trader: {TraderHelper.GetTraderIdByName(trader.Key)}");
AssortMerger.ListDuplicatesInMergedAssorts(flatAssorts); AssortMerger.ListDuplicatesInMergedAssorts(flatAssorts);
Assort unflattenedAssorts = AssortFlattener.UnFlatten(flatAssorts); List<FlatAssort> roundedFlattenedAssorts = RoundFlatAssortStackCounts(flatAssorts);
Assort unflattenedAssorts = AssortFlattener.UnFlatten(roundedFlattenedAssorts);
JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort"); JsonWriter.WriteJson(unflattenedAssorts, traderId, Directory.GetCurrentDirectory(), "assort");
var questAssorts = QuestAssortGenerator.CreateQuestAssorts(trader.Key, traderQuestAssortUnlocks, flatAssorts); var questAssorts = QuestAssortGenerator.CreateQuestAssorts(trader.Key, traderQuestAssortUnlocks, flatAssorts);
@ -48,6 +52,24 @@ class Program
} }
} }
private static List<FlatAssort> RoundFlatAssortStackCounts(List<FlatAssort> 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) private static void LogQuestUnlocks(QuestAssorts questAssorts, Assort unflattenedAssorts)
{ {
foreach (var item in questAssorts.success) foreach (var item in questAssorts.success)

View File

@ -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;
}
}
}