Files
wwdpublic/Content.Shared/EntityTable/Conditions/MaxRuleOccurenceCondition.cs
Kai5 e097ac1750 Dynamic real (#825)
* Add support for contextual information in EntityTables (#37737)

* Add context support for entityTables

* fix build fail

* comments

* Update Content.Shared/EntityTable/EntityTableSystem.cs

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

(cherry picked from commit e92b6b6a7e2ed2e5f7473321e391394f28b9ee4a)

* Multiantag Gamemode (#37783)

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Co-authored-by: Southbridge <7013162+southbridge-fur@users.noreply.github.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>

(cherry picked from commit f23e8c286153b5742de258a4e722803a1a4fba78)

* Гейммоды

* Ребаланс цен

* Фикс линтера

* Баланс бюджета + фикс повторения

---------

Co-authored-by: Nemanja <98561806+emogarbage404@users.noreply.github.com>
2025-09-03 08:49:15 +03:00

55 lines
1.6 KiB
C#

using System.Linq;
using Content.Shared.EntityTable.EntitySelectors;
using Content.Shared.GameTicking;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityTable.Conditions;
/// <summary>
/// Condition that succeeds only when the specified gamerule has been run under a certain amount of times
/// </summary>
/// <remarks>
/// This is meant to be attached directly to EntSelector. If it is not, then you'll need to specify what rule
/// is being used inside RuleOverride.
/// </remarks>
public sealed partial class MaxRuleOccurenceCondition : EntityTableCondition
{
/// <summary>
/// The maximum amount of times this rule can have already be run.
/// </summary>
[DataField]
public int Max = 1;
/// <summary>
/// The rule that is being checked for occurrences.
/// If null, it will use the value on the attached selector.
/// </summary>
[DataField]
public EntProtoId? RuleOverride;
protected override bool EvaluateImplementation(EntityTableSelector root,
IEntityManager entMan,
IPrototypeManager proto,
EntityTableContext ctx)
{
string rule;
if (RuleOverride is { } ruleOverride)
{
rule = ruleOverride;
}
else
{
rule = root is EntSelector entSelector
? entSelector.Id
: string.Empty;
}
if (rule == string.Empty)
return false;
var gameTicker = entMan.System<SharedGameTicker>();
return gameTicker.AllPreviousGameRules.Count(p => p.Item2 == rule) < Max;
}
}