Files
LuaCsForBarotraumaEP/Barotrauma/BarotraumaShared/SharedSource/Map/Outposts/NPCSet.cs
2022-02-26 02:43:01 +09:00

56 lines
1.6 KiB
C#

#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
internal class NPCSet : Prefab
{
public readonly static PrefabCollection<NPCSet> Sets = new PrefabCollection<NPCSet>();
private readonly ImmutableArray<HumanPrefab> Humans;
private bool Disposed { get; set; }
public NPCSet(ContentXElement element, NPCSetsFile file) : base(file, element.GetAttributeIdentifier("identifier", ""))
{
Humans = element.Elements().Select(npcElement => new HumanPrefab(npcElement, file)).ToImmutableArray();
}
public static HumanPrefab? Get(Identifier setIdentifier, Identifier npcidentifier)
{
HumanPrefab? prefab = Sets.Where(set => set.Identifier == setIdentifier).SelectMany(npcSet => npcSet.Humans.Where(npcSetHuman => npcSetHuman.Identifier == npcidentifier)).FirstOrDefault();
if (prefab == null)
{
DebugConsole.ThrowError($"Could not find human prefab \"{npcidentifier}\" from \"{setIdentifier}\".");
return null;
}
return prefab;
}
private void Dispose(bool disposing)
{
if (!Disposed)
{
if (disposing)
{
Humans.Clear();
}
}
Disposed = true;
}
public override void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}