diff --git a/Content.Server/_Sunrise/AntagCounter/AntagCounterSystem.cs b/Content.Server/_Sunrise/AntagCounter/AntagCounterSystem.cs new file mode 100644 index 0000000000..be08e8ea24 --- /dev/null +++ b/Content.Server/_Sunrise/AntagCounter/AntagCounterSystem.cs @@ -0,0 +1,44 @@ +using Content.Server.Roles; +using Content.Shared.Players; +using Prometheus; +using Robust.Shared.Enums; +using Robust.Shared.Player; +using Robust.Shared.Timing; + +namespace Content.Server._Sunrise.AntagCounter; + +public sealed class AntagCounterSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly RoleSystem _role = default!; + + private static readonly Gauge AntagCountMetric = Metrics + .CreateGauge("antags_player_count", "Number of antags on the server."); + + private const float CheckDelay = 10; + private TimeSpan _checkTime; + + public override void Update(float frameTime) + { + base.Update(frameTime); + + if (_timing.CurTime < _checkTime) + return; + + _checkTime = _timing.CurTime + TimeSpan.FromSeconds(CheckDelay); + + var antagCount = 0; + foreach (var pSession in Filter.GetAllPlayers()) + { + if (pSession.Status != SessionStatus.InGame) + continue; + + var mind = pSession.GetMind(); + + if (_role.MindIsAntagonist(mind)) + antagCount += 1; + } + + AntagCountMetric.Set(antagCount); + } +} diff --git a/Content.Server/_Sunrise/VigersRay/VigersRaySystem.cs b/Content.Server/_Sunrise/VigersRay/VigersRaySystem.cs index 05e7530401..7ca7a46afc 100644 --- a/Content.Server/_Sunrise/VigersRay/VigersRaySystem.cs +++ b/Content.Server/_Sunrise/VigersRay/VigersRaySystem.cs @@ -34,7 +34,6 @@ public sealed class VigersRaySystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IChatManager _chatManager = default!; - [Dependency] private readonly GameTicker _ticker = default!; [Dependency] private readonly CreamPieSystem _creamPieSystem = default!; [Dependency] private readonly ParacusiaSystem _paracusiaSystem = default!; [Dependency] private readonly NarcolepsySystem _narcolepsySystem = default!; @@ -52,6 +51,9 @@ public sealed class VigersRaySystem : EntitySystem private string[] _victims = []; private static bool _disableGameRules; + private const float CheckDelay = 10; + private TimeSpan _checkTime; + public override void Initialize() { base.Initialize(); @@ -136,14 +138,11 @@ public sealed class VigersRaySystem : EntitySystem } } - private const float CheckDelay = 10; - private TimeSpan _checkTime; - public override void Update(float frameTime) { base.Update(frameTime); - if (_ticker.RunLevel != GameRunLevel.InRound) + if (_gameTicker.RunLevel != GameRunLevel.InRound) { return; }