protected void AddVisitor(int nodeId, Visitors nodeVisitors, int visitorId, int position, int currentTick) { if (VisitorMatcherGroup.TryGetMatchingEntity(visitorId, out var visitorTuple)) { nodeVisitors.Values.Add(visitorId); visitorTuple.Component1.SetPosition(position, currentTick); visitorTuple.Component2.Value = nodeId; visitorTuple.Entity.EntityDisposing += EntityOnEntityDisposing; } }
public bool Evaluate(Simulation ecs, SimulationConfiguration configuration) { return(_playerMatcherGroup.TryGetMatchingEntity(_player.EntityId, out var playerTuple) && playerTuple.Component2.Items[0]?.Item != null && _itemMatcherGroup.TryGetMatchingEntity(playerTuple.Component2.Items[0].Item.Value, out var itemTuple) && (_filter == null || _filter.Evaluate(itemTuple.Entity))); }
private bool TryHandleDisconectOnSubsystem(ComponentEntityTuple <Subsystem, ItemStorage> subsystemTuple, ComponentEntityTuple <Player, ItemStorage, CurrentLocation> playerTuple, InventoryItemContainer inventoryItemContainer) { if (subsystemTuple.Component2.TryGetEmptyContainer(out var emptyContainer, out var containerIndex)) { #region copied from DropItemCommandHandler // TODO: this should be replaced with an intent based approach, the command handler should abstract through the intent as well if (_itemMatcherGroup.TryGetMatchingEntity(inventoryItemContainer.Item.Value, out var itemTuple) && playerTuple.Component3.Value.HasValue && itemTuple.Component2.Value == playerTuple.Entity.Id) { var inventory = playerTuple.Component2.Items[0] as InventoryItemContainer; var target = subsystemTuple.Component2.Items[containerIndex]; if (inventory != null && inventory.Item == itemTuple.Entity.Id && target != null && target.CanCapture(itemTuple.Entity.Id)) { target.Item = itemTuple.Entity.Id; itemTuple.Component3.Value = subsystemTuple.Entity.Id; inventory.Item = null; itemTuple.Component2.Value = null; return(true); } } #endregion } return(false); }
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); }
protected override bool TryHandleCommand(DropItemTypeCommand command, int currentTick, bool handlerEnabled) { if (command.ItemType == null || typeof(IItemType).IsAssignableFrom(command.ItemType) == false) { return(false); } if (_playerSystem.TryGetPlayerEntityId(command.PlayerId, out var playerEntityId) && _playerMatcherGroup.TryGetMatchingEntity(playerEntityId, out var playerTuple) && playerTuple.Component3.Value.HasValue && _subsystemMatcherGroup.TryGetMatchingEntity(playerTuple.Component3.Value.Value, out var subsystemTuple) && subsystemTuple.Component2.TryGetEmptyContainer(out var target, out var containerIndex)) { var inventory = playerTuple.Component2.Items[0] as InventoryItemContainer; if (inventory != null && inventory.Item.HasValue && _itemMatcherGroup.TryGetMatchingEntity(inventory.Item.Value, out var inventoryItemTuple) && inventoryItemTuple.Entity.TryGetComponent(command.ItemType, out var itemTypeComponent) && target != null && target.CanCapture(inventory.Item.Value)) { target.Item = inventoryItemTuple.Entity.Id; inventoryItemTuple.Component3.Value = subsystemTuple.Entity.Id; inventory.Item = null; inventoryItemTuple.Component4.Value = null; return(true); } } return(false); }
public void OnActivating(ComponentEntityTuple <Engine.Systems.Activation.Components.Activation, TransferActivator, CurrentLocation, Owner, TimedActivation> entityTuple, int currentTick) { if (entityTuple.Component3.Value.HasValue && // TODO: this should never fail so might be able to remove it _transferSystemMatcherGroup.TryGetMatchingEntity(entityTuple.Component3.Value.Value, out var localTransferSystemTuple) && entityTuple.Component4.Value.HasValue) { var otherTransferSystemTuple = _transferSystemMatcherGroup.MatchingEntities.SingleOrDefault(t => t.Entity.Id != localTransferSystemTuple.Entity.Id); if (otherTransferSystemTuple != null && localTransferSystemTuple.Component3.TryGetItemContainer <TransferItemContainer>(out var localTransferItemContainer) && otherTransferSystemTuple.Component3.TryGetItemContainer <TransferItemContainer>(out var remoterTransferItemContainer) && otherTransferSystemTuple.Component3.TryGetItemContainer <TransferActivatorTargetItemContainer>(out var remoteTransferActivatorContainer) && remoteTransferActivatorContainer.Item.HasValue && _transferActivatorMatcherGroup.TryGetMatchingEntity(remoteTransferActivatorContainer.Item.Value, out var remoteTransferActivatorTuple)) { // Make sure items haven't recently been locked by another player. if (localTransferItemContainer.Locked == false) { localTransferItemContainer.Locked = true; remoterTransferItemContainer.Locked = true; remoteTransferActivatorTuple.Component1.SetState(ActivationState.Active, currentTick); // TODO: find a better way of doing this remoteTransferActivatorTuple.Component5.Synchronized = true; remoteTransferActivatorTuple.Component5.ActivationTicksRemaining = remoteTransferActivatorTuple.Component5.ActivationDuration; } } else { entityTuple.Component1.SetState(ActivationState.NotActive, currentTick); } }
public bool Evaluate(Simulation ecs, SimulationConfiguration configuration) { return(ecs.Entities.TryGetValue(_node.EntityId, out var locationEntity) && locationEntity.TryGetComponent <Visitors>(out var visitors) && visitors.Values.Any(v => _malwareMatcherGroup.TryGetMatchingEntity(v, out var visitorTuple) && (visitorTuple.Component1.Value & _genome) == _genome && (visitorTuple.Component2.VisibleTo & _revealedTo) == _revealedTo)); }
private void OnActivating(ComponentEntityTuple <Engine.Systems.Activation.Components.Activation, GarbageDisposalActivator, CurrentLocation, Owner> entityTuple, int currentTick) { if (entityTuple.Component3.Value.HasValue && _subsystemMatcherGroup.TryGetMatchingEntity(entityTuple.Component3.Value.Value, out var locationTuple) && locationTuple.Component2.TryGetItemContainer <GarbageDisposalTargetItemContainer>(out var targetItemContainer) && targetItemContainer.Item.HasValue) { targetItemContainer.Locked = true; }
private void OnActive(ComponentEntityTuple <Engine.Systems.Activation.Components.Activation, TimedActivation, CurrentLocation> entityTuple) { if (entityTuple.Component3.Value.HasValue && _subsystemMatcher.TryGetMatchingEntity(entityTuple.Component3.Value.Value, out var subsystemTuple)) { var activationTickModifier = (1 - (subsystemTuple.Component2.Value / (decimal)subsystemTuple.Component2.Maximum) * CPURatioScalingFactor); entityTuple.Component2.ActivationTickModifier = RangeHelper.AssignWithinBounds(activationTickModifier, 0, Int32.MaxValue); } }
public Score GetScoreForPlayerEntity(int playerEntityId) { if (_playerMatcherGroup.TryGetMatchingEntity(playerEntityId, out var playerTuple)) { return(playerTuple.Component2); } return(new Score()); }
public void OnPlayerDisconnected(int playerEntityId) { if (_playerMatcherGroup.TryGetMatchingEntity(playerEntityId, out var playerTuple) && playerTuple.Component3.Value.HasValue && _visitorsMatcherGroup.TryGetMatchingEntity(playerTuple.Component3.Value.Value, out var visitorsTuple)) { visitorsTuple.Component1.Values.Remove(playerEntityId); playerTuple.Entity.Dispose(); } }
public override void AddVisitorToNode(int nodeId, int visitorId, int sourceId, int initialPosition, int currentTick) { if (_connectionMatcherGroup.TryGetMatchingEntity(nodeId, out var connectionTuple)) { var position = connectionTuple.Component2.EntrancePositions.ContainsKey(sourceId) ? connectionTuple.Component2.EntrancePositions[sourceId] + initialPosition : initialPosition; AddVisitor(nodeId, connectionTuple.Component3, visitorId, position, currentTick); } }
private void RemoveVisitorFromNode(int visitorId) { if (VisitorMatcherGroup.TryGetMatchingEntity(visitorId, out var visitorTuple)) { if (visitorTuple.Component2.Value.HasValue && _visitorsMatcherGroup.TryGetMatchingEntity(visitorTuple.Component2.Value.Value, out var visitorsTuple)) { RemoveVisitorFromNode(visitorsTuple.Entity.Id, visitorsTuple.Component1, visitorTuple.Entity, visitorTuple.Component2); } } }
private void OnActivating(ComponentEntityTuple <Engine.Systems.Activation.Components.Activation, Analyser, CurrentLocation, Owner> entityTuple, int currentTick) { if (entityTuple.Component3.Value.HasValue && _subsystemMatcherGroup.TryGetMatchingEntity(entityTuple.Component3.Value.Value, out var locationTuple) && locationTuple.Component2.TryGetItemContainer <AnalysisTargetItemContainer>(out var analysisTargetItemContainer) && analysisTargetItemContainer.Item.HasValue && _captureMatcherGroup.TryGetMatchingEntity(analysisTargetItemContainer.Item.Value, out var captureTuple) && captureTuple.Component1.CapturedGenome != 0) { analysisTargetItemContainer.Locked = true; }
protected override bool TryHandleCommand(SetHighlightCommand command, int currentTick, bool handlerEnabled) { if (handlerEnabled && _highlightMatcherGroup.TryGetMatchingEntity(command.EntityId, out var highlightTuple)) { highlightTuple.Component1.Enabled = command.Value; return(true); } return(false); }
private void OnDeactivating(ComponentEntityTuple <Activation, Components.Antivirus, CurrentLocation, Owner, ConsumableActivation> entityTuple) { if (entityTuple.Component3.Value.HasValue && _visitorsMatcherGroup.TryGetMatchingEntity(entityTuple.Component3.Value.Value, out var locationTuple)) { var malwareVisitors = locationTuple.Component1.Values .Join(_malwareMatcherGroup.MatchingEntities, k => k, k => k.Entity.Id, (o, i) => i) .ToArray(); var @event = new AntivirusActivationEvent() { PlayerEntityId = entityTuple.Component4.Value.Value, SubsystemEntityId = locationTuple.Entity.Id, Uses = entityTuple.Component5.ActivationsRemaining - 1, }; if (malwareVisitors.Length == 0) { @event.ActivationResult = AntivirusActivationEvent.AntivirusActivationResult.NoVirusPresent; } // join the current locations list of visitors with all malware entities foreach (var malwareVisitor in malwareVisitors) { if ((malwareVisitor.Component1.Value & entityTuple.Component2.TargetGenome) == malwareVisitor.Component1.Value) { @event.GenomeEradicated = malwareVisitor.Component1.Value; @event.ActivationResult = AntivirusActivationEvent.AntivirusActivationResult.SoloExtermination; malwareVisitor.Entity.Dispose(); } else { @event.ActivationResult = AntivirusActivationEvent.AntivirusActivationResult.IncorrectGenome; } } @event.MalwareCount = new System.Collections.Generic.Dictionary <int, int>(); var infections = _malwareMatcherGroup.MatchingEntities.Join(_subsystemMatcherGroup.MatchingEntities, mw => mw.Component3.Value, ss => ss.Entity.Id, (mw, ss) => mw) .ToArray(); @event.MalwareCount.Add(SimulationConstants.MalwareGeneRed, infections.Count(i => i.Component1.Value == SimulationConstants.MalwareGeneRed || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneGreen) || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneBlue) || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneGreen | SimulationConstants.MalwareGeneBlue))); @event.MalwareCount.Add(SimulationConstants.MalwareGeneGreen, infections.Count(i => i.Component1.Value == SimulationConstants.MalwareGeneGreen || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneGreen) || i.Component1.Value == (SimulationConstants.MalwareGeneGreen | SimulationConstants.MalwareGeneBlue) || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneGreen | SimulationConstants.MalwareGeneBlue))); @event.MalwareCount.Add(SimulationConstants.MalwareGeneBlue, infections.Count(i => i.Component1.Value == SimulationConstants.MalwareGeneBlue || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneBlue) || i.Component1.Value == (SimulationConstants.MalwareGeneGreen | SimulationConstants.MalwareGeneBlue) || i.Component1.Value == (SimulationConstants.MalwareGeneRed | SimulationConstants.MalwareGeneGreen | SimulationConstants.MalwareGeneBlue))); _eventSystem.Publish(@event); } }
public bool Evaluate(Simulation ecs, SimulationConfiguration configuration) { if (_nodeEntityConfig == null) { return(_locationMatcherGroup.MatchingEntities.Any(locationTuple => locationTuple.Component1.Values.Any(v => _malwareMatcherGroup.TryGetMatchingEntity(v, out var malwareTuple) && (_filter == null || _filter.Evaluate(malwareTuple.Entity))))); } else { return(_locationMatcherGroup.TryGetMatchingEntity(_nodeEntityConfig.EntityId, out var locationTuple) && locationTuple.Component1.Values.Any(v => _malwareMatcherGroup.TryGetMatchingEntity(v, out var malwareTuple) && (_filter == null || _filter.Evaluate(malwareTuple.Entity)))); } }
protected override bool TryHandleCommand(ActivateItemCommand command, int currentTick, bool handlerEnabled) { if (_activationMatcherGroup.TryGetMatchingEntity(command.ItemId, out var itemTuple)) { var @event = new ActivateItemEvent() { ItemId = itemTuple.Entity.Id, ItemType = itemTuple.Component5.GetType().Name, PlayerEntityId = command.PlayerId, SubsystemEntityId = itemTuple.Component3.Value ?? -1 }; var itemNotActive = itemTuple.Component2.ActivationState == ActivationState.NotActive; // item is not active var playerCanActivate = (itemTuple.Component4.AllowAll || itemTuple.Component4.Value == null || itemTuple.Component4.Value == command.PlayerId); // player can activate item // TODO: should an item have to have a location to be activated? var playerHasActive = _activationMatcherGroup.MatchingEntities.Any(it => it.Component4.Value == command.PlayerId && it.Component2.ActivationState != ActivationState.NotActive); // player has no other active items if (handlerEnabled && itemNotActive && playerCanActivate && playerHasActive == false && itemTuple.Component3.Value.HasValue && // item is on a subsystem _subsystemMatcherGroup.TryGetMatchingEntity(itemTuple.Component3.Value.Value, out var subsystemTuple) && _playerMatcherGroup.TryGetMatchingEntity(command.PlayerId, out var playerTuple) && playerTuple.Component3.Value.HasValue && itemTuple.Component3.Value.Value == playerTuple.Component3.Value.Value) { itemTuple.Component2.SetState(ActivationState.Activating, currentTick); itemTuple.Component4.Value = command.PlayerId; @event.Result = ActivateItemEvent.ActivationResult.Success; _eventSystem.Publish(@event); return(true); } @event.Result = handlerEnabled ? itemNotActive ? playerCanActivate ? playerHasActive ? ActivateItemEvent.ActivationResult.Failure_PlayerHasActive : ActivateItemEvent.ActivationResult.Error : ActivateItemEvent.ActivationResult.Failure_PlayerCannotActivate : ActivateItemEvent.ActivationResult.Failure_ItemAlreadyActive : ActivateItemEvent.ActivationResult.Failure_CommandDisabled; _eventSystem.Publish(@event); } return(false); }
public void Tick() { foreach (var subsystemTuple in _subsystemMatcher.MatchingEntities) { var sum = subsystemTuple.Component3.Value; foreach (var visitorId in subsystemTuple.Component2.Values) { ComponentEntityTuple <VisitorPosition, ConsumeCPU> visitorTuple; if (_visitorMatcher.TryGetMatchingEntity(visitorId, out visitorTuple)) { sum += visitorTuple.Component2.Value; } } subsystemTuple.Component3.Value = RangeHelper.AssignWithinBounds(sum, 0, subsystemTuple.Component3.Maximum); } }
public void Tick() { foreach (var subsystemTuple in _subsystemMatcher.MatchingEntities) { var sum = subsystemTuple.Component3.Value; foreach (var itemContainer in subsystemTuple.Component2.Items) { ComponentEntityTuple <IItemType, ConsumeMemory> itemTuple; if (itemContainer.Item != null && _itemMatcher.TryGetMatchingEntity(itemContainer.Item.Value, out itemTuple)) { sum += itemTuple.Component2.Value; } } subsystemTuple.Component3.Value = RangeHelper.AssignWithinBounds(sum, 0, subsystemTuple.Component3.Maximum); } }
protected override bool TryHandleCommand(MoveItemCommand command, int currentTick, bool handlerEnabled) { if (_itemMatcherGroup.TryGetMatchingEntity(command.ItemId, out var itemTuple) && _subsystemMatcherGroup.TryGetMatchingEntity(command.SystemEntityId, out var subsystemTuple)) { var @event = new MoveItemCommandEvent() { ItemId = itemTuple.Entity.Id, ItemType = itemTuple.Component4.GetType().Name, PlayerEntityId = command.PlayerId, SubsystemEntityId = itemTuple.Component3.Value ?? -1 }; var source = subsystemTuple.Component2.Items[command.SourceContainerId]; var target = subsystemTuple.Component2.Items[command.DestinationContainerId]; @event.TargetContainerType = target.GetType().Name; if (handlerEnabled && itemTuple.Component2.Value == null && source != null && source.Item == itemTuple.Entity.Id && source.CanRelease && target != null && target.CanCapture(itemTuple.Entity.Id)) { target.Item = itemTuple.Entity.Id; source.Item = null; @event.Result = MoveItemCommandEvent.ActivationResult.Success; _eventSystem.Publish(@event); return(true); } @event.Result = handlerEnabled ? itemTuple.Component2.Value == null ? target.CanCapture(itemTuple.Entity.Id) ? MoveItemCommandEvent.ActivationResult.Error : MoveItemCommandEvent.ActivationResult.Failure_DestinationCannotCapture : MoveItemCommandEvent.ActivationResult.Failure_ItemAlreadyActive : MoveItemCommandEvent.ActivationResult.Failure_CommandDisabled; _eventSystem.Publish(@event); } return(false); }
public void OnPlayerDisconnected(int playerEntityId) { if (_playerMatcherGroup.TryGetMatchingEntity(playerEntityId, out var playerTuple) && playerTuple.Component3.Value.HasValue && playerTuple.Component2.TryGetItemContainer <InventoryItemContainer>(out var inventoryItemContainer) && inventoryItemContainer.Item.HasValue) { if (_subsystemMatcherGroup.TryGetMatchingEntity(playerTuple.Component3.Value.Value, out var subsystemTuple)) { if (TryHandleDisconectOnSubsystem(subsystemTuple, playerTuple, inventoryItemContainer) == false) { } } else if (_connectionMatcherGroup.TryGetMatchingEntity(playerTuple.Component3.Value.Value, out var connectionTuple)) { } } }
protected override bool TryHandleCommand(PickupItemCommand command, int currentTick, bool handlerEnabled) { if (_playerMatcherGroup.TryGetMatchingEntity(command.PlayerId, out var playerTuple) && _itemMatcherGroup.TryGetMatchingEntity(command.ItemId, out var itemTuple) && itemTuple.Component2.Value.HasValue == false && itemTuple.Component3.Value.HasValue && itemTuple.Component3.Value == playerTuple.Component3.Value && _subsystemMatcherGroup.TryGetMatchingEntity(itemTuple.Component3.Value.Value, out var subsystemTuple)) { var @event = new PickupItemEvent() { PlayerEntityId = command.PlayerId, ItemId = itemTuple.Entity.Id, ItemType = itemTuple.Component5.GetType().Name, SubsystemEntityId = itemTuple.Component3.Value ?? -1 }; var itemNotActive = itemTuple.Component4.ActivationState == ActivationState.NotActive; if (handlerEnabled && itemNotActive) { var inventory = playerTuple.Component2.Items[0] as InventoryItemContainer; var source = subsystemTuple.Component2.Items.SingleOrDefault(ic => ic.Item == itemTuple.Entity.Id); if (inventory != null && inventory.Item.HasValue == false && source != null && source.CanRelease) { inventory.Item = itemTuple.Entity.Id; itemTuple.Component2.Value = playerTuple.Entity.Id; itemTuple.Component3.Value = null; source.Item = null; @event.Result = PickupItemEvent.ActivationResult.Success; _eventSystem.Publish(@event); return(true); } } else { @event.Result = handlerEnabled ? PickupItemEvent.ActivationResult.Failure_ItemActive : PickupItemEvent.ActivationResult.Failure_CommandDisabled; _eventSystem.Publish(@event); } } return(false); }
private void OnPickupItemEvent(PickupItemEvent pickupItemEvent) { if (pickupItemEvent.Result == PickupItemEvent.ActivationResult.Success && _transferTiming.TryGetValue(pickupItemEvent.ItemId, out var transferEvent)) { if (pickupItemEvent.Tick - transferEvent.Tick <= TickWindow && _playerScoreMatcherGroup.TryGetMatchingEntity(transferEvent.PlayerEntityId, out var playerTuple)) { playerTuple.Component2.ResourceManagement += 1; } _transferTiming.Remove(pickupItemEvent.ItemId); } }
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); } } }
private void OnDeactivating(ComponentEntityTuple <Activation, Scanner, CurrentLocation, Owner> entityTuple) { if (entityTuple.Component3.Value.HasValue && _visitorsMatcherGroup.TryGetMatchingEntity(entityTuple.Component3.Value.Value, out var locationTuple) && _playerMatcherGroup.TryGetMatchingEntity(entityTuple.Component4.Value.Value, out var playerTuple)) { var malwareVisitors = locationTuple.Component2.Values .Join(_malwareMatcherGroup.MatchingEntities, k => k, k => k.Entity.Id, (o, i) => i) .ToArray(); // join the current locations list of visitors with all malware entities foreach (var malwareVisitor in malwareVisitors) { var @event = new ScannerActivationEvent { PlayerEntityId = entityTuple.Component4.Value.Value, SubsystemEntityId = locationTuple.Entity.Id, ActivationResult = (malwareVisitor.Component2.VisibleTo == 0 || (malwareVisitor.Component2.VisibleTo & playerTuple.Component2.Value) == 0) ? ScannerActivationEvent.ScannerActivationResult.VirusRevealed : ScannerActivationEvent.ScannerActivationResult.VirusAlreadyVisisble, }; _eventSystem.Publish(@event); // add the visible gene malwareVisitor.Component2.VisibleTo |= VisibleToAll ? MalwareVisibility.All : playerTuple.Component2.Value; } if (malwareVisitors.Length == 0) { var @event = new ScannerActivationEvent { PlayerEntityId = entityTuple.Component4.Value.Value, SubsystemEntityId = locationTuple.Entity.Id, ActivationResult = ScannerActivationEvent.ScannerActivationResult.NoVirusPresent, }; _eventSystem.Publish(@event); } } }
protected override bool TryHandleCommand(ActivateItemTypeCommand command, int currentTick, bool handlerEnabled) { if (handlerEnabled && command.ItemType == null || typeof(IItemType).IsAssignableFrom(command.ItemType) == false || (command.PlayerId.HasValue == false && command.LocationEntityId.HasValue == false)) { return(false); } if (command.PlayerId.HasValue && _playerSystem.TryGetPlayerEntityId(command.PlayerId.Value, out var playerEntityId) && command.LocationEntityId.HasValue == false && _playerMatcherGroup.TryGetMatchingEntity(playerEntityId, out var playerTuple) && playerTuple.Component2.Value.HasValue) { command.LocationEntityId = playerTuple.Component2.Value; } if (command.LocationEntityId.HasValue && _subsystemMatcherGroup.TryGetMatchingEntity(command.LocationEntityId.Value, out var subsystemTuple)) { foreach (var ic in subsystemTuple.Component2.Items.Where(ic => ic?.Item != null)) { if ( _activationMatcherGroup.TryGetMatchingEntity(ic.Item.Value, out var itemTuple) && itemTuple.Entity.TryGetComponent(command.ItemType, out var itemComponent) && // item is of correct type itemTuple.Component2.ActivationState == ActivationState.NotActive && // item is not active command.PlayerId.HasValue && _playerSystem.TryGetPlayerEntityId(command.PlayerId.Value, out playerEntityId) && (itemTuple.Component4.AllowAll || itemTuple.Component4.Value == null || itemTuple.Component4.Value == playerEntityId) && // player can activate item _activationMatcherGroup.MatchingEntities.Any(it => it.Component4.Value == playerEntityId && it.Component2.ActivationState != ActivationState.NotActive) == false) // player has no other active items { itemTuple.Component2.SetState(ActivationState.Activating, currentTick); itemTuple.Component4.Value = playerEntityId; return(true); } } } return(false); }
protected override bool TryHandleCommand(HideTextCommand command, int currentTick, bool handlerEnabled) { if (handlerEnabled) { if (command.TextEntityId.HasValue && _textMatcher.TryGetMatchingEntity(command.TextEntityId.Value, out var tuple)) { tuple.Entity.Dispose(); return(true); } else { foreach (var textTuple in _textMatcher.MatchingEntities.ToArray()) { textTuple.Entity.Dispose(); } return(true); } } return(false); }
protected override bool TryHandleCommand(SetActorDestinationCommand command, int currentTick, bool handlerEnabled) { // TODO: this logic sucks hard. var playerEntityId = -1; if (command.PlayerEntityId.HasValue) { playerEntityId = command.PlayerEntityId.Value; } else if (command.PlayerId.HasValue) { _playerSystem.TryGetPlayerEntityId(command.PlayerId.Value, out playerEntityId); } var @event = new SetActorDestinationEvent() { PlayerEntityId = command.PlayerEntityId ?? playerEntityId, DestinationEntityId = command.DestinationEntityId, }; if (playerEntityId >= 0 && handlerEnabled && _playerMatcherGroup.TryGetMatchingEntity(command.PlayerEntityId ?? playerEntityId, out var playerTuple) && _subsystemMatcherGroup.TryGetMatchingEntity(command.DestinationEntityId, out var subsystemTuple)) { playerTuple.Component2.Value = command.DestinationEntityId; @event.Result = SetActorDestinationEvent.CommandResult.Success; _eventSystem.Publish(@event); return(true); } if (handlerEnabled == false) { @event.Result = SetActorDestinationEvent.CommandResult.Failure_CommandDisabled; } _eventSystem.Publish(@event); return(false); }
protected override bool TryHandleCommand(PickupItemTypeCommand command, int currentTick, bool handlerEnabled) { if (command.ItemType == null || typeof(IItemType).IsAssignableFrom(command.ItemType) == false) { return(false); } if (_playerSystem.TryGetPlayerEntityId(command.PlayerId, out var playerEntityId) && _playerMatcherGroup.TryGetMatchingEntity(playerEntityId, out var playerTuple) && playerTuple.Component3.Value.HasValue && _subsystemMatcherGroup.TryGetMatchingEntity(playerTuple.Component3.Value.Value, out var subsystemTuple)) { foreach (var ic in subsystemTuple.Component2.Items.Where(ic => ic?.Item != null)) { if (_itemMatcherGroup.TryGetMatchingEntity(ic.Item.Value, out var itemTuple) && itemTuple.Entity.TryGetComponent(command.ItemType, out var itemComponent) && // item is of correct type itemTuple.Component2.ActivationState == ActivationState.NotActive && // item is not active (itemTuple.Component4.AllowAll || itemTuple.Component4.Value == null || itemTuple.Component4.Value == playerEntityId) && // player can activate item _itemMatcherGroup.MatchingEntities.Any(it => it.Component4.Value == playerEntityId && it.Component2.ActivationState != ActivationState.NotActive) == false) // player has no other active items { var inventory = playerTuple.Component2.Items[0] as InventoryItemContainer; if (inventory != null && inventory.Item.HasValue == false && ic.CanRelease) { inventory.Item = itemTuple.Entity.Id; itemTuple.Component4.Value = playerTuple.Entity.Id; itemTuple.Component3.Value = null; ic.Item = null; return(true); } } } } return(false); }