Счетчик антагов для метрики

This commit is contained in:
Vigers Ray 2025-01-10 01:18:16 +03:00
parent 49c2165703
commit bee4a1492e
2 changed files with 48 additions and 5 deletions

View file

@ -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);
}
}

View file

@ -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;
}