public IEnumerable <(EntityUid, IPhysBody)> GetEntitiesToMove(ConveyorComponent comp) { //todo uuuhhh cache this foreach (var entity in _entityLookup.GetEntitiesIntersecting(comp.Owner, flags: LookupFlags.Approximate)) { if (Deleted(entity)) { continue; } if (entity == comp.Owner) { continue; } if (!EntityManager.TryGetComponent(entity, out IPhysBody? physics) || physics.BodyType == BodyType.Static || physics.BodyStatus == BodyStatus.InAir || entity.IsWeightless()) { continue; } if (EntityManager.HasComponent <IMapGridComponent>(entity)) { continue; } if (entity.IsInContainer()) { continue; } yield return(entity, physics); } }
/// <summary> /// Calculates the angle in which entities on top of this conveyor /// belt are pushed in /// </summary> /// <returns> /// The angle when taking into account if the conveyor is reversed /// </returns> public Angle GetAngle(ConveyorComponent component) { var adjustment = component.State == ConveyorState.Reversed ? MathHelper.Pi / 2 : -MathHelper.Pi / 2; var radians = MathHelper.DegreesToRadians(component.Angle); return(new Angle(EntityManager.GetComponent <TransformComponent>(component.Owner).LocalRotation.Theta + radians + adjustment)); }
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args) { switch (args.Port) { case "state": SetState(component, (TwoWayLeverSignal)args.Value !); break; } }
private void OnLinkAttempt(EntityUid uid, ConveyorComponent component, LinkAttemptEvent args) { if (args.TransmitterComponent.Outputs.GetPort(args.TransmitterPort).Signal is TwoWayLeverSignal signal && signal != TwoWayLeverSignal.Middle) { args.Cancel(); _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true); component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link")); } }
private void UpdateAppearance(ConveyorComponent component) { if (!EntityManager.TryGetComponent <AppearanceComponent?>(component.Owner, out var appearance)) { return; } var isPowered = this.IsPowered(component.Owner, EntityManager); appearance.SetData(ConveyorVisuals.State, isPowered ? component.State : ConveyorState.Off); }
private void SetState(ConveyorComponent component, TwoWayLeverSignal signal) { component.State = signal switch { TwoWayLeverSignal.Left => ConveyorState.Reversed, TwoWayLeverSignal.Middle => ConveyorState.Off, TwoWayLeverSignal.Right => ConveyorState.Forward, _ => ConveyorState.Off }; UpdateAppearance(component); }
private void UpdateAppearance(ConveyorComponent component) { if (component.Owner.TryGetComponent <AppearanceComponent>(out var appearance)) { if (component.Owner.TryGetComponent <ApcPowerReceiverComponent>(out var receiver) && receiver.Powered) { appearance.SetData(ConveyorVisuals.State, component.State); } else { appearance.SetData(ConveyorVisuals.State, ConveyorState.Off); } }
private void OnLinkAttempt(EntityUid uid, ConveyorComponent component, LinkAttemptEvent args) { if (args.TransmitterComponent.Outputs.GetPort(args.TransmitterPort).Signal is TwoWayLeverSignal signal && signal != TwoWayLeverSignal.Middle) { args.Cancel(); if (args.Attemptee.TryGetComponent <StunnableComponent>(out var stunnableComponent)) { stunnableComponent.Paralyze(2); component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link")); } } }
private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args) { if (args.Port == component.OffPort) { SetState(component, ConveyorState.Off); } else if (args.Port == component.ForwardPort) { SetState(component, ConveyorState.Forward); } else if (args.Port == component.ReversePort) { SetState(component, ConveyorState.Reverse); } }
private void SetState(ConveyorComponent component, ConveyorState state) { component.State = state; if (TryComp <RecyclerComponent>(component.Owner, out var recycler)) { if (component.State != ConveyorState.Off) { _recycler.EnableRecycler(recycler); } else { _recycler.DisableRecycler(recycler); } } UpdateAppearance(component); }
public bool CanRun(ConveyorComponent component) { if (component.State == ConveyorState.Off) { return(false); } if (EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) && !receiver.Powered) { return(false); } if (EntityManager.HasComponent <ItemComponent>(component.Owner)) { return(false); } return(true); }
private void SetState(ConveyorComponent component, TwoWayLeverSignal signal) { component.State = signal switch { TwoWayLeverSignal.Left => ConveyorState.Reversed, TwoWayLeverSignal.Middle => ConveyorState.Off, TwoWayLeverSignal.Right => ConveyorState.Forward, _ => ConveyorState.Off }; if (TryComp <RecyclerComponent>(component.Owner, out var recycler)) { if (component.State != ConveyorState.Off) { _recycler.EnableRecycler(recycler); } else { _recycler.DisableRecycler(recycler); } } UpdateAppearance(component); }
private void OnPortDisconnected(EntityUid uid, ConveyorComponent component, PortDisconnectedEvent args) { SetState(component, TwoWayLeverSignal.Middle); }
private void OnPowerChanged(EntityUid uid, ConveyorComponent component, PowerChangedEvent args) { UpdateAppearance(component); }
public bool CanRun(ConveyorComponent component) { return(component.State != ConveyorState.Off && !EntityManager.HasComponent <SharedItemComponent>(component.Owner) && this.IsPowered(component.Owner, EntityManager)); }
private void OnInit(EntityUid uid, ConveyorComponent component, ComponentInit args) { _signalSystem.EnsureReceiverPorts(uid, component.ReversePort, component.ForwardPort, component.OffPort); }