Пример #1
0
        public async Task Reset()
        {
            logger.LogInformation("Sleeping 2 seconds");
            await Task.Delay(2000);

            while (new List <double> {
                playerReader.XCoord, playerReader.YCoord, corpseLocation.X, corpseLocation.Y
            }.Max() > 100)
            {
                logger.LogInformation($"Waiting... odd coords read. Player {playerReader.XCoord},{playerReader.YCoord} corpse { corpseLocation.X}{corpseLocation.Y}");
                await Task.Delay(5000);
            }

            var closestRouteAndSpiritPathPoints = routePoints.SelectMany(s => spiritWalkerPath.Select(swp => (pathPoint: s, spiritPathPoint: swp, distance: DistanceTo(s, swp))))
                                                  .OrderBy(s => s.distance)
                                                  .First();

            // spirit walker path leg
            var spiritWalkerLeg = new List <WowPoint>();

            for (int i = 0; i < spiritWalkerPath.Count; i++)
            {
                spiritWalkerLeg.Add(spiritWalkerPath[i]);
                if (spiritWalkerPath[i] == closestRouteAndSpiritPathPoints.spiritPathPoint)
                {
                    break;
                }
            }

            var closestRoutePointToCorpse = routePoints.Select(s => (pathPoint: s, distance: DistanceTo(s, corpseLocation)))
                                            .OrderBy(s => s.distance)
                                            .First()
                                            .pathPoint;

            //from closestRouteAndSpiritPathPoints to closestRoutePointToCorpse
            var pathStartPoint = closestRouteAndSpiritPathPoints.pathPoint;

            // see if we can walk forward through the points
            var legFromSpiritEndToCorpse = FillPathToCorpse(closestRoutePointToCorpse, pathStartPoint, routePoints);

            if (legFromSpiritEndToCorpse.Count == 0)
            {
                var reversePath = routePoints.Select(s => s).ToList();
                reversePath.Reverse();
                legFromSpiritEndToCorpse = FillPathToCorpse(closestRoutePointToCorpse, pathStartPoint, reversePath);
            }

            var routeToCorpse = spiritWalkerLeg.Select(s => s).ToList();

            routeToCorpse.AddRange(legFromSpiritEndToCorpse);

            var myLocation     = new WowPoint(playerReader.XCoord, playerReader.YCoord);
            var truncatedRoute = WowPoint.ShortenRouteFromLocation(myLocation, routeToCorpse);

            for (int i = truncatedRoute.Count - 1; i > -1; i--)
            {
                points.Push(truncatedRoute[i]);
            }

            var cp = new CorpsePath {
                MyLocation = myLocation, CorpseLocation = corpseLocation
            };

            cp.RouteToCorpse.Clear();
            cp.RouteToCorpse.AddRange(routeToCorpse);
            cp.TruncatedRoute.Clear();
            cp.TruncatedRoute.AddRange(truncatedRoute);

            //File.WriteAllText($"../../../../CorpsePath_{DateTime.Now.ToString("yyyyMMddHHmmss")}.json", JsonConvert.SerializeObject(cp));
            NeedsToReset = false;
        }
Пример #2
0
        public async Task Reset()
        {
            await this.stopMoving.Stop();

            points.Clear();

            logger.LogInformation("Sleeping 5 seconds");
            await Task.Delay(5000);

            while (new List <double> {
                playerReader.XCoord, playerReader.YCoord, corpseLocation.X, corpseLocation.Y
            }.Max() > 100)
            {
                logger.LogInformation($"Waiting... odd coords read. Player {playerReader.XCoord},{playerReader.YCoord} corpse { corpseLocation.X}{corpseLocation.Y}");
                await Task.Delay(5000);
            }

            logger.LogInformation($"player location {playerReader.XCoord},{playerReader.YCoord}. Corpse {corpseLocation.X},{corpseLocation.Y}.");

            var path = await pather.FindRouteTo(this.playerReader, corpseLocation);

            if (path.Any())
            {
                path.Reverse();
                path.ForEach(p => points.Push(p));
            }
            else
            {
                var closestRouteAndSpiritPathPoints = routePoints.SelectMany(s => spiritWalkerPath.Select(swp => (pathPoint: s, spiritPathPoint: swp, distance: DistanceTo(s, swp))))
                                                      .OrderBy(s => s.distance)
                                                      .First();

                // spirit walker path leg
                var spiritWalkerLeg = new List <WowPoint>();
                for (int i = 0; i < spiritWalkerPath.Count; i++)
                {
                    spiritWalkerLeg.Add(spiritWalkerPath[i]);
                    if (spiritWalkerPath[i] == closestRouteAndSpiritPathPoints.spiritPathPoint)
                    {
                        break;
                    }
                }

                var closestRoutePointToCorpse = routePoints.Select(s => (pathPoint: s, distance: DistanceTo(s, corpseLocation)))
                                                .OrderBy(s => s.distance)
                                                .First()
                                                .pathPoint;

                //from closestRouteAndSpiritPathPoints to closestRoutePointToCorpse
                var pathStartPoint = closestRouteAndSpiritPathPoints.pathPoint;

                // see if we can walk forward through the points
                var legFromSpiritEndToCorpse = FillPathToCorpse(closestRoutePointToCorpse, pathStartPoint, routePoints);
                if (legFromSpiritEndToCorpse.Count == 0)
                {
                    var reversePath = routePoints.Select(s => s).ToList();
                    reversePath.Reverse();
                    legFromSpiritEndToCorpse = FillPathToCorpse(closestRoutePointToCorpse, pathStartPoint, reversePath);
                }

                var routeToCorpse = spiritWalkerLeg.Select(s => s).ToList();
                routeToCorpse.AddRange(legFromSpiritEndToCorpse);

                var myLocation     = new WowPoint(playerReader.XCoord, playerReader.YCoord);
                var truncatedRoute = WowPoint.ShortenRouteFromLocation(myLocation, routeToCorpse);

                for (int i = truncatedRoute.Count - 1; i > -1; i--)
                {
                    points.Push(truncatedRoute[i]);
                }

                var cp = new CorpsePath {
                    MyLocation = myLocation, CorpseLocation = corpseLocation
                };
                cp.RouteToCorpse.Clear();
                cp.RouteToCorpse.AddRange(routeToCorpse);
                cp.TruncatedRoute.Clear();
                cp.TruncatedRoute.AddRange(truncatedRoute);

#if DEBUG
                //File.WriteAllText($"CorpsePath_{DateTime.Now.ToString("yyyyMMddHHmmss")}.json", JsonConvert.SerializeObject(cp));
#endif
            }
            if (points.Any())
            {
                lastDistance = 999;
                NeedsToReset = false;
                this.stuckDetector.SetTargetLocation(points.Peek());
                var heading = DirectionCalculator.CalculateHeading(this.playerReader.PlayerLocation, points.Peek());
                await playerDirection.SetDirection(heading, this.playerReader.CorpseLocation, "Heading to corpse");

                wowProcess.SetKeyState(ConsoleKey.UpArrow, true, false, "WalkToCorpse");
                this.stuckDetector.SetTargetLocation(points.Peek());
                this.LastActive = DateTime.Now;
            }
        }