/// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (LocationRetrieveTimer != null)
            {
                // Destroy the timer
                LocationRetrieveTimer.Dispose();
                LocationRetrieveTimer = null;
            }

            if (LocationManager != null)
            {
                // Stop listen to location changes
                LocationManager.StopUpdatingLocation();
                LocationManager.LocationsUpdated -= LocationManager_LocationsUpdated;

                // Remove the reference
                LocationManager = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }
 private void Start()
 {
     _playerGO          = GameObject.FindGameObjectWithTag("Player");
     _playerController  = _playerGO.GetComponent <PlayerController>();
     _charLocomotion    = _playerGO.GetComponent <CharacterLocomotion>();
     _aiHealth          = GetComponent <Health>();
     _lastKnownLocation = FindObjectOfType <LastKnownLocation>();
 }
 public void Initialize(AIAgent agent)
 {
     _aiWeapon          = agent.GetComponent <AIWeapons>();
     _navAgent          = agent.GetComponent <NavMeshAgent>();
     _aiHealth          = agent.GetComponent <AIHealth>();
     _fov               = agent.GetComponent <FieldOfView>();
     _lastKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>();
     _agent             = agent;
 }
Ejemplo n.º 4
0
        public override VoyageState DepartFrom(ILocation location)
        {
            if (LastKnownLocation.Equals(location.UnLocode))
            {
                return(new MovingVoyage(Number, Schedule, _movementIndex));
            }
            string message = string.Format("The voyage stopped over at {0}.", LastKnownLocation);

            throw new ArgumentException(message, "location");
        }
Ejemplo n.º 5
0
        public override VoyageState StopOverAt(ILocation location)
        {
            if (LastKnownLocation.Equals(location.UnLocode))
            {
                return(this);
            }
            string message = string.Format("The voyage stopped over at {0}.", LastKnownLocation);

            throw new ArgumentException(message, "location");
        }
Ejemplo n.º 6
0
        public override VoyageState DepartFrom(ILocation location)
        {
            if (LastKnownLocation.Equals(location.UnLocode))
            {
                return(this);
            }
            string message = string.Format("The voyage departed from {0}.", LastKnownLocation);

            throw new ArgumentException(message, "location");
        }
Ejemplo n.º 7
0
    public AISearchForPlayerState(AIAgent agent)
    {
        _agent = agent;
        _playersKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>();

        if (_playersKnownLocation == null)
        {
            Debug.LogError("Last Player Location prefab not placed in scene.");
        }

        _navAgent = agent.GetComponent <NavMeshAgent>();

        _fov = agent.GetComponent <FieldOfView>();
    }
    public void Enter()
    {
        _arrivedAtPoint = false;

        if (_lastKnownLocation == null)
        {
            _lastKnownLocation = GameObject.FindObjectOfType <LastKnownLocation>();

            if (_lastKnownLocation == null)
            {
                Debug.LogError("Last Player Location prefab not placed in scene.");
            }
        }

        //Generates a point near the last known location of the player for the AI to stand
        _navAgent.SetDestination(_lastKnownLocation.GeneratePointInRange(7.5f));
    }
Ejemplo n.º 9
0
        /// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (LocationRetrieveTimer != null)
            {
                // Destroy the timer
                LocationRetrieveTimer.Dispose();
                LocationRetrieveTimer = null;
            }

            if (FusedLocationClient != null)
            {
                // Stop listen to location changes
                if (FusedLocationCallback != null)
                {
                    FusedLocationCallback.LocationResult -= FusedLocationCallback_LocationResult;
                    FusedLocationClient.RemoveLocationUpdates(FusedLocationCallback);
                    FusedLocationCallback = null;
                }
                FusedLocationClient.Dispose();
                FusedLocationClient = null;
            }

            if (LocationManager != null)
            {
                // Stop listen to location changes
                LocationManager.RemoveUpdates(this);
                LocationManager.Dispose();
                LocationManager = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (WindowsGeolocator != null)
            {
                WindowsGeolocator.PositionChanged -= WindowsGeolocator_PositionChanged;
                WindowsGeolocator = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }
Ejemplo n.º 11
0
 public bool Equals(IDelivery other)
 {
     if (null == other)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, other))
     {
         return(true);
     }
     if (null != CurrentVoyage && !CurrentVoyage.Equals(other.CurrentVoyage))
     {
         return(false);
     }
     if (null == CurrentVoyage && null != other.CurrentVoyage)
     {
         return(false);
     }
     if (null != LastKnownLocation && !LastKnownLocation.Equals(other.LastKnownLocation))
     {
         return(false);
     }
     if (null == LastKnownLocation && null != other.LastKnownLocation)
     {
         return(false);
     }
     if (TransportStatus != other.TransportStatus)
     {
         return(false);
     }
     if (_routingStatus != other.RoutingStatus)
     {
         return(false);
     }
     if (IsUnloadedAtDestination != other.IsUnloadedAtDestination)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 12
0
    private void Awake()
    {
        _aiHealth          = GetComponent <Health>();
        _audioSource       = GetComponent <AudioSource>();
        _owningZone        = GetComponentInParent <CombatZone>();
        _defaultMoveSpeed  = GetComponent <NavMeshAgent>().speed;
        _lastKnownLocation = FindObjectOfType <LastKnownLocation>();

        //Error Logging
        if (!_aiHealth)
        {
            Debug.LogError(gameObject.name + " has no derivative of Health Component attached to it");
        }
        if (!_audioSource)
        {
            Debug.LogError(gameObject.name + " has no AudioSource component attached to it");
        }
        if (!_owningZone)
        {
            Debug.LogError(gameObject.name + " has no CombatZone component in parent GameObject");
        }
    }
Ejemplo n.º 13
0
 public sealed override int GetHashCode()
 {
     return(this.GetType().GetHashCode() ^ LastKnownLocation.GetHashCode());
 }
 /// <summary>
 /// Check if the retrieve last known location is still consider fresh and but ignore the accurate.
 /// </summary>
 private bool IsLastKnownLocationFresh()
 {
     return(LastKnownLocation != null &&
            LastKnownLocation.IsFresh(TargetFreshness));
 }
 /// <summary>
 /// Check if the retrieve last known location is still consider fresh and accurate.
 /// </summary>
 private bool IsLastKnownLocationFreshAndAccurate()
 {
     return(LastKnownLocation != null &&
            LastKnownLocation.IsFresh(TargetFreshness) &&
            LastKnownLocation.IsAccurate(TargetAccuracy));
 }