Files
tbd-station-14/Content.Shared/EntityTable/EntitySelectors/EntityTableSelector.cs
Nemanja 437c861622 Entity Tables (EntitySpawnEntry replacement) (#30579)
* Entity table code

* entity table examples

* fix dat shit

* access

* tests tests tests

* sloth review
2024-08-09 22:12:40 -04:00

50 lines
1.4 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, 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<EntProtoId> GetSpawnsImplementation(System.Random rand,
IEntityManager entMan,
IPrototypeManager proto);
}