using Content.Server.Popups; using Content.Server.Storage.Components; using Content.Shared.Destructible; using Content.Shared.Hands.Components; using Content.Shared.Hands.EntitySystems; using Content.Shared.Item; using Robust.Shared.Containers; using Robust.Shared.Player; namespace Content.Server.Storage.EntitySystems { public sealed class SecretStashSystem : EntitySystem { [Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedContainerSystem _containerSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnDestroyed); } private void OnInit(EntityUid uid, SecretStashComponent component, ComponentInit args) { component.ItemContainer = _containerSystem.EnsureContainer(uid, "stash", out _); } private void OnDestroyed(EntityUid uid, SecretStashComponent component, DestructionEventArgs args) { component.ItemContainer.EmptyContainer(); } /// /// Is there something inside secret stash item container? /// public bool HasItemInside(EntityUid uid, SecretStashComponent? component = null) { if (!Resolve(uid, ref component)) return false; return component.ItemContainer.ContainedEntity != null; } /// /// Tries to hide item inside secret stash from hands of user. /// /// True if item was hidden inside stash public bool TryHideItem(EntityUid uid, EntityUid userUid, EntityUid itemToHideUid, SecretStashComponent? component = null, ItemComponent? item = null, MetaDataComponent? itemMeta = null, SharedHandsComponent? hands = null) { if (!Resolve(uid, ref component)) return false; if (!Resolve(itemToHideUid, ref item, ref itemMeta)) return false; if (!Resolve(userUid, ref hands)) return false; // check if secret stash is already occupied var container = component.ItemContainer; if (container.ContainedEntity != null) { var msg = Loc.GetString("comp-secret-stash-action-hide-container-not-empty"); _popupSystem.PopupEntity(msg, uid, userUid); return false; } // check if item is too big to fit into secret stash var itemName = itemMeta.EntityName; if (item.Size > component.MaxItemSize) { var msg = Loc.GetString("comp-secret-stash-action-hide-item-too-big", ("item", itemName), ("stash", GetSecretPartName(uid, component))); _popupSystem.PopupEntity(msg, uid, userUid); return false; } // try to move item from hands to stash container if (!_handsSystem.TryDropIntoContainer(userUid, itemToHideUid, container)) { return false; } // all done, show success message var successMsg = Loc.GetString("comp-secret-stash-action-hide-success", ("item", itemName), ("this", GetSecretPartName(uid, component))); _popupSystem.PopupEntity(successMsg, uid, userUid); return true; } /// /// Try get item and place it in users hand. /// If user can't take it by hands, will drop item from container. /// /// True if user received item public bool TryGetItem(EntityUid uid, EntityUid userUid, SecretStashComponent? component = null, SharedHandsComponent? hands = null) { if (!Resolve(uid, ref component)) return false; if (!Resolve(userUid, ref hands)) return false; // check if secret stash has something inside var container = component.ItemContainer; if (container.ContainedEntity == null) { return false; } _handsSystem.PickupOrDrop(userUid, container.ContainedEntity.Value, handsComp: hands); // show success message var successMsg = Loc.GetString("comp-secret-stash-action-get-item-found-something", ("stash", GetSecretPartName(uid, component))); _popupSystem.PopupEntity(successMsg, uid, userUid); return true; } private string GetSecretPartName(EntityUid uid, SecretStashComponent stash) { if (stash.SecretPartName != "") return Loc.GetString(stash.SecretPartName); var meta = EntityManager.GetComponent(uid); var entityName = Loc.GetString("comp-secret-stash-secret-part-name", ("name", meta.EntityName)); return entityName; } } }