Client LuaCsForBarotrauma
ICircuitBoxIdentifiable.cs
1 using System.Collections.Generic;
2 using System.Collections.Immutable;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
7  public interface ICircuitBoxIdentifiable
8  {
9  public const ushort NullComponentID = ushort.MaxValue;
10 
11  public ushort ID { get; }
12 
13  public static ushort FindFreeID<T>(IReadOnlyCollection<T> ids) where T : ICircuitBoxIdentifiable
14  {
15  var sortedIds = ids.Select(static i => i.ID).ToImmutableHashSet();
16 
17  for (ushort i = 0; i < NullComponentID - 1; i++)
18  {
19  if (!sortedIds.Contains(i))
20  {
21  return i;
22  }
23  }
24 
25  return NullComponentID;
26  }
27  }
28 }
static ushort FindFreeID< T >(IReadOnlyCollection< T > ids)