예제 #1
0
        protected override bool TryHandleCommand(CreateMalwareCommand command, int currentTick, bool handlerEnabled)
        {
            if (handlerEnabled &&
                string.IsNullOrEmpty(command.Archetype) == false &&
                _nodeMatcherGroup.TryGetMatchingEntity(command.NodeId, out var nodeTuple))
            {
                if (_entityFactoryProvider.TryCreateEntityFromArchetype(command.Archetype, out var malware))
                {
                    var initialPosition = 0;
                    switch (nodeTuple.Component3)
                    {
                    case Subsystem s:
                        initialPosition = _rngSystem.Next(SimulationConstants.SubsystemPositions);
                        break;

                    case Connection c:
                        initialPosition = _rngSystem.Next(SimulationConstants.ConnectionPositions);
                        break;
                    }

                    _movementSystem.AddVisitor(nodeTuple.Entity, malware, initialPosition);
                    return(true);
                }
                malware?.Dispose();
            }
            return(false);
        }
예제 #2
0
        public Entity CreateSystem(NodeConfig config)
        {
            if (_entityFactoryProvider.TryCreateEntityFromArchetype(config.Archetype, out var subsystem))
            {
                config.EntityId = subsystem.Id;

                subsystem.GetComponent <Coordinate2DProperty>().X = config.X;
                subsystem.GetComponent <Coordinate2DProperty>().Y = config.Y;
                subsystem.GetComponent <Name>().Value             = config.Name;

                return(subsystem);
            }
            subsystem?.Dispose();

            throw new SimulationException($"Could not create system for archetype '{config.Archetype}'");
        }
예제 #3
0
 protected override bool TryHandleCommand(DisplayTextCommand command, int currentTick, bool handlerEnabled)
 {
     if (handlerEnabled)
     {
         if (_entityFactoryProvider.TryCreateEntityFromArchetype(TutorialText.Archetype, out var textEntity) &&
             textEntity.TryGetComponent <Text>(out var text))
         {
             text.Value        = command.Text;
             text.ShowContinue = command.Continue;
             return(true);
         }
         textEntity?.Dispose();
     }
     return(false);
 }
예제 #4
0
 public static bool TryCreateItem(this IEntityFactoryProvider entityFactoryProvider,
                                  string archetype,
                                  int?currentLocationId,
                                  int?ownerId,
                                  out ComponentEntityTuple <CurrentLocation, Owner> entityTuple)
 {
     if (entityFactoryProvider.TryCreateEntityFromArchetype(archetype, out var item) &&
         item.TryGetComponent <CurrentLocation>(out var currentLocation) &&
         item.TryGetComponent <Owner>(out var owner))
     {
         currentLocation.Value = currentLocationId;
         owner.Value           = ownerId;
         entityTuple           = new ComponentEntityTuple <CurrentLocation, Owner>(item, currentLocation, owner);
         return(true);
     }
     item?.Dispose();
     entityTuple = null;
     return(false);
 }
예제 #5
0
        private void Propogate(ComponentEntityTuple <MalwareGenome, CurrentLocation, MalwarePropogation, MalwareVisibility> malwareTuple, ComponentEntityTuple <Subsystem, GraphNode> subsystemTuple)
        {
            if (_rngSystem.Next(0, 99) > malwareTuple.Component3.RollThreshold)
            {
                var exitNodes = subsystemTuple.Component2.ExitPositions.Keys.ToArray();

                // TODO: currently the direction to spread in is picked randomly by the PRNG - maybe have a more deterministic solution
                var propogateTo = exitNodes[_rngSystem.Next(0, exitNodes.Length)];

                if (_entityFactoryProvider.TryCreateEntityFromArchetype(malwareTuple.Entity.CreatedFromArchetype, out var entity) &&
                    _malwareMatcher.TryGetMatchingEntity(entity.Id, out var newMalwareTuple))
                {
                    newMalwareTuple.Component1.Value     = malwareTuple.Component1.Value;
                    newMalwareTuple.Component4.VisibleTo = malwareTuple.Component4.VisibleTo;

                    _movementSystem.AddVisitor(propogateTo, newMalwareTuple.Entity.Id);
                }
            }
        }
예제 #6
0
        public Entity CreatePlayer(PlayerConfig playerConfig)
        {
            if (_entityFactoryProvider.TryCreateEntityFromArchetype(playerConfig.Archetype, out var player) &&
                player.TryGetComponent <PlayerBitMask>(out var playerBitMask) &&
                player.TryGetComponent <PlayerColour>(out var playerColour))
            {
                playerConfig.EntityId = player.Id;
                playerConfig.Id       = _playerId;

                var startingLocationId = playerConfig.StartingLocation ?? 0;
                _movementSystem.AddVisitor(_graphSystem.Subsystems[startingLocationId], player);
                playerBitMask.Value      = 1 << _playerId;
                playerColour.HexColour   = playerConfig.Colour;
                playerColour.PlayerGlyph = playerConfig.Glyph;

                _playerEntityMapping.Add(_playerId, player.Id);

                _playerId++;
                return(player);
            }