Entity Tables (EntitySpawnEntry replacement) (#30579)
* Entity table code * entity table examples * fix dat shit * access * tests tests tests * sloth review
This commit is contained in:
28
Content.Shared/EntityTable/EntitySelectors/GroupSelector.cs
Normal file
28
Content.Shared/EntityTable/EntitySelectors/GroupSelector.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.EntityTable.EntitySelectors;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the spawns from one of the child selectors, based on the weight of the children
|
||||
/// </summary>
|
||||
public sealed partial class GroupSelector : EntityTableSelector
|
||||
{
|
||||
[DataField(required: true)]
|
||||
public List<EntityTableSelector> Children = new();
|
||||
|
||||
protected override IEnumerable<EntProtoId> GetSpawnsImplementation(System.Random rand,
|
||||
IEntityManager entMan,
|
||||
IPrototypeManager proto)
|
||||
{
|
||||
var children = new Dictionary<EntityTableSelector, float>(Children.Count);
|
||||
foreach (var child in Children)
|
||||
{
|
||||
children.Add(child, child.Weight);
|
||||
}
|
||||
|
||||
var pick = SharedRandomExtensions.Pick(children, rand);
|
||||
|
||||
return pick.GetSpawns(rand, entMan, proto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user