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); }
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); } } }
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); }