Esempio n. 1
0
        /// <summary>
        /// Give the user the rider component if they're buckling to the vehicle,
        /// otherwise remove it.
        /// </summary>
        private void OnBuckleChange(EntityUid uid, VehicleComponent component, BuckleChangeEvent args)
        {
            // Send an event that our vehicle buckle changed
            if (TryComp <MindComponent>(args.BuckledEntity, out var mind) && mind.Mind != null && mind.Mind.TryGetSession(out var session))
            {
                RaiseNetworkEvent(new BuckledToVehicleEvent(uid, args.BuckledEntity, args.Buckling), Filter.SinglePlayer(session));
            }

            if (args.Buckling)
            {
                // Add a virtual item to rider's hand, unbuckle if we can't.
                if (!_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.BuckledEntity))
                {
                    _riderSystem.UnbuckleFromVehicle(args.BuckledEntity);
                    return;
                }
                // Set up the rider and vehicle with each other
                EnsureComp <SharedPlayerInputMoverComponent>(uid);
                var rider = EnsureComp <RiderComponent>(args.BuckledEntity);
                component.Rider    = args.BuckledEntity;
                rider.Vehicle      = component;
                component.HasRider = true;

                // Handle pulling
                RemComp <SharedPullableComponent>(args.BuckledEntity);
                RemComp <SharedPullableComponent>(uid);

                // Let this open doors if it has the key in it
                if (component.HasKey)
                {
                    _tagSystem.AddTag(uid, "DoorBumpOpener");
                }
                // Update appearance stuff, add actions
                UpdateBuckleOffset(Transform(uid), component);
                UpdateDrawDepth(uid, GetDrawDepth(Transform(uid), component.NorthOnly));
                if (TryComp <ActionsComponent>(args.BuckledEntity, out var actions) && TryComp <UnpoweredFlashlightComponent>(uid, out var flashlight))
                {
                    _actionsSystem.AddAction(args.BuckledEntity, flashlight.ToggleAction, uid, actions);
                }
                if (component.HornSound != null)
                {
                    _actionsSystem.AddAction(args.BuckledEntity, component.HornAction, uid, actions);
                }
                _itemSlotsSystem.SetLock(uid, component.Name, true);
                return;
            }
            // Clean up actions and virtual items
            _actionsSystem.RemoveProvidedActions(args.BuckledEntity, uid);
            _virtualItemSystem.DeleteInHandsMatching(args.BuckledEntity, uid);
            // Go back to old pullable behavior
            _tagSystem.RemoveTag(uid, "DoorBumpOpener");
            EnsureComp <SharedPullableComponent>(args.BuckledEntity);
            EnsureComp <SharedPullableComponent>(uid);
            // Entity is no longer riding
            RemComp <RiderComponent>(args.BuckledEntity);
            // Reset component
            component.HasRider = false;
            component.Rider    = null;
            _itemSlotsSystem.SetLock(uid, component.Name, false);
        }
        /// <summary>
        /// Give the user the rider component if they're buckling to the vehicle,
        /// otherwise remove it.
        /// </summary>
        private void OnBuckleChange(EntityUid uid, VehicleComponent component, BuckleChangeEvent args)
        {
            // Add Rider
            if (args.Buckling)
            {
                // Add a virtual item to rider's hand, unbuckle if we can't.
                if (!_virtualItemSystem.TrySpawnVirtualItemInHand(uid, args.BuckledEntity))
                {
                    UnbuckleFromVehicle(args.BuckledEntity);
                    return;
                }

                // Set up the rider and vehicle with each other
                EnsureComp <InputMoverComponent>(uid);
                var rider = EnsureComp <RiderComponent>(args.BuckledEntity);
                component.Rider = args.BuckledEntity;

                var relay = EnsureComp <RelayInputMoverComponent>(args.BuckledEntity);
                relay.RelayEntity  = uid;
                rider.Vehicle      = uid;
                component.HasRider = true;

                // Update appearance stuff, add actions
                UpdateBuckleOffset(Transform(uid), component);
                UpdateDrawDepth(uid, GetDrawDepth(Transform(uid), component.NorthOnly));

                if (TryComp <ActionsComponent>(args.BuckledEntity, out var actions) && TryComp <UnpoweredFlashlightComponent>(uid, out var flashlight))
                {
                    _actionsSystem.AddAction(args.BuckledEntity, flashlight.ToggleAction, uid, actions);
                }

                if (component.HornSound != null)
                {
                    _actionsSystem.AddAction(args.BuckledEntity, component.HornAction, uid, actions);
                }

                return;
            }

            // Remove rider

            // Clean up actions and virtual items
            _actionsSystem.RemoveProvidedActions(args.BuckledEntity, uid);
            _virtualItemSystem.DeleteInHandsMatching(args.BuckledEntity, uid);

            // Entity is no longer riding
            RemComp <RiderComponent>(args.BuckledEntity);
            RemComp <RelayInputMoverComponent>(args.BuckledEntity);

            // Reset component
            component.HasRider = false;
            component.Rider    = null;
        }
        private void OnBuckleChange(EntityUid uid, StasisBedComponent component, BuckleChangeEvent args)
        {
            // In testing this also received an unbuckle event when the bed is destroyed
            // So don't worry about that
            if (!TryComp <SharedBodyComponent>(args.BuckledEntity, out var body))
            {
                return;
            }

            if (!this.IsPowered(uid, EntityManager))
            {
                return;
            }

            var metabolicEvent = new ApplyMetabolicMultiplierEvent()
            {
                Uid = args.BuckledEntity, Multiplier = component.Multiplier, Apply = args.Buckling
            };

            RaiseLocalEvent(args.BuckledEntity, metabolicEvent, false);
        }
        private void ManageUpdateList(EntityUid uid, HealOnBuckleComponent component, BuckleChangeEvent args)
        {
            _prototypeManager.TryIndex <InstantActionPrototype>("Sleep", out var sleepAction);
            if (args.Buckling)
            {
                AddComp <HealOnBuckleHealingComponent>(uid);
                if (sleepAction != null)
                {
                    _actionsSystem.AddAction(args.BuckledEntity, new InstantAction(sleepAction), null);
                }
                return;
            }

            if (sleepAction != null)
            {
                _actionsSystem.RemoveAction(args.BuckledEntity, sleepAction, null);
            }

            _sleepingSystem.TryWaking(args.BuckledEntity);
            RemComp <HealOnBuckleHealingComponent>(uid);
            component.Accumulator = 0;
        }
Esempio n. 5
0
        private void ManageUpdateList(EntityUid uid, HealOnBuckleComponent component, BuckleChangeEvent args)
        {
            if (args.Buckling)
            {
                AddComp <HealOnBuckleHealingComponent>(uid);
                return;
            }

            RemComp <HealOnBuckleHealingComponent>(uid);
            component.Accumulator = 0;
        }