Ejemplo n.º 1
0
        /// <summary>
        ///     Serialize suit sensor status into device network package.
        /// </summary>
        public NetworkPayload SuitSensorToPacket(SuitSensorStatus status)
        {
            var payload = new NetworkPayload()
            {
                [DeviceNetworkConstants.Command]   = DeviceNetworkConstants.CmdUpdatedState,
                [SuitSensorConstants.NET_NAME]     = status.Name,
                [SuitSensorConstants.NET_JOB]      = status.Job,
                [SuitSensorConstants.NET_IS_ALIVE] = status.IsAlive,
            };

            if (status.TotalDamage != null)
            {
                payload.Add(SuitSensorConstants.NET_TOTAL_DAMAGE, status.TotalDamage);
            }
            if (status.Coordinates != null)
            {
                payload.Add(SuitSensorConstants.NET_CORDINATES, status.Coordinates);
            }

            return(payload);
        }
Ejemplo n.º 2
0
        private void OnPacketRecv(EntityUid uid, GasVentPumpComponent component, DeviceNetworkPacketEvent args)
        {
            if (!EntityManager.TryGetComponent(uid, out DeviceNetworkComponent? netConn) ||
                !EntityManager.TryGetComponent(uid, out AtmosAlarmableComponent? alarmable) ||
                !args.Data.TryGetValue(DeviceNetworkConstants.Command, out var cmd))
            {
                return;
            }

            var payload = new NetworkPayload();

            switch (cmd)
            {
            case AirAlarmSystem.AirAlarmSyncCmd:
                payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSyncData);
                payload.Add(AirAlarmSystem.AirAlarmSyncData, component.ToAirAlarmData());

                _deviceNetSystem.QueuePacket(uid, args.SenderAddress, payload, device: netConn);

                return;

            case AirAlarmSystem.AirAlarmSetData:
                if (!args.Data.TryGetValue(AirAlarmSystem.AirAlarmSetData, out GasVentPumpData? setData))
                {
                    break;
                }

                component.FromAirAlarmData(setData);
                UpdateState(uid, component);
                alarmable.IgnoreAlarms = setData.IgnoreAlarms;
                payload.Add(DeviceNetworkConstants.Command, AirAlarmSystem.AirAlarmSetDataStatus);
                payload.Add(AirAlarmSystem.AirAlarmSetDataStatus, true);

                _deviceNetSystem.QueuePacket(uid, null, payload, device: netConn);

                return;
            }
        }