using Content.Server.Storage.EntitySystems; using Content.Shared.Clothing.Components; using Content.Shared.Explosion; using Content.Shared.Interaction.Events; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; using Content.Shared.Storage; namespace Content.Server.Inventory { public sealed class ServerInventorySystem : InventorySystem { [Dependency] private readonly StorageSystem _storageSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnExploded); SubscribeLocalEvent(OnUseInHand); SubscribeNetworkEvent(OnOpenSlotStorage); } private void OnExploded(Entity ent, ref BeforeExplodeEvent args) { // explode each item in their inventory too var slots = new InventorySlotEnumerator(ent); while (slots.MoveNext(out var slot)) { if (slot.ContainedEntity != null) args.Contents.Add(slot.ContainedEntity.Value); } } private void OnUseInHand(EntityUid uid, ClothingComponent component, UseInHandEvent args) { if (args.Handled || !component.QuickEquip) return; QuickEquip(uid, component, args); } private void OnOpenSlotStorage(OpenSlotStorageNetworkMessage ev, EntitySessionEventArgs args) { if (args.SenderSession.AttachedEntity is not { Valid: true } uid) return; if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp(entityUid, out var storageComponent)) { _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent); } } public void TransferEntityInventories(Entity source, Entity target) { if (!Resolve(source.Owner, ref source.Comp) || !Resolve(target.Owner, ref target.Comp)) return; var enumerator = new InventorySlotEnumerator(source.Comp); while (enumerator.NextItem(out var item, out var slot)) { if (TryUnequip(source, slot.Name, true, true, inventory: source.Comp)) TryEquip(target, item, slot.Name , true, true, inventory: target.Comp); } } } }