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>
This commit is contained in:
51
Content.Shared/EntityTable/Conditions/HasBudgetCondition.cs
Normal file
51
Content.Shared/EntityTable/Conditions/HasBudgetCondition.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Content.Shared.EntityTable.EntitySelectors;
|
||||
using Content.Shared.GameTicking.Rules;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.EntityTable.Conditions;
|
||||
|
||||
/// <summary>
|
||||
/// Condition that only succeeds if a table supplies a sufficient "cost" to a given
|
||||
/// </summary>
|
||||
public sealed partial class HasBudgetCondition : EntityTableCondition
|
||||
{
|
||||
public const string BudgetContextKey = "Budget";
|
||||
|
||||
/// <summary>
|
||||
/// Used for determining the cost for the budget.
|
||||
/// If null, attempts to fetch the cost from the attached selector.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public int? CostOverride;
|
||||
|
||||
protected override bool EvaluateImplementation(EntityTableSelector root,
|
||||
IEntityManager entMan,
|
||||
IPrototypeManager proto,
|
||||
EntityTableContext ctx)
|
||||
{
|
||||
if (!ctx.TryGetData<float>(BudgetContextKey, out var budget))
|
||||
return false;
|
||||
|
||||
int cost;
|
||||
if (CostOverride != null)
|
||||
{
|
||||
cost = CostOverride.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (root is not EntSelector entSelector)
|
||||
return false;
|
||||
|
||||
if (!proto.Index(entSelector.Id).TryGetComponent(out DynamicRuleCostComponent? costComponent, entMan.ComponentFactory))
|
||||
{
|
||||
var log = Logger.GetSawmill("HasBudgetCondition");
|
||||
log.Error($"Rule {entSelector.Id} does not have a DynamicRuleCostComponent.");
|
||||
return false;
|
||||
}
|
||||
|
||||
cost = costComponent.Cost;
|
||||
}
|
||||
|
||||
return budget >= cost;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using Content.Shared.EntityTable.EntitySelectors;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.EntityTable.Conditions;
|
||||
|
||||
public sealed partial class ReoccurrenceDelayCondition : EntityTableCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum amount of times this rule can have already be run.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Delay = TimeSpan.Zero;
|
||||
|
||||
/// <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.Any(
|
||||
p => p.Item2 == rule && p.Item1 + Delay <= gameTicker.RoundDuration());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Content.Shared.EntityTable.EntitySelectors;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.EntityTable.Conditions;
|
||||
|
||||
/// <summary>
|
||||
/// Condition that passes only if the current round time falls between the minimum and maximum time values.
|
||||
/// </summary>
|
||||
public sealed partial class RoundDurationCondition : EntityTableCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// Minimum time the round must have gone on for this condition to pass.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Min = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum amount of time the round could go on for this condition to pass.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Max = TimeSpan.MaxValue;
|
||||
|
||||
protected override bool EvaluateImplementation(EntityTableSelector root,
|
||||
IEntityManager entMan,
|
||||
IPrototypeManager proto,
|
||||
EntityTableContext ctx)
|
||||
{
|
||||
var gameTicker = entMan.System<SharedGameTicker>();
|
||||
var duration = gameTicker.RoundDuration();
|
||||
|
||||
return duration >= Min && duration <= Max;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,9 @@ public sealed partial class GroupSelector : EntityTableSelector
|
||||
children.Add(child, child.Weight);
|
||||
}
|
||||
|
||||
if (children.Count == 0)
|
||||
return Array.Empty<EntProtoId>();
|
||||
|
||||
var pick = SharedRandomExtensions.Pick(children, rand);
|
||||
|
||||
return pick.GetSpawns(rand, entMan, proto, ctx);
|
||||
|
||||
Reference in New Issue
Block a user