Exemplo n.º 1
0
 public TargetingSystem(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _activitySystem  = systemContainer.ActivitySystem;
     _rendererSystem  = systemContainer.RendererSystem;
     _systemContainer = systemContainer;
 }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 13
0
 public PrototypeSystem(IEntityEngine engine, IPositionSystem positionSystem, ISystemContainer systemContainer)
 {
     _engine          = engine;
     _positionSystem  = positionSystem;
     _systemContainer = systemContainer;
 }
Exemplo n.º 14
0
 public InteractionSystem(IPositionSystem positionSystem)
 {
     _positionSystem = positionSystem;
 }
Exemplo n.º 15
0
 public BumpAttackRule(ISystemContainer systemContainer)
 {
     _positionSystem         = systemContainer.PositionSystem;
     _eventSystem            = systemContainer.EventSystem;
     _animatedMovementSystem = systemContainer.AnimatedMovementSystem;
 }
Exemplo n.º 16
0
 public RandomlyMoveBehaviour(ISystemContainer systemContainer)
 {
     _positionSystem  = systemContainer.PositionSystem;
     _eventRuleSystem = systemContainer.EventSystem;
     _random          = systemContainer.Random;
 }
Exemplo n.º 17
0
 public MoveThroughPortalRule(ISystemContainer systemContainer)
 {
     _positionSystem = systemContainer.PositionSystem;
     _eventSystem    = systemContainer.EventSystem;
 }
Exemplo n.º 18
0
 public CantMoveIntoSameFactionRule(ISystemContainer systemContainer)
 {
     _positionSystem = systemContainer.PositionSystem;
     _factionSystem  = systemContainer.FactionSystem;
 }
Exemplo n.º 19
0
 public CompleteMoveRule(ISystemContainer systemContainer)
 {
     positionSystem          = systemContainer.PositionSystem;
     eventRuleSystem         = systemContainer.EventSystem;
     _animatedMovementSystem = systemContainer.AnimatedMovementSystem;
 }