CatStation/Content.Shared/EntityTable/Conditions/ExcludeEntitiesFromContextCondition.cs
Fildrance ec01361c4e
Bind type of EntityTableContext keys to expected values (#46214)
* refactor: EntityTableContext methods now use strongly typed keys, which are bound to type of value you want to extract from context.

* refactor: remove unused attributes

* refactor: extracted EntityTableContext into separate file, fixed xml-doc
2026-09-30 03:04:19 +00:00

34 lines
1.1 KiB
C#

using Content.Shared.EntityTable.EntitySelectors;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityTable.Conditions;
/// <summary>
/// Condition for checking that selector is not going to spawn entity that is marked in current context as excluded .
/// Can be used to keep spawns unique (if no selector rolls more than 1).
/// </summary>
public sealed partial class ExcludeEntitiesFromContextCondition : EntityTableCondition
{
/// <summary>
/// Context key used to track which entity prototypes should not be spawned.
/// Value should be <see cref="HashSet{EntityUid}"/>.
/// </summary>
public static readonly EntityTableContextKey<HashSet<EntProtoId>> EntitiesToExclude = new("EntitiesToExclude");
/// <inheritdoc/>>
protected override bool EvaluateImplementation(
EntityTableSelector root,
IEntityManager entMan,
IPrototypeManager proto,
EntityTableContext ctx
)
{
if (!ctx.TryGetData(EntitiesToExclude, out var used))
return true;
if (root is not EntSelector entSelector)
return true;
return !used.Contains(entSelector.Id);
}
}