CatStation/Content.Shared/EntityTable/EntitySelectors/EntSelector.cs
Fildrance 8bf0961e5a
Feature/refactor xenoarch trigger to be entity table ed (#45608)
* refactor: rough strokes for initial implementation

* refactor: fix ada remarks

* refactor: fix XenoArtifactNodeParser not displaying trigger and effect properly in autocompletion

* refactor: more changes for IsNotRepeatingCondition

* refactor: update triggers declarations

* refactor: remove IsNotRepeatingCondition - duplicate

* refactor: fixup after merge with master

* refactor: properly handle creation of improper trigger set, all selectors gt ToString override!

* refactor: fix missing weight for some triggers, XenoArtifactCommand.UnlockAllNodes now accepts multiple entries

* refactor: fix trigger hints loc being name explicitly and failing tests

* yaml changes

* rename

* refactor: fix xml-doc copy-paste for XenoArtifactTriggerParser

---------

Co-authored-by: iaada <iaada@users.noreply.github.com>
2026-08-31 20:58:52 +00:00

53 lines
1.5 KiB
C#

using Content.Shared.EntityTable.ValueSelector;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Shared.EntityTable.EntitySelectors;
/// <summary>
/// Gets the spawn for the entity prototype specified at whatever count specified.
/// </summary>
public sealed partial class EntSelector : EntityTableSelector
{
public const string IdDataFieldTag = "id";
/// <summary>
/// The prototype this entry yields.
/// </summary>
[DataField(IdDataFieldTag, required: true)]
public EntProtoId Id;
/// <summary>
/// The amount of entities this entry might yield.
/// </summary>
[DataField]
public NumberSelector Amount = new ConstantNumberSelector(1);
protected override IEnumerable<EntProtoId> GetSpawnsImplementation(IRobustRandom rand,
IEntityManager entMan,
IPrototypeManager proto,
EntityTableContext ctx)
{
var num = Amount.Get(rand);
for (var i = 0; i < num; i++)
{
yield return Id;
}
}
protected override IEnumerable<(EntProtoId spawn, double)> ListSpawnsImplementation(IEntityManager entMan, IPrototypeManager proto, EntityTableContext ctx)
{
yield return (Id, 1f);
}
protected override IEnumerable<(EntProtoId spawn, double)> AverageSpawnsImplementation(IEntityManager entMan, IPrototypeManager proto, EntityTableContext ctx)
{
yield return (Id, Amount.Average());
}
/// <inheritdoc/>
public override string ToString()
{
return $"{Id} x{Amount.Average()}";
}
}