コード例 #1
0
        /// <summary>
        ///     If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
        /// </summary>
        /// <param name="session"></param>
        public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return;
            }

            if (storageComp.StoredEntities == null)
            {
                return;
            }

            // for each containing thing
            // if it has a storage comp
            // ensure unsubscribe from session
            // if it has a ui component
            // close ui
            foreach (var entity in storageComp.StoredEntities)
            {
                if (TryComp(entity, out ServerStorageComponent? storedStorageComp))
                {
                    DebugTools.Assert(storedStorageComp != storageComp, $"Storage component contains itself!? Entity: {uid}");
                }

                if (TryComp(entity, out ServerUserInterfaceComponent? uiComponent))
                {
                    foreach (var ui in uiComponent.Interfaces)
                    {
                        ui.Close(session);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Move entities from one storage to another.
        /// </summary>
        public void TransferEntities(EntityUid source, EntityUid target,
                                     ServerStorageComponent?sourceComp = null, LockComponent?sourceLock = null,
                                     ServerStorageComponent?targetComp = null, LockComponent?targetLock = null)
        {
            if (!Resolve(source, ref sourceComp) || !Resolve(target, ref targetComp))
            {
                return;
            }

            var entities = sourceComp.Storage?.ContainedEntities;

            if (entities == null || entities.Count == 0)
            {
                return;
            }

            if (Resolve(source, ref sourceLock, false) && sourceLock.Locked ||
                Resolve(target, ref targetLock, false) && targetLock.Locked)
            {
                return;
            }

            foreach (var entity in entities.ToList())
            {
                Insert(target, entity, targetComp);
            }
            RecalculateStorageUsed(sourceComp);
            UpdateStorageUI(source, sourceComp);
        }
コード例 #3
0
    private void UpdateAppearance(EntityUid uid, ServerStorageComponent? storage = null, AppearanceComponent? appearance = null,
        StorageFillVisualizerComponent? component = null)
    {
        if (!Resolve(uid, ref storage, ref appearance, ref component, false))
            return;

        if (component.MaxFillLevels < 1)
            return;

        var level = ContentHelpers.RoundToEqualLevels(storage.StorageUsed, storage.StorageCapacityMax, component.MaxFillLevels);
        appearance.SetData(StorageFillVisuals.FillLevel, level);
    }
コード例 #4
0
        // REMOVE: remove and drop on the ground
        public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return(false);
            }

            var itemRemoved = storageComp.Storage?.Remove(removeEnt) == true;

            if (itemRemoved)
            {
                RecalculateStorageUsed(storageComp);
            }

            return(itemRemoved);
        }
コード例 #5
0
        /// <summary>
        ///     Verifies if an entity can be stored and if it fits
        /// </summary>
        /// <param name="entity">The entity to check</param>
        /// <param name="reason">If returning false, the reason displayed to the player</param>
        /// <returns>true if it can be inserted, false otherwise</returns>
        public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string?reason, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                reason = null;
                return(false);
            }

            if (TryComp(insertEnt, out ServerStorageComponent? storage) &&
                storage.StorageCapacityMax >= storageComp.StorageCapacityMax)
            {
                reason = "comp-storage-insufficient-capacity";
                return(false);
            }

            if (TryComp(insertEnt, out ItemComponent? itemComp) &&
                itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed)
            {
                reason = "comp-storage-insufficient-capacity";
                return(false);
            }

            if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false)
            {
                reason = "comp-storage-invalid-container";
                return(false);
            }

            if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true)
            {
                reason = "comp-storage-invalid-container";
                return(false);
            }

            if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored)
            {
                reason = "comp-storage-anchored-failure";
                return(false);
            }

            reason = null;
            return(true);
        }
コード例 #6
0
        /// <summary>
        ///     Opens the storage UI for an entity
        /// </summary>
        /// <param name="entity">The entity to open the UI for</param>
        public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return;
            }

            if (!TryComp(entity, out ActorComponent? player))
            {
                return;
            }

            if (storageComp.StorageOpenSound is not null)
            {
                SoundSystem.Play(storageComp.StorageOpenSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, storageComp.StorageOpenSound.Params);
            }

            Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");

            _uiSystem.GetUiOrNull(uid, StorageUiKey.Key)?.Open(player.PlayerSession);
        }
コード例 #7
0
        /// <summary>
        ///     Inserts into the storage container
        /// </summary>
        /// <param name="entity">The entity to insert</param>
        /// <returns>true if the entity was inserted, false otherwise</returns>
        public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return(false);
            }

            if (!CanInsert(uid, insertEnt, out _, storageComp) || storageComp.Storage?.Insert(insertEnt) == false)
            {
                return(false);
            }

            if (storageComp.StorageInsertSound is not null)
            {
                SoundSystem.Play(storageComp.StorageInsertSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, AudioParams.Default);
            }

            RecalculateStorageUsed(storageComp);
            UpdateStorageUI(uid, storageComp);
            return(true);
        }
コード例 #8
0
        /// <summary>
        ///     Inserts an entity into storage from the player's active hand
        /// </summary>
        /// <param name="player">The player to insert an entity from</param>
        /// <returns>true if inserted, false otherwise</returns>
        public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return(false);
            }

            if (!TryComp(player, out HandsComponent? hands) ||
                hands.ActiveHandEntity == null)
            {
                return(false);
            }

            var toInsert = hands.ActiveHandEntity;

            if (!CanInsert(uid, toInsert.Value, out var reason, storageComp) || !_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands))
            {
                Popup(uid, player, reason ?? "comp-storage-cant-insert", storageComp);
                return(false);
            }

            return(PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp));
        }
コード例 #9
0
        /// <summary>
        ///     Verifies if an entity can be stored and if it fits
        /// </summary>
        /// <param name="entity">The entity to check</param>
        /// <returns>true if it can be inserted, false otherwise</returns>
        public bool CanInsert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return(false);
            }

            if (TryComp(insertEnt, out ServerStorageComponent? storage) &&
                storage.StorageCapacityMax >= storageComp.StorageCapacityMax)
            {
                return(false);
            }

            if (TryComp(insertEnt, out SharedItemComponent? itemComp) &&
                itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed)
            {
                return(false);
            }

            if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false)
            {
                return(false);
            }

            if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true)
            {
                return(false);
            }

            if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored)
            {
                return(false);
            }

            return(true);
        }
コード例 #10
0
        /// <summary>
        ///     Try to insert all light bulbs from storage (for example light tubes box)
        /// </summary>
        /// <returns>
        ///     Returns true if storage contained at least one light bulb
        ///     which was successfully inserted inside light replacer
        /// </returns>
        public bool TryInsertBulbsFromStorage(EntityUid replacerUid, EntityUid storageUid, EntityUid?userUid = null,
                                              LightReplacerComponent?replacer = null, ServerStorageComponent?storage = null)
        {
            if (!Resolve(replacerUid, ref replacer))
            {
                return(false);
            }
            if (!Resolve(storageUid, ref storage))
            {
                return(false);
            }

            if (storage.StoredEntities == null)
            {
                return(false);
            }

            var insertedBulbs = 0;
            var storagedEnts  = storage.StoredEntities.ToArray();

            foreach (var ent in storagedEnts)
            {
                if (EntityManager.TryGetComponent(ent, out LightBulbComponent? bulb))
                {
                    if (TryInsertBulb(replacerUid, ent, userUid, false, replacer, bulb))
                    {
                        insertedBulbs++;
                    }
                }
            }

            // show some message if success
            if (insertedBulbs > 0 && userUid != null)
            {
                var msg = Loc.GetString("comp-light-replacer-refill-from-storage", ("light-replacer", storage.Owner));
                _popupSystem.PopupEntity(msg, replacerUid, Filter.Entities(userUid.Value));
            }

            return(insertedBulbs > 0);
        }
コード例 #11
0
        /// <summary>
        ///     Inserts an Entity (<paramref name="toInsert"/>) in the world into storage, informing <paramref name="player"/> if it fails.
        ///     <paramref name="toInsert"/> is *NOT* held, see <see cref="PlayerInsertHeldEntity(Robust.Shared.GameObjects.EntityUid)"/>.
        /// </summary>
        /// <param name="player">The player to insert an entity with</param>
        /// <returns>true if inserted, false otherwise</returns>
        public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, ServerStorageComponent?storageComp = null)
        {
            if (!Resolve(uid, ref storageComp))
            {
                return(false);
            }

            if (!_sharedInteractionSystem.InRangeUnobstructed(player, uid, popup: storageComp.ShowPopup))
            {
                return(false);
            }

            if (!Insert(uid, toInsert, storageComp))
            {
                Popup(uid, player, "comp-storage-cant-insert", storageComp);
                return(false);
            }
            return(true);
        }