Entity Tables (EntitySpawnEntry replacement) (#30579)
* Entity table code * entity table examples * fix dat shit * access * tests tests tests * sloth review
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user