Пример #1
0
        private async Task PrepareForFight(Tile enemyTile)
        {
            var moveDirection = Location.Tile.Neighbours.Single(t => t.Item1 == enemyTile).Item2;

            while (true)
            {
                var routeToSide = GroupLayout.GetToSide(this, Location.Tile, moveDirection);
                if (routeToSide != null)
                {
                    foreach (var space in routeToSide.Skip(1))
                    {
                        if (!await MoveToSpace(space))
                        {
                            goto whileLoop;
                        }
                        await Task.Delay(MoveDuration);
                    }

                    await Fight(enemyTile, moveDirection);

                    break;
                }

whileLoop:
                await Task.Delay(100);
            }
        }
Пример #2
0
        protected virtual async Task PrepareForFight(ITile enemyTile)
        {
            if (Location == null)
            {
                return;
            }

            var moveDirection = Location.Tile.Neighbors.SingleOrDefault(t => t.Item1 == enemyTile)?.Item2;

            if (moveDirection == null)
            {
                //creature fall to pit for example
                return;
            }

            var routeToSide = GroupLayout.GetToSide(Location, moveDirection.Value, false);

            if (routeToSide != null)
            {
                foreach (var space in routeToSide.Skip(1))
                {
                    if (!await MoveToSpace(space))
                    {
                        return;
                    }
                    await Task.Delay(MoveDuration);
                }
                if (Location == null)
                {
                    return;
                }
                new CreatureAttack(this).Apply(moveDirection.Value);
                await Task.Delay(attackDuration);
            }
        }