CatStation/Content.Shared/EntityTable/Conditions/ExcludeEntitiesFromContextCondition.cs
Fildrance ff495df549
Injecting entity table conditions into context (#45231)
* refactor: entity table condition injection and hierarhical condition checks

* refactor: rename IsNotRepeatingCondition into ExcludeEntitiesFromContextCondition, simplify EntityTableSelectorWithChildrenBase.CheckConditions logic, + new test

* refactor: fix test using old name of condition

* refactor: renaming

* refactor: fix no condition + RequireAll case and added test

* refactor: GetSpawns no more virtual

* refactor: more tests!

* refactor: use ScopedConditionsRestore for child conditions in EntityTableSelectorWithChildrenBase, not for current type conditions
2026-08-24 00:12:07 +00:00

33 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.
/// </summary>
public const string EntitiesToExclude = "EntitiesToExclude";
/// <inheritdoc/>>
protected override bool EvaluateImplementation(
EntityTableSelector root,
IEntityManager entMan,
IPrototypeManager proto,
EntityTableContext ctx
)
{
if (!ctx.TryGetData<HashSet<EntProtoId>>(EntitiesToExclude, out var used))
return true;
if (root is not EntSelector entSelector)
return true;
return !used.Contains(entSelector.Id);
}
}