コード例 #1
0
        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);
            }
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
 private void OnSignalReceived(EntityUid uid, ConveyorComponent component, SignalReceivedEvent args)
 {
     switch (args.Port)
     {
     case "state":
         SetState(component, (TwoWayLeverSignal)args.Value !);
         break;
     }
 }
コード例 #4
0
 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"));
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 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);
 }
コード例 #7
0
 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);
         }
     }
コード例 #8
0
 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"));
         }
     }
 }
コード例 #9
0
 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);
     }
 }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
 private void OnPortDisconnected(EntityUid uid, ConveyorComponent component, PortDisconnectedEvent args)
 {
     SetState(component, TwoWayLeverSignal.Middle);
 }
コード例 #14
0
 private void OnPowerChanged(EntityUid uid, ConveyorComponent component, PowerChangedEvent args)
 {
     UpdateAppearance(component);
 }
コード例 #15
0
 public bool CanRun(ConveyorComponent component)
 {
     return(component.State != ConveyorState.Off &&
            !EntityManager.HasComponent <SharedItemComponent>(component.Owner) &&
            this.IsPowered(component.Owner, EntityManager));
 }
コード例 #16
0
 private void OnInit(EntityUid uid, ConveyorComponent component, ComponentInit args)
 {
     _signalSystem.EnsureReceiverPorts(uid, component.ReversePort, component.ForwardPort, component.OffPort);
 }