first commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LitJson;
|
||||
using NitroxModel.DataStructures.GameLogic.Entities;
|
||||
using NitroxModel.Helper;
|
||||
using static LootDistributionData;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Entities;
|
||||
|
||||
public class SubnauticaUwePrefabFactory : IUwePrefabFactory
|
||||
{
|
||||
private readonly LootDistributionData lootDistributionData;
|
||||
private readonly Dictionary<string, List<UwePrefab>> cache = new();
|
||||
|
||||
public SubnauticaUwePrefabFactory(string lootDistributionJson)
|
||||
{
|
||||
lootDistributionData = GetLootDistributionData(lootDistributionJson);
|
||||
}
|
||||
|
||||
public bool TryGetPossiblePrefabs(string biome, out List<UwePrefab> prefabs)
|
||||
{
|
||||
if (biome == null)
|
||||
{
|
||||
prefabs = null;
|
||||
return false;
|
||||
}
|
||||
if (cache.TryGetValue(biome, out prefabs))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
prefabs = new();
|
||||
BiomeType biomeType = (BiomeType)Enum.Parse(typeof(BiomeType), biome);
|
||||
if (lootDistributionData.GetBiomeLoot(biomeType, out DstData dstData))
|
||||
{
|
||||
foreach (PrefabData prefabData in dstData.prefabs)
|
||||
{
|
||||
if (lootDistributionData.srcDistribution.TryGetValue(prefabData.classId, out SrcData srcData))
|
||||
{
|
||||
// Manually went through the list of those to make this "filter"
|
||||
// You can verify this by looping through all of SrcData (e.g in LootDistributionData.Initialize)
|
||||
// print the prefabPath and check the TechType related to the provided classId (WorldEntityDatabase.TryGetInfo) with PDAScanner.IsFragment
|
||||
bool isFragment = srcData.prefabPath.Contains("Fragment") || srcData.prefabPath.Contains("BaseGlassDome");
|
||||
prefabs.Add(new(prefabData.classId, prefabData.count, prefabData.probability, isFragment));
|
||||
}
|
||||
}
|
||||
}
|
||||
cache[biome] = prefabs;
|
||||
return true;
|
||||
}
|
||||
|
||||
private LootDistributionData GetLootDistributionData(string lootDistributionJson)
|
||||
{
|
||||
// LitJson uses the computer's local CultureInfo when parsing the JSON files.
|
||||
// However, these json files were saved in en_US. Ensure that this is done for the current thread.
|
||||
CultureManager.ConfigureCultureInfo();
|
||||
|
||||
JsonMapper.RegisterImporter((double value) => Convert.ToSingle(value));
|
||||
|
||||
Dictionary<string, LootDistributionData.SrcData> result = JsonMapper.ToObject<Dictionary<string, LootDistributionData.SrcData>>(lootDistributionJson);
|
||||
|
||||
LootDistributionData lootDistributionData = new LootDistributionData();
|
||||
lootDistributionData.Initialize(result);
|
||||
|
||||
return lootDistributionData;
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using NitroxModel.DataStructures.GameLogic.Entities;
|
||||
using UWE;
|
||||
|
||||
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Entities;
|
||||
|
||||
public class SubnauticaUweWorldEntityFactory : IUweWorldEntityFactory
|
||||
{
|
||||
private readonly Dictionary<string, WorldEntityInfo> worldEntitiesByClassId;
|
||||
|
||||
public SubnauticaUweWorldEntityFactory(Dictionary<string, WorldEntityInfo> worldEntitiesByClassId)
|
||||
{
|
||||
this.worldEntitiesByClassId = worldEntitiesByClassId;
|
||||
}
|
||||
|
||||
public bool TryFind(string classId, out UweWorldEntity uweWorldEntity)
|
||||
{
|
||||
if (worldEntitiesByClassId.TryGetValue(classId, out WorldEntityInfo worldEntityInfo))
|
||||
{
|
||||
uweWorldEntity = new(worldEntityInfo.classId,
|
||||
worldEntityInfo.techType.ToDto(),
|
||||
worldEntityInfo.slotType.ToString(),
|
||||
worldEntityInfo.prefabZUp,
|
||||
(int)worldEntityInfo.cellLevel,
|
||||
worldEntityInfo.localScale.ToDto());
|
||||
|
||||
return true;
|
||||
}
|
||||
uweWorldEntity = null;
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user