예제 #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);
        }
예제 #2
0
        private void OnMindAdded(EntityUid uid, DroneComponent drone, MindAddedMessage args)
        {
            UpdateDroneAppearance(uid, DroneStatus.On);
            _tagSystem.AddTag(uid, "DoorBumpOpener");
            _popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid, Filter.Pvs(uid));

            if (drone.AlreadyAwoken == false)
            {
                var spawnCoord = Transform(uid).Coordinates;

                if (drone.Tools.Count == 0)
                {
                    return;
                }

                if (TryComp <HandsComponent>(uid, out var hands) && hands.Count >= drone.Tools.Count)
                {
                    foreach (var entry in drone.Tools)
                    {
                        var item = EntityManager.SpawnEntity(entry.PrototypeId, spawnCoord);
                        AddComp <UnremoveableComponent>(item);
                        hands.PutInHand(item);
                        drone.ToolUids.Add(item);
                    }
                }

                drone.AlreadyAwoken = true;
            }
        }
        /// <summary>
        /// Handle adding keys to the ignition, give stuff the InVehicleComponent so it can't be picked
        /// up by people not in the vehicle.
        /// </summary>
        private void OnEntInserted(EntityUid uid, VehicleComponent component, EntInsertedIntoContainerMessage args)
        {
            if (args.Container.ID != KeySlot ||
                !_tagSystem.HasTag(args.Entity, "VehicleKey"))
            {
                return;
            }

            // Enable vehicle
            var inVehicle = AddComp <InVehicleComponent>(args.Entity);

            inVehicle.Vehicle = component;

            component.HasKey = true;

            // Audiovisual feedback
            _ambientSound.SetAmbience(uid, true);
            _tagSystem.AddTag(uid, "DoorBumpOpener");
            _modifier.RefreshMovementSpeedModifiers(uid);
        }