using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityTable.Conditions;
///
/// Condition that passes only if the server player count is within a certain range.
///
public sealed partial class PlayerCountCondition : EntityTableCondition
{
///
/// Minimum players of needed for this condition to succeed. Inclusive.
///
[DataField]
public int Min = int.MinValue;
///
/// Maximum numbers of players there can be for this condition to succeed. Inclusive.
///
[DataField]
public int Max = int.MaxValue;
private static ISharedPlayerManager? _playerManager;
public override bool EvaluateImplementation(IEntityManager entMan, IPrototypeManager proto)
{
// Don't resolve this repeatedly
_playerManager ??= IoCManager.Resolve();
var playerCount = _playerManager.PlayerCount;
return playerCount >= Min && playerCount <= Max;
}
}