Esempio n. 1
0
        /// <summary>
        /// 바로 죽입니다.
        /// </summary>
        /// <param name="iDamageAmount"></param>
        public void DoKill(IDictionary <string, object> mapMsg)
        {
            int iHPOrigin = _iHP_Current;

            _iHP_Current = 0;
            OnHealthEvent?.Invoke(new OnHealthEventMsg(this, mapMsg, EHealthEvent.Dead, iHPOrigin, iHPOrigin));
        }
Esempio n. 2
0
        /// <summary>
        /// 체력을 최대 체력만큼 회복합니다. <see cref="EHealthEvent"/>는 <see cref="EHealthEvent.Reset"/>입니다
        /// </summary>
        public void DoReset(IDictionary <string, object> mapMsg)
        {
            int          iHPMax = _iHP_MAX;
            EHealthEvent eEvent = ExecuteLogic(EHealthEvent.Reset, ref iHPMax, ref mapMsg);

            _iHP_Current = iHPMax;

            OnHealthEvent?.Invoke(new OnHealthEventMsg(this, mapMsg, eEvent, 0, 0));
        }
Esempio n. 3
0
        /// <summary>
        /// 체력을 회복시킵니다. <see cref="EHealthEvent"/>는 <see cref="EHealthEvent.Recovery"/>입니다
        /// </summary>
        public void DoRecovery(int iRecoveryAmount, IDictionary <string, object> mapMsg)
        {
            if (_iHP_Current == _iHP_MAX)
            {
                return;
            }

            int          iOriginalValue = iRecoveryAmount;
            EHealthEvent eEvent         = ExecuteLogic(EHealthEvent.Recovery, ref iRecoveryAmount, ref mapMsg);

            _iHP_Current += iRecoveryAmount;

            OnHealthEvent?.Invoke(new OnHealthEventMsg(this, mapMsg, eEvent, iOriginalValue, iRecoveryAmount));
        }
Esempio n. 4
0
        public LinuxHealthHub()
        {
            var devId  = Bluez.hci_get_route(IntPtr.Zero);
            var sockFd = Linux.socket(Consts.AF_BLUETOOTH, Consts.SOCK_RAW | Consts.SOCK_CLOEXEC, Consts.BTPROTO_HCI);
            var addr   = new Sockaddr_hci
            {
                hci_family  = Consts.AF_BLUETOOTH,
                hci_dev     = (ushort)devId,
                hci_channel = Consts.HCI_CHANNEL_RAW
            };
            var status = Linux.bind(sockFd, ref addr, Marshal.SizeOf(addr));

            status = Bluez.hci_le_set_scan_parameters(sockFd, 0, 0x10, 0x10, 0, 0, 1000);
            var filter = new Hci_filter
            {
                type_mask  = 0x00000010,
                event_mask = 0x4000000000000000ul,
                opcode     = 0
            };

            status  = Linux.setsockopt(sockFd, Consts.SOL_HCI, Consts.HCI_FILTER, ref filter, Marshal.SizeOf(filter));
            status  = Bluez.hci_le_set_scan_enable(sockFd, 1, 0, 1000);
            watcher = new Thread(() =>
            {
                while (shouldRun)
                {
                    var bytes = new byte[44];
                    Reflect.Call("Mono.Unix.Native.Syscall, Mono.Posix", "recv", sockFd, bytes, (ulong)bytes.Length, 0);
                    var offset            = 16;
                    const DeviceKind kind = DeviceKind.Scale;
                    var ts       = new DateTimeOffset();
                    var weightKg = BitConverter.ToUInt16(new[] { bytes[5 + offset], bytes[4 + offset] }, 0) / 10f;
                    var finished = bytes[6 + offset] != 255 && bytes[7 + offset] != 255;
                    OnHealthEvent?.Invoke(this, new SimpleData
                    {
                        Kind   = kind,
                        Time   = ts,
                        Data   = weightKg,
                        Unit   = Unit.kg,
                        Status = finished ? DataKind.Final : DataKind.Transitional
                    });
                }
            })
            {
                IsBackground = true,
                Name         = "Watcher"
            };
            watcher.Start();
        }
Esempio n. 5
0
        /// <summary>
        /// 체력을 해당 양만큼 감소시킵니다. <see cref="EHealthEvent"/>는 <see cref="EHealthEvent.Damaged"/> 혹은  <see cref="EHealthEvent.Dead"/>입니다.
        /// </summary>
        /// <param name="iDamageAmount"></param>
        public void DoDamage(int iDamageAmount, IDictionary <string, object> mapMsg)
        {
            if (_iHP_Current <= 0)
            {
                return;
            }

            int          iOriginalValue = iDamageAmount;
            EHealthEvent eEvent         = ExecuteLogic(EHealthEvent.Damaged, ref iDamageAmount, ref mapMsg);

            _iHP_Current -= iDamageAmount;
            if (_iHP_Current <= 0)
            {
                _iHP_Current = 0;
                eEvent       = EHealthEvent.Dead;
            }

            OnHealthEvent?.Invoke(new OnHealthEventMsg(this, mapMsg, eEvent, iOriginalValue, iDamageAmount));
        }
Esempio n. 6
0
        private void Scale_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
        {
            const DeviceKind kind = DeviceKind.Scale;
            var addr     = args.BluetoothAddress;
            var ts       = args.Timestamp;
            var data     = args.Advertisement.DataSections.First(d => d.DataType == 255);
            var bytes    = data.Data.ToArray();
            var weightKg = BitConverter.ToUInt16(new[] { bytes[5], bytes[4] }, 0) / 10f;
            var finished = bytes[6] != 255 && bytes[7] != 255;

            OnHealthEvent?.Invoke(this, new SimpleData
            {
                Kind   = kind,
                Origin = addr,
                Time   = ts,
                Data   = weightKg,
                Unit   = Unit.kg,
                Status = finished ? DataKind.Final : DataKind.Transitional
            });
        }
Esempio n. 7
0
 /// <summary>
 /// 체력을 강제로 Set합니다. <see cref="EHealthEvent"/>는 <see cref="EHealthEvent.None"/>입니다
 /// </summary>
 public void DoSet(int iHP)
 {
     _iHP_MAX = iHP;
     OnHealthEvent?.Invoke(new OnHealthEventMsg(this, const_mapMsg_Empty, EHealthEvent.None, 0, 0));
 }