From b96e27868c834616a7d36e57201e59edbfc2d5a9 Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 13 Aug 2023 16:18:29 +0100 Subject: [PATCH] Test to see if reading statics data from json is better --- LootDumpProcessorContext.cs | 3 ++- Model/Tarkov/Handbook.cs | 13 +++++++++++++ .../MultithreadSteppedDumpProcessor.cs | 14 ++++++++++++-- Process/TarkovItems.cs | 9 ++++++++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/LootDumpProcessorContext.cs b/LootDumpProcessorContext.cs index 47cb433..3db2ce0 100644 --- a/LootDumpProcessorContext.cs +++ b/LootDumpProcessorContext.cs @@ -117,7 +117,8 @@ public class LootDumpProcessorContext { _tarkovItems = new TarkovItems( $"{GetConfig().ServerLocation}/project/assets/database/templates/items.json", - $"{GetConfig().ServerLocation}/project/assets/database/templates/handbook.json" + $"{GetConfig().ServerLocation}/project/assets/database/templates/handbook.json", + $"{GetConfig().ServerLocation}/project/assets/database/locations/tarkovstreets/statics.json" ); } } diff --git a/Model/Tarkov/Handbook.cs b/Model/Tarkov/Handbook.cs index 5d4c8d9..c78f848 100644 --- a/Model/Tarkov/Handbook.cs +++ b/Model/Tarkov/Handbook.cs @@ -20,4 +20,17 @@ public class HandbookRoot { public List Categories { get; set; } public List Items { get; set; } +} + +public class StaticContainerRoot +{ + public decimal probability { get; set; } + public StaticContainerTemplate template { get; set; } +} + +public class StaticContainerTemplate +{ + public string Id { get; set; } + public decimal SpawnChance { get; set; } + public bool IsAlwaysSpawn { get; set; } } \ No newline at end of file diff --git a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs index b75f7ba..e4a10de 100644 --- a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs +++ b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs @@ -39,7 +39,7 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor // dictionary of maps, that has a dictionary of template and hit count var mapStaticContainersAggregated = new Dictionary>(); var mapStaticContainersAggregatedLock = new object(); - + Runners.Clear(); // BSG changed the map data so static containers are now dynamic, so we need to scan all dumps for the static containers. foreach (var dumped in dumps) @@ -102,7 +102,7 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor td => new StaticDataPoint { Template = td.Key, - Probability = Math.Round((double)((decimal)td.Value / (decimal)mapDumpCounter[kv.Key]), 2) + Probability = GetStaticProbability(kv.Key, td, mapDumpCounter) } ).ToList() ).ToList().ForEach(kv => staticContainers[kv.Key].StaticContainers = kv.Value); @@ -136,6 +136,16 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor return output; } + private static double GetStaticProbability(string mapName, KeyValuePair td, Dictionary mapDumpCounter) + { + if (mapName == "Streets of Tarkov") + { + return Math.Round((double)(LootDumpProcessorContext.GetTarkovItems().GetProbabilityByContainerId(td.Key.Id).probability), 2); + } + + return Math.Round((double)((decimal)td.Value / (decimal)mapDumpCounter[mapName]), 2); + } + private DumpProcessData GetDumpProcessData(List dumps) { var dumpProcessData = new DumpProcessData(); diff --git a/Process/TarkovItems.cs b/Process/TarkovItems.cs index a818fb1..9857d39 100644 --- a/Process/TarkovItems.cs +++ b/Process/TarkovItems.cs @@ -9,11 +9,13 @@ public class TarkovItems private Dictionary _items; private HandbookRoot _handbook; + private List _streetsStatics; - public TarkovItems(string items, string handbook) + public TarkovItems(string items, string handbook, string streetsStatics) { _items = _jsonSerializer.Deserialize>(File.ReadAllText(items)); _handbook = _jsonSerializer.Deserialize(File.ReadAllText(handbook)); + _streetsStatics = _jsonSerializer.Deserialize>(File.ReadAllText(streetsStatics)); } public virtual bool IsBaseClass(string tpl, string baseclass_id) @@ -42,4 +44,9 @@ public class TarkovItems var item_template = _items[tpl]; return item_template.Props.Caliber; } + + public virtual StaticContainerRoot GetProbabilityByContainerId(string id) + { + return _streetsStatics.FirstOrDefault(x => x.template.Id == id); + } } \ No newline at end of file