2024-08-09 22:12:40 -04:00
|
|
|
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)
|
|
|
|
|
{
|
2025-04-14 14:02:49 -07:00
|
|
|
var rolls = Rolls.Get(rand);
|
2024-08-09 22:12:40 -04:00
|
|
|
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);
|
|
|
|
|
}
|