Exemplo n.º 1
0
        public static List <WowPoint> ShortenRouteFromLocation(WowPoint location, List <WowPoint> pointsList)
        {
            var result = new List <WowPoint>();

            var closestDistance = pointsList.Select(p => (point: p, distance: DistanceTo(location, p)))
                                  .OrderBy(s => s.distance);

            var closestPoint = closestDistance.First();

            var startPoint = 0;

            for (int i = 0; i < pointsList.Count; i++)
            {
                if (pointsList[i] == closestPoint.point)
                {
                    startPoint = i;
                    break;
                }
            }

            for (int i = startPoint; i < pointsList.Count; i++)
            {
                result.Add(pointsList[i]);
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <List <WowPoint> > FindRoute(int map, WowPoint fromPoint, WowPoint toPoint)
        {
            try
            {
                //logger.LogInformation($"Finding route to {toPoint}");
                var url = $"{api}MapRoute?map1={map}&x1={fromPoint.X}&y1={fromPoint.Y}&map2={map}&x2={toPoint.X}&y2={toPoint.Y}";
                var sw  = new Stopwatch();
                sw.Start();

                using (var handler = new HttpClientHandler())
                {
                    using (var client = new HttpClient(handler))
                    {
                        var responseString = await client.GetStringAsync(url);

                        logger.LogInformation($"Finding route from {fromPoint} map {map} to {toPoint} took {sw.ElapsedMilliseconds} ms.");
                        var path   = JsonConvert.DeserializeObject <IEnumerable <WorldMapAreaSpot> >(responseString);
                        var result = path.Select(l => new WowPoint(l.X, l.Y)).ToList();
                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Finding route from {fromPoint} to {toPoint}");
                Console.WriteLine(ex);
                return(new List <WowPoint>());
            }
        }
Exemplo n.º 3
0
        public static double CalculateHeading(WowPoint from, WowPoint to)
        {
            //logger.LogInformation($"from: ({from.X},{from.Y}) to: ({to.X},{to.Y})");

            var target = Math.Atan2(to.X - from.X, to.Y - from.Y);

            return(Math.PI + target);
        }
Exemplo n.º 4
0
        public static double DistanceTo(WowPoint l1, WowPoint l2)
        {
            var x = l1.X - l2.X;
            var y = l1.Y - l2.Y;

            x = x * 100;
            y = y * 100;
            var distance = Math.Sqrt((x * x) + (y * y));

            //logger.LogInformation($"distance:{x} {y} {distance.ToString()}");
            return(distance);
        }
Exemplo n.º 5
0
        internal bool IsMoving()
        {
            var currentDistanceToTarget = WowPoint.DistanceTo(this.playerReader.PlayerLocation, targetLocation);

            if (Math.Abs(currentDistanceToTarget - previousDistanceToTarget) > 1)
            {
                ResetStuckParameters();
                previousDistanceToTarget = currentDistanceToTarget;
                return(true);
            }

            if ((DateTime.Now - timeOfLastSignificantMovement).TotalSeconds > 3)
            {
                logger.LogInformation("We seem to be stuck!");
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public async Task SetDirection(double desiredDirection, WowPoint point, string source)
        {
            var location = new WowPoint(playerReader.XCoord, playerReader.YCoord);
            var distance = WowPoint.DistanceTo(location, point);

            logger.LogInformation("===============");
            logger.LogInformation($"SetDirection:- {source} Desired: {desiredDirection.ToString("0.000")}, Current: {playerReader.Direction.ToString("0.000")}, distance: {distance.ToString("0.000")}");

            if (distance < 40)
            {
                logger.LogInformation("Too close, ignoring direction change.");
                return;
            }

            var key = GetDirectionKeyToPress(desiredDirection);

            TurnUsingTimedPress(desiredDirection, key);

            //await TurnAndReadActualDirection(desiredDirection, key);
            await Task.Delay(1);

            LastSetDirection = DateTime.Now;
        }
Exemplo n.º 7
0
        public string DeathImage(WowPoint pt)
        {
            var size = this.canvasSize / 25;

            return(pt == null ? string.Empty : $"<image href = 'death.svg' x = '{ToCanvasPointX(pt.X) - size / 2}' y = '{ToCanvasPointY(pt.Y) - size / 2}' height='{size}' width='{size}' />");
        }
Exemplo n.º 8
0
 public void SetTargetLocation(WowPoint targetLocation)
 {
     this.targetLocation = targetLocation;
     ResetStuckParameters();
 }
Exemplo n.º 9
0
 public Task <List <WowPoint> > FindRouteTo(PlayerReader playerReader, WowPoint destination)
 {
     return(FindRoute(playerReader.ZoneId, playerReader.PlayerLocation, destination));
 }
Exemplo n.º 10
0
 public async Task SetDirection(double desiredDirection, WowPoint point, string source)
 {
     await SetDirection(desiredDirection, point, source, 40);
 }