コード例 #1
0
 /// <summary>
 /// Sets the state of the drone.
 /// </summary>
 /// <param name="droneState">The state of the drone.</param>
 public void SetDroneState(DroneState droneState)
 {
     this.SetSpeed(droneState.Speed);
     this.SetHeight(droneState.Height > 0 ? droneState.Height : droneState.ToF);
     this.SetWiFiSnr(droneState.WiFiSnr);
     this.SetBatteryLevel(droneState.BatteryPercentage);
 }
コード例 #2
0
        public DeviceState Deserialize(byte[] payload, ILogger log)
        {
            DroneState restored = serializer.Deserialize(payload);

            log.LogInformation("Deserialize message for device ID {DeviceId}", restored.DeviceId);

            var deviceState = new DeviceState();

            deviceState.DeviceId = restored.DeviceId;

            if (restored.Battery != null)
            {
                deviceState.Battery = restored.Battery;
            }
            if (restored.FlightMode != null)
            {
                deviceState.FlightMode = (int)restored.FlightMode;
            }
            if (restored.Position != null)
            {
                deviceState.Latitude  = restored.Position.Value.Latitude;
                deviceState.Longitude = restored.Position.Value.Longitude;
                deviceState.Altitude  = restored.Position.Value.Altitude;
            }
            if (restored.Health != null)
            {
                deviceState.AccelerometerOK = restored.Health.Value.AccelerometerOK;
                deviceState.GyrometerOK     = restored.Health.Value.GyrometerOK;
                deviceState.MagnetometerOK  = restored.Health.Value.MagnetometerOK;
            }
            return(deviceState);
        }
コード例 #3
0
 public Drone(string model, DroneState state, double batteryRemaining)
 {
     this.id               = id;
     this.model            = model;
     this.state            = state;
     this.batteryRemaining = batteryRemaining;
 }
コード例 #4
0
        private void ReturnToStartPoint()
        {
            _state = DroneState.RETURN_TO_START_POINT_AFTER_HIT;
            _returnToStartPointRoutine = CoroutineManager.StartCoroutine(ReturnToStartPointRoutine(), this);

            _iesDebug.Add(_returnToStartPointRoutine);
        }
コード例 #5
0
        public void DroneHitEnemy()
        {
            _state           = DroneState.HIT_ENEMY;
            _hitEnemyRoutine = CoroutineManager.StartCoroutine(HitEnemyRoutine(), this);

            _iesDebug.Add(_hitEnemyRoutine);
        }
コード例 #6
0
        private IEnumerator EnemyDetectedRoutine()
        {
            _state = DroneState.ENEMY_DETECTED;

            yield return(null);

            CoroutineManager.StopCoroutine(_blinkLedRoutine);
            _ledSprite.alpha = 1;
            _ledSprite.SetColor(1, 0, 0);

            SoundManager.Instance.PlayFx(7);

            Console.WriteLine($"{this.name} EnemyDetectedRoutine | {Time.time}");

            if (_hasDroneBehaviourListener)
            {
                _droneBehaviorListener.OnEnemyDetected(this, _enemy);
            }

            yield return(new WaitForMilliSeconds(500));

            _ledSprite.alpha = 1;

            _iesDebug.Remove(_enemyDetectedRoutine);

            _chasingRoutine = CoroutineManager.StartCoroutine(ChasingRoutine(_enemy), this);
            _iesDebug.Add(_chasingRoutine);
        }
コード例 #7
0
    void UpdateDrone()
    {
        switch (_State)
        {
        case DroneState.DRONE_STATE_IDLE:
            break;

        case DroneState.DRONE_STATE_START_TAKINGOFF:
            _anim.SetBool("TakeOff", true);
            _State = DroneState.DRONE_STATE_TAKINGOFF;
            break;

        case DroneState.DRONE_STATE_TAKINGOFF:
            if (_anim.GetBool("TakeOff") == false)
            {
                _State = DroneState.DRONE_STATE_MOVING_UP;
            }
            break;

        case DroneState.DRONE_STATE_MOVING_UP:
            if (_anim.GetBool("MoveUp") == false)
            {
                _State = DroneState.DRONE_STATE_FLYING;
            }
            break;

        case DroneState.DRONE_STATE_FLYING:
            float angleZ = -30.0f * _Speed.x * 60.0f * Time.deltaTime;
            float angleX = 30.0f * _Speed.z * 60.0f * Time.deltaTime;

            Vector3 rotation = transform.localRotation.eulerAngles;
            transform.localPosition += _Speed * Time.deltaTime * _SpeedMultipler;
            transform.localRotation  = Quaternion.Euler(angleX, rotation.y, angleZ);
            break;

        case DroneState.DRONE_STATE_START_LANDING:
            _anim.SetBool("MoveDown", true);
            _State = DroneState.DRONE_STATE_LANDING;
            break;

        case DroneState.DRONE_STATE_LANDING:
            if (_anim.GetBool("MoveDown") == false)
            {
                _State = DroneState.DRONE_STATE_LANDED;
            }
            break;

        case DroneState.DRONE_STATE_LANDED:
            _anim.SetBool("Land", true);
            _State = DroneState.DRONE_STATE_WAIT_ENGINE_STOP;
            break;

        case DroneState.DRONE_STATE_WAIT_ENGINE_STOP:
            if (_anim.GetBool("Land") == false)
            {
                _State = DroneState.DRONE_STATE_IDLE;
            }
            break;
        }
    }
コード例 #8
0
        /// <summary>
        /// Parses the state of the Tello received as a sequence of bytes.
        /// After converting the bytes into ASCII characters it has to match the following pattern:
        /// “pitch:%d;roll:%d;yaw:%d;vgx:%d;vgy%d;vgz:%d;templ:%d;temph:%d;tof:%d;h:%d;bat:%d;baro:%.2f; time:%d;agx:%.2f;agy:%.2f;agz:%.2f;\r\n”.
        /// </summary>
        /// <param name="stateData">The Tello's state as a sequence of bytes.</param>
        /// <returns>Tello's parsed state information as <see cref="DroneState"/>.</returns>
        public DroneState Parse(byte[] stateData)
        {
            string[]   properties = stateData.AsString().Trim().Split(';');
            DroneState droneState = new DroneState();

            try
            {
                droneState.Pitch = int.Parse(properties[0].Substring(6));
                droneState.Roll  = int.Parse(properties[1].Substring(5));
                droneState.Yaw   = int.Parse(properties[2].Substring(4));

                // with Tello X and Y speed is only provided if VPN (visual positioning system) works
                droneState.SpeedX             = int.Parse(properties[3].Substring(4));
                droneState.SpeedY             = int.Parse(properties[4].Substring(4));
                droneState.SpeedZ             = int.Parse(properties[5].Substring(4));
                droneState.LowestTemperature  = int.Parse(properties[6].Substring(6));
                droneState.HighestTemperature = int.Parse(properties[7].Substring(6));
                droneState.ToF               = int.Parse(properties[8].Substring(4));
                droneState.Height            = int.Parse(properties[9].Substring(2));
                droneState.BatteryPercentage = int.Parse(properties[10].Substring(4));
                droneState.Barometer         = double.Parse(properties[11].Substring(5));
                droneState.Time              = int.Parse(properties[12].Substring(5));

                // with Tello X and Y acceleration is only provided if VPN (visual positioning system) works
                droneState.AccelerationX = double.Parse(properties[13].Substring(4));
                droneState.AccelerationY = double.Parse(properties[14].Substring(4));
                droneState.AccelerationZ = double.Parse(properties[15].Substring(4));
            }
            catch (Exception)
            {
            }

            return(droneState);
        }
コード例 #9
0
    // Update is called once per frame
    void UpdateDrone()
    {
        switch (state)
        {
        case DroneState.Drone_state_Idle:
            break;

        case DroneState.Drone_state_start_takingoff:
            anime.SetBool("TakeOff", true);
            state = DroneState.Drone_state_takingoff;
            break;

        case DroneState.Drone_state_takingoff:
            if (anime.GetBool("TakeOff") == false)
            {
                state = DroneState.Drone_state_movingup;
            }
            break;

        case DroneState.Drone_state_movingup:
            if (anime.GetBool("MoveUp") == false)
            {
                state = DroneState.Drone_state_flying;
            }
            break;

        case DroneState.Drone_state_flying:
            float   angleZ   = -30.0f * speed.x * 60.0f * Time.deltaTime;
            float   angleX   = -30.0f * speed.z * 60.0f * Time.deltaTime;
            Vector3 rotation = transform.localRotation.eulerAngles;
            transform.localPosition += speed * movementspeed * Time.deltaTime;
            transform.localRotation  = Quaternion.Euler(angleX, rotation.y, angleZ);
            break;

        case DroneState.Drone_state_start_landing:
            anime.SetBool("MoveDown", true);
            state = DroneState.Drone_state_landing;
            break;

        case DroneState.Drone_state_landing:
            if (anime.GetBool("MoveDown") == false)
            {
                state = DroneState.Drone_state_landed;
            }
            break;

        case DroneState.Drone_state_landed:
            anime.SetBool("Land", true);
            state = DroneState.Drone_state_wait_ending_stop;
            break;

        case DroneState.Drone_state_wait_ending_stop:
            if (anime.GetBool("Land") == false)
            {
                state = DroneState.Drone_state_Idle;
            }
            break;
        }
    }
コード例 #10
0
        private void OnHandle_SomethingChanged(object o, GattValueChangedEventArgs args)
        {
            var sender     = (GattCharacteristic)o;
            var senderData = sender.Uuid;
            var byteArray  = args.CharacteristicValue.ToArray();

            if (senderData == ParrotUuids.Characteristic_B0E_DroneState)
            {
                if ((byteArray[0] == 4) &&
                    (byteArray[2] == 2) &&
                    (byteArray[3] == 3) &&
                    (byteArray[4] == 1))
                {
                    switch (byteArray[6])
                    {
                    case 0:
                        State = DroneState.Landed;
                        break;

                    case 1:
                        State = DroneState.TakeingOff;
                        break;

                    case 2:
                        State = DroneState.Hovering;
                        break;

                    case 3:
                        State = DroneState.Flying;
                        break;

                    case 4:
                        State = DroneState.Landing;
                        break;

                    case 5:
                        State = DroneState.Emergency;
                        break;

                    case 6:
                        State = DroneState.Rolling;
                        break;
                    }
                }

                SomethingChanged?.Invoke(this, new CustomEventArgs("Drone State: " + State));
                return;
            }

            if (senderData == ParrotUuids.Characteristic_B0F_Battery)
            {
                SomethingChanged?.Invoke(this, new CustomEventArgs("Battery: " + BitConverter.ToString(byteArray)));
                return;
            }

            var StateString = BitConverter.ToString(byteArray);

            SomethingChanged?.Invoke(this, new CustomEventArgs(senderData + ": " + StateString));
        }
コード例 #11
0
 public DroneData(DroneState state, QuadMotorValues motorValues, SensorData sensor, float batteryVoltage, int wifiRssi)
 {
     this.State          = state;
     this.MotorValues    = motorValues;
     this.Sensor         = sensor;
     this.BatteryVoltage = batteryVoltage;
     this.WifiRssi       = wifiRssi;
 }
コード例 #12
0
ファイル: Drone.cs プロジェクト: darren-dev/DroneHub
        public void GoToClient()
        {
            _toPort       = false;
            _canMove      = true;
            _currentState = DroneState.toClient;

            NewTimer();
        }
コード例 #13
0
    /// <summary>
    /// Applies the yaw.
    /// </summary>
    /// <param name="inputYaw">yaw input</param>
    void ApplyYaw(HandlingInput input, DroneState currentState)
    {
        float targetVelocity = maxYawSpeed * input.yaw;
        float velocityOffset = targetVelocity - currentState.angularVelocityLocal.y;
        float acceleration   = MathHelper.Aserp(velocityOffset, yawAccelerationMultiplier, maxYawTorque);

        GetComponent <Rigidbody> ().AddRelativeTorque(0, acceleration, 0);
    }
コード例 #14
0
    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        string s = hit.transform.name;

        audio.PlayOneShot(hitSound);
        state = DroneState.Stop;
        MoveToLastCheckPoint();
    }
コード例 #15
0
 public DroneData(DroneState state, QuadMotorValues motorValues, GyroData gyro, float batteryVoltage, int wifiRssi)
 {
     this.State          = state;
     this.MotorValues    = motorValues;
     this.Gyro           = gyro;
     this.BatteryVoltage = batteryVoltage;
     this.WifiRssi       = wifiRssi;
 }
コード例 #16
0
        private void Update()
        {
            if (!isServer)
            {
                return;
            }
            //Think about what to do
            //state transitions? actions

            GameObject target = FindUnit(stats.GiveUpDistanceThreshold, u => u.GetComponent <Unit>().Side != this.Side);

            float distToClosest = float.PositiveInfinity;

            if (target != null)
            {
                distToClosest = Vector2.Distance(this.transform.position, target.transform.position);
            }

            switch (state)
            {
            case DroneState.Wander:
                if (distToClosest <= stats.ChaseThreshold)
                {
                    state = DroneState.Chase;
                }
                else
                {
                    wanderTimer += Time.deltaTime;
                    if (wanderTimer > stats.WanderTime)
                    {
                        wanderTimer = 0;
                        var newDirection = UnityEngine.Random.insideUnitCircle;
                        xMove = newDirection.x;
                        yMove = newDirection.y;
                    }
                }
                break;

            case DroneState.Chase:
                if (distToClosest >= stats.GiveUpDistanceThreshold)
                {
                    state = DroneState.Wander;
                    break;
                }
                var dirToPlayer = (target.transform.position - this.transform.position).normalized;
                xMove = dirToPlayer.x;
                yMove = dirToPlayer.y;


                break;
            }


            //actually move
            xMove = Mathf.Clamp(xMove, -1, 1);
            yMove = Mathf.Clamp(yMove, -1, 1);
            rb.AddForce(new Vector2(xMove, yMove) * stats.Speed * Time.deltaTime, ForceMode2D.Force);
        }
コード例 #17
0
ファイル: AI.cs プロジェクト: AidenGzr76/BattleOfTank
 public void checkEscape()
 {
     if (AIHealth.isEscape && AIHealth.escapeEnemyName == this.transform.name)
     {
         PlayerFind.playerFinded = false;
         _currentState           = DroneState.Escape;
         //_currentState = DroneState.Saerch;
     }
 }
コード例 #18
0
ファイル: Drone.cs プロジェクト: darren-dev/DroneHub
        public void GoToPort()
        {
            _toPort = true;
            GetPathToPort();
            _canMove      = true;
            _currentState = DroneState.toWarehouse;

            NewTimer();
        }
コード例 #19
0
ファイル: Drone.cs プロジェクト: darren-dev/DroneHub
        /// <summary>
        /// Creates a new Drone - Implements a new event dispatcher
        /// </summary>
        public Drone(string name)
        {
            _hasOrder       = false;
            _name           = name;
            _currentState   = DroneState.off;
            _gridPositionId = 0;

            NewTimer();
        }
コード例 #20
0
        public override void updateme(GameTime gt)
        {
            base.updateme(gt);

            if (m_rect.Right < 0)
            {
                m_state = DroneState.dead;
            }
        }
コード例 #21
0
    void GetBreakTilt(out float targetRoll,
                      out float targetPitch,
                      DroneState currentState)
    {
        Vector3 rotatedVelocityWorld = Quaternion.AngleAxis(-currentState.rotation.y, Vector3.up) * currentState.velocityWorld;

        targetRoll  = MathHelper.Aserp(rotatedVelocityWorld.x, breakTiltMultiplier, maxBreakTiltAngle);
        targetPitch = MathHelper.Aserp(-rotatedVelocityWorld.z, breakTiltMultiplier, maxBreakTiltAngle);
    }
コード例 #22
0
        private void Update()
        {
            switch (_currentState)
            {
            case DroneState.Wander:
                if (NeddsDestination())
                {
                    GetDestination();
                }
                transform.rotation = _desiredRotation;
                transform.Translate(Vector3.forward * Time.deltaTime * 5f);

                var rayColor = IsPathBlocked() ? Color.red : Color.green;
                Debug.DrawRay(transform.position, _direction * _rayDistance, rayColor);

                while (IsPathBlocked())
                {
                    Debug.Log("Path Blocked");
                    GetDestination();
                }

                var targetToAggro = CheckForAggro();

                if (targetToAggro != null)
                {
                    _target       = targetToAggro.GetComponent <Drone>();
                    _currentState = DroneState.Chase;
                }
                break;

            case DroneState.Chase:
                if (_target == null)
                {
                    _currentState = DroneState.Wander;
                    return;
                }

                transform.LookAt(_target.transform);
                transform.Translate(Vector3.forward * Time.deltaTime * 5f);

                if (Vector3.Distance(transform.position, _target.transform.position) < _attackRange)
                {
                    _currentState = DroneState.Attack;
                }
                break;

            case DroneState.Attack:
                if (_target == null)
                {
                    Destroy(_target.gameObject);
                }

                _currentState = DroneState.Wander;
                break;
            }
        }
コード例 #23
0
        private IEnumerator HitEnemyRoutine()
        {
            _state = DroneState.HIT_ENEMY;

            yield return(new WaitForMilliSeconds(500));

            ReturnToStartPoint();

            _iesDebug.Remove(_hitEnemyRoutine);
        }
コード例 #24
0
        public void EndLevel()
        {
            _state = DroneState.END_LEVEL;

            DroneBehaviorListener = null;

            CoroutineManager.StopAllCoroutines(this);

            CoroutineManager.StartCoroutine(GoToPoint(_startPosition), this);
        }
コード例 #25
0
ファイル: Drone.cs プロジェクト: danm-de/DrunkenOctoNinja
 public async Task Initialize()
 {
     State = DroneState.Landed;
     motorCommandsCounter = 1;
     simpleCommandsCounter = 1;
     emergencyCommandsCounter = 1;
     Network = new NetworkAl();
     await Network.Initialize();
     Network.SomethingChanged += OnHandle_SomethingChanged;
 }
コード例 #26
0
    // Update is called once per frame
    void FixedUpdate()
    {
        HandlingInput input        = GetInput();
        DroneState    currentState = GetCurrentState();

        // apply forces
        ApplyTilt(input, currentState);
        ApplyYaw(input, currentState);
        ApplyThrust(input, currentState);
    }
コード例 #27
0
 public Drone(Texture2D txr, Rectangle rect, int fps, GameTime gt, int screenHeight, int screenWidth) : base(txr, fps, rect)
 {
     m_scale       = (float)Game1.RNG.NextDouble() + 0.5f;
     m_rect.Width  = (int)(27 * m_scale);
     m_rect.Height = (int)(13 * m_scale);
     m_position.X  = screenWidth;
     m_position.Y  = Game1.RNG.Next(0, screenHeight - rect.Height);
     m_velocity.X  = -(Game1.RNG.Next(50, 200) * (float)gt.ElapsedGameTime.TotalSeconds);
     m_state       = DroneState.live;
     m_tint        = new Color(1.0f, 1.0f, (float)Game1.RNG.NextDouble());
 }
コード例 #28
0
        public async Task Initialize()
        {
            State = DroneState.Landed;
            motorCommandsCounter     = 1;
            simpleCommandsCounter    = 1;
            emergencyCommandsCounter = 1;
            Network = new NetworkAl();
            await Network.Initialize();

            Network.SomethingChanged += OnHandle_SomethingChanged;
        }
コード例 #29
0
 private void _DroneUpdateService_StatusUpdateReceivedFromDrone(DroneState newState)
 {
     DispatchService.Invoke(() =>
     {
         if (_DroneStateHistory != null)
         {
             _DroneStateHistory.Add(new DroneStateViewModel(newState));
         }
     });
     // todo: add to list, thread safe
 }
コード例 #30
0
    private void Update()
    {
        switch (_currentState)
        {
        case DroneState.Wander:
        {
            var rayColor = IsPathBlocked() ? Color.red : Color.green;
            Debug.DrawRay(transform.position, _direction * _rayDistance, rayColor);

            while (IsPathBlocked())
            {
                Debug.Log("Path Blocked");
            }

            var targetToAggro = CheckForAggro();
            if (targetToAggro != null)
            {
                _target       = targetToAggro.GetComponent <Drone>();
                _currentState = DroneState.Chase;
            }

            break;
        }

        case DroneState.Chase:
        {
            if (_target == null)
            {
                _currentState = DroneState.Wander;
                return;
            }


            if (Vector3.Distance(transform.position, _target.transform.position) < _attackRange)
            {
                _currentState = DroneState.Attack;
            }
            break;
        }

        case DroneState.Attack:
        {
            if (_target != null)
            {
                Destroy(_target.gameObject);
            }

            // play laser beam

            _currentState = DroneState.Wander;
            break;
        }
        }
    }
コード例 #31
0
 public static string getMessageTextFromState(DroneState state)
 {
     return(formatStringForMessage(
                state.getPitch(), state.getRoll(), state.getYaw(),
                state.getSpeedX(), state.getSpeedY(), state.getSpeedZ(),
                state.getLowTemperature(), state.getHighTemperature(),
                state.getFlightDistance(), state.getHeight(),
                state.getBatteryPercentage(), state.getBarometerMeasurement(),
                state.getMotorTime(), state.getAccelerationX(),
                state.getAccelerationY(), state.getAccelerationZ()
                ));
 }
コード例 #32
0
ファイル: MainController.cs プロジェクト: Pgde/EBot-master
 public void backupstates()
 {
     backuptravel = _States.TravelerState;
         backupmining = _States.MiningState;
         backupdrone = _States.DroneState;
         backupfitting = _States.fittingstate;
         backuplogin = _States.LoginState;
         backupskill = _States.SkillState;
         backuptut = _States.tutstates;
 }
コード例 #33
0
ファイル: Drones.cs プロジェクト: rixim/Questor
        public void ProcessState()
        {
            if (!Settings.Instance.UseDrones)
                return;

            switch (State)
            {
                case DroneState.WaitingForTargets:
                    // Are we in the right state ?
                    if (Cache.Instance.ActiveDrones.Count() > 0)
                    {
                        // Apparently not, we have drones out, go into fight mode
                        State = DroneState.Fighting;
                        break;
                    }

                    // Should we launch drones?
                    var launch = true;
                    // Always launch if we're scrambled
                    if (!Cache.Instance.PriorityTargets.Any(pt => pt.IsWarpScramblingMe))
                    {
                        // Are we done with this mission pocket?
                        launch &= !Cache.Instance.IsMissionPocketDone;

                        // If above minimums
                        launch &= Cache.Instance.DirectEve.ActiveShip.ShieldPercentage >= Settings.Instance.DroneMinimumShieldPct;
                        launch &= Cache.Instance.DirectEve.ActiveShip.ArmorPercentage >= Settings.Instance.DroneMinimumArmorPct;
                        launch &= Cache.Instance.DirectEve.ActiveShip.CapacitorPercentage >= Settings.Instance.DroneMinimumCapacitorPct;

                        // yes if there are targets to kill
                        launch &= Cache.Instance.TargetedBy.Count(e => !e.IsSentry && e.CategoryId == (int)CategoryID.Entity && e.IsNpc && !e.IsContainer && e.GroupId != (int)Group.LargeCollidableStructure && e.Distance < Settings.Instance.DroneControlRange) > 0;

                        // If drones get agro'd within 30 seconds, then wait (5 * _recallCount + 5) seconds since the last recall
                        if (_lastLaunch < _lastRecall && _lastRecall.Subtract(_lastLaunch).TotalSeconds < 30)
                        {
                            if (_lastRecall.AddSeconds(5 * _recallCount + 5) < DateTime.Now)
                            {
                                // Increase recall count and allow the launch
                                _recallCount++;

                                // Never let _recallCount go above 5
                                if (_recallCount > 5)
                                    _recallCount = 5;
                            }
                            else
                            {
                                // Do not launch the drones until the delay has passed
                                launch = false;
                            }
                        }
                        else // Drones have been out for more then 30s
                            _recallCount = 0;
                    }

                    if (launch)
                    {
                        // Reset launch tries
                        _launchTries = 0;
                        _lastLaunch = DateTime.Now;
                        State = DroneState.Launch;
                    }
                    break;

                case DroneState.Launch:
                    // Launch all drones
                    _launchTimeout = DateTime.Now;
                    Cache.Instance.DirectEve.ActiveShip.LaunchAllDrones();
                    State = DroneState.Launching;
                    break;

                case DroneState.Launching:
                    // We haven't launched anything yet, keep waiting
                    if (Cache.Instance.ActiveDrones.Count() == 0)
                    {
                        if (DateTime.Now.Subtract(_launchTimeout).TotalSeconds > 10)
                        {
                            // Relaunch if tries < 10
                            if (_launchTries < 10)
                            {
                                _launchTries++;
                                State = DroneState.Launch;
                                break;
                            }
                            else
                                State = DroneState.OutOfDrones;
                        }
                        break;
                    }

                    // Are we done launching?
                    if (_lastDroneCount == Cache.Instance.ActiveDrones.Count())
                        State = DroneState.Fighting;
                    break;

                case DroneState.Fighting:
                    // Should we recall our drones? This is a possible list of reasons why we should
                    var recall = false;

                    // Are we done (for now) ?
                    if (Cache.Instance.TargetedBy.Count(e => !e.IsSentry && e.IsNpc && e.Distance < Settings.Instance.DroneControlRange) == 0)
                    {
                        Logging.Log("Drones: Recalling drones because no NPC is targeting us within dronerange");
                        recall = true;
                    }

                    if (Cache.Instance.IsMissionPocketDone)
                    {
                        Logging.Log("Drones: Recalling drones because we are done with this pocket.");
                        recall = true;
                    }
                    else if (_shieldPctTotal > GetShieldPctTotal())
                    {
                        Logging.Log("Drones: Recalling drones because we have lost shields! [Old: " + _shieldPctTotal.ToString("N2") + "][New: " + GetShieldPctTotal().ToString("N2") + "]");
                        recall = true;
                    }
                    else if (_armorPctTotal > GetArmorPctTotal())
                    {
                        Logging.Log("Drones: Recalling drones because we have lost armor! [Old:" + _armorPctTotal.ToString("N2") + "][New: " + GetArmorPctTotal().ToString("N2") + "]");
                        recall = true;
                    }
                    else if (_structurePctTotal > GetStructurePctTotal())
                    {
                        Logging.Log("Drones: Recalling drones because we have lost structure! [Old:" + _structurePctTotal.ToString("N2") + "][New: " + GetStructurePctTotal().ToString("N2") + "]");
                        recall = true;
                    }
                    else if (Cache.Instance.ActiveDrones.Count() < _lastDroneCount)
                    {
                        // Did we lose a drone? (this should be covered by total's as well though)
                        Logging.Log("Drones: Recalling drones because we have lost a drone! [Old:" + _lastDroneCount + "][New: " + Cache.Instance.ActiveDrones.Count() + "]");
                        recall = true;
                    }
                    else
                    {
                        // Default to long range recall
                        var lowShieldWarning = Settings.Instance.LongRangeDroneRecallShieldPct;
                        var lowArmorWarning = Settings.Instance.LongRangeDroneRecallArmorPct;
                        var lowCapWarning = Settings.Instance.LongRangeDroneRecallCapacitorPct;

                        if (Cache.Instance.ActiveDrones.Average(d => d.Distance) < (Settings.Instance.DroneControlRange/2d))
                        {
                            lowShieldWarning = Settings.Instance.DroneRecallShieldPct;
                            lowArmorWarning = Settings.Instance.DroneRecallArmorPct;
                            lowCapWarning = Settings.Instance.DroneRecallCapacitorPct;
                        }

                        if (Cache.Instance.DirectEve.ActiveShip.ShieldPercentage < lowShieldWarning)
                        {
                            Logging.Log("Drones: Recalling drones due to shield [" + Cache.Instance.DirectEve.ActiveShip.ShieldPercentage + "%] below [" + lowShieldWarning + "%] minimum");
                            recall = true;
                        }
                        else if (Cache.Instance.DirectEve.ActiveShip.ArmorPercentage < lowArmorWarning)
                        {
                            Logging.Log("Drones: Recalling drones due to armor [" + Cache.Instance.DirectEve.ActiveShip.ArmorPercentage + "%] below [" + lowArmorWarning + "%] minimum");
                            recall = true;
                        }
                        else if (Cache.Instance.DirectEve.ActiveShip.CapacitorPercentage < lowCapWarning)
                        {
                            Logging.Log("Drones: Recalling drones due to capacitor [" + Cache.Instance.DirectEve.ActiveShip.CapacitorPercentage + "%] below [" + lowCapWarning + "%] minimum");
                            recall = true;
                        }
                    }

                    if (Cache.Instance.ActiveDrones.Count() == 0)
                    {
                        Logging.Log("Drones: Apparently we have lost all our drones");
                        recall = true;
                    }
                    else
                    {
                        var isPanicking = false;
                        isPanicking |= Cache.Instance.DirectEve.ActiveShip.ShieldPercentage < Settings.Instance.MinimumShieldPct;
                        isPanicking |= Cache.Instance.DirectEve.ActiveShip.ArmorPercentage < Settings.Instance.MinimumArmorPct;
                        isPanicking |= Cache.Instance.DirectEve.ActiveShip.CapacitorPercentage < Settings.Instance.MinimumCapacitorPct;
                        if (Cache.Instance.PriorityTargets.Any(pt => pt.IsWarpScramblingMe) && recall)
                        {
                            Logging.Log("Drones: Overriding drone recall, we are scrambled!");
                            recall = false;
                        }
                    }

                    // Recall or engage
                    if (recall)
                        State = DroneState.Recalling;
                    else
                    {
                        EngageTarget();

                        // We lost a drone and did not recall, assume panicking and launch (if any) additional drones
                        if (Cache.Instance.ActiveDrones.Count() < _lastDroneCount)
                            State = DroneState.Launch;
                    }
                    break;

                case DroneState.Recalling:
                    // Are we done?
                    if (Cache.Instance.ActiveDrones.Count() == 0)
                    {
                        _lastRecall = DateTime.Now;
                        State = DroneState.WaitingForTargets;
                        break;
                    }

                    // Give recall command every 5 seconds
                    if (DateTime.Now.Subtract(_lastRecallCommand).TotalSeconds > 5)
                    {
                        Cache.Instance.DirectEve.ExecuteCommand(DirectCmd.CmdDronesReturnToBay);
                        _lastRecallCommand = DateTime.Now;
                    }
                    break;
            }

            // Update health values
            _shieldPctTotal = GetShieldPctTotal();
            _armorPctTotal = GetArmorPctTotal();
            _structurePctTotal = GetStructurePctTotal();
            _lastDroneCount = Cache.Instance.ActiveDrones.Count();
        }
コード例 #34
0
ファイル: Drone.cs プロジェクト: danm-de/DrunkenOctoNinja
        private void OnHandle_SomethingChanged(object o, GattValueChangedEventArgs args)
        {
            var sender = (GattCharacteristic) o;
            var senderData = sender.Uuid;
            var byteArray = args.CharacteristicValue.ToArray();

            if (senderData == ParrotUuids.Characteristic_B0E_DroneState)
            {
                if ((byteArray[0] == 4)
                    && (byteArray[2] == 2)
                    && (byteArray[3] == 3)
                    && (byteArray[4] == 1))
                {
                    switch (byteArray[6])
                    {
                        case 0:
                            State = DroneState.Landed;
                            break;
                        case 1:
                            State = DroneState.TakeingOff;
                            break;
                        case 2:
                            State = DroneState.Hovering;
                            break;
                        case 3:
                            State = DroneState.Flying;
                            break;
                        case 4:
                            State = DroneState.Landing;
                            break;
                        case 5:
                            State = DroneState.Emergency;
                            break;
                        case 6:
                            State = DroneState.Rolling;
                            break;
                    }

                }

                SomethingChanged?.Invoke(this, new CustomEventArgs("Drone State: " + State));
                return;
            }

            if (senderData == ParrotUuids.Characteristic_B0F_Battery)
            {
                SomethingChanged?.Invoke(this, new CustomEventArgs("Battery: " + BitConverter.ToString(byteArray)));
                return;
            }

            var StateString = BitConverter.ToString(byteArray);
            SomethingChanged?.Invoke(this, new CustomEventArgs(senderData + ": " + StateString));


        }
コード例 #35
0
ファイル: MotorControl.cs プロジェクト: Hendrik410/KKS_Drone
 private void UpdateEnabled(DroneState state)
 {
     UpdateEnabled(state == DroneState.Armed, state != DroneState.Flying);
 }