From 82059d1d1332854976edf09b8c8e0adf72885519 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 22 Apr 2024 22:29:06 +0100 Subject: [PATCH] Migrate static ammo values to be per-map --- .../MultithreadSteppedDumpProcessor.cs | 8 +- Process/Processor/StaticLootProcessor.cs | 112 +++++++++++++----- Process/Writer/FileWriter.cs | 11 +- 3 files changed, 93 insertions(+), 38 deletions(-) diff --git a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs index cc7ced4..329f4de 100644 --- a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs +++ b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs @@ -141,10 +141,10 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) LoggerFactory.GetInstance().Log("Processing ammo distribution", LogLevel.Info); // Ammo distribution - //output.Add( - // OutputFileType.StaticAmmo, - // StaticLootProcessor.CreateAmmoDistribution(dumpProcessData.ContainerCounts) - //); + output.Add( + OutputFileType.StaticAmmo, + StaticLootProcessor.CreateAmmoDistribution(dumpProcessData.ContainerCounts) + ); if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info)) LoggerFactory.GetInstance().Log("Processing static loot distribution", LogLevel.Info); diff --git a/Process/Processor/StaticLootProcessor.cs b/Process/Processor/StaticLootProcessor.cs index 9d12296..6251d67 100644 --- a/Process/Processor/StaticLootProcessor.cs +++ b/Process/Processor/StaticLootProcessor.cs @@ -4,6 +4,7 @@ using LootDumpProcessor.Model.Output; using LootDumpProcessor.Model.Output.StaticContainer; using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Utils; +using System.Collections.Generic; namespace LootDumpProcessor.Process.Processor; @@ -74,43 +75,92 @@ public static class StaticLootProcessor return data; } - public static Dictionary> CreateAmmoDistribution( - List container_counts + /// + /// + /// + /// + /// key = mapid / + public static Dictionary>> CreateAmmoDistribution( + Dictionary> container_counts ) { - var ammo = new List(); - foreach (var ci in container_counts) + var allMapsAmmoDistro = new Dictionary>>(); + foreach (var mapAndContainers in container_counts) { - ammo.AddRange(from item in ci.Items - where LootDumpProcessorContext.GetTarkovItems().IsBaseClass(item.Tpl, BaseClasses.Ammo) - select item.Tpl); + var mapid = mapAndContainers.Key; + var containers = mapAndContainers.Value; + + + var ammo = new List(); + foreach (var ci in containers) + { + ammo.AddRange(from item in ci.Items + where LootDumpProcessorContext.GetTarkovItems().IsBaseClass(item.Tpl, BaseClasses.Ammo) + select item.Tpl); + } + + var ammo_counts = new List(); + ammo_counts.AddRange( + ammo.GroupBy(a => a) + .Select(g => new CaliberTemplateCount + { + Caliber = LootDumpProcessorContext.GetTarkovItems().AmmoCaliber(g.Key), + Template = g.Key, + Count = g.Count() + }) + ); + ammo_counts = ammo_counts.OrderBy(x => x.Caliber).ToList(); + var ammo_distribution = new Dictionary>(); + foreach (var _tup_3 in ammo_counts.GroupBy(x => x.Caliber)) + { + var k = _tup_3.Key; + var g = _tup_3.ToList(); + ammo_distribution[k] = (from gi in g + select new AmmoDistribution + { + Tpl = gi.Template, + RelativeProbability = gi.Count + }).ToList(); + } + + allMapsAmmoDistro.TryAdd(mapid, ammo_distribution); } - var ammo_counts = new List(); - ammo_counts.AddRange( - ammo.GroupBy(a => a) - .Select(g => new CaliberTemplateCount - { - Caliber = LootDumpProcessorContext.GetTarkovItems().AmmoCaliber(g.Key), - Template = g.Key, - Count = g.Count() - }) - ); - ammo_counts = ammo_counts.OrderBy(x => x.Caliber).ToList(); - var ammo_distribution = new Dictionary>(); - foreach (var _tup_3 in ammo_counts.GroupBy(x => x.Caliber)) - { - var k = _tup_3.Key; - var g = _tup_3.ToList(); - ammo_distribution[k] = (from gi in g - select new AmmoDistribution - { - Tpl = gi.Template, - RelativeProbability = gi.Count - }).ToList(); - } + return allMapsAmmoDistro; - return ammo_distribution; + //var ammo = new List(); + //foreach (var ci in container_counts) + //{ + // ammo.AddRange(from item in ci.Items + // where LootDumpProcessorContext.GetTarkovItems().IsBaseClass(item.Tpl, BaseClasses.Ammo) + // select item.Tpl); + //} + + //var ammo_counts = new List(); + //ammo_counts.AddRange( + // ammo.GroupBy(a => a) + // .Select(g => new CaliberTemplateCount + // { + // Caliber = LootDumpProcessorContext.GetTarkovItems().AmmoCaliber(g.Key), + // Template = g.Key, + // Count = g.Count() + // }) + //); + //ammo_counts = ammo_counts.OrderBy(x => x.Caliber).ToList(); + //var ammo_distribution = new Dictionary>(); + //foreach (var _tup_3 in ammo_counts.GroupBy(x => x.Caliber)) + //{ + // var k = _tup_3.Key; + // var g = _tup_3.ToList(); + // ammo_distribution[k] = (from gi in g + // select new AmmoDistribution + // { + // Tpl = gi.Template, + // RelativeProbability = gi.Count + // }).ToList(); + //} + + //return ammo_distribution; } /// diff --git a/Process/Writer/FileWriter.cs b/Process/Writer/FileWriter.cs index b32ffd7..ab36955 100644 --- a/Process/Writer/FileWriter.cs +++ b/Process/Writer/FileWriter.cs @@ -77,9 +77,14 @@ public class FileWriter : IWriter break; case OutputFileType.StaticAmmo: - var staticAmmo = (Dictionary>)data; - File.WriteAllText($@"{_outputPath}\loot\staticAmmo.json", - _jsonSerializer.Serialize(staticAmmo)); + var staticAmmo = (Dictionary>>)data; + foreach (var (key, value) in staticAmmo) + { + if (!Directory.Exists($@"{_outputPath}\locations\{key}")) + Directory.CreateDirectory($@"{_outputPath}\locations\{key}"); + File.WriteAllText($@"{_outputPath}\locations\{key}\staticAmmo.json", + _jsonSerializer.Serialize(value)); + } break; default: