using Content.Server.DeviceNetwork.Systems; using Content.Server.Emp; using Content.Server.Medical.CrewMonitoring; using Content.Shared.DeviceNetwork.Components; using Content.Shared.Medical.SuitSensor; using Content.Shared.Medical.SuitSensors; using Robust.Shared.Timing; namespace Content.Server.Medical.SuitSensors; public sealed class SuitSensorSystem : SharedSuitSensorSystem { [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!; [Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnEmpPulse); SubscribeLocalEvent(OnEmpFinished); } public override void Update(float frameTime) { base.Update(frameTime); var curTime = _gameTiming.CurTime; var sensors = EntityQueryEnumerator(); while (sensors.MoveNext(out var uid, out var sensor, out var device)) { if (device.TransmitFrequency is null) continue; // check if sensor is ready to update if (curTime < sensor.NextUpdate) continue; if (!CheckSensorAssignedStation((uid, sensor))) continue; sensor.NextUpdate += sensor.UpdateRate; // get sensor status var status = GetSensorState((uid, sensor)); if (status == null) continue; //Retrieve active server address if the sensor isn't connected to a server if (sensor.ConnectedServer == null) { if (!_singletonServerSystem.TryGetActiveServerAddress(sensor.StationId!.Value, out var address)) continue; sensor.ConnectedServer = address; } // Send it to the connected server var payload = SuitSensorToPacket(status); // Clear the connected server if its address isn't on the network if (!_deviceNetworkSystem.IsAddressPresent(device.DeviceNetId, sensor.ConnectedServer)) { sensor.ConnectedServer = null; continue; } _deviceNetworkSystem.QueuePacket(uid, sensor.ConnectedServer, payload, device: device); } } private void OnEmpPulse(Entity ent, ref EmpPulseEvent args) { args.Affected = true; args.Disabled = true; ent.Comp.PreviousMode = ent.Comp.Mode; SetSensor(ent.AsNullable(), SuitSensorMode.SensorOff, null); ent.Comp.PreviousControlsLocked = ent.Comp.ControlsLocked; ent.Comp.ControlsLocked = true; } private void OnEmpFinished(Entity ent, ref EmpDisabledRemoved args) { SetSensor(ent.AsNullable(), ent.Comp.PreviousMode, null); ent.Comp.ControlsLocked = ent.Comp.PreviousControlsLocked; } }