using System.Linq; using Content.Server.Administration; using Content.Server.Radiation.Components; using Content.Shared.Administration; using Content.Shared.Radiation.Events; using Content.Shared.Radiation.Systems; using Robust.Shared.Console; using Robust.Shared.Debugging; using Robust.Shared.Enums; using Robust.Shared.Map.Components; using Robust.Shared.Player; namespace Content.Server.Radiation.Systems; // radiation overlay debug logic // rad rays send only to clients that enabled debug overlay public partial class RadiationSystem { private readonly HashSet _debugSessions = new(); /// /// Toggle radiation debug overlay for selected player. /// public void ToggleDebugView(ICommonSession session) { bool isEnabled; if (_debugSessions.Add(session)) { isEnabled = true; } else { _debugSessions.Remove(session); isEnabled = false; } var ev = new OnRadiationOverlayToggledEvent(isEnabled); RaiseNetworkEvent(ev, session.Channel); } /// /// Send new information for radiation overlay. /// private void UpdateDebugOverlay(EntityEventArgs ev) { foreach (var session in _debugSessions) { if (session.Status != SessionStatus.InGame) _debugSessions.Remove(session); else RaiseNetworkEvent(ev, session); } } private void UpdateResistanceDebugOverlay() { if (_debugSessions.Count == 0) return; var dict = new Dictionary>(); var gridQuery = AllEntityQuery(); while (gridQuery.MoveNext(out var gridUid, out _, out var resistance)) { var resMap = resistance.ResistancePerTile; dict.Add(GetNetEntity(gridUid), resMap); } var ev = new OnRadiationOverlayResistanceUpdateEvent(dict); UpdateDebugOverlay(ev); } private void UpdateGridcastDebugOverlay( double elapsedTime, int totalSources, int totalReceivers, List? rays) { if (_debugSessions.Count == 0) return; var ev = new OnRadiationOverlayUpdateEvent(elapsedTime, totalSources, totalReceivers, rays ?? new()); UpdateDebugOverlay(ev); } } /// /// Toggle visibility of radiation rays coming from rad sources. /// [AdminCommand(AdminFlags.Admin)] public sealed class RadiationViewCommand : LocalizedEntityCommands { [Dependency] private readonly RadiationSystem _radiation = default!; public override string Command => "showradiation"; public override void Execute(IConsoleShell shell, string argStr, string[] args) { var session = shell.Player; if (session == null) return; _radiation.ToggleDebugView(session); } }