From bee4a1492ea25a6ea2a5bdd06ff5094ef1682841 Mon Sep 17 00:00:00 2001 From: Vigers Ray Date: Fri, 10 Jan 2025 01:18:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=87=D0=B5=D1=82=D1=87=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=B0=D0=BD=D1=82=D0=B0=D0=B3=D0=BE=D0=B2=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AntagCounter/AntagCounterSystem.cs | 44 +++++++++++++++++++ .../_Sunrise/VigersRay/VigersRaySystem.cs | 9 ++-- 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 Content.Server/_Sunrise/AntagCounter/AntagCounterSystem.cs 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; }