public override ActionEventData ChooseAction(IEntity entity)
        {
            var position       = _positionSystem.CoordinateOf(entity);
            var playerPosition = _positionSystem.CoordinateOf(_playerSystem.Player);

            if (position == null ||
                playerPosition == null ||
                Math.Abs(position.X - playerPosition.X) > 3 ||
                Math.Abs(position.Y - playerPosition.Y) > 3)
            {
                return(null);
            }

            var adjacentToMe     = position.AdjacentCells().Where(c => !_positionSystem.IsBlocked(c));
            var adjacentToPlayer = playerPosition.AdjacentCells();

            var validCells = adjacentToMe.Except(adjacentToPlayer).Except(new [] { playerPosition }).ToList();

            if (validCells.Any())
            {
                var vector = _random.PickOne(validCells) - position;

                return(new ActionEventData {
                    Action = ActionType.Move, Parameters = vector.ToString(), Speed = entity.Get <Actor>().Speed
                });
            }

            return(null);
        }
        public List <IEntity> GetInteractablesNear(IEntity entity)
        {
            var playerPosition = _positionSystem.CoordinateOf(entity);

            var nearbyPositions = Vector.GetAdjacentAndDiagonalCellVectors().Select(v => playerPosition + v).ToList();

            nearbyPositions.Add(playerPosition);

            var interactables = Entities.Where(e => nearbyPositions.Contains(_positionSystem.CoordinateOf(e))).ToList();

            return(interactables);
        }
示例#3
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            if (IsFighter(sender))
            {
                var vector           = (Vector)eventData;
                var targetCoordinate = _positionSystem.CoordinateOf(sender) + vector;

                var entitiesAtPosition = _positionSystem.EntitiesAt(targetCoordinate);

                if (entitiesAtPosition.Any(IsFighter))
                {
                    var defender = entitiesAtPosition.Single(e => IsFighter(e));

                    var action = new ActionEventData {
                        Action = ActionType.MeleeAttack, Parameters = $"{sender.EntityId},{defender.EntityId}", Speed = null, KeyPress = null
                    };

                    if (_eventSystem.Try(EventType.Action, sender, action))
                    {
                        _animatedMovementSystem.StartAnimatedMovement(sender, new List <AnimationMovement> {
                            new AnimationMovement(new VectorDouble((double)vector.X / (double)-2, (double)vector.Y / (double)-2), 750)
                        });
                    }

                    return(false);
                }
            }

            return(true);
        }
示例#4
0
 private void SetPosition(IEntity of, MapCoordinate coordinate)
 {
     _positionSystem.CoordinateOf(of).Returns(coordinate);
     _positionSystem.EntitiesAt(coordinate).Returns(new List <IEntity> {
         of
     });
 }
示例#5
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            var vector           = (Vector)eventData;
            var targetCoordinate = _positionSystem.CoordinateOf(sender) + vector;

            var entitiesAtPosition = _positionSystem.EntitiesAt(targetCoordinate);

            if (entitiesAtPosition.Any(e => _factionSystem.IsSameFaction(e, sender)))
            {
                return(false);
            }

            return(true);
        }
示例#6
0
        public override ActionEventData ChooseAction(IEntity entity)
        {
            var position = _positionSystem.CoordinateOf(entity);

            var monsterFov = _mapSystem.MapCollection[position.Key].FovFrom(_positionSystem, position, 9);

            var enemiesInFov = GetEnemiesIn(monsterFov, entity);

            if (enemiesInFov.Any())
            {
                (MapCoordinate, IEntity)closest = GetClosestEnemy(enemiesInFov, position);

                var target = closest.Item1;

                return(MoveTowards(entity, position, target));
            }

            return(null);
        }
        private IEnumerable <IEntity> GetEnemiesInFov()
        {
            var currentMap = _mapSystem.MapCollection[_rendererSystem.CameraPosition.Key];

            MapCoordinate playerPosition = _positionSystem.CoordinateOf(_playerSystem.Player);
            var           playerFov      = currentMap.FovFrom(_positionSystem, playerPosition, 9);

            foreach (MapCoordinate coord in playerFov)
            {
                var entities = _positionSystem.EntitiesAt(coord);

                foreach (var entity in entities)
                {
                    if (IsEnemy(entity))
                    {
                        yield return(entity);
                    }
                }
            }
        }
示例#8
0
        public override ActionEventData ChooseAction(IEntity entity)
        {
            var currentCoordinate = _positionSystem.CoordinateOf(entity);

            if (Path.FirstOrDefault() == currentCoordinate)
            {
                Path.Remove(currentCoordinate);
            }

            if (Path.Any())
            {
                SetWaitingForInputIfPlayer(entity, false);

                if (_playerSystem.Player == entity && _eventRuleSystem.GetStat(entity, "Tension") > 0)
                {
                    _messageSystem.Write("You can't auto-walk when tension is this high.");
                    EndPath(entity);
                    return(null);
                }

                var coordinate = Path.First();
                var vector     = currentCoordinate - coordinate;

                if (CantReach(vector))
                {
                    EndPath(entity);
                }

                return(new ActionEventData {
                    Action = ActionType.Move, Parameters = vector.ToString(), Speed = entity.Get <Actor>().Speed
                });
            }
            else
            {
                EndPath(entity);
                return(null);
            }
        }
示例#9
0
        public bool Apply(EventType type, IEntity sender, object eventData)
        {
            var vector           = (Vector)eventData;
            var targetCoordinate = _positionSystem.CoordinateOf(sender);

            var entitiesAtPosition = _positionSystem.EntitiesAt(targetCoordinate);

            if (entitiesAtPosition.Any(IsAutoPortal))
            {
                var portal = entitiesAtPosition.Single(e => IsAutoPortal(e));

                var action = new ActionEventData {
                    Action = ActionType.Enter, Parameters = $"{StairDirection.Down}", Speed = null, KeyPress = null
                };

                if (_eventSystem.Try(EventType.Action, sender, action))
                {
                }

                return(false);
            }

            return(true);
        }
        public void CoordinateOf_HasPosition_ReturnsPosition()
        {
            var result = positionSystem.CoordinateOf(mover);

            result.Should().BeEquivalentTo(GetTestMapCoordinate());
        }