35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
#nullable enable
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
internal class NPCSet : Prefab
|
|
{
|
|
public readonly static PrefabCollection<NPCSet> Sets = new PrefabCollection<NPCSet>();
|
|
|
|
public readonly ImmutableArray<HumanPrefab> Humans;
|
|
|
|
public NPCSet(ContentXElement element, NPCSetsFile file) : base(file, element.GetAttributeIdentifier("identifier", ""))
|
|
{
|
|
Humans = element.Elements().Select(npcElement => new HumanPrefab(npcElement, file, Identifier)).ToImmutableArray();
|
|
}
|
|
|
|
public static HumanPrefab? Get(Identifier setIdentifier, Identifier npcidentifier, bool logError = true, ContentPackage? contentPackageToLogInError = null)
|
|
{
|
|
HumanPrefab? prefab = Sets.Where(set => set.Identifier == setIdentifier).SelectMany(npcSet => npcSet.Humans.Where(npcSetHuman => npcSetHuman.Identifier == npcidentifier)).FirstOrDefault();
|
|
|
|
if (prefab == null)
|
|
{
|
|
if (logError)
|
|
{
|
|
DebugConsole.ThrowError($"Could not find human prefab \"{npcidentifier}\" from \"{setIdentifier}\".", contentPackage: contentPackageToLogInError);
|
|
}
|
|
return null;
|
|
}
|
|
return prefab;
|
|
}
|
|
|
|
public override void Dispose() { }
|
|
}
|
|
} |