Exemple #1
0
 public TargetingSystem(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _activitySystem  = systemContainer.ActivitySystem;
     _rendererSystem  = systemContainer.RendererSystem;
     _systemContainer = systemContainer;
 }
Exemple #2
0
        public void SetUp()
        {
            _targetingData    = GetTargetingData();
            _callbackTarget   = null;
            _callbackHappened = false;

            _renderer = Substitute.For <IUnifiedRenderer>();
            var rendererSystem = Substitute.For <IRendererSystem>();

            rendererSystem.Renderer.Returns(_renderer);

            var playerSystem = Substitute.For <IPlayerSystem>();

            _activityStack = new ActivityStack();
            _ioConfig      = new IOSystemConfiguration();
            _activityStack.Push(new GameplayActivity(new Rectangle(0, 0, 0, 0), new Padding(0), _ioConfig, playerSystem));
            _activitySystem  = Substitute.For <IActivitySystem>();
            _positionSystem  = Substitute.For <IPositionSystem>();
            _targetingSystem = Substitute.For <ITargetingSystem>();
            _systemContainer = Substitute.For <ISystemContainer>();
            _systemContainer.ActivitySystem.Returns(_activitySystem);
            _systemContainer.PositionSystem.Returns(_positionSystem);
            _systemContainer.RendererSystem.Returns(rendererSystem);
            _systemContainer.TargetingSystem.Returns(_targetingSystem);

            SetTargetableCells(new MapCoordinate("Map", 1, 0));

            _targetingActivity = new TargetingActivity(_activitySystem.DefaultPosition, _activitySystem.DefaultPadding, _targetingData, _callback, _systemContainer, new MapCoordinate("Map", 0, 0), _ioConfig);
            _activityStack.Push(_targetingActivity);
        }
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 public AttackClosestEnemyBehaviour(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _eventRuleSystem = systemContainer.EventSystem;
     _playerSystem    = systemContainer.PlayerSystem;
     _mapSystem       = systemContainer.MapSystem;
     _factionSystem   = systemContainer.FactionSystem;
 }
 public MoveAwayFromPlayerBehaviour(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _eventRuleSystem = systemContainer.EventSystem;
     _playerSystem    = systemContainer.PlayerSystem;
     _mapSystem       = systemContainer.MapSystem;
     _random          = systemContainer.Random;
 }
        public static MapCoordinate GetEmptyPosition(this IMap map, IPositionSystem positionSystem, IRandom random)
        {
            var emptyPositions = map.Cells
                                 .Where(c => c.Value.Get <Physical>().Passable&& c.Value.Get <Physical>().Transparent)
                                 .Where(c => !positionSystem.Any(c.Key))
                                 .ToList();

            return(random.PickOne(emptyPositions).Key);
        }
Exemple #8
0
 public FollowPathBehaviour(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _eventRuleSystem = systemContainer.EventSystem;
     _playerSystem    = systemContainer.PlayerSystem;
     _mapSystem       = systemContainer.MapSystem;
     _entityEngine    = systemContainer.EntityEngine;
     _messageSystem   = systemContainer.MessageSystem;
     _timeSystem      = systemContainer.TimeSystem;
 }
        public static void DrawCell(RLConsole mapConsole, int x, int y, IPositionSystem positionSystem, IMap currentMap, int lookupX, int lookupY, List <MapCoordinate> playerFov, TargetingStatus cellTargeting = TargetingStatus.NotTargeted)
        {
            MapCoordinate coordinate = new MapCoordinate(currentMap.MapKey, lookupX, lookupY);
            var           backColor  = RLColor.Black;

            var isInFov = playerFov.Contains(coordinate);

            Appearance appearance = GetAppearanceAt(positionSystem, currentMap, coordinate, ref backColor, isInFov);

            var foreColor = isInFov ? appearance.Color.ToRLColor() : RLColor.Gray;

            backColor = ApplyTargetingColor(cellTargeting, backColor, isInFov);

            mapConsole.Set(x, y, foreColor, backColor, appearance.Glyph);
        }
        public static MapCoordinate GetQuickEmptyPosition(this IMap map, IPositionSystem positionSystem, IRandom random, int tries = 5)
        {
            for (int i = 0; i < tries; i++)
            {
                var emptyPositions = map.Cells
                                     .ToList();
                var cell = random.PickOne(emptyPositions);

                if (cell.Value.Get <Physical>().Passable&& cell.Value.Get <Physical>().Transparent&& !positionSystem.Any(cell.Key))
                {
                    return(cell.Key);
                }
            }

            return(null);
        }
        public TargetingActivity(Rectangle position, Padding padding, Targeting targetingData, Action <MapCoordinate> callback, ISystemContainer systemContainer, MapCoordinate targetFrom, IOSystemConfiguration ioSystemConfiguration) : base(position, padding)
        {
            _activitySystem  = systemContainer.ActivitySystem;
            _systemContainer = systemContainer;
            _positionSystem  = systemContainer.PositionSystem;
            _targetingSystem = systemContainer.TargetingSystem;

            TargetingData = targetingData;
            CurrentTarget = null;
            Callback      = callback;
            TargetFrom    = targetFrom;

            _targetableCells = _targetingSystem.TargetableCellsFrom(TargetingData, TargetFrom);

            PickInitialTarget();
            _ioSystemConfiguration = ioSystemConfiguration;
        }
Exemple #12
0
        public void SetUp()
        {
            _sender = CreateSkillUser();
            _player = CreatePlayer();

            _systemContainer = Substitute.For <ISystemContainer>();
            _positionSystem  = Substitute.For <IPositionSystem>();
            _playerSystem    = Substitute.For <IPlayerSystem>();
            _targetingSystem = Substitute.For <ITargetingSystem>();
            _mapSystem       = Substitute.For <IMapSystem>();
            _mapCollection   = new Atlas();
            _map             = Substitute.For <IMap>();
            _systemContainer.PositionSystem.ReturnsForAnyArgs(_positionSystem);
            _systemContainer.PlayerSystem.ReturnsForAnyArgs(_playerSystem);
            _systemContainer.MapSystem.ReturnsForAnyArgs(_mapSystem);
            _systemContainer.Random.ReturnsForAnyArgs(new RNG("test seed"));
            _systemContainer.TargetingSystem.ReturnsForAnyArgs(_targetingSystem);
            _mapSystem.MapCollection.ReturnsForAnyArgs(_mapCollection);
            _mapCollection[new MapKey("test")] = _map;

            SetTargetableCells(new MapCoordinate(MAP_KEY, 0, 0));

            _playerSystem.Player.ReturnsForAnyArgs(_player);

            _data = CreateTargetingData();

            UNUSED = new MapCoordinate("UNUSED", 0, 0);
            _callbackCoordinate = UNUSED;

            _callback = m =>
            {
                _callbackCoordinate = m;
            };

            _senderLocation = new MapCoordinate(MAP_KEY, 0, 0);

            SetPosition(_sender, _senderLocation);
        }
 public PrototypeSystem(IEntityEngine engine, IPositionSystem positionSystem, ISystemContainer systemContainer)
 {
     _engine          = engine;
     _positionSystem  = positionSystem;
     _systemContainer = systemContainer;
 }
 public InteractionSystem(IPositionSystem positionSystem)
 {
     _positionSystem = positionSystem;
 }
Exemple #15
0
 public BumpAttackRule(ISystemContainer systemContainer)
 {
     _positionSystem         = systemContainer.PositionSystem;
     _eventSystem            = systemContainer.EventSystem;
     _animatedMovementSystem = systemContainer.AnimatedMovementSystem;
 }
 public RandomlyMoveBehaviour(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _eventRuleSystem = systemContainer.EventSystem;
     _random          = systemContainer.Random;
 }
Exemple #17
0
 public MoveThroughPortalRule(ISystemContainer systemContainer)
 {
     _positionSystem = systemContainer.PositionSystem;
     _eventSystem    = systemContainer.EventSystem;
 }
Exemple #18
0
 public CantMoveIntoSameFactionRule(ISystemContainer systemContainer)
 {
     _positionSystem = systemContainer.PositionSystem;
     _factionSystem  = systemContainer.FactionSystem;
 }
Exemple #19
0
 public CompleteMoveRule(ISystemContainer systemContainer)
 {
     positionSystem          = systemContainer.PositionSystem;
     eventRuleSystem         = systemContainer.EventSystem;
     _animatedMovementSystem = systemContainer.AnimatedMovementSystem;
 }