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); }
private void SetPosition(IEntity of, MapCoordinate coordinate) { _positionSystem.CoordinateOf(of).Returns(coordinate); _positionSystem.EntitiesAt(coordinate).Returns(new List <IEntity> { of }); }
public static Appearance GetAppearanceAt(IPositionSystem positionSystem, IMap currentMap, MapCoordinate coordinate, ref RLColor backColor, bool isInFov) { Appearance appearance = null; var entity = positionSystem .EntitiesAt(coordinate) .OrderByDescending(a => a.Get <Appearance>().ZOrder) .FirstOrDefault(e => isInFov || IsRemembered(currentMap, coordinate, e)); if (entity != null) { appearance = entity.Get <Appearance>(); backColor = RLColor.Black; } else { appearance = new Appearance() { Color = Color.Black, Glyph = ' ', ZOrder = 0 }; backColor = RLColor.Black; } return(appearance); }
public List <MapCoordinate> FovFrom(IPositionSystem positionSystem, MapCoordinate mapCoordinate, int range, Func <Vector, bool> transparentTest = null) { var cachedFov = FovCache.TryGetCachedFov(mapCoordinate, range); if (cachedFov != null) { return(cachedFov); } if (mapCoordinate.Key != MapKey) { return(new List <MapCoordinate>()); } if (transparentTest == null) { transparentTest = (Vector v) => { var entities = positionSystem.EntitiesAt(mapCoordinate + v); var physicals = entities.Select(e => e.TryGet <Physical>()).Where(p => p != null); return(!physicals.Any(p => p.Transparent == false)); }; } var visibleVectors = ShadowcastingFovCalculator.InFov(range, transparentTest); var visibleCells = visibleVectors.Select(v => mapCoordinate + v).ToList(); FovCache.Cache(mapCoordinate, range, visibleCells); return(visibleCells); }
public void EntitiesAt_ReturnsListOfEntities() { IEntity mapCell = SetUpTestMapCell(map, 0, 0); var expected = new List <IEntity> { mover, mapCell }; IEnumerable <IEntity> result; result = positionSystem.EntitiesAt(TEST_MAP_KEY, 0, 0); result.Should().BeEquivalentTo(expected); result = positionSystem.EntitiesAt(GetTestMapCoordinate()); result.Should().BeEquivalentTo(expected); }
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); }
public void Complete_WithDefaultTarget_ReturnsDefaultTarget() { var entity = Substitute.For <IEntity>(); var entityList = new List <IEntity> { entity }; entity.Has <Health>().Returns(true); _positionSystem.EntitiesAt(Arg.Any <MapCoordinate>()).ReturnsForAnyArgs(entityList); _systemContainer.PositionSystem.Returns(_positionSystem); _targetingActivity = new TargetingActivity(_activitySystem.DefaultPosition, _activitySystem.DefaultPadding, _targetingData, _callback, _systemContainer, new MapCoordinate("Map", 0, 0), _ioConfig); _targetingActivity.Complete(); _callbackHappened.Should().BeTrue(); var distance = Math.Abs(_callbackTarget.X) + Math.Abs(_callbackTarget.Y); distance.Should().Be(1); }
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); } } } }
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); }