mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-13 09:50:44 -05:00
Refactored loose loot processor to process single map
This commit is contained in:
parent
8366915048
commit
1a4003595a
@ -3,6 +3,7 @@ using LootDumpProcessor.Logger;
|
|||||||
using LootDumpProcessor.Model;
|
using LootDumpProcessor.Model;
|
||||||
using LootDumpProcessor.Model.Input;
|
using LootDumpProcessor.Model.Input;
|
||||||
using LootDumpProcessor.Model.Output;
|
using LootDumpProcessor.Model.Output;
|
||||||
|
using LootDumpProcessor.Model.Output.LooseLoot;
|
||||||
using LootDumpProcessor.Model.Output.StaticContainer;
|
using LootDumpProcessor.Model.Output.StaticContainer;
|
||||||
using LootDumpProcessor.Model.Processing;
|
using LootDumpProcessor.Model.Processing;
|
||||||
using LootDumpProcessor.Process.Processor.v2.AmmoProcessor;
|
using LootDumpProcessor.Process.Processor.v2.AmmoProcessor;
|
||||||
@ -222,17 +223,22 @@ public class MultithreadSteppedDumpProcessor(
|
|||||||
|
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
||||||
LoggerFactory.GetInstance().Log("Processing loose loot distribution", LogLevel.Info);
|
LoggerFactory.GetInstance().Log("Processing loose loot distribution", LogLevel.Info);
|
||||||
// Loose loot distribution
|
|
||||||
var looseLootDistribution = _looseLootProcessor.CreateLooseLootDistribution(
|
|
||||||
dumpProcessData.MapCounts,
|
|
||||||
dumpProcessData.LooseLootCounts
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// Loose loot distribution
|
||||||
|
var looseLoot = new ConcurrentDictionary<string, LooseLootRoot>();
|
||||||
|
Parallel.ForEach(dumpProcessData.MapCounts.Keys, mapId =>
|
||||||
|
{
|
||||||
|
var mapCount = dumpProcessData.MapCounts[mapId];
|
||||||
|
var looseLootCount = dumpProcessData.LooseLootCounts[mapId];
|
||||||
|
var looseLootDistribution =
|
||||||
|
_looseLootProcessor.CreateLooseLootDistribution(mapId, mapCount, looseLootCount);
|
||||||
|
looseLoot[mapId] = looseLootDistribution;
|
||||||
|
});
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
||||||
LoggerFactory.GetInstance().Log("Collecting loose loot distribution information", LogLevel.Info);
|
LoggerFactory.GetInstance().Log("Collecting loose loot distribution information", LogLevel.Info);
|
||||||
var loot = dumpProcessData.MapCounts
|
var loot = dumpProcessData.MapCounts
|
||||||
.Select(mapCount => mapCount.Key)
|
.Select(mapCount => mapCount.Key)
|
||||||
.ToDictionary(mi => mi, mi => looseLootDistribution[mi]);
|
.ToDictionary(mi => mi, mi => looseLoot[mi]);
|
||||||
|
|
||||||
output.Add(OutputFileType.LooseLoot, loot);
|
output.Add(OutputFileType.LooseLoot, loot);
|
||||||
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
if (LoggerFactory.GetInstance().CanBeLogged(LogLevel.Info))
|
||||||
|
@ -9,9 +9,10 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
{
|
{
|
||||||
PreProcessedLooseLoot PreProcessLooseLoot(List<Template> looseLoot);
|
PreProcessedLooseLoot PreProcessLooseLoot(List<Template> looseLoot);
|
||||||
|
|
||||||
Dictionary<string, LooseLootRoot> CreateLooseLootDistribution(
|
LooseLootRoot CreateLooseLootDistribution(
|
||||||
Dictionary<string, int> mapCounts,
|
string mapId,
|
||||||
Dictionary<string, IKey> looseLootCounts
|
int mapCount,
|
||||||
|
IKey looseLootCountKey
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -36,8 +36,8 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
if (!uniqueLootIds.ContainsKey(sanitizedId))
|
if (!uniqueLootIds.ContainsKey(sanitizedId))
|
||||||
{
|
{
|
||||||
uniqueLootIds[sanitizedId] = template.Id;
|
uniqueLootIds[sanitizedId] = template.Id;
|
||||||
preProcessedLoot.Counts[sanitizedId] = preProcessedLoot.Counts.ContainsKey(sanitizedId)
|
preProcessedLoot.Counts[sanitizedId] = preProcessedLoot.Counts.TryGetValue(sanitizedId, out var count)
|
||||||
? preProcessedLoot.Counts[sanitizedId] + 1
|
? count + 1
|
||||||
: 1;
|
: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,22 +54,18 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
return preProcessedLoot;
|
return preProcessedLoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<string, LooseLootRoot> CreateLooseLootDistribution(
|
public LooseLootRoot CreateLooseLootDistribution(
|
||||||
Dictionary<string, int> mapCounts,
|
string mapId,
|
||||||
Dictionary<string, IKey> looseLootCounts
|
int mapCount,
|
||||||
|
IKey looseLootCountKey
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var config = LootDumpProcessorContext.GetConfig();
|
var config = LootDumpProcessorContext.GetConfig();
|
||||||
var spawnPointTolerance = config.ProcessorConfig.SpawnPointToleranceForForced / 100;
|
var spawnPointTolerance = config.ProcessorConfig.SpawnPointToleranceForForced / 100;
|
||||||
var looseLootDistribution = new Dictionary<string, LooseLootRoot>();
|
var looseLootDistribution = new LooseLootRoot();
|
||||||
|
|
||||||
foreach (var map in mapCounts)
|
|
||||||
{
|
|
||||||
var mapName = map.Key;
|
|
||||||
var mapCount = map.Value;
|
|
||||||
|
|
||||||
var probabilities = new Dictionary<string, double>();
|
var probabilities = new Dictionary<string, double>();
|
||||||
var looseLootCountsItem = _dataStorage.GetItem<LooseLootCounts>(looseLootCounts[mapName]);
|
var looseLootCountsItem = _dataStorage.GetItem<LooseLootCounts>(looseLootCountKey);
|
||||||
|
|
||||||
var counts = _dataStorage.GetItem<FlatKeyableDictionary<string, int>>(looseLootCountsItem.Counts);
|
var counts = _dataStorage.GetItem<FlatKeyableDictionary<string, int>>(looseLootCountsItem.Counts);
|
||||||
foreach (var (itemId, count) in counts)
|
foreach (var (itemId, count) in counts)
|
||||||
@ -86,16 +82,13 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
.Where(count => count <= highThreshold)
|
.Where(count => count <= highThreshold)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
looseLootDistribution[mapName] = new LooseLootRoot
|
looseLootDistribution.SpawnPointCount = new SpawnPointCount
|
||||||
{
|
|
||||||
SpawnPointCount = new SpawnPointCount
|
|
||||||
{
|
{
|
||||||
Mean = np.mean(np.array(looseLootCountsItem.MapSpawnpointCount)),
|
Mean = np.mean(np.array(looseLootCountsItem.MapSpawnpointCount)),
|
||||||
Std = np.std(np.array(looseLootCountsItem.MapSpawnpointCount))
|
Std = np.std(np.array(looseLootCountsItem.MapSpawnpointCount))
|
||||||
},
|
|
||||||
SpawnPointsForced = new List<SpawnPointsForced>(),
|
|
||||||
SpawnPoints = new List<SpawnPoint>()
|
|
||||||
};
|
};
|
||||||
|
looseLootDistribution.SpawnPointsForced = new List<SpawnPointsForced>();
|
||||||
|
looseLootDistribution.SpawnPoints = new List<SpawnPoint>();
|
||||||
|
|
||||||
var itemProperties = _dataStorage.GetItem<FlatKeyableDictionary<string, IKey>>(looseLootCountsItem.ItemProperties);
|
var itemProperties = _dataStorage.GetItem<FlatKeyableDictionary<string, IKey>>(looseLootCountsItem.ItemProperties);
|
||||||
foreach (var (spawnPoint, itemListKey) in itemProperties)
|
foreach (var (spawnPoint, itemListKey) in itemProperties)
|
||||||
@ -131,7 +124,7 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
|
|
||||||
if (itemDistributions.Count == 1 &&
|
if (itemDistributions.Count == 1 &&
|
||||||
(LootDumpProcessorContext.GetTarkovItems().IsQuestItem(itemDistributions[0].ComposedKey?.FirstItem?.Tpl) ||
|
(LootDumpProcessorContext.GetTarkovItems().IsQuestItem(itemDistributions[0].ComposedKey?.FirstItem?.Tpl) ||
|
||||||
LootDumpProcessorContext.GetForcedLooseItems()[mapName].Contains(itemDistributions[0].ComposedKey?.FirstItem?.Tpl)))
|
LootDumpProcessorContext.GetForcedLooseItems()[mapId].Contains(itemDistributions[0].ComposedKey?.FirstItem?.Tpl)))
|
||||||
{
|
{
|
||||||
var forcedSpawnPoint = new SpawnPointsForced
|
var forcedSpawnPoint = new SpawnPointsForced
|
||||||
{
|
{
|
||||||
@ -139,7 +132,7 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
Probability = probabilities[spawnPoint],
|
Probability = probabilities[spawnPoint],
|
||||||
Template = templateCopy
|
Template = templateCopy
|
||||||
};
|
};
|
||||||
looseLootDistribution[mapName].SpawnPointsForced.Add(forcedSpawnPoint);
|
looseLootDistribution.SpawnPointsForced.Add(forcedSpawnPoint);
|
||||||
}
|
}
|
||||||
else if (probabilities[spawnPoint] > spawnPointTolerance)
|
else if (probabilities[spawnPoint] > spawnPointTolerance)
|
||||||
{
|
{
|
||||||
@ -149,7 +142,7 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
Probability = probabilities[spawnPoint],
|
Probability = probabilities[spawnPoint],
|
||||||
Template = templateCopy
|
Template = templateCopy
|
||||||
};
|
};
|
||||||
looseLootDistribution[mapName].SpawnPointsForced.Add(forcedSpawnPoint);
|
looseLootDistribution.SpawnPointsForced.Add(forcedSpawnPoint);
|
||||||
_logger.LogWarning(
|
_logger.LogWarning(
|
||||||
"Item: {ItemId} has > {Tolerance}% spawn chance in spawn point: {LocationId} but isn't in forced loot, adding to forced",
|
"Item: {ItemId} has > {Tolerance}% spawn chance in spawn point: {LocationId} but isn't in forced loot, adding to forced",
|
||||||
templateCopy.Id,
|
templateCopy.Id,
|
||||||
@ -198,16 +191,16 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
looseLootDistribution[mapName].SpawnPoints.Add(spawnPointEntry);
|
looseLootDistribution.SpawnPoints.Add(spawnPointEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
looseLootDistribution[mapName].SpawnPoints = looseLootDistribution[mapName].SpawnPoints
|
looseLootDistribution.SpawnPoints = looseLootDistribution.SpawnPoints
|
||||||
.OrderBy(x => x.Template.Id)
|
.OrderBy(x => x.Template.Id)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var configuredForcedTemplates = new HashSet<string>(LootDumpProcessorContext.GetForcedLooseItems()[mapName].Select(item => item));
|
var configuredForcedTemplates = new HashSet<string>(LootDumpProcessorContext.GetForcedLooseItems()[mapId].Select(item => item));
|
||||||
var foundForcedTemplates = new HashSet<string>(looseLootDistribution[mapName].SpawnPointsForced.Select(fp => fp.Template.Items[0].Tpl));
|
var foundForcedTemplates = new HashSet<string>(looseLootDistribution.SpawnPointsForced.Select(fp => fp.Template.Items[0].Tpl));
|
||||||
|
|
||||||
foreach (var expectedTpl in configuredForcedTemplates)
|
foreach (var expectedTpl in configuredForcedTemplates)
|
||||||
{
|
{
|
||||||
@ -226,12 +219,11 @@ namespace LootDumpProcessor.Process.Processor.v2.LooseLootProcessor
|
|||||||
{
|
{
|
||||||
_logger.LogWarning(
|
_logger.LogWarning(
|
||||||
"Map: {MapName} Item: {ItemTpl} not defined in forced_loose.yaml config but was flagged as forced by code",
|
"Map: {MapName} Item: {ItemTpl} not defined in forced_loose.yaml config but was flagged as forced by code",
|
||||||
mapName,
|
mapId,
|
||||||
foundTpl
|
foundTpl
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return looseLootDistribution;
|
return looseLootDistribution;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user