Example #1
0
        public override double CalculateDistance(double sourceLat, double sourceLng, double destinationLat, double destinationLng, ISession session = null)
        {
            if (session != null)
            {
                GetYoursInstance(session);
            }

            if (_yoursDirectionsService != null)
            {
                var yoursResult = _yoursDirectionsService.GetDirections(new GeoCoordinate(sourceLat, sourceLng), new GeoCoordinate(destinationLat, destinationLng));
                if (string.IsNullOrEmpty(yoursResult) || yoursResult.StartsWith("<?xml version=\"1.0\"") || yoursResult.Contains("error"))
                {
                    return(1.5 * base.CalculateDistance(sourceLat, sourceLng, destinationLat, destinationLng));
                }
                else
                {
                    var yoursWalk = YoursWalk.Get(yoursResult);
                    return(yoursWalk.Distance);
                }
            }
            else
            {
                return(1.5 * base.CalculateDistance(sourceLat, sourceLng, destinationLat, destinationLng));
            }
        }
Example #2
0
        public override async Task <PlayerUpdateResponse> Walk(GeoCoordinate targetLocation, Func <Task <bool> > functionExecutedWhileWalking, ISession session, CancellationToken cancellationToken, double walkSpeed = 0.0)
        {
            GetYoursInstance(session);
            var sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude);
            var yoursResult    = _yoursDirectionsService.GetDirections(sourceLocation, targetLocation);

            if (string.IsNullOrEmpty(yoursResult) || yoursResult.StartsWith("<?xml version=\"1.0\"") || yoursResult.Contains("error"))
            {
                return(await RedirectToNextFallbackStrategy(session.LogicSettings, targetLocation, functionExecutedWhileWalking, session, cancellationToken));
            }

            var yoursWalk = YoursWalk.Get(yoursResult);

            session.EventDispatcher.Send(new FortTargetEvent {
                Name = FortInfo.Name, Distance = yoursWalk.Distance, Route = "YoursWalk"
            });
            List <GeoCoordinate> points = yoursWalk.Waypoints;

            return(await DoWalk(points, session, functionExecutedWhileWalking, sourceLocation, targetLocation, cancellationToken));
        }
        public YoursWalk GetDirections(GeoCoordinate sourceLocation, GeoCoordinate destLocation)
        {
            WebRequest request = WebRequest.Create(GetUrl(sourceLocation, destLocation));

            request.Credentials = CredentialCache.DefaultCredentials;

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (Stream dataStream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(dataStream))
                        {
                            string responseFromServer = reader.ReadToEnd();
                            return(YoursWalk.Get(responseFromServer));
                        }
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }