Files
wwdpublic/Content.Shared/EntityTable/EntitySelectors/EntityTableSelector.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

91 lines
2.5 KiB
C#

using Content.Shared.EntityTable.Conditions;
using Content.Shared.EntityTable.ValueSelector;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Shared.EntityTable.EntitySelectors;
[ImplicitDataDefinitionForInheritors, UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public abstract partial class EntityTableSelector
{
/// <summary>
/// The number of times this selector is run
/// </summary>
[DataField]
public NumberSelector Rolls = new ConstantNumberSelector(1);
/// <summary>
/// A weight used to pick between selectors.
/// </summary>
[DataField]
public float Weight = 1;
/// <summary>
/// A simple chance that the selector will run.
/// </summary>
[DataField]
public double Prob = 1;
/// <summary>
/// A list of conditions that must evaluate to 'true' for the selector to apply.
/// </summary>
[DataField]
public List<EntityTableCondition> Conditions = new();
/// <summary>
/// If true, all the conditions must be successful in order for the selector to process.
/// Otherwise, only one of them must be.
/// </summary>
[DataField]
public bool RequireAll = true;
public IEnumerable<EntProtoId> GetSpawns(System.Random rand,
IEntityManager entMan,
IPrototypeManager proto,
EntityTableContext ctx)
{
if (!CheckConditions(entMan, proto, ctx))
yield break;
var rolls = Rolls.Get(rand, entMan, proto);
for (var i = 0; i < rolls; i++)
{
if (!rand.Prob(Prob))
continue;
foreach (var spawn in GetSpawnsImplementation(rand, entMan, proto, ctx))
{
yield return spawn;
}
}
}
public bool CheckConditions(IEntityManager entMan, IPrototypeManager proto, EntityTableContext ctx)
{
if (Conditions.Count == 0)
return true;
var success = false;
foreach (var condition in Conditions)
{
var res = condition.Evaluate(this, entMan, proto, ctx);
if (RequireAll && !res)
return false; // intentional break out of loop and function
success |= res;
}
if (RequireAll)
return true;
return success;
}
protected abstract IEnumerable<EntProtoId> GetSpawnsImplementation(System.Random rand,
IEntityManager entMan,
IPrototypeManager proto,
EntityTableContext ctx);
}