1
0

GroupSelector.cs 874 B

12345678910111213141516171819202122232425262728
  1. using Content.Shared.Random.Helpers;
  2. using Robust.Shared.Prototypes;
  3. namespace Content.Shared.EntityTable.EntitySelectors;
  4. /// <summary>
  5. /// Gets the spawns from one of the child selectors, based on the weight of the children
  6. /// </summary>
  7. public sealed partial class GroupSelector : EntityTableSelector
  8. {
  9. [DataField(required: true)]
  10. public List<EntityTableSelector> Children = new();
  11. protected override IEnumerable<EntProtoId> GetSpawnsImplementation(System.Random rand,
  12. IEntityManager entMan,
  13. IPrototypeManager proto)
  14. {
  15. var children = new Dictionary<EntityTableSelector, float>(Children.Count);
  16. foreach (var child in Children)
  17. {
  18. children.Add(child, child.Weight);
  19. }
  20. var pick = SharedRandomExtensions.Pick(children, rand);
  21. return pick.GetSpawns(rand, entMan, proto);
  22. }
  23. }