Add rounding of stack counts based on stack size
This commit is contained in:
parent
b8bcb4ab62
commit
dbb12d1241
@ -39,7 +39,11 @@ class Program
|
||||
LoggingHelpers.LogInfo($"trader: {TraderHelper.GetTraderIdByName(trader.Key)}");
|
||||
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");
|
||||
|
||||
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)
|
||||
{
|
||||
foreach (var item in questAssorts.success)
|
||||
|
38
AssortValidator.Common/Helpers/MathHelpers.cs
Normal file
38
AssortValidator.Common/Helpers/MathHelpers.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user