From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 5 May 2023 17:51:58 +0000 (+1000) Subject: Set station suit sensors on player spawn (#16111) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=2dd535284dacea5ca2e71105ac1ca3b068ae3382;p=space-station-14.git Set station suit sensors on player spawn (#16111) --- diff --git a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs index 7786b349ba..0929d88c71 100644 --- a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs +++ b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs @@ -2,6 +2,7 @@ using Content.Server.Access.Systems; using Content.Server.DeviceNetwork; using Content.Server.DeviceNetwork.Components; using Content.Server.DeviceNetwork.Systems; +using Content.Server.GameTicking; using Content.Server.Medical.CrewMonitoring; using Content.Server.Popups; using Content.Server.Station.Systems; @@ -34,6 +35,7 @@ namespace Content.Server.Medical.SuitSensors public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnPlayerSpawn); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnUnpaused); SubscribeLocalEvent(OnEquipped); @@ -56,7 +58,7 @@ namespace Content.Server.Medical.SuitSensors var curTime = _gameTiming.CurTime; var sensors = EntityManager.EntityQueryEnumerator(); - while (sensors.MoveNext(out var sensor, out var device)) + while (sensors.MoveNext(out var uid, out var sensor, out var device)) { if (device.TransmitFrequency is null || !sensor.StationId.HasValue) continue; @@ -69,7 +71,7 @@ namespace Content.Server.Medical.SuitSensors sensor.NextUpdate = curTime + sensor.UpdateRate; // get sensor status - var status = GetSensorState(sensor.Owner, sensor); + var status = GetSensorState(uid, sensor); if (status == null) continue; @@ -92,13 +94,40 @@ namespace Content.Server.Medical.SuitSensors continue; } - _deviceNetworkSystem.QueuePacket(sensor.Owner, sensor.ConnectedServer, payload, device: device); + _deviceNetworkSystem.QueuePacket(uid, sensor.ConnectedServer, payload, device: device); + } + } + + private void OnPlayerSpawn(PlayerSpawnCompleteEvent ev) + { + // If the player spawns in arrivals then the grid underneath them may not be appropriate. + // in which case we'll just use the station spawn code told us they are attached to and set all of their + // sensors. + var sensorQuery = GetEntityQuery(); + var xformQuery = GetEntityQuery(); + RecursiveSensor(ev.Mob, ev.Station, sensorQuery, xformQuery); + } + + private void RecursiveSensor(EntityUid uid, EntityUid stationUid, EntityQuery sensorQuery, EntityQuery xformQuery) + { + var xform = xformQuery.GetComponent(uid); + var enumerator = xform.ChildEnumerator; + + while (enumerator.MoveNext(out var child)) + { + if (sensorQuery.TryGetComponent(child, out var sensor)) + { + sensor.StationId = stationUid; + } + + RecursiveSensor(child.Value, stationUid, sensorQuery, xformQuery); } } private void OnMapInit(EntityUid uid, SuitSensorComponent component, MapInitEvent args) { - component.StationId = _stationSystem.GetOwningStation(uid); + // Fallback + component.StationId ??= _stationSystem.GetOwningStation(uid); // generate random mode if (component.RandomMode)