Ejemplo n.º 1
0
        public async Task PlayAsync(CancellationToken cancellationToken)
        {
            await LoadAndGenerateRoute();

            // Fire and forget task to continuously search for gather nodes and update CurrentDetourNode.
            await Task.Run(() => SearchForGatherNodes(cancellationToken));

            // Start by facing the target before moving.
            IsTurningInPlace = true;

            while (!cancellationToken.IsCancellationRequested)
            {
                var x = character.GetX();
                var y = character.GetY();

                // Acquire target node.
                var target = GenerateViaAndTarget(x, y);

                // Turn towards the target.
                TurnToward(x, y, target);

                // Move towards the target.
                if (!IsTurningInPlace)
                {
                    MoveToward(x, y, target);
                }

                // Wait for movement.
                await Task.Delay(UpdateInterval, cancellationToken);

                // Check completion.
                await CheckCompletion(target, cancellationToken);
            }
        }