* Add context support for entityTables * fix build fail * comments * Update Content.Shared/EntityTable/EntityTableSystem.cs --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
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,
|
|
EntityTableContext ctx)
|
|
{
|
|
var children = new Dictionary<EntityTableSelector, float>(Children.Count);
|
|
foreach (var child in Children)
|
|
{
|
|
// Don't include invalid groups
|
|
if (!child.CheckConditions(entMan, proto, ctx))
|
|
continue;
|
|
|
|
children.Add(child, child.Weight);
|
|
}
|
|
|
|
var pick = SharedRandomExtensions.Pick(children, rand);
|
|
|
|
return pick.GetSpawns(rand, entMan, proto, ctx);
|
|
}
|
|
}
|