using Content.Shared.EntityTable.ValueSelector; using JetBrains.Annotations; using Robust.Shared.Prototypes; using Robust.Shared.Random; namespace Content.Shared.EntityTable.EntitySelectors; [ImplicitDataDefinitionForInheritors, UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public abstract partial class EntityTableSelector { /// /// The number of times this selector is run /// [DataField] public NumberSelector Rolls = new ConstantNumberSelector(1); /// /// A weight used to pick between selectors. /// [DataField] public float Weight = 1; /// /// A simple chance that the selector will run. /// [DataField] public double Prob = 1; public IEnumerable GetSpawns(System.Random rand, IEntityManager entMan, IPrototypeManager proto) { var rolls = Rolls.Get(rand, entMan, proto); for (var i = 0; i < rolls; i++) { if (!rand.Prob(Prob)) continue; foreach (var spawn in GetSpawnsImplementation(rand, entMan, proto)) { yield return spawn; } } } protected abstract IEnumerable GetSpawnsImplementation(System.Random rand, IEntityManager entMan, IPrototypeManager proto); }