mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-13 01:50:45 -05:00
Cleanup of variable names and extracted some methods to help with readability
This commit is contained in:
parent
6e4c7abf73
commit
e1de79f0be
@ -52,46 +52,45 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
|
|||||||
Runners.Add(
|
Runners.Add(
|
||||||
Task.Factory.StartNew(() =>
|
Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
|
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Debug))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Debug))
|
||||||
LoggerFactory.GetInstance().Log($"Processing static data for file {dumped.BasicInfo.FileName}", LogLevel.Debug);
|
LoggerFactory.GetInstance().Log($"Processing static data for file {dumped.BasicInfo.FileName}", LogLevel.Debug);
|
||||||
var data = _jsonSerializer.Deserialize<RootData>(File.ReadAllText(dumped.BasicInfo.FileName));
|
var data = _jsonSerializer.Deserialize<RootData>(File.ReadAllText(dumped.BasicInfo.FileName));
|
||||||
// the if statement below takes care of processing "forced" or real static data for each map, we only need
|
var mapName = data.Data.Name;
|
||||||
// to do this once per map, so we dont care about doing it again
|
|
||||||
|
// the if statement below takes care of processing "forced" or real static data for each map, only need
|
||||||
|
// to do this once per map, we dont care about doing it again
|
||||||
lock (staticContainersLock)
|
lock (staticContainersLock)
|
||||||
{
|
{
|
||||||
if (!staticContainers.ContainsKey(data.Data.Name))
|
if (!staticContainers.ContainsKey(mapName))
|
||||||
{
|
{
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
||||||
LoggerFactory.GetInstance().Log($"Doing first time process for map {data.Data.Name} of real static data", LogLevel.Info);
|
LoggerFactory.GetInstance().Log($"Doing first time process for map {mapName} of real static data", LogLevel.Info);
|
||||||
var mapStaticLoot = StaticLootProcessor.CreateRealStaticContainers(data);
|
var mapStaticContainers = StaticLootProcessor.CreateStaticWeaponsAndStaticForcedContainers(data);
|
||||||
staticContainers[mapStaticLoot.Item1] = mapStaticLoot.Item2;
|
// .Item1 = map name
|
||||||
|
staticContainers[mapStaticContainers.Item1] = mapStaticContainers.Item2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the section below takes care of finding how many "dynamic static containers" we have on the map
|
// Takes care of finding how many "dynamic static containers" we have on the map
|
||||||
Dictionary<Template, int> mapAggregatedData;
|
Dictionary<Template, int> mapAggregatedDataDict;
|
||||||
lock (mapStaticContainersAggregatedLock)
|
lock (mapStaticContainersAggregatedLock)
|
||||||
{
|
{
|
||||||
if (!mapStaticContainersAggregated.TryGetValue(data.Data.Name, out mapAggregatedData))
|
// Init dict if map key doesnt exist
|
||||||
|
if (!mapStaticContainersAggregated.TryGetValue(mapName, out mapAggregatedDataDict))
|
||||||
{
|
{
|
||||||
mapAggregatedData = new Dictionary<Template, int>();
|
mapAggregatedDataDict = new Dictionary<Template, int>();
|
||||||
mapStaticContainersAggregated.Add(data.Data.Name, mapAggregatedData);
|
mapStaticContainersAggregated.Add(mapName, mapAggregatedDataDict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only process the dump file if the date is higher (after) the configuration date
|
// Only process the dump file if the date is higher (after) the configuration date
|
||||||
if (FileDateParser.TryParseFileDate(dumped.BasicInfo.FileName, out var fileDate) &&
|
if (DumpWasMadeAfterConfigThresholdDate(dumped))
|
||||||
fileDate.HasValue &&
|
|
||||||
fileDate.Value > LootDumpProcessorContext.GetConfig().DumpProcessorConfig
|
|
||||||
.SpawnContainerChanceIncludeAfterDate)
|
|
||||||
{
|
{
|
||||||
// the if statement below will keep track of how many dumps we have for each map
|
// Keep track of how many dumps we have for each map
|
||||||
lock (mapDumpCounterLock)
|
lock (mapDumpCounterLock)
|
||||||
{
|
{
|
||||||
if (mapDumpCounter.ContainsKey(data.Data.Name))
|
IncrementMapCounterDictionaryValue(mapDumpCounter, mapName);
|
||||||
mapDumpCounter[data.Data.Name] += 1;
|
|
||||||
else
|
|
||||||
mapDumpCounter.Add(data.Data.Name, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var containerIgnoreListExists = LootDumpProcessorContext.GetConfig().ContainerIgnoreList.TryGetValue(data.Data.Id.ToLower(), out string[]? ignoreListForMap);
|
var containerIgnoreListExists = LootDumpProcessorContext.GetConfig().ContainerIgnoreList.TryGetValue(data.Data.Id.ToLower(), out string[]? ignoreListForMap);
|
||||||
@ -105,10 +104,9 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapAggregatedData.ContainsKey(dynamicStaticContainer))
|
// Increment count by 1
|
||||||
mapAggregatedData[dynamicStaticContainer] += 1;
|
if (!mapAggregatedDataDict.TryAdd(dynamicStaticContainer, 1))
|
||||||
else
|
mapAggregatedDataDict[dynamicStaticContainer] += 1;
|
||||||
mapAggregatedData.Add(dynamicStaticContainer, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +126,7 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
|
|||||||
td => new StaticDataPoint
|
td => new StaticDataPoint
|
||||||
{
|
{
|
||||||
Template = td.Key,
|
Template = td.Key,
|
||||||
Probability = GetStaticProbability(kv.Key, td, mapDumpCounter)
|
Probability = GetStaticContainerProbability(kv.Key, td, mapDumpCounter)
|
||||||
}
|
}
|
||||||
).ToList()
|
).ToList()
|
||||||
).ToList().ForEach(kv => staticContainers[kv.Key].StaticContainers = kv.Value);
|
).ToList().ForEach(kv => staticContainers[kv.Key].StaticContainers = kv.Value);
|
||||||
@ -171,16 +169,33 @@ public class MultithreadSteppedDumpProcessor : IDumpProcessor
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double GetStaticProbability(string mapName, KeyValuePair<Template, int> td, Dictionary<string, int> mapDumpCounter)
|
private static bool DumpWasMadeAfterConfigThresholdDate(PartialData dataDump)
|
||||||
|
{
|
||||||
|
return FileDateParser.TryParseFileDate(dataDump.BasicInfo.FileName, out var fileDate) &&
|
||||||
|
fileDate.HasValue &&
|
||||||
|
fileDate.Value > LootDumpProcessorContext.GetConfig().DumpProcessorConfig
|
||||||
|
.SpawnContainerChanceIncludeAfterDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void IncrementMapCounterDictionaryValue(Dictionary<string, int> mapDumpCounter, string mapName)
|
||||||
|
{
|
||||||
|
if (!mapDumpCounter.TryAdd(mapName, 1))
|
||||||
|
{
|
||||||
|
// Dict has map, increment count by 1
|
||||||
|
mapDumpCounter[mapName] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double GetStaticContainerProbability(string mapName, KeyValuePair<Template, int> td, Dictionary<string, int> mapDumpCounter)
|
||||||
{
|
{
|
||||||
return Math.Round((double)((decimal)td.Value / (decimal)mapDumpCounter[mapName]), 2);
|
return Math.Round((double)((decimal)td.Value / (decimal)mapDumpCounter[mapName]), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DumpProcessData GetDumpProcessData(List<PartialData> dumps)
|
private static DumpProcessData GetDumpProcessData(List<PartialData> dumps)
|
||||||
{
|
{
|
||||||
var dumpProcessData = new DumpProcessData();
|
var dumpProcessData = new DumpProcessData();
|
||||||
|
|
||||||
dumps.GroupBy(x => x.BasicInfo.Map)
|
dumps.GroupBy(dump => dump.BasicInfo.Map)
|
||||||
.ToList()
|
.ToList()
|
||||||
.ForEach(tuple =>
|
.ForEach(tuple =>
|
||||||
{
|
{
|
||||||
|
@ -12,16 +12,17 @@ public static class StaticLootProcessor
|
|||||||
public static List<PreProcessedStaticLoot> PreProcessStaticLoot(List<Template> staticloot)
|
public static List<PreProcessedStaticLoot> PreProcessStaticLoot(List<Template> staticloot)
|
||||||
{
|
{
|
||||||
var containers = new List<PreProcessedStaticLoot>();
|
var containers = new List<PreProcessedStaticLoot>();
|
||||||
foreach (var li in staticloot)
|
foreach (var lootSpawnPosition in staticloot)
|
||||||
{
|
{
|
||||||
var tpl = li.Items[0].Tpl;
|
var tpl = lootSpawnPosition.Items[0].Tpl;
|
||||||
if (!LootDumpProcessorContext.GetStaticWeaponIds().Contains(tpl))
|
if (!LootDumpProcessorContext.GetStaticWeaponIds().Contains(tpl))
|
||||||
{
|
{
|
||||||
|
// Only add non-weapon static containers
|
||||||
containers.Add(new PreProcessedStaticLoot
|
containers.Add(new PreProcessedStaticLoot
|
||||||
{
|
{
|
||||||
Type = tpl,
|
Type = tpl,
|
||||||
ContainerId = li.Items[0].Id,
|
ContainerId = lootSpawnPosition.Items[0].Id,
|
||||||
Items = li.Items.Skip(1).ToList()
|
Items = lootSpawnPosition.Items.Skip(1).ToList()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,7 +30,7 @@ public static class StaticLootProcessor
|
|||||||
return containers;
|
return containers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tuple<string, MapStaticLoot> CreateRealStaticContainers(RootData rawMapDump)
|
public static Tuple<string, MapStaticLoot> CreateStaticWeaponsAndStaticForcedContainers(RootData rawMapDump)
|
||||||
{
|
{
|
||||||
var mapName = rawMapDump.Data.Name;
|
var mapName = rawMapDump.Data.Name;
|
||||||
var staticLootPositions = (from li in rawMapDump.Data.Loot
|
var staticLootPositions = (from li in rawMapDump.Data.Loot
|
||||||
@ -39,8 +40,7 @@ public static class StaticLootProcessor
|
|||||||
staticLootPositions = staticLootPositions.OrderBy(x => x.Id).ToList();
|
staticLootPositions = staticLootPositions.OrderBy(x => x.Id).ToList();
|
||||||
foreach (var staticLootPosition in staticLootPositions)
|
foreach (var staticLootPosition in staticLootPositions)
|
||||||
{
|
{
|
||||||
var itemTpl = staticLootPosition.Items[0].Tpl;
|
if (LootDumpProcessorContext.GetStaticWeaponIds().Contains(staticLootPosition.Items[0].Tpl))
|
||||||
if (LootDumpProcessorContext.GetStaticWeaponIds().Contains(itemTpl))
|
|
||||||
{
|
{
|
||||||
staticWeapons.Add(ProcessorUtil.Copy(staticLootPosition));
|
staticWeapons.Add(ProcessorUtil.Copy(staticLootPosition));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user