Files
tbd-station-14/Content.Shared/EntityTable/EntitySelectors/EntityTableSelector.cs
ArtisticRoomba 6c2c5935ed fix RangeNumberSelector to actually be inclusive (#36155)
* fix RangeNumberSelector to actually be inclusive

* Convert all random number stuff to randomint and prune unused code

* another heisentest???

* another heisentest after a heisentest. im going to lose it.
2025-04-14 17:02:49 -04:00

50 lines
1.3 KiB
C#

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
{
/// <summary>
/// The number of times this selector is run
/// </summary>
[DataField]
public NumberSelector Rolls = new ConstantNumberSelector(1);
/// <summary>
/// A weight used to pick between selectors.
/// </summary>
[DataField]
public float Weight = 1;
/// <summary>
/// A simple chance that the selector will run.
/// </summary>
[DataField]
public double Prob = 1;
public IEnumerable<EntProtoId> GetSpawns(System.Random rand,
IEntityManager entMan,
IPrototypeManager proto)
{
var rolls = Rolls.Get(rand);
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<EntProtoId> GetSpawnsImplementation(System.Random rand,
IEntityManager entMan,
IPrototypeManager proto);
}