Client LuaCsForBarotrauma
NPCSet.cs
1 #nullable enable
2 using System.Collections.Immutable;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
7  internal class NPCSet : Prefab
8  {
9  public readonly static PrefabCollection<NPCSet> Sets = new PrefabCollection<NPCSet>();
10 
11  private readonly ImmutableArray<HumanPrefab> Humans;
12 
13  public NPCSet(ContentXElement element, NPCSetsFile file) : base(file, element.GetAttributeIdentifier("identifier", ""))
14  {
15  Humans = element.Elements().Select(npcElement => new HumanPrefab(npcElement, file, Identifier)).ToImmutableArray();
16  }
17 
18  public static HumanPrefab? Get(Identifier setIdentifier, Identifier npcidentifier, bool logError = true)
19  {
20  HumanPrefab? prefab = Sets.Where(set => set.Identifier == setIdentifier).SelectMany(npcSet => npcSet.Humans.Where(npcSetHuman => npcSetHuman.Identifier == npcidentifier)).FirstOrDefault();
21 
22  if (prefab == null)
23  {
24  if (logError)
25  {
26  DebugConsole.ThrowError($"Could not find human prefab \"{npcidentifier}\" from \"{setIdentifier}\".");
27  }
28  return null;
29  }
30  return prefab;
31  }
32 
33  public override void Dispose() { }
34  }
35 }