示例#1
0
        public Node GenerateViaAndTarget(float x, float y)
        {
            var target = ViaRoute.PeekOrDefault() ?? FoundNodes.PeekOrDefault() ?? Route[NextRouteIndex];

            if (!target.Tri.ContainsPoint(x, y))
            {
                // Recalculate ViaRoute.
                target = FoundNodes.PeekOrDefault() ?? Route[NextRouteIndex];
                GenerateViaRoute(x, y, target);

                if (ViaRoute.Count != 0)
                {
                    target = ViaRoute.PeekOrDefault();
                }
            }

            return(target);
        }
示例#2
0
        public async Task CheckCompletion(Node target, CancellationToken cancellationToken)
        {
            var x = character.GetX();
            var y = character.GetY();

            if (MathUtils.GetDistSqr(x, y, target.X, target.Y) < DistanceThresholdSquared)
            {
                // Check if we should turn in place at this node.
                IsTurningInPlace = target.ShouldTurnInPlace;
                if (IsTurningInPlace)
                {
                    input.Move(0);
                }

                // Check which target list to advance.
                if (target == ViaRoute.PeekOrDefault())
                {
                    ViaRoute.Dequeue();
                }
                else if (target == FoundNodes.PeekOrDefault())
                {
                    // Gather this node.
                    await Gather(cancellationToken);

                    lock (FoundNodes)
                    {
                        FoundNodes.Dequeue();
                    }
                }
                else if (target == Route[NextRouteIndex])
                {
                    ++NextRouteIndex;
                    if (NextRouteIndex == Route.Count)
                    {
                        NextRouteIndex = 0;
                    }
                }
                else
                {
                    throw new Exception("Completed node was not found in any list.");
                }
            }
        }
示例#3
0
        private async void SearchForGatherNodes(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                // TODO: use screenshots and cv to find gathering nodes, and convert the coordinates to mumble units.
                IEnumerable <Node> newFoundNodes = null;

                if (newFoundNodes != null)
                {
                    // Add new found nodes to the list.
                    lock (FoundNodes)
                    {
                        foreach (Node newFoundNode in newFoundNodes)
                        {
                            bool alreadyFound = false;

                            foreach (Node alreadyFoundNode in FoundNodes)
                            {
                                if (MathUtils.GetDistSqr(newFoundNode.X, newFoundNode.Y, alreadyFoundNode.X, alreadyFoundNode.Y) < SameNodeDistanceToleranceSquared)
                                {
                                    alreadyFound = true;
                                    break;
                                }
                            }

                            if (!alreadyFound)
                            {
                                FoundNodes.Enqueue(newFoundNode);
                            }
                        }
                    }
                }

                await Task.Delay(SearchInterval, cancellationToken);
            }
        }