diff --git a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs index 292759dc87..be45e57c8b 100644 --- a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs +++ b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs @@ -5,6 +5,7 @@ using Content.Shared.CrewManifest; using Robust.Client.GameObjects; using Robust.Shared.Prototypes; using static Content.Shared.Access.Components.IdCardConsoleComponent; + namespace Content.Client.Access.UI { public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface diff --git a/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs b/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs index 3f7f1e73ee..8f3b507c80 100644 --- a/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs +++ b/Content.Client/Atmos/Monitor/UI/AirAlarmBoundUserInterface.cs @@ -48,7 +48,7 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface { SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data)); } - + private void OnDeviceDataCopied(IAtmosDeviceData data) { SendMessage(new AirAlarmCopyDeviceDataMessage(data)); diff --git a/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs b/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs index 23850cb25a..1664c8b9d7 100644 --- a/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs +++ b/Content.Client/Atmos/UI/GasThermomachineBoundUserInterface.cs @@ -19,7 +19,7 @@ namespace Content.Client.Atmos.UI [ViewVariables] private float _maxTemp = 0.0f; - + [ViewVariables] private bool _isHeater = true; diff --git a/Content.Client/Interactable/InteractionSystem.cs b/Content.Client/Interactable/InteractionSystem.cs index bb8ca89576..cdfd3aa54f 100644 --- a/Content.Client/Interactable/InteractionSystem.cs +++ b/Content.Client/Interactable/InteractionSystem.cs @@ -1,5 +1,5 @@ -using Content.Client.Storage; using Content.Shared.Interaction; +using Content.Shared.Storage; using Robust.Shared.Containers; namespace Content.Client.Interactable @@ -14,7 +14,7 @@ namespace Content.Client.Interactable if (!target.TryGetContainer(out var container)) return false; - if (!TryComp(container.Owner, out ClientStorageComponent? storage)) + if (!TryComp(container.Owner, out StorageComponent? storage)) return false; // we don't check if the user can access the storage entity itself. This should be handed by the UI system. diff --git a/Content.Client/Inventory/ClientInventorySystem.cs b/Content.Client/Inventory/ClientInventorySystem.cs index e74df5d570..d6a487f3fd 100644 --- a/Content.Client/Inventory/ClientInventorySystem.cs +++ b/Content.Client/Inventory/ClientInventorySystem.cs @@ -1,6 +1,5 @@ using Content.Client.Clothing; using Content.Client.Examine; -using Content.Client.Storage; using Content.Client.UserInterface.Controls; using Content.Client.Verbs.UI; using Content.Shared.Clothing.Components; @@ -9,6 +8,7 @@ using Content.Shared.Interaction; using Content.Shared.Interaction.Events; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; +using Content.Shared.Storage; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.Player; @@ -101,7 +101,7 @@ namespace Content.Client.Inventory if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity) return; var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot, - HasComp(args.Equipment)); + HasComp(args.Equipment)); OnSpriteUpdate?.Invoke(update); } diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs deleted file mode 100644 index 19fa84b24f..0000000000 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Content.Client.Animations; -using Content.Shared.DragDrop; -using Content.Shared.Storage; - -namespace Content.Client.Storage -{ - /// - /// Client version of item storage containers, contains a UI which displays stored entities and their size - /// - [RegisterComponent] - [ComponentReference(typeof(SharedStorageComponent))] - public sealed partial class ClientStorageComponent : SharedStorageComponent - { - private List _storedEntities = new(); - public override IReadOnlyList StoredEntities => _storedEntities; - - public override bool Remove(EntityUid entity) - { - return false; - } - } -} diff --git a/Content.Client/Storage/StorageBoundUserInterface.cs b/Content.Client/Storage/StorageBoundUserInterface.cs index 25024aa8c5..1842417a6e 100644 --- a/Content.Client/Storage/StorageBoundUserInterface.cs +++ b/Content.Client/Storage/StorageBoundUserInterface.cs @@ -4,12 +4,13 @@ using Content.Client.UserInterface.Controls; using Content.Client.Verbs.UI; using Content.Shared.Input; using Content.Shared.Interaction; +using Content.Shared.Storage; using JetBrains.Annotations; using Robust.Client.GameObjects; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Shared.Input; -using static Content.Shared.Storage.SharedStorageComponent; +using static Content.Shared.Storage.StorageComponent; namespace Content.Client.Storage { @@ -19,8 +20,11 @@ namespace Content.Client.Storage [ViewVariables] private StorageWindow? _window; + [Dependency] private readonly IEntityManager _entManager = default!; + public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { + IoCManager.InjectDependencies(this); } protected override void Open() @@ -29,17 +33,22 @@ namespace Content.Client.Storage if (_window == null) { - _window = new StorageWindow(EntMan) - { - Title = EntMan.GetComponent(Owner).EntityName - }; + // TODO: This is a bit of a mess but storagecomponent got moved to shared and cleaned up a bit. + var controller = IoCManager.Resolve().GetUIController(); + _window = controller.EnsureStorageWindow(Owner); + _window.Title = EntMan.GetComponent(Owner).EntityName; _window.EntityList.GenerateItem += _window.GenerateButton; _window.EntityList.ItemPressed += InteractWithItem; _window.StorageContainerButton.OnPressed += TouchedContainerButton; _window.OnClose += Close; - _window.OpenCenteredLeft(); + + if (EntMan.TryGetComponent(Owner, out var storageComp)) + { + BuildEntityList(Owner, storageComp); + } + } else { @@ -47,6 +56,11 @@ namespace Content.Client.Storage } } + public void BuildEntityList(EntityUid uid, StorageComponent component) + { + _window?.BuildEntityList(uid, component); + } + public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData) { if (cData is not EntityListData { Uid: var entity }) @@ -54,7 +68,7 @@ namespace Content.Client.Storage if (args.Event.Function == EngineKeyFunctions.UIClick) { - SendMessage(new StorageInteractWithItemEvent(EntMan.GetNetEntity(entity))); + SendPredictedMessage(new StorageInteractWithItemEvent(_entManager.GetNetEntity(entity))); } else if (EntMan.EntityExists(entity)) { @@ -92,17 +106,7 @@ namespace Content.Client.Storage public void TouchedContainerButton(BaseButton.ButtonEventArgs args) { - SendMessage(new StorageInsertItemMessage()); - } - - protected override void UpdateState(BoundUserInterfaceState state) - { - base.UpdateState(state); - - if (_window == null || state is not StorageBoundUserInterfaceState cast) - return; - - _window?.BuildEntityList(cast); + SendPredictedMessage(new StorageInsertItemMessage()); } protected override void Dispose(bool disposing) @@ -113,14 +117,13 @@ namespace Content.Client.Storage if (_window != null) { + _window.Orphan(); _window.EntityList.GenerateItem -= _window.GenerateButton; _window.EntityList.ItemPressed -= InteractWithItem; _window.StorageContainerButton.OnPressed -= TouchedContainerButton; _window.OnClose -= Close; + _window = null; } - - _window?.Dispose(); - _window = null; } } } diff --git a/Content.Client/Storage/Systems/StorageSystem.cs b/Content.Client/Storage/Systems/StorageSystem.cs index 27fbfe651e..725c79ffc6 100644 --- a/Content.Client/Storage/Systems/StorageSystem.cs +++ b/Content.Client/Storage/Systems/StorageSystem.cs @@ -1,11 +1,17 @@ using Content.Client.Animations; using Content.Shared.Storage; +using Content.Shared.Storage.EntitySystems; +using Robust.Shared.Timing; namespace Content.Client.Storage.Systems; // TODO kill this is all horrid. -public sealed class StorageSystem : EntitySystem +public sealed class StorageSystem : SharedStorageSystem { + [Dependency] private readonly IGameTiming _timing = default!; + + public event Action? StorageUpdated; + public override void Initialize() { base.Initialize(); @@ -13,22 +19,24 @@ public sealed class StorageSystem : EntitySystem SubscribeNetworkEvent(HandleAnimatingInsertingEntities); } + public override void UpdateUI(EntityUid uid, StorageComponent component) + { + // Should we wrap this in some prediction call maybe? + StorageUpdated?.Invoke(uid, component); + } + /// /// Animate the newly stored entities in flying towards this storage's position /// /// public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg) { - var store = GetEntity(msg.Storage); - - if (!HasComp(store)) - return; - - TryComp(store, out TransformComponent? transformComp); + TryComp(GetEntity(msg.Storage), out TransformComponent? transformComp); for (var i = 0; msg.StoredEntities.Count > i; i++) { var entity = GetEntity(msg.StoredEntities[i]); + var initialPosition = msg.EntityPositions[i]; if (EntityManager.EntityExists(entity) && transformComp != null) { diff --git a/Content.Client/Storage/UI/StorageUIController.cs b/Content.Client/Storage/UI/StorageUIController.cs new file mode 100644 index 0000000000..9fc7909c34 --- /dev/null +++ b/Content.Client/Storage/UI/StorageUIController.cs @@ -0,0 +1,60 @@ +using Content.Client.Storage.Systems; +using Content.Shared.Storage; +using Robust.Client.UserInterface.Controllers; + +namespace Content.Client.Storage.UI; + +public sealed class StorageUIController : UIController, IOnSystemChanged +{ + // This is mainly to keep legacy functionality for now. + private readonly Dictionary _storageWindows = new(); + + public override void Initialize() + { + base.Initialize(); + EntityManager.EventBus.SubscribeLocalEvent(OnStorageShutdown); + } + public StorageWindow EnsureStorageWindow(EntityUid uid) + { + if (_storageWindows.TryGetValue(uid, out var window)) + { + UIManager.WindowRoot.AddChild(window); + return window; + } + + window = new StorageWindow(EntityManager); + _storageWindows[uid] = window; + window.OpenCenteredLeft(); + return window; + } + + private void OnStorageShutdown(EntityUid uid, StorageComponent component, ComponentShutdown args) + { + if (!_storageWindows.TryGetValue(uid, out var window)) + return; + + _storageWindows.Remove(uid); + window.Dispose(); + } + + private void OnStorageUpdate(EntityUid uid, StorageComponent component) + { + if (EntityManager.TryGetComponent(uid, out var uiComp) && + uiComp.OpenInterfaces.TryGetValue(StorageComponent.StorageUiKey.Key, out var bui)) + { + var storageBui = (StorageBoundUserInterface) bui; + + storageBui.BuildEntityList(uid, component); + } + } + + public void OnSystemLoaded(StorageSystem system) + { + system.StorageUpdated += OnStorageUpdate; + } + + public void OnSystemUnloaded(StorageSystem system) + { + system.StorageUpdated -= OnStorageUpdate; + } +} diff --git a/Content.Client/Storage/UI/StorageWindow.cs b/Content.Client/Storage/UI/StorageWindow.cs index 9ea60aa03c..62c0615a4b 100644 --- a/Content.Client/Storage/UI/StorageWindow.cs +++ b/Content.Client/Storage/UI/StorageWindow.cs @@ -8,7 +8,9 @@ using Content.Client.UserInterface.Controls; using Content.Shared.IdentityManagement; using Content.Shared.Item; using Content.Shared.Stacks; +using Content.Shared.Storage; using Robust.Client.UserInterface; +using Robust.Shared.Containers; using static Robust.Client.UserInterface.Controls.BoxContainer; using static Content.Shared.Storage.SharedStorageComponent; using Direction = Robust.Shared.Maths.Direction; @@ -18,9 +20,9 @@ namespace Content.Client.Storage.UI /// /// GUI class for client storage component /// - public sealed class StorageWindow : DefaultWindow + public sealed class StorageWindow : FancyWindow { - private IEntityManager _entityManager; + private readonly IEntityManager _entityManager; private readonly Label _information; public readonly ContainerButton StorageContainerButton; @@ -41,7 +43,7 @@ namespace Content.Client.Storage.UI MouseFilter = MouseFilterMode.Pass, }; - Contents.AddChild(StorageContainerButton); + ContentsContainer.AddChild(StorageContainerButton); var innerContainerButton = new PanelContainer { @@ -54,6 +56,7 @@ namespace Content.Client.Storage.UI { Orientation = LayoutOrientation.Vertical, MouseFilter = MouseFilterMode.Ignore, + Margin = new Thickness(5), }; StorageContainerButton.AddChild(vBox); @@ -87,20 +90,27 @@ namespace Content.Client.Storage.UI /// /// Loops through stored entities creating buttons for each, updates information labels /// - public void BuildEntityList(StorageBoundUserInterfaceState state) + public void BuildEntityList(EntityUid entity, StorageComponent component) { - var list = state.StoredEntities.ConvertAll(nent => new EntityListData(_entityManager.GetEntity(nent))); + var storedCount = component.Container.ContainedEntities.Count; + var list = new List(storedCount); + + foreach (var uid in component.Container.ContainedEntities) + { + list.Add(new EntityListData(uid)); + } + EntityList.PopulateList(list); - //Sets information about entire storage container current capacity - if (state.StorageCapacityMax != 0) + // Sets information about entire storage container current capacity + if (component.StorageCapacityMax != 0) { - _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", state.StoredEntities.Count), - ("usedVolume", state.StorageSizeUsed), ("maxVolume", state.StorageCapacityMax)); + _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", storedCount), + ("usedVolume", component.StorageUsed), ("maxVolume", component.StorageCapacityMax)); } else { - _information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", state.StoredEntities.Count)); + _information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", storedCount)); } } diff --git a/Content.Client/Strip/StrippableSystem.cs b/Content.Client/Strip/StrippableSystem.cs index 9aefde6211..c5083d2204 100644 --- a/Content.Client/Strip/StrippableSystem.cs +++ b/Content.Client/Strip/StrippableSystem.cs @@ -5,7 +5,6 @@ using Content.Shared.Hands; using Content.Shared.Inventory.Events; using Content.Shared.Strip; using Content.Shared.Strip.Components; -using Robust.Client.GameObjects; namespace Content.Client.Strip; @@ -33,7 +32,7 @@ public sealed class StrippableSystem : SharedStrippableSystem public void UpdateUi(EntityUid uid, StrippableComponent? component = null, EntityEventArgs? args = null) { - if (!TryComp(uid, out ClientUserInterfaceComponent? uiComp)) + if (!TryComp(uid, out UserInterfaceComponent? uiComp)) return; foreach (var ui in uiComp.OpenInterfaces.Values) diff --git a/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs b/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs index 7b71cc28df..59beaa5a02 100644 --- a/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs +++ b/Content.Client/UserInterface/Systems/Inventory/InventoryUIController.cs @@ -1,12 +1,12 @@ using Content.Client.Gameplay; using Content.Client.Hands.Systems; using Content.Client.Inventory; -using Content.Client.Storage; using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Systems.Inventory.Controls; using Content.Client.UserInterface.Systems.Inventory.Windows; using Content.Shared.Hands.Components; using Content.Shared.Input; +using Content.Shared.Storage; using Robust.Client.GameObjects; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controllers; @@ -126,7 +126,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(data.HeldEntity); + var showStorage = _entities.HasComponent(data.HeldEntity); var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage); SpriteUpdated(update); } @@ -151,7 +151,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered(data.HeldEntity); + var showStorage = _entities.HasComponent(data.HeldEntity); var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage); SpriteUpdated(update); } diff --git a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs index 530970407c..1442c0b670 100644 --- a/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs +++ b/Content.IntegrationTests/Tests/Interaction/InteractionTest.Helpers.cs @@ -18,7 +18,6 @@ using Content.Shared.Construction.Prototypes; using Content.Shared.DoAfter; using Content.Shared.Gravity; using Content.Shared.Item; -using Robust.Client.GameObjects; using Robust.Client.UserInterface; using Robust.Client.UserInterface.CustomControls; using Robust.Shared.GameObjects; @@ -785,9 +784,7 @@ public abstract partial class InteractionTest return false; } - var clientTarget = CEntMan.GetEntity(target); - - if (!CEntMan.TryGetComponent(clientTarget, out var ui)) + if (!CEntMan.TryGetComponent(CEntMan.GetEntity(target), out var ui)) { if (shouldSucceed) Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have a bui component"); diff --git a/Content.IntegrationTests/Tests/StorageTest.cs b/Content.IntegrationTests/Tests/StorageTest.cs index 7f8d569d5a..ea7f3f5866 100644 --- a/Content.IntegrationTests/Tests/StorageTest.cs +++ b/Content.IntegrationTests/Tests/StorageTest.cs @@ -4,6 +4,7 @@ using System.Linq; using Content.Server.Storage.Components; using Content.Shared.Item; using Content.Shared.Storage; +using Content.Shared.Storage.Components; using Robust.Shared.GameObjects; using Robust.Shared.Prototypes; using Robust.UnitTesting; @@ -29,7 +30,7 @@ namespace Content.IntegrationTests.Tests { foreach (var proto in protoManager.EnumeratePrototypes()) { - if (!proto.TryGetComponent("Storage", out var storage) || + if (!proto.TryGetComponent("Storage", out var storage) || storage.Whitelist != null || !proto.TryGetComponent("Item", out var item)) continue; @@ -84,7 +85,7 @@ namespace Content.IntegrationTests.Tests int capacity; var isEntStorage = false; - if (proto.TryGetComponent("Storage", out var storage)) + if (proto.TryGetComponent("Storage", out var storage)) { capacity = storage.StorageCapacityMax; } diff --git a/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs b/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs index e73ffb88cf..7e1de7d0c8 100644 --- a/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs +++ b/Content.IntegrationTests/Tests/VendingMachineRestockTest.cs @@ -12,6 +12,7 @@ using Content.Shared.VendingMachines; using Content.Shared.Wires; using Content.Server.Wires; using Content.Shared.Prototypes; +using Content.Shared.Storage.Components; namespace Content.IntegrationTests.Tests { diff --git a/Content.Server/Arcade/BlockGame/BlockGameArcadeSystem.cs b/Content.Server/Arcade/BlockGame/BlockGameArcadeSystem.cs index 06390a4245..dac29accc9 100644 --- a/Content.Server/Arcade/BlockGame/BlockGameArcadeSystem.cs +++ b/Content.Server/Arcade/BlockGame/BlockGameArcadeSystem.cs @@ -30,7 +30,7 @@ public sealed class BlockGameArcadeSystem : EntitySystem } } - private void UpdatePlayerStatus(EntityUid uid, IPlayerSession session, BoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null) + private void UpdatePlayerStatus(EntityUid uid, IPlayerSession session, PlayerBoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null) { if (!Resolve(uid, ref blockGame)) return; diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs index 3468310855..7f5f58fe4b 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasThermoMachineSystem.cs @@ -150,7 +150,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems DirtyUI(uid, thermoMachine); } - private void DirtyUI(EntityUid uid, GasThermoMachineComponent? thermoMachine, ServerUserInterfaceComponent? ui=null) + private void DirtyUI(EntityUid uid, GasThermoMachineComponent? thermoMachine, UserInterfaceComponent? ui=null) { if (!Resolve(uid, ref thermoMachine, ref ui, false)) return; diff --git a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs index 30c666cdd0..be8f54dfee 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs @@ -9,7 +9,6 @@ using Content.Shared.Cargo.Prototypes; using Content.Shared.Database; using JetBrains.Annotations; using Robust.Server.Containers; -using Robust.Server.GameObjects; using Robust.Shared.Collections; using Robust.Shared.Containers; using Robust.Shared.Random; @@ -314,7 +313,7 @@ public sealed partial class CargoSystem public void UpdateBountyConsoles() { - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out _, out var ui)) { if (_station.GetOwningStation(uid) is not { } station || diff --git a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs index 3e5250d8bd..5e1baa71bb 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemMasterSystem.cs @@ -3,7 +3,6 @@ using System.Linq; using Content.Server.Chemistry.Components; using Content.Server.Labels; using Content.Server.Popups; -using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Shared.Administration.Logs; using Content.Shared.Chemistry; @@ -12,6 +11,7 @@ using Content.Shared.Chemistry.Reagent; using Content.Shared.Containers.ItemSlots; using Content.Shared.Database; using Content.Shared.FixedPoint; +using Content.Shared.Storage; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.Audio; @@ -174,8 +174,8 @@ namespace Content.Server.Chemistry.EntitySystems var user = message.Session.AttachedEntity; var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName); if (maybeContainer is not { Valid: true } container - || !TryComp(container, out ServerStorageComponent? storage) - || storage.Storage is null) + || !TryComp(container, out StorageComponent? storage) + || storage.Container is null) { return; // output can't fit pills } @@ -201,7 +201,7 @@ namespace Content.Server.Chemistry.EntitySystems for (var i = 0; i < message.Number; i++) { var item = Spawn(PillPrototypeId, Transform(container).Coordinates); - _storageSystem.Insert(container, item, storage); + _storageSystem.Insert(container, item, user, storage); _labelSystem.Label(item, message.Label); var itemSolution = _solutionContainerSystem.EnsureSolution(item, SharedChemMaster.PillSolutionName); @@ -340,10 +340,10 @@ namespace Content.Server.Chemistry.EntitySystems } } - if (!TryComp(container, out ServerStorageComponent? storage)) + if (!TryComp(container, out StorageComponent? storage)) return null; - var pills = storage.Storage?.ContainedEntities.Select((Func) (pill => + var pills = storage.Container?.ContainedEntities.Select((Func) (pill => { _solutionContainerSystem.TryGetSolution(pill, SharedChemMaster.PillSolutionName, out var solution); var quantity = solution?.Volume ?? FixedPoint2.Zero; diff --git a/Content.Server/Communications/CommunicationsConsoleComponent.cs b/Content.Server/Communications/CommunicationsConsoleComponent.cs index 634a87d627..e7b5f20cf3 100644 --- a/Content.Server/Communications/CommunicationsConsoleComponent.cs +++ b/Content.Server/Communications/CommunicationsConsoleComponent.cs @@ -57,6 +57,6 @@ namespace Content.Server.Communications [DataField("sound")] public SoundSpecifier AnnouncementSound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg"); - public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key); + public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key); } } diff --git a/Content.Server/Construction/ConstructionSystem.Initial.cs b/Content.Server/Construction/ConstructionSystem.Initial.cs index 5c2aecb548..e74edb5da2 100644 --- a/Content.Server/Construction/ConstructionSystem.Initial.cs +++ b/Content.Server/Construction/ConstructionSystem.Initial.cs @@ -2,7 +2,6 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Content.Server.Construction.Components; -using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Shared.ActionBlocker; using Content.Shared.Construction; @@ -30,7 +29,6 @@ namespace Content.Server.Construction [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly EntityLookupSystem _lookupSystem = default!; - [Dependency] private readonly StorageSystem _storageSystem = default!; // --- WARNING! LEGACY CODE AHEAD! --- // This entire file contains the legacy code for initial construction. @@ -51,9 +49,9 @@ namespace Content.Server.Construction { foreach (var item in _handsSystem.EnumerateHeld(user)) { - if (TryComp(item, out ServerStorageComponent? storage)) + if (TryComp(item, out StorageComponent? storage)) { - foreach (var storedEntity in storage.StoredEntities!) + foreach (var storedEntity in storage.Container.ContainedEntities!) { yield return storedEntity; } @@ -66,10 +64,12 @@ namespace Content.Server.Construction { while (containerSlotEnumerator.MoveNext(out var containerSlot)) { - if(!containerSlot.ContainedEntity.HasValue) continue; - if (EntityManager.TryGetComponent(containerSlot.ContainedEntity.Value, out ServerStorageComponent? storage)) + if(!containerSlot.ContainedEntity.HasValue) + continue; + + if (EntityManager.TryGetComponent(containerSlot.ContainedEntity.Value, out StorageComponent? storage)) { - foreach (var storedEntity in storage.StoredEntities!) + foreach (var storedEntity in storage.Container.ContainedEntities) { yield return storedEntity; } @@ -207,12 +207,9 @@ namespace Content.Server.Construction continue; // Dump out any stored entities in used entity - if (TryComp(entity, out var storage) && storage.StoredEntities != null) + if (TryComp(entity, out var storage)) { - foreach (var storedEntity in storage.StoredEntities.ToList()) - { - _storageSystem.RemoveAndDrop(entity, storedEntity, storage); - } + _container.EmptyContainer(storage.Container); } if (string.IsNullOrEmpty(arbitraryStep.Store)) diff --git a/Content.Server/Construction/PartExchangerSystem.cs b/Content.Server/Construction/PartExchangerSystem.cs index a4030a70d4..3f73201965 100644 --- a/Content.Server/Construction/PartExchangerSystem.cs +++ b/Content.Server/Construction/PartExchangerSystem.cs @@ -1,12 +1,12 @@ using System.Linq; using Content.Server.Construction.Components; -using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Shared.DoAfter; using Content.Shared.Construction.Components; using Content.Shared.Exchanger; using Content.Shared.Interaction; using Content.Shared.Popups; +using Content.Shared.Storage; using Robust.Shared.Containers; using Robust.Shared.Utility; using Content.Shared.Wires; @@ -41,13 +41,13 @@ public sealed class PartExchangerSystem : EntitySystem if (args.Handled || args.Args.Target == null) return; - if (!TryComp(uid, out var storage) || storage.Storage == null) + if (!TryComp(uid, out var storage) || storage.Container == null) return; //the parts are stored in here var machinePartQuery = GetEntityQuery(); var machineParts = new List<(EntityUid, MachinePartComponent)>(); - foreach (var item in storage.Storage.ContainedEntities) //get parts in RPED + foreach (var item in storage.Container.ContainedEntities) //get parts in RPED { if (machinePartQuery.TryGetComponent(item, out var part)) machineParts.Add((item, part)); @@ -96,7 +96,7 @@ public sealed class PartExchangerSystem : EntitySystem //put the unused parts back into rped. (this also does the "swapping") foreach (var (unused, _) in machineParts) { - _storage.Insert(storageUid, unused, null, false); + _storage.Insert(storageUid, unused, playSound: false); } _construction.RefreshParts(uid, machine); } @@ -146,7 +146,7 @@ public sealed class PartExchangerSystem : EntitySystem //put the unused parts back into rped. (this also does the "swapping") foreach (var (unused, _) in machineParts) { - _storage.Insert(storageEnt, unused, null, false); + _storage.Insert(storageEnt, unused, playSound: false); } } diff --git a/Content.Server/Crayon/CrayonComponent.cs b/Content.Server/Crayon/CrayonComponent.cs index c1747fc8f1..6f2cd6d397 100644 --- a/Content.Server/Crayon/CrayonComponent.cs +++ b/Content.Server/Crayon/CrayonComponent.cs @@ -25,6 +25,6 @@ namespace Content.Server.Crayon [DataField("deleteEmpty")] public bool DeleteEmpty = true; - [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key); + [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key); } } diff --git a/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs b/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs index cbecba701c..7bed97db12 100644 --- a/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs +++ b/Content.Server/Eye/Blinding/ActivatableUIRequiresVisionSystem.cs @@ -44,7 +44,7 @@ public sealed class ActivatableUIRequiresVisionSystem : EntitySystem if (uiList == null) return; - Queue closeList = new(); // foreach collection modified moment + Queue closeList = new(); // foreach collection modified moment foreach (var ui in uiList) { diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index b746eea6ec..5a9afe0144 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -1,8 +1,8 @@ +using System.Linq; using System.Numerics; using Content.Server.Popups; using Content.Server.Pulling; using Content.Server.Stack; -using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Server.Stunnable; using Content.Shared.ActionBlocker; @@ -16,6 +16,7 @@ using Content.Shared.Inventory; using Content.Shared.Physics.Pull; using Content.Shared.Pulling.Components; using Content.Shared.Stacks; +using Content.Shared.Storage; using Content.Shared.Throwing; using JetBrains.Annotations; using Robust.Server.Player; @@ -30,8 +31,7 @@ using Robust.Shared.Utility; namespace Content.Server.Hands.Systems { - [UsedImplicitly] - internal sealed class HandsSystem : SharedHandsSystem + public sealed class HandsSystem : SharedHandsSystem { [Dependency] private readonly InventorySystem _inventorySystem = default!; [Dependency] private readonly StackSystem _stackSystem = default!; @@ -252,7 +252,7 @@ namespace Content.Server.Hands.Systems return; if (!_inventorySystem.TryGetSlotEntity(plyEnt, equipmentSlot, out var slotEntity) || - !TryComp(slotEntity, out ServerStorageComponent? storageComponent)) + !TryComp(slotEntity, out StorageComponent? storageComponent)) { if (_inventorySystem.HasSlot(plyEnt, equipmentSlot)) { @@ -287,16 +287,17 @@ namespace Content.Server.Hands.Systems { _storageSystem.PlayerInsertHeldEntity(slotEntity.Value, plyEnt, storageComponent); } - else if (storageComponent.StoredEntities != null) + else { - if (storageComponent.StoredEntities.Count == 0) + if (!storageComponent.Container.ContainedEntities.Any()) { _popupSystem.PopupEntity(Loc.GetString("hands-system-empty-equipment-slot", ("slotName", equipmentSlot)), plyEnt, session); } else { - var lastStoredEntity = storageComponent.StoredEntities[^1]; - if (storageComponent.Remove(lastStoredEntity)) + var lastStoredEntity = storageComponent.Container.ContainedEntities[^1]; + + if (storageComponent.Container.Remove(lastStoredEntity)) { PickupOrDrop(plyEnt, lastStoredEntity, animateUser: true, handsComp: hands); } diff --git a/Content.Server/Instruments/InstrumentComponent.cs b/Content.Server/Instruments/InstrumentComponent.cs index e133025576..51de0ed35b 100644 --- a/Content.Server/Instruments/InstrumentComponent.cs +++ b/Content.Server/Instruments/InstrumentComponent.cs @@ -21,7 +21,7 @@ public sealed partial class InstrumentComponent : SharedInstrumentComponent _entMan.GetComponentOrNull(Owner)?.CurrentSingleUser ?? _entMan.GetComponentOrNull(Owner)?.PlayerSession; - [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key); + [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key); } [RegisterComponent] diff --git a/Content.Server/Interaction/InteractionSystem.cs b/Content.Server/Interaction/InteractionSystem.cs index 30eeb6e946..c39c086960 100644 --- a/Content.Server/Interaction/InteractionSystem.cs +++ b/Content.Server/Interaction/InteractionSystem.cs @@ -2,7 +2,6 @@ using Content.Server.Administration.Logs; using Content.Server.Pulling; -using Content.Server.Storage.Components; using Content.Shared.ActionBlocker; using Content.Shared.DragDrop; using Content.Shared.Input; @@ -46,17 +45,17 @@ namespace Content.Server.Interaction if (!_container.TryGetContainingContainer(target, out var container)) return false; - if (!TryComp(container.Owner, out ServerStorageComponent? storage)) + if (!TryComp(container.Owner, out StorageComponent? storage)) return false; - if (storage.Storage?.ID != container.ID) + if (storage.Container?.ID != container.ID) return false; if (!TryComp(user, out ActorComponent? actor)) return false; // we don't check if the user can access the storage entity itself. This should be handed by the UI system. - return _uiSystem.SessionHasOpenUi(container.Owner, SharedStorageComponent.StorageUiKey.Key, actor.PlayerSession); + return _uiSystem.SessionHasOpenUi(container.Owner, StorageComponent.StorageUiKey.Key, actor.PlayerSession); } #region Drag drop diff --git a/Content.Server/Inventory/ServerInventorySystem.cs b/Content.Server/Inventory/ServerInventorySystem.cs index a1cb007d91..f80a604ad5 100644 --- a/Content.Server/Inventory/ServerInventorySystem.cs +++ b/Content.Server/Inventory/ServerInventorySystem.cs @@ -1,9 +1,9 @@ -using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Shared.Clothing.Components; using Content.Shared.Interaction.Events; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; +using Content.Shared.Storage; namespace Content.Server.Inventory { @@ -33,7 +33,7 @@ namespace Content.Server.Inventory if (args.SenderSession.AttachedEntity is not { Valid: true } uid) return; - if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp(entityUid, out var storageComponent)) + if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp(entityUid, out var storageComponent)) { _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent); } diff --git a/Content.Server/Item/ItemSystem.cs b/Content.Server/Item/ItemSystem.cs index 33c95d3780..55fb5aae09 100644 --- a/Content.Server/Item/ItemSystem.cs +++ b/Content.Server/Item/ItemSystem.cs @@ -1,7 +1,7 @@ -using Content.Server.Storage.Components; -using Content.Server.Storage.EntitySystems; +using Content.Server.Storage.EntitySystems; using Content.Shared.Item; using Content.Shared.Stacks; +using Content.Shared.Storage; namespace Content.Server.Item; @@ -14,9 +14,12 @@ public sealed class ItemSystem : SharedItemSystem base.OnStackCountChanged(uid, component, args); if (!Container.TryGetContainingContainer(uid, out var container) || - !TryComp(container.Owner, out var storage)) + !TryComp(container.Owner, out var storage)) + { return; + } + _storage.RecalculateStorageUsed(storage); - _storage.UpdateStorageUI(container.Owner, storage); + _storage.UpdateUI(container.Owner, storage); } } diff --git a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs index e6297eebc5..d37080a1e1 100644 --- a/Content.Server/Light/EntitySystems/LightReplacerSystem.cs +++ b/Content.Server/Light/EntitySystems/LightReplacerSystem.cs @@ -1,6 +1,5 @@ using System.Linq; using Content.Server.Light.Components; -using Content.Server.Storage.Components; using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Light.Components; @@ -101,7 +100,7 @@ public sealed class LightReplacerSystem : EntitySystem if (TryComp(usedUid, out var bulb)) eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb); // add bulbs from storage? - else if (TryComp(usedUid, out var storage)) + else if (TryComp(usedUid, out var storage)) eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage); } @@ -205,23 +204,23 @@ public sealed class LightReplacerSystem : EntitySystem /// which was successfully inserted inside light replacer /// public bool TryInsertBulbsFromStorage(EntityUid replacerUid, EntityUid storageUid, EntityUid? userUid = null, - LightReplacerComponent? replacer = null, ServerStorageComponent? storage = null) + LightReplacerComponent? replacer = null, StorageComponent? 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(); + var storagedEnts = storage.Container.ContainedEntities.ToArray(); + foreach (var ent in storagedEnts) { if (TryComp(ent, out var bulb) && TryInsertBulb(replacerUid, ent, userUid, false, replacer, bulb)) + { insertedBulbs++; + } } // show some message if success diff --git a/Content.Server/Medical/Components/HealthAnalyzerComponent.cs b/Content.Server/Medical/Components/HealthAnalyzerComponent.cs index 1148c3afff..4b0bb5ff1f 100644 --- a/Content.Server/Medical/Components/HealthAnalyzerComponent.cs +++ b/Content.Server/Medical/Components/HealthAnalyzerComponent.cs @@ -17,7 +17,7 @@ namespace Content.Server.Medical.Components [DataField("scanDelay")] public float ScanDelay = 0.8f; - public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key); + public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key); /// /// Sound played on scanning begin diff --git a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs index 67e19ae17d..125edd2c4c 100644 --- a/Content.Server/Nutrition/EntitySystems/FoodSystem.cs +++ b/Content.Server/Nutrition/EntitySystems/FoodSystem.cs @@ -28,7 +28,7 @@ using Robust.Shared.Audio; using Robust.Shared.Player; using Robust.Shared.Utility; using Content.Shared.Tag; -using Content.Server.Storage.Components; +using Content.Shared.Storage; namespace Content.Server.Nutrition.EntitySystems { @@ -120,7 +120,7 @@ namespace Content.Server.Nutrition.EntitySystems } // Check for used storage on the food item - if (TryComp(food, out var storageState) && storageState.StorageUsed != 0) + if (TryComp(food, out var storageState) && storageState.StorageUsed != 0) { _popupSystem.PopupEntity(Loc.GetString("food-has-used-storage", ("food", food)), user, user); return (false, true); diff --git a/Content.Server/PDA/PdaSystem.cs b/Content.Server/PDA/PdaSystem.cs index ae0fc1e1dc..6c506dc3dd 100644 --- a/Content.Server/PDA/PdaSystem.cs +++ b/Content.Server/PDA/PdaSystem.cs @@ -53,7 +53,7 @@ namespace Content.Server.PDA { base.OnComponentInit(uid, pda, args); - if (!HasComp(uid)) + if (!HasComp(uid)) return; UpdateAlertLevel(uid, pda); diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index 5356318aaa..8d9a62cd73 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -40,13 +40,13 @@ public sealed class ApcSystem : EntitySystem public override void Update(float deltaTime) { - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var apc, out var battery, out var ui)) { if (apc.LastUiUpdate + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime) { apc.LastUiUpdate = _gameTiming.CurTime; - UpdateUIState(uid, apc, battery, ui); + UpdateUIState(uid, apc, battery); } } } @@ -146,7 +146,7 @@ public sealed class ApcSystem : EntitySystem public void UpdateUIState(EntityUid uid, ApcComponent? apc = null, PowerNetworkBatteryComponent? netBat = null, - ServerUserInterfaceComponent? ui = null) + UserInterfaceComponent? ui = null) { if (!Resolve(uid, ref apc, ref netBat, ref ui)) return; diff --git a/Content.Server/Resist/EscapeInventorySystem.cs b/Content.Server/Resist/EscapeInventorySystem.cs index 64f3baf9c7..eb7c4c8478 100644 --- a/Content.Server/Resist/EscapeInventorySystem.cs +++ b/Content.Server/Resist/EscapeInventorySystem.cs @@ -60,7 +60,7 @@ public sealed class EscapeInventorySystem : EntitySystem } // Uncontested - if (HasComp(container.Owner) || HasComp(container.Owner) || HasComp(container.Owner)) + if (HasComp(container.Owner) || HasComp(container.Owner) || HasComp(container.Owner)) AttemptEscape(uid, container.Owner, component); } diff --git a/Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs b/Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs index 324bdf9e01..c814e9c36b 100644 --- a/Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs +++ b/Content.Server/Salvage/SalvageSystem.ExpeditionConsole.cs @@ -1,6 +1,5 @@ using Content.Shared.Salvage; using Content.Shared.Salvage.Expeditions; -using Robust.Server.GameObjects; namespace Content.Server.Salvage; @@ -38,7 +37,7 @@ public sealed partial class SalvageSystem { var state = GetState(component); - foreach (var (console, xform, uiComp) in EntityQuery(true)) + foreach (var (console, xform, uiComp) in EntityQuery(true)) { var station = _station.GetOwningStation(console.Owner, xform); diff --git a/Content.Server/SensorMonitoring/SensorMonitoringConsoleComponent.cs b/Content.Server/SensorMonitoring/SensorMonitoringConsoleComponent.cs index 64430042d6..cd4f2ea23b 100644 --- a/Content.Server/SensorMonitoring/SensorMonitoringConsoleComponent.cs +++ b/Content.Server/SensorMonitoring/SensorMonitoringConsoleComponent.cs @@ -1,6 +1,7 @@ using Content.Shared.SensorMonitoring; using Robust.Server.Player; using Robust.Shared.Collections; +using Robust.Shared.Players; namespace Content.Server.SensorMonitoring; @@ -26,7 +27,7 @@ public sealed partial class SensorMonitoringConsoleComponent : Component public TimeSpan RetentionTime = TimeSpan.FromMinutes(1); // UI update tracking stuff. - public HashSet InitialUIStateSent = new(); + public HashSet InitialUIStateSent = new(); public TimeSpan LastUIUpdate; public ValueList RemovedSensors; diff --git a/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs b/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs index d79f993d87..179cadcfbc 100644 --- a/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs +++ b/Content.Server/Solar/EntitySystems/PowerSolarControlConsoleSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Solar.EntitySystems { _updateTimer -= 1; var state = new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun); - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var _, out var uiComp)) { _uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp); diff --git a/Content.Server/Stack/StackSystem.cs b/Content.Server/Stack/StackSystem.cs index 12bd2a1bd3..4fc50ce595 100644 --- a/Content.Server/Stack/StackSystem.cs +++ b/Content.Server/Stack/StackSystem.cs @@ -1,7 +1,7 @@ -using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems; using Content.Shared.Popups; using Content.Shared.Stacks; +using Content.Shared.Storage; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.Containers; @@ -163,9 +163,9 @@ namespace Content.Server.Stack return; if (_container.TryGetContainingContainer(uid, out var container) && - TryComp(container.Owner, out var storage)) + TryComp(container.Owner, out var storage)) { - _storage.UpdateStorageUI(container.Owner, storage); + _storage.UpdateUI(container.Owner, storage); } Hands.PickupOrDrop(userUid, split); diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs deleted file mode 100644 index bfea401b5d..0000000000 --- a/Content.Server/Storage/Components/ServerStorageComponent.cs +++ /dev/null @@ -1,88 +0,0 @@ -using Content.Shared.Storage; -using Content.Shared.Whitelist; -using Robust.Shared.Audio; -using Robust.Shared.Containers; -using System.Threading; - -namespace Content.Server.Storage.Components -{ - /// - /// Storage component for containing entities within this one, matches a UI on the client which shows stored entities - /// - [RegisterComponent] - [ComponentReference(typeof(SharedStorageComponent))] - public sealed partial class ServerStorageComponent : SharedStorageComponent - { - public string LoggerName = "Storage"; - - public Container? Storage; - - public readonly Dictionary SizeCache = new(); - - private bool _occludesLight = true; - - [DataField("quickInsert")] - public bool QuickInsert = false; // Can insert storables by "attacking" them with the storage entity - - [DataField("clickInsert")] - public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it - - [DataField("areaInsert")] - public bool AreaInsert = false; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay - - [DataField("areaInsertRadius")] - public int AreaInsertRadius = 1; - - [DataField("whitelist")] - public EntityWhitelist? Whitelist = null; - [DataField("blacklist")] - public EntityWhitelist? Blacklist = null; - - /// - /// If true, storage will show popup messages to the player after failed interactions. - /// Usually this is message that item doesn't fit inside container. - /// - [DataField("popup")] - public bool ShowPopup = true; - - /// - /// This storage has an open UI - /// - public bool IsOpen = false; - public int StorageUsed; - [DataField("capacity")] - public int StorageCapacityMax = 10000; - - [DataField("storageOpenSound")] - public SoundSpecifier? StorageOpenSound { get; set; } = new SoundCollectionSpecifier("storageRustle"); - - [DataField("storageInsertSound")] - public SoundSpecifier? StorageInsertSound { get; set; } = new SoundCollectionSpecifier("storageRustle"); - - [DataField("storageRemoveSound")] - public SoundSpecifier? StorageRemoveSound { get; set; } - [DataField("storageCloseSound")] - public SoundSpecifier? StorageCloseSound { get; set; } - - [ViewVariables] - public override IReadOnlyList? StoredEntities => Storage?.ContainedEntities; - - [ViewVariables(VVAccess.ReadWrite)] - [DataField("occludesLight")] - public bool OccludesLight - { - get => _occludesLight; - set - { - _occludesLight = value; - if (Storage != null) Storage.OccludesLight = value; - } - } - - // neccesary for abstraction, should be deleted on complete storage ECS - public override bool Remove(EntityUid entity) - { - return true; - } - } -} diff --git a/Content.Server/Storage/Components/StorageFillComponent.cs b/Content.Server/Storage/Components/StorageFillComponent.cs deleted file mode 100644 index 2c8af2855b..0000000000 --- a/Content.Server/Storage/Components/StorageFillComponent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Content.Server.Storage.EntitySystems; -using Content.Shared.Storage; - -namespace Content.Server.Storage.Components -{ - [RegisterComponent, Access(typeof(StorageSystem))] - public sealed partial class StorageFillComponent : Component - { - [DataField("contents")] public List Contents = new(); - } -} diff --git a/Content.Server/Storage/EntitySystems/ItemCounterSystem.cs b/Content.Server/Storage/EntitySystems/ItemCounterSystem.cs index e9c42a401a..415e8d9246 100644 --- a/Content.Server/Storage/EntitySystems/ItemCounterSystem.cs +++ b/Content.Server/Storage/EntitySystems/ItemCounterSystem.cs @@ -1,4 +1,4 @@ -using Content.Server.Storage.Components; +using Content.Shared.Storage; using Content.Shared.Storage.Components; using Content.Shared.Storage.EntitySystems; using JetBrains.Annotations; @@ -11,16 +11,16 @@ namespace Content.Server.Storage.EntitySystems { protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter) { - if (!EntityManager.TryGetComponent(msg.Container.Owner, out ServerStorageComponent? component) - || component.StoredEntities == null) + if (!EntityManager.TryGetComponent(msg.Container.Owner, out StorageComponent? component)) { return null; } var count = 0; - foreach (var entity in component.StoredEntities) + foreach (var entity in component.Container.ContainedEntities) { - if (itemCounter.Count.IsValid(entity)) count++; + if (itemCounter.Count.IsValid(entity)) + count++; } return count; diff --git a/Content.Server/Storage/EntitySystems/PickRandomSystem.cs b/Content.Server/Storage/EntitySystems/PickRandomSystem.cs index 3b73ecb6bb..50f6db459c 100644 --- a/Content.Server/Storage/EntitySystems/PickRandomSystem.cs +++ b/Content.Server/Storage/EntitySystems/PickRandomSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.Verbs; using Robust.Shared.Containers; using Robust.Shared.Random; using System.Linq; +using Content.Shared.Storage; namespace Content.Server.Storage.EntitySystems; @@ -24,21 +25,20 @@ public sealed class PickRandomSystem : EntitySystem private void OnGetAlternativeVerbs(EntityUid uid, PickRandomComponent comp, GetVerbsEvent args) { - if (!args.CanAccess || !args.CanInteract || !TryComp(uid, out var storage)) + if (!args.CanAccess || !args.CanInteract || !TryComp(uid, out var storage)) return; var user = args.User; - var enabled = false; - if (storage.StoredEntities != null) - enabled = storage.StoredEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true); + var enabled = storage.Container.ContainedEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true); // alt-click / alt-z to pick an item args.Verbs.Add(new AlternativeVerb { - Act = (() => { + Act = () => + { TryPick(uid, comp, storage, user); - }), + }, Impact = LogImpact.Low, Text = Loc.GetString(comp.VerbText), Disabled = !enabled, @@ -46,16 +46,14 @@ public sealed class PickRandomSystem : EntitySystem }); } - private void TryPick(EntityUid uid, PickRandomComponent comp, ServerStorageComponent storage, EntityUid user) + private void TryPick(EntityUid uid, PickRandomComponent comp, StorageComponent storage, EntityUid user) { - if (storage.StoredEntities == null) - return; + var entities = storage.Container.ContainedEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true).ToArray(); - var entities = storage.StoredEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true); if (!entities.Any()) return; - var picked = _random.Pick(entities.ToList()); + var picked = _random.Pick(entities); // if it fails to go into a hand of the user, will be on the storage _container.AttachParentToContainerOrGrid(Transform(picked)); diff --git a/Content.Server/Storage/EntitySystems/StorageFillVisualizerSystem.cs b/Content.Server/Storage/EntitySystems/StorageFillVisualizerSystem.cs index 786e0bc93c..ed48de2e45 100644 --- a/Content.Server/Storage/EntitySystems/StorageFillVisualizerSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageFillVisualizerSystem.cs @@ -1,5 +1,5 @@ -using Content.Server.Storage.Components; -using Content.Shared.Rounding; +using Content.Shared.Rounding; +using Content.Shared.Storage; using Content.Shared.Storage.Components; using Robust.Server.GameObjects; using Robust.Shared.Containers; @@ -33,7 +33,7 @@ public sealed class StorageFillVisualizerSystem : EntitySystem UpdateAppearance(uid, component: component); } - private void UpdateAppearance(EntityUid uid, ServerStorageComponent? storage = null, AppearanceComponent? appearance = null, + private void UpdateAppearance(EntityUid uid, StorageComponent? storage = null, AppearanceComponent? appearance = null, StorageFillVisualizerComponent? component = null) { if (!Resolve(uid, ref storage, ref appearance, ref component, false)) diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs b/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs index 9a58ff87e8..77c8458b91 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs @@ -1,5 +1,6 @@ using Content.Server.Storage.Components; using Content.Shared.Storage; +using Content.Shared.Storage.Components; namespace Content.Server.Storage.EntitySystems; @@ -7,32 +8,33 @@ public sealed partial class StorageSystem { private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args) { - if (component.Contents.Count == 0) return; + if (component.Contents.Count == 0) + return; - TryComp(uid, out var serverStorageComp); + TryComp(uid, out var storageComp); TryComp(uid, out var entityStorageComp); - if (entityStorageComp == null && serverStorageComp == null) + if (entityStorageComp == null && storageComp == null) { - Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})"); + Log.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})"); return; } var coordinates = Transform(uid).Coordinates; - var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, _random); + var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, Random); foreach (var item in spawnItems) { var ent = EntityManager.SpawnEntity(item, coordinates); // handle depending on storage component, again this should be unified after ECS - if (entityStorageComp != null && _entityStorage.Insert(ent, uid)) - continue; - - if (serverStorageComp != null && Insert(uid, ent, serverStorageComp, false)) + if (entityStorageComp != null && EntityStorage.Insert(ent, uid)) continue; - Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't."); + if (storageComp != null && Insert(uid, ent, storageComp: storageComp, playSound: false)) + continue; + + Log.Error($"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't."); EntityManager.DeleteEntity(ent); } } diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 99ed0e17d9..da6a462752 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -1,762 +1,148 @@ -using System.Linq; using Content.Server.Administration.Managers; -using Content.Server.Interaction; -using Content.Server.Popups; -using Content.Server.Stack; -using Content.Server.Storage.Components; -using Content.Shared.ActionBlocker; using Content.Shared.Administration; -using Content.Shared.CombatMode; -using Content.Shared.Containers.ItemSlots; -using Content.Shared.Destructible; -using Content.Shared.DoAfter; using Content.Shared.Ghost; -using Content.Shared.Hands.Components; -using Content.Shared.Hands.EntitySystems; -using Content.Shared.Implants.Components; -using Content.Shared.Interaction; -using Content.Shared.Item; using Content.Shared.Lock; -using Content.Shared.Placeable; -using Content.Shared.Stacks; using Content.Shared.Storage; using Content.Shared.Storage.Components; +using Content.Shared.Storage.EntitySystems; using Content.Shared.Timing; using Content.Shared.Verbs; -using Robust.Server.Containers; using Robust.Server.GameObjects; using Robust.Server.Player; -using Robust.Shared.Audio; -using Robust.Shared.Containers; -using Robust.Shared.Map; -using Robust.Shared.Physics.Systems; using Robust.Shared.Player; -using Robust.Shared.Random; +using Robust.Shared.Players; using Robust.Shared.Utility; -using static Content.Shared.Storage.SharedStorageComponent; -namespace Content.Server.Storage.EntitySystems +namespace Content.Server.Storage.EntitySystems; + +public sealed partial class StorageSystem : SharedStorageSystem { - public sealed partial class StorageSystem : EntitySystem + [Dependency] private readonly IAdminManager _admin = default!; + [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; + + public override void Initialize() { - [Dependency] private readonly IRobustRandom _random = default!; - [Dependency] private readonly IAdminManager _admin = default!; - [Dependency] private readonly ILogManager _logManager = default!; - [Dependency] private readonly ContainerSystem _containerSystem = default!; - [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; - [Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!; - [Dependency] private readonly EntityStorageSystem _entityStorage = default!; - [Dependency] private readonly InteractionSystem _interactionSystem = default!; - [Dependency] private readonly PopupSystem _popupSystem = default!; - [Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!; - [Dependency] private readonly SharedInteractionSystem _sharedInteractionSystem = default!; - [Dependency] private readonly UserInterfaceSystem _uiSystem = default!; - [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; - [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] private readonly SharedAudioSystem _audio = default!; - [Dependency] private readonly SharedCombatModeSystem _combatMode = default!; - [Dependency] private readonly SharedTransformSystem _transform = default!; - [Dependency] private readonly StackSystem _stack = default!; - [Dependency] private readonly UseDelaySystem _useDelay = default!; + base.Initialize(); + SubscribeLocalEvent>(AddUiVerb); + SubscribeLocalEvent(OnBoundUIClosed); - /// - public override void Initialize() + SubscribeLocalEvent(OnStorageFillMapInit); + } + + private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent args) + { + var silent = false; + if (!args.CanAccess || !args.CanInteract || TryComp(uid, out var lockComponent) && lockComponent.Locked) { - base.Initialize(); + // we allow admins to open the storage anyways + if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin)) + return; - SubscribeLocalEvent(OnComponentInit); - SubscribeLocalEvent>(AddOpenUiVerb); - SubscribeLocalEvent>(AddTransferVerbs); - SubscribeLocalEvent(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) }); - SubscribeLocalEvent(OnActivate); - SubscribeLocalEvent(OnImplantActivate); - SubscribeLocalEvent(AfterInteract); - SubscribeLocalEvent(OnDestroy); - SubscribeLocalEvent(OnInteractWithItem); - SubscribeLocalEvent(OnInsertItemMessage); - SubscribeLocalEvent(OnBoundUIOpen); - SubscribeLocalEvent(OnBoundUIClosed); - SubscribeLocalEvent(OnStorageItemRemoved); - - SubscribeLocalEvent(OnDoAfter); - - SubscribeLocalEvent(OnStorageFillMapInit); + silent = true; } - private void OnComponentInit(EntityUid uid, ServerStorageComponent storageComp, ComponentInit args) - { - base.Initialize(); + silent |= HasComp(args.User); - // ReSharper disable once StringLiteralTypo - storageComp.Storage = _containerSystem.EnsureContainer(uid, "storagebase"); - storageComp.Storage.OccludesLight = storageComp.OccludesLight; + // Get the session for the user + if (!TryComp(args.User, out var actor)) + return; + + // Does this player currently have the storage UI open? + var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession); + + ActivationVerb verb = new() + { + Act = () => + { + if (uiOpen) + { + _uiSystem.TryClose(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession); + } + else + { + OpenStorageUI(uid, args.User, component, silent); + } + } + }; + if (uiOpen) + { + verb.Text = Loc.GetString("verb-common-close-ui"); + verb.Icon = new SpriteSpecifier.Texture( + new("/Textures/Interface/VerbIcons/close.svg.192dpi.png")); + } + else + { + verb.Text = Loc.GetString("verb-common-open-ui"); + verb.Icon = new SpriteSpecifier.Texture( + new("/Textures/Interface/VerbIcons/open.svg.192dpi.png")); + } + args.Verbs.Add(verb); + } + + private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundUIClosedEvent args) + { + if (TryComp(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null) + CloseNestedInterfaces(uid, actor.PlayerSession, storageComp); + + // If UI is closed for everyone + if (!_uiSystem.IsUiOpen(uid, args.UiKey)) + { + storageComp.IsUiOpen = false; UpdateStorageVisualization(uid, storageComp); - RecalculateStorageUsed(storageComp); - UpdateStorageUI(uid, storageComp); + + if (storageComp.StorageCloseSound is not null) + Audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params); + } + } + + /// + /// Opens the storage UI for an entity + /// + /// The entity to open the UI for + public override void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false) + { + if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player)) + return; + + // prevent spamming bag open / honkerton honk sound + silent |= TryComp(uid, out var useDelay) && UseDelay.ActiveDelay(uid, useDelay); + if (!silent) + { + Audio.PlayPvs(storageComp.StorageOpenSound, uid); + if (useDelay != null) + UseDelay.BeginDelay(uid, useDelay); } - private void AddOpenUiVerb(EntityUid uid, ServerStorageComponent component, GetVerbsEvent args) + Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity})."); + + var bui = _uiSystem.GetUiOrNull(uid, StorageComponent.StorageUiKey.Key); + if (bui != null) + _uiSystem.OpenUi(bui, player.PlayerSession); + } + + /// + /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them. + /// + /// + public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, StorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + 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.Container.ContainedEntities) { - var silent = false; - if (!args.CanAccess || !args.CanInteract || TryComp(uid, out var lockComponent) && lockComponent.Locked) - { - // we allow admins to open the storage anyways - if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin)) - return; + if (!TryComp(entity, out UserInterfaceComponent? ui)) + continue; - silent = true; + foreach (var bui in ui.Interfaces.Values) + { + _uiSystem.TryClose(entity, bui.UiKey, session, ui); } - - silent |= HasComp(args.User); - - // Get the session for the user - if (!TryComp(args.User, out var actor)) - return; - - // Does this player currently have the storage UI open? - var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession); - - ActivationVerb verb = new() - { - Act = () => OpenStorageUI(uid, args.User, component, silent) - }; - if (uiOpen) - { - verb.Text = Loc.GetString("verb-common-close-ui"); - verb.Icon = new SpriteSpecifier.Texture( - new("/Textures/Interface/VerbIcons/close.svg.192dpi.png")); - } - else - { - verb.Text = Loc.GetString("verb-common-open-ui"); - verb.Icon = new SpriteSpecifier.Texture( - new("/Textures/Interface/VerbIcons/open.svg.192dpi.png")); - } - args.Verbs.Add(verb); - } - - private void AddTransferVerbs(EntityUid uid, ServerStorageComponent component, GetVerbsEvent args) - { - if (!args.CanAccess || !args.CanInteract) - return; - - var entities = component.Storage?.ContainedEntities; - if (entities == null || entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) - return; - - // if the target is storage, add a verb to transfer storage. - if (TryComp(args.Target, out ServerStorageComponent? targetStorage) - && (!TryComp(uid, out LockComponent? targetLock) || !targetLock.Locked)) - { - UtilityVerb verb = new() - { - Text = Loc.GetString("storage-component-transfer-verb"), - IconEntity = GetNetEntity(args.Using), - Act = () => TransferEntities(uid, args.Target, component, lockComponent, targetStorage, targetLock) - }; - - args.Verbs.Add(verb); - } - } - - /// - /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user - /// - /// true if inserted, false otherwise - private void OnInteractUsing(EntityUid uid, ServerStorageComponent storageComp, InteractUsingEvent args) - { - if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) - return; - - _logManager.GetSawmill(storageComp.LoggerName) - .Debug($"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used})."); - - if (HasComp(uid)) - return; - - PlayerInsertHeldEntity(uid, args.User, storageComp); - // Always handle it, even if insertion fails. - // We don't want to trigger any AfterInteract logic here. - // Example bug: placing wires if item doesn't fit in backpack. - args.Handled = true; - } - - /// - /// Sends a message to open the storage UI - /// - /// - private void OnActivate(EntityUid uid, ServerStorageComponent storageComp, ActivateInWorldEvent args) - { - if (args.Handled || _combatMode.IsInCombatMode(args.User) || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) - return; - - OpenStorageUI(uid, args.User, storageComp); - } - - /// - /// Specifically for storage implants. - /// - private void OnImplantActivate(EntityUid uid, ServerStorageComponent storageComp, OpenStorageImplantEvent args) - { - if (args.Handled || !TryComp(uid, out var xform)) - return; - - OpenStorageUI(uid, xform.ParentUid, storageComp); - } - - /// - /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius - /// around a click. - /// - /// - private async void AfterInteract(EntityUid uid, ServerStorageComponent storageComp, AfterInteractEvent args) - { - if (!args.CanReach) - return; - - // Pick up all entities in a radius around the clicked location. - // The last half of the if is because carpets exist and this is terrible - if (storageComp.AreaInsert && (args.Target == null || !HasComp(args.Target.Value))) - { - var validStorables = new List(); - var itemQuery = GetEntityQuery(); - - foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries)) - { - if (entity == args.User - || !itemQuery.HasComponent(entity) - || !CanInsert(uid, entity, out _, storageComp) - || !_interactionSystem.InRangeUnobstructed(args.User, entity)) - { - continue; - } - - validStorables.Add(GetNetEntity(entity)); - } - - //If there's only one then let's be generous - if (validStorables.Count > 1) - { - var doAfterArgs = new DoAfterArgs(EntityManager, args.User, 0.2f * validStorables.Count, new AreaPickupDoAfterEvent(validStorables), uid, target: uid) - { - BreakOnDamage = true, - BreakOnUserMove = true, - NeedHand = true - }; - - _doAfterSystem.TryStartDoAfter(doAfterArgs); - } - - return; - } - - // Pick up the clicked entity - if (storageComp.QuickInsert) - { - if (args.Target is not { Valid: true } target) - return; - - if (_containerSystem.IsEntityInContainer(target) - || target == args.User - || !HasComp(target)) - return; - - if (TryComp(uid, out var transformOwner) && TryComp(target, out var transformEnt)) - { - var parent = transformOwner.ParentUid; - - var position = EntityCoordinates.FromMap( - parent.IsValid() ? parent : uid, - transformEnt.MapPosition, - _transform - ); - - if (PlayerInsertEntityInWorld(uid, args.User, target, storageComp)) - { - RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(GetNetEntity(uid), - new List { GetNetEntity(target) }, - new List { GetNetCoordinates(position) }, - new List { transformOwner.LocalRotation })); - } - } - } - } - - private void OnDoAfter(EntityUid uid, ServerStorageComponent component, AreaPickupDoAfterEvent args) - { - if (args.Handled || args.Cancelled) - return; - - var successfullyInserted = new List(); - var successfullyInsertedPositions = new List(); - var successfullyInsertedAngles = new List(); - var itemQuery = GetEntityQuery(); - var xformQuery = GetEntityQuery(); - xformQuery.TryGetComponent(uid, out var xform); - - foreach (var nent in args.Entities) - { - var entity = GetEntity(nent); - - // Check again, situation may have changed for some entities, but we'll still pick up any that are valid - if (_containerSystem.IsEntityInContainer(entity) - || entity == args.Args.User - || !itemQuery.HasComponent(entity)) - continue; - - if (xform == null || - !xformQuery.TryGetComponent(entity, out var targetXform) || - targetXform.MapID != xform.MapID) - { - continue; - } - - var position = EntityCoordinates.FromMap( - xform.ParentUid.IsValid() ? xform.ParentUid : uid, - new MapCoordinates(_transform.GetWorldPosition(targetXform, xformQuery), targetXform.MapID), - _transform - ); - - var angle = targetXform.LocalRotation; - - if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component)) - { - successfullyInserted.Add(entity); - successfullyInsertedPositions.Add(position); - successfullyInsertedAngles.Add(angle); - } - } - - // If we picked up atleast one thing, play a sound and do a cool animation! - if (successfullyInserted.Count > 0) - { - _audio.PlayPvs(component.StorageInsertSound, uid); - RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(GetNetEntity(uid), GetNetEntityList(successfullyInserted), GetNetCoordinatesList(successfullyInsertedPositions), successfullyInsertedAngles)); - } - - args.Handled = true; - } - - private void OnDestroy(EntityUid uid, ServerStorageComponent storageComp, DestructionEventArgs args) - { - var storedEntities = storageComp.StoredEntities?.ToList(); - - if (storedEntities == null) - return; - - foreach (var entity in storedEntities) - { - RemoveAndDrop(uid, entity, storageComp); - } - } - - /// - /// This function gets called when the user clicked on an item in the storage UI. This will either place the - /// item in the user's hand if it is currently empty, or interact with the item using the user's currently - /// held item. - /// - private void OnInteractWithItem(EntityUid uid, ServerStorageComponent storageComp, StorageInteractWithItemEvent args) - { - // TODO move this to shared for prediction. - if (args.Session.AttachedEntity is not EntityUid player) - return; - - var interacted = GetEntity(args.InteractedItemUID); - - if (!Exists(interacted)) - { - Log.Error($"Player {args.Session} interacted with non-existent item {interacted} stored in {ToPrettyString(uid)}"); - return; - } - - if (!_actionBlockerSystem.CanInteract(player, interacted) || storageComp.Storage == null || !storageComp.Storage.Contains(interacted)) - return; - - // Does the player have hands? - if (!TryComp(player, out HandsComponent? hands) || hands.Count == 0) - return; - - // If the user's active hand is empty, try pick up the item. - if (hands.ActiveHandEntity == null) - { - if (_sharedHandsSystem.TryPickupAnyHand(player, interacted, handsComp: hands) - && storageComp.StorageRemoveSound != null) - _audio.Play(storageComp.StorageRemoveSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, AudioParams.Default); - return; - } - - // Else, interact using the held item - _interactionSystem.InteractUsing(player, hands.ActiveHandEntity.Value, interacted, Transform(interacted).Coordinates, checkCanInteract: false); - } - - private void OnInsertItemMessage(EntityUid uid, ServerStorageComponent storageComp, StorageInsertItemMessage args) - { - // TODO move this to shared for prediction. - if (args.Session.AttachedEntity == null) - return; - - PlayerInsertHeldEntity(uid, args.Session.AttachedEntity.Value, storageComp); - } - - private void OnBoundUIOpen(EntityUid uid, ServerStorageComponent storageComp, BoundUIOpenedEvent args) - { - if (!storageComp.IsOpen) - { - storageComp.IsOpen = true; - UpdateStorageVisualization(uid, storageComp); - } - } - - private void OnBoundUIClosed(EntityUid uid, ServerStorageComponent storageComp, BoundUIClosedEvent args) - { - if (TryComp(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null) - CloseNestedInterfaces(uid, actor.PlayerSession, storageComp); - - // If UI is closed for everyone - if (!_uiSystem.IsUiOpen(uid, args.UiKey)) - { - storageComp.IsOpen = false; - UpdateStorageVisualization(uid, storageComp); - - if (storageComp.StorageCloseSound is not null) - _audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params); - } - } - - private void OnStorageItemRemoved(EntityUid uid, ServerStorageComponent storageComp, EntRemovedFromContainerMessage args) - { - RecalculateStorageUsed(storageComp); - UpdateStorageUI(uid, storageComp); - } - - private void UpdateStorageVisualization(EntityUid uid, ServerStorageComponent storageComp) - { - if (!TryComp(uid, out var appearance)) - return; - - _appearance.SetData(uid, StorageVisuals.Open, storageComp.IsOpen, appearance); - _appearance.SetData(uid, SharedBagOpenVisuals.BagState, storageComp.IsOpen ? SharedBagState.Open : SharedBagState.Closed); - - if (HasComp(uid)) - _appearance.SetData(uid, StackVisuals.Hide, !storageComp.IsOpen); - } - - public void RecalculateStorageUsed(ServerStorageComponent storageComp) - { - storageComp.StorageUsed = 0; - storageComp.SizeCache.Clear(); - - if (storageComp.Storage == null) - return; - - var itemQuery = GetEntityQuery(); - - foreach (var entity in storageComp.Storage.ContainedEntities) - { - if (!itemQuery.TryGetComponent(entity, out var itemComp)) - continue; - - var size = itemComp.Size; - storageComp.StorageUsed += size; - storageComp.SizeCache.Add(entity, size); - } - } - - public int GetAvailableSpace(EntityUid uid, ServerStorageComponent? component = null) - { - if (!Resolve(uid, ref component)) - return 0; - - return component.StorageCapacityMax - component.StorageUsed; - } - - /// - /// Move entities from one storage to another. - /// - 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); - } - - /// - /// Verifies if an entity can be stored and if it fits - /// - /// The entity to check - /// If returning false, the reason displayed to the player - /// true if it can be inserted, false otherwise - 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 TransformComponent? transformComp) && transformComp.Anchored) - { - reason = "comp-storage-anchored-failure"; - 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 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; - } - - reason = null; - return true; - } - - /// - /// Inserts into the storage container - /// - /// true if the entity was inserted, false otherwise - public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? storageComp = null, bool playSound = true) - { - if (!Resolve(uid, ref storageComp) || !CanInsert(uid, insertEnt, out _, storageComp) || storageComp.Storage == null) - return false; - - /* - * 1. If the inserted thing is stackable then try to stack it to existing stacks - * 2. If anything remains insert whatever is possible. - * 3. If insertion is not possible then leave the stack as is. - * At either rate still play the insertion sound - * - * For now we just treat items as always being the same size regardless of stack count. - */ - - // If it's stackable then prefer to stack it - var stackQuery = GetEntityQuery(); - - if (stackQuery.TryGetComponent(insertEnt, out var insertStack)) - { - var toInsertCount = insertStack.Count; - - foreach (var ent in storageComp.Storage.ContainedEntities) - { - if (!stackQuery.TryGetComponent(ent, out var containedStack) || !insertStack.StackTypeId.Equals(containedStack.StackTypeId)) - continue; - - if (!_stack.TryAdd(insertEnt, ent, insertStack, containedStack)) - continue; - - var remaining = insertStack.Count; - toInsertCount -= toInsertCount - remaining; - - if (remaining > 0) - continue; - - break; - } - - // Still stackable remaining - if (insertStack.Count > 0) - { - // Try to insert it as a new stack. - if (TryComp(insertEnt, out ItemComponent? itemComp) && - itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed || - !storageComp.Storage.Insert(insertEnt)) - { - // If we also didn't do any stack fills above then just end - // otherwise play sound and update UI anyway. - if (toInsertCount == insertStack.Count) - return false; - } - } - } - // Non-stackable but no insertion for reasons. - else if (!storageComp.Storage.Insert(insertEnt)) - { - return false; - } - - if (playSound && storageComp.StorageInsertSound is not null) - _audio.PlayPvs(storageComp.StorageInsertSound, uid); - - RecalculateStorageUsed(storageComp); - UpdateStorageUI(uid, storageComp); - return true; - } - - // 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; - } - - /// - /// Inserts an entity into storage from the player's active hand - /// - /// The player to insert an entity from - /// true if inserted, false otherwise - public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, ServerStorageComponent? storageComp = null) - { - if (!Resolve(uid, ref storageComp) || !TryComp(player, out HandsComponent? hands) || hands.ActiveHandEntity == null) - return false; - - var toInsert = hands.ActiveHandEntity; - - if (!CanInsert(uid, toInsert.Value, out var reason, storageComp)) - { - Popup(uid, player, reason ?? "comp-storage-cant-insert", storageComp); - return false; - } - - if (!_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands)) - { - PopupEnt(uid, player, "comp-storage-cant-drop", toInsert.Value, storageComp); - return false; - } - - return PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp); - } - - /// - /// Inserts an Entity () in the world into storage, informing if it fails. - /// is *NOT* held, see . - /// - /// The player to insert an entity with - /// true if inserted, false otherwise - public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, ServerStorageComponent? storageComp = null) - { - if (!Resolve(uid, ref storageComp) || !_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; - } - - /// - /// Opens the storage UI for an entity - /// - /// The entity to open the UI for - public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent? storageComp = null, bool silent = false) - { - if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player)) - return; - - // prevent spamming bag open / honkerton honk sound - silent |= TryComp(uid, out var useDelay) && _useDelay.ActiveDelay(uid, useDelay); - if (!silent) - { - _audio.PlayPvs(storageComp.StorageOpenSound, uid); - if (useDelay != null) - _useDelay.BeginDelay(uid, useDelay); - } - - _logManager.GetSawmill(storageComp.LoggerName) - .Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity})."); - - var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key); - if (bui != null) - _uiSystem.OpenUi(bui, player.PlayerSession); - } - - /// - /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them. - /// - /// - public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent? storageComp = null) - { - if (!Resolve(uid, ref storageComp) || 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? ui)) - continue; - - foreach (var bui in ui.Interfaces.Values) - { - _uiSystem.TryClose(entity, bui.UiKey, session, ui); - } - } - } - - public void UpdateStorageUI(EntityUid uid, ServerStorageComponent storageComp) - { - if (storageComp.Storage == null) - return; - - var state = new StorageBoundUserInterfaceState(GetNetEntityList(storageComp.Storage.ContainedEntities.ToList()), storageComp.StorageUsed, storageComp.StorageCapacityMax); - - var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key); - if (bui != null) - _uiSystem.SetUiState(bui, state); - } - - private void Popup(EntityUid _, EntityUid player, string message, ServerStorageComponent storageComp) - { - if (!storageComp.ShowPopup) - return; - - _popupSystem.PopupEntity(Loc.GetString(message), player, player); - } - - private void PopupEnt(EntityUid _, EntityUid player, string message, EntityUid entityUid, ServerStorageComponent storageComp) - { - if (!storageComp.ShowPopup) - return; - - _popupSystem.PopupEntity(Loc.GetString(message, ("entity", entityUid)), player, player); } } } diff --git a/Content.Server/Store/Systems/StoreSystem.Ui.cs b/Content.Server/Store/Systems/StoreSystem.Ui.cs index c5b8761808..d2fccd1b9c 100644 --- a/Content.Server/Store/Systems/StoreSystem.Ui.cs +++ b/Content.Server/Store/Systems/StoreSystem.Ui.cs @@ -67,7 +67,7 @@ public sealed partial class StoreSystem /// The store entity itself /// The store component being refreshed. /// - public void UpdateUserInterface(EntityUid? user, EntityUid store, StoreComponent? component = null, BoundUserInterface? ui = null) + public void UpdateUserInterface(EntityUid? user, EntityUid store, StoreComponent? component = null, PlayerBoundUserInterface? ui = null) { if (!Resolve(store, ref component)) return; diff --git a/Content.Server/UserInterface/ActivatableUIComponent.cs b/Content.Server/UserInterface/ActivatableUIComponent.cs index 3b61ad6d3c..fe9ae850c8 100644 --- a/Content.Server/UserInterface/ActivatableUIComponent.cs +++ b/Content.Server/UserInterface/ActivatableUIComponent.cs @@ -12,7 +12,7 @@ namespace Content.Server.UserInterface [ViewVariables] public Enum? Key { get; set; } - [ViewVariables] public BoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null; + [ViewVariables] public PlayerBoundUserInterface? UserInterface => (Key != null) ? Owner.GetUIOrNull(Key) : null; [ViewVariables(VVAccess.ReadWrite)] [DataField("inHandsOnly")] diff --git a/Content.Server/UserInterface/ActivatableUISystem.cs b/Content.Server/UserInterface/ActivatableUISystem.cs index c7f07c2f70..c200d7a3f0 100644 --- a/Content.Server/UserInterface/ActivatableUISystem.cs +++ b/Content.Server/UserInterface/ActivatableUISystem.cs @@ -33,7 +33,7 @@ public sealed partial class ActivatableUISystem : EntitySystem SubscribeLocalEvent>(AddOpenUiVerb); - SubscribeLocalEvent(OnActionPerform); + SubscribeLocalEvent(OnActionPerform); InitializePower(); } @@ -50,7 +50,7 @@ public sealed partial class ActivatableUISystem : EntitySystem ev.Cancel(); } - private void OnActionPerform(EntityUid uid, ServerUserInterfaceComponent component, OpenUiActionEvent args) + private void OnActionPerform(EntityUid uid, UserInterfaceComponent component, OpenUiActionEvent args) { if (args.Handled || args.Key == null) return; diff --git a/Content.Server/UserInterface/IntrinsicUISystem.cs b/Content.Server/UserInterface/IntrinsicUISystem.cs index c7360c15bf..ce89974f63 100644 --- a/Content.Server/UserInterface/IntrinsicUISystem.cs +++ b/Content.Server/UserInterface/IntrinsicUISystem.cs @@ -59,7 +59,7 @@ public sealed class IntrinsicUISystem : EntitySystem return true; } - private BoundUserInterface? GetUIOrNull(EntityUid uid, Enum? key, IntrinsicUIComponent? component = null) + private PlayerBoundUserInterface? GetUIOrNull(EntityUid uid, Enum? key, IntrinsicUIComponent? component = null) { if (!Resolve(uid, ref component)) return null; diff --git a/Content.Server/UserInterface/UserInterfaceHelpers.cs b/Content.Server/UserInterface/UserInterfaceHelpers.cs index 4a0e9d1543..865772c772 100644 --- a/Content.Server/UserInterface/UserInterfaceHelpers.cs +++ b/Content.Server/UserInterface/UserInterfaceHelpers.cs @@ -5,7 +5,7 @@ namespace Content.Server.UserInterface public static class UserInterfaceHelpers { [Obsolete("Use UserInterfaceSystem")] - public static BoundUserInterface? GetUIOrNull(this EntityUid entity, Enum uiKey) + public static PlayerBoundUserInterface? GetUIOrNull(this EntityUid entity, Enum uiKey) { return IoCManager.Resolve().GetEntitySystem().GetUiOrNull(entity, uiKey); } diff --git a/Content.Server/Wires/WiresSystem.cs b/Content.Server/Wires/WiresSystem.cs index 07f0de2ebe..0baf0c5c22 100644 --- a/Content.Server/Wires/WiresSystem.cs +++ b/Content.Server/Wires/WiresSystem.cs @@ -565,7 +565,7 @@ public sealed class WiresSystem : SharedWiresSystem UpdateUserInterface(uid); } - private void UpdateUserInterface(EntityUid uid, WiresComponent? wires = null, ServerUserInterfaceComponent? ui = null) + private void UpdateUserInterface(EntityUid uid, WiresComponent? wires = null, UserInterfaceComponent? ui = null) { if (!Resolve(uid, ref wires, ref ui, false)) // logging this means that we get a bunch of errors return; diff --git a/Content.Shared/Access/SharedAgentIDCardSystem.cs b/Content.Shared/Access/SharedAgentIDCardSystem.cs index d127b326cc..ef6690cc35 100644 --- a/Content.Shared/Access/SharedAgentIDCardSystem.cs +++ b/Content.Shared/Access/SharedAgentIDCardSystem.cs @@ -8,7 +8,7 @@ namespace Content.Shared.Access.Systems } /// - /// Key representing which is currently open. + /// Key representing which is currently open. /// Useful when there are multiple UI for an object. Here it's future-proofing only. /// [Serializable, NetSerializable] diff --git a/Content.Shared/Atmos/Piping/Binary/Components/SharedGasCanisterComponent.cs b/Content.Shared/Atmos/Piping/Binary/Components/SharedGasCanisterComponent.cs index c7694aaae7..23300cb2a0 100644 --- a/Content.Shared/Atmos/Piping/Binary/Components/SharedGasCanisterComponent.cs +++ b/Content.Shared/Atmos/Piping/Binary/Components/SharedGasCanisterComponent.cs @@ -3,7 +3,7 @@ namespace Content.Shared.Atmos.Piping.Binary.Components { /// - /// Key representing which is currently open. + /// Key representing which is currently open. /// Useful when there are multiple UI for an object. Here it's future-proofing only. /// [Serializable, NetSerializable] diff --git a/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs b/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs index 423a829809..c84078bace 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.Strap.cs @@ -108,7 +108,7 @@ public abstract partial class SharedBuckleSystem private void OnStrapContainerGettingInsertedAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args) { // If someone is attempting to put this item inside of a backpack, ensure that it has no entities strapped to it. - if (HasComp(args.Container.Owner) && component.BuckledEntities.Count != 0) + if (HasComp(args.Container.Owner) && component.BuckledEntities.Count != 0) args.Cancel(); } diff --git a/Content.Shared/Labels/LabelEvents.cs b/Content.Shared/Labels/LabelEvents.cs index c8d6e950ef..362500b768 100644 --- a/Content.Shared/Labels/LabelEvents.cs +++ b/Content.Shared/Labels/LabelEvents.cs @@ -3,7 +3,7 @@ using Robust.Shared.Serialization; namespace Content.Shared.Labels { /// - /// Key representing which is currently open. + /// Key representing which is currently open. /// Useful when there are multiple UI for an object. Here it's future-proofing only. /// [Serializable, NetSerializable] diff --git a/Content.Shared/Speech/Components/MeleeSpeechComponent.cs b/Content.Shared/Speech/Components/MeleeSpeechComponent.cs index ca8c7a073b..c457fec43f 100644 --- a/Content.Shared/Speech/Components/MeleeSpeechComponent.cs +++ b/Content.Shared/Speech/Components/MeleeSpeechComponent.cs @@ -37,7 +37,7 @@ public sealed partial class MeleeSpeechComponent : Component } /// -/// Key representing which is currently open. +/// Key representing which is currently open. /// Useful when there are multiple UI for an object. Here it's future-proofing only. /// [Serializable, NetSerializable] diff --git a/Content.Shared/Storage/Components/StorageFillComponent.cs b/Content.Shared/Storage/Components/StorageFillComponent.cs new file mode 100644 index 0000000000..e112368a49 --- /dev/null +++ b/Content.Shared/Storage/Components/StorageFillComponent.cs @@ -0,0 +1,12 @@ +using Content.Shared.Storage.EntitySystems; +using Robust.Shared.GameStates; + +namespace Content.Shared.Storage.Components; + +// TODO: +// REPLACE THIS WITH CONTAINERFILL +[RegisterComponent, NetworkedComponent, Access(typeof(SharedStorageSystem))] +public sealed partial class StorageFillComponent : Component +{ + [DataField("contents")] public List Contents = new(); +} diff --git a/Content.Shared/Storage/EntitySystems/DumpableSystem.cs b/Content.Shared/Storage/EntitySystems/DumpableSystem.cs index d44cda40f4..cb53ea8298 100644 --- a/Content.Shared/Storage/EntitySystems/DumpableSystem.cs +++ b/Content.Shared/Storage/EntitySystems/DumpableSystem.cs @@ -1,5 +1,5 @@ +using System.Linq; using Content.Shared.Disposal; -using Content.Shared.Disposal.Components; using Content.Shared.DoAfter; using Content.Shared.Interaction; using Content.Shared.Placeable; @@ -49,7 +49,7 @@ public sealed class DumpableSystem : EntitySystem if (!args.CanAccess || !args.CanInteract) return; - if (!TryComp(uid, out var storage) || storage.StoredEntities == null || storage.StoredEntities.Count == 0) + if (!TryComp(uid, out var storage) || !storage.Container.ContainedEntities.Any()) return; AlternativeVerb verb = new() @@ -69,7 +69,7 @@ public sealed class DumpableSystem : EntitySystem if (!args.CanAccess || !args.CanInteract) return; - if (!TryComp(uid, out var storage) || storage.StoredEntities == null || storage.StoredEntities.Count == 0) + if (!TryComp(uid, out var storage) || !storage.Container.ContainedEntities.Any()) return; if (_disposalUnitSystem.HasDisposals(args.Target)) @@ -103,10 +103,10 @@ public sealed class DumpableSystem : EntitySystem public void StartDoAfter(EntityUid storageUid, EntityUid? targetUid, EntityUid userUid, DumpableComponent dumpable) { - if (!TryComp(storageUid, out var storage) || storage.StoredEntities == null) + if (!TryComp(storageUid, out var storage)) return; - float delay = storage.StoredEntities.Count * (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier; + float delay = storage.Container.ContainedEntities.Count * (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier; _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, userUid, delay, new DumpableDoAfterEvent(), storageUid, target: targetUid, used: storageUid) { @@ -118,11 +118,11 @@ public sealed class DumpableSystem : EntitySystem private void OnDoAfter(EntityUid uid, DumpableComponent component, DoAfterEvent args) { - if (args.Handled || args.Cancelled || !TryComp(uid, out var storage) || storage.StoredEntities == null) + if (args.Handled || args.Cancelled || !TryComp(uid, out var storage)) return; Queue dumpQueue = new(); - foreach (var entity in storage.StoredEntities) + foreach (var entity in storage.Container.ContainedEntities) { dumpQueue.Enqueue(entity); } diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs new file mode 100644 index 0000000000..fac772371d --- /dev/null +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -0,0 +1,606 @@ +using System.Linq; +using Content.Shared.ActionBlocker; +using Content.Shared.CombatMode; +using Content.Shared.Containers.ItemSlots; +using Content.Shared.Destructible; +using Content.Shared.DoAfter; +using Content.Shared.Hands.Components; +using Content.Shared.Hands.EntitySystems; +using Content.Shared.Implants.Components; +using Content.Shared.Interaction; +using Content.Shared.Item; +using Content.Shared.Lock; +using Content.Shared.Placeable; +using Content.Shared.Popups; +using Content.Shared.Stacks; +using Content.Shared.Storage.Components; +using Content.Shared.Timing; +using Content.Shared.Verbs; +using Robust.Shared.Containers; +using Robust.Shared.Map; +using Robust.Shared.Random; + +namespace Content.Shared.Storage.EntitySystems; + +public abstract class SharedStorageSystem : EntitySystem +{ + [Dependency] protected readonly IRobustRandom Random = default!; + [Dependency] private readonly SharedContainerSystem _containerSystem = default!; + [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!; + [Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!; + [Dependency] protected readonly SharedEntityStorageSystem EntityStorage = default!; + [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!; + [Dependency] private readonly SharedInteractionSystem _sharedInteractionSystem = default!; + [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; + [Dependency] protected readonly SharedAudioSystem Audio = default!; + [Dependency] private readonly SharedCombatModeSystem _combatMode = default!; + [Dependency] private readonly SharedTransformSystem _transform = default!; + [Dependency] private readonly SharedStackSystem _stack = default!; + [Dependency] protected readonly UseDelaySystem UseDelay = default!; + + private EntityQuery _itemQuery; + private EntityQuery _stackQuery; + private EntityQuery _xformQuery; + + /// + public override void Initialize() + { + base.Initialize(); + + _itemQuery = GetEntityQuery(); + _stackQuery = GetEntityQuery(); + _xformQuery = GetEntityQuery(); + + SubscribeLocalEvent(OnComponentInit, before: new[] { typeof(SharedContainerSystem) }); + SubscribeLocalEvent>(AddTransferVerbs); + SubscribeLocalEvent(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) }); + SubscribeLocalEvent(OnActivate); + SubscribeLocalEvent(OnImplantActivate); + SubscribeLocalEvent(AfterInteract); + SubscribeLocalEvent(OnDestroy); + SubscribeLocalEvent(OnInsertItemMessage); + SubscribeLocalEvent(OnBoundUIOpen); + + SubscribeLocalEvent(OnStorageItemInserted); + SubscribeLocalEvent(OnStorageItemRemoved); + + SubscribeLocalEvent(OnDoAfter); + + SubscribeLocalEvent(OnInteractWithItem); + } + + private void OnComponentInit(EntityUid uid, StorageComponent storageComp, ComponentInit args) + { + // ReSharper disable once StringLiteralTypo + storageComp.Container = _containerSystem.EnsureContainer(uid, "storagebase"); + UpdateStorage(uid, storageComp); + } + + /// + /// Updates the storage UI, visualizer, etc. + /// + /// + /// + private void UpdateStorage(EntityUid uid, StorageComponent component) + { + // TODO: I had this. + // We can get states being applied before the container is ready. + if (component.Container == default) + return; + + RecalculateStorageUsed(component); + UpdateStorageVisualization(uid, component); + UpdateUI(uid, component); + Dirty(uid, component); + } + + public virtual void UpdateUI(EntityUid uid, StorageComponent component) {} + + public virtual void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false) { } + + private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerbsEvent args) + { + if (!args.CanAccess || !args.CanInteract) + return; + + var entities = component.Container.ContainedEntities; + + if (entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) + return; + + // if the target is storage, add a verb to transfer storage. + if (TryComp(args.Target, out StorageComponent? targetStorage) + && (!TryComp(uid, out LockComponent? targetLock) || !targetLock.Locked)) + { + UtilityVerb verb = new() + { + Text = Loc.GetString("storage-component-transfer-verb"), + IconEntity = GetNetEntity(args.Using), + Act = () => TransferEntities(uid, args.Target, args.User, component, lockComponent, targetStorage, targetLock) + }; + + args.Verbs.Add(verb); + } + } + + /// + /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user + /// + /// true if inserted, false otherwise + private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, InteractUsingEvent args) + { + if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) + return; + + Log.Debug($"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used})."); + + if (HasComp(uid)) + return; + + PlayerInsertHeldEntity(uid, args.User, storageComp); + // Always handle it, even if insertion fails. + // We don't want to trigger any AfterInteract logic here. + // Example bug: placing wires if item doesn't fit in backpack. + args.Handled = true; + } + + /// + /// Sends a message to open the storage UI + /// + private void OnActivate(EntityUid uid, StorageComponent storageComp, ActivateInWorldEvent args) + { + if (args.Handled || _combatMode.IsInCombatMode(args.User) || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) + return; + + OpenStorageUI(uid, args.User, storageComp); + } + + /// + /// Specifically for storage implants. + /// + private void OnImplantActivate(EntityUid uid, StorageComponent storageComp, OpenStorageImplantEvent args) + { + // TODO: Make this an action or something. + if (args.Handled || !_xformQuery.TryGetComponent(uid, out var xform)) + return; + + OpenStorageUI(uid, xform.ParentUid, storageComp); + } + + /// + /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius + /// around a click. + /// + /// + private void AfterInteract(EntityUid uid, StorageComponent storageComp, AfterInteractEvent args) + { + if (!args.CanReach) + return; + + // Pick up all entities in a radius around the clicked location. + // The last half of the if is because carpets exist and this is terrible + if (storageComp.AreaInsert && (args.Target == null || !HasComp(args.Target.Value))) + { + var validStorables = new List(); + + foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries)) + { + if (entity == args.User + || !_itemQuery.HasComponent(entity) + || !CanInsert(uid, entity, out _, storageComp) + || !_interactionSystem.InRangeUnobstructed(args.User, entity)) + { + continue; + } + + validStorables.Add(entity); + } + + //If there's only one then let's be generous + if (validStorables.Count > 1) + { + var doAfterArgs = new DoAfterArgs(EntityManager, args.User, 0.2f * validStorables.Count, new AreaPickupDoAfterEvent(GetNetEntityList(validStorables)), uid, target: uid) + { + BreakOnDamage = true, + BreakOnUserMove = true, + NeedHand = true + }; + + _doAfterSystem.TryStartDoAfter(doAfterArgs); + } + + return; + } + + // Pick up the clicked entity + if (storageComp.QuickInsert) + { + if (args.Target is not { Valid: true } target) + return; + + if (_containerSystem.IsEntityInContainer(target) + || target == args.User + || !HasComp(target)) + { + return; + } + + if (TryComp(uid, out var transformOwner) && TryComp(target, out var transformEnt)) + { + var parent = transformOwner.ParentUid; + + var position = EntityCoordinates.FromMap( + parent.IsValid() ? parent : uid, + transformEnt.MapPosition, + _transform + ); + + if (PlayerInsertEntityInWorld(uid, args.User, target, storageComp)) + { + RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(GetNetEntity(uid), + new List { GetNetEntity(target) }, + new List { GetNetCoordinates(position) }, + new List { transformOwner.LocalRotation })); + } + } + } + } + + private void OnDoAfter(EntityUid uid, StorageComponent component, AreaPickupDoAfterEvent args) + { + if (args.Handled || args.Cancelled) + return; + + var successfullyInserted = new List(); + var successfullyInsertedPositions = new List(); + var successfullyInsertedAngles = new List(); + _xformQuery.TryGetComponent(uid, out var xform); + + foreach (var netEntity in args.Entities) + { + var entity = GetEntity(netEntity); + + // Check again, situation may have changed for some entities, but we'll still pick up any that are valid + if (_containerSystem.IsEntityInContainer(entity) + || entity == args.Args.User + || !_itemQuery.HasComponent(entity)) + continue; + + if (xform == null || + !_xformQuery.TryGetComponent(entity, out var targetXform) || + targetXform.MapID != xform.MapID) + { + continue; + } + + var position = EntityCoordinates.FromMap( + xform.ParentUid.IsValid() ? xform.ParentUid : uid, + new MapCoordinates(_transform.GetWorldPosition(targetXform), targetXform.MapID), + _transform + ); + + var angle = targetXform.LocalRotation; + + if (PlayerInsertEntityInWorld(uid, args.Args.User, entity, component)) + { + successfullyInserted.Add(entity); + successfullyInsertedPositions.Add(position); + successfullyInsertedAngles.Add(angle); + } + } + + // If we picked up atleast one thing, play a sound and do a cool animation! + if (successfullyInserted.Count > 0) + { + Audio.PlayPvs(component.StorageInsertSound, uid); + RaiseNetworkEvent(new AnimateInsertingEntitiesEvent( + GetNetEntity(uid), + GetNetEntityList(successfullyInserted), + GetNetCoordinatesList(successfullyInsertedPositions), + successfullyInsertedAngles)); + } + + args.Handled = true; + } + + private void OnDestroy(EntityUid uid, StorageComponent storageComp, DestructionEventArgs args) + { + var coordinates = _transform.GetMoverCoordinates(uid); + + // Being destroyed so need to recalculate. + _containerSystem.EmptyContainer(storageComp.Container, destination: coordinates); + } + + /// + /// This function gets called when the user clicked on an item in the storage UI. This will either place the + /// item in the user's hand if it is currently empty, or interact with the item using the user's currently + /// held item. + /// + private void OnInteractWithItem(EntityUid uid, StorageComponent storageComp, StorageInteractWithItemEvent args) + { + if (args.Session.AttachedEntity is not EntityUid player) + return; + + var entity = GetEntity(args.InteractedItemUID); + + if (!Exists(entity)) + { + Log.Error($"Player {args.Session} interacted with non-existent item {args.InteractedItemUID} stored in {ToPrettyString(uid)}"); + return; + } + + if (!_actionBlockerSystem.CanInteract(player, entity) || !storageComp.Container.Contains(entity)) + return; + + // Does the player have hands? + if (!TryComp(player, out HandsComponent? hands) || hands.Count == 0) + return; + + // If the user's active hand is empty, try pick up the item. + if (hands.ActiveHandEntity == null) + { + if (_sharedHandsSystem.TryPickupAnyHand(player, entity, handsComp: hands) + && storageComp.StorageRemoveSound != null) + Audio.PlayPredicted(storageComp.StorageRemoveSound, uid, player); + { + return; + } + } + + // Else, interact using the held item + _interactionSystem.InteractUsing(player, hands.ActiveHandEntity.Value, entity, Transform(entity).Coordinates, checkCanInteract: false); + } + + private void OnInsertItemMessage(EntityUid uid, StorageComponent storageComp, StorageComponent.StorageInsertItemMessage args) + { + if (args.Session.AttachedEntity == null) + return; + + PlayerInsertHeldEntity(uid, args.Session.AttachedEntity.Value, storageComp); + } + + private void OnBoundUIOpen(EntityUid uid, StorageComponent storageComp, BoundUIOpenedEvent args) + { + if (!storageComp.IsUiOpen) + { + storageComp.IsUiOpen = true; + UpdateStorageVisualization(uid, storageComp); + } + } + + private void OnStorageItemInserted(EntityUid uid, StorageComponent component, EntInsertedIntoContainerMessage args) + { + UpdateStorage(uid, component); + } + + private void OnStorageItemRemoved(EntityUid uid, StorageComponent storageComp, EntRemovedFromContainerMessage args) + { + UpdateStorage(uid, storageComp); + } + + protected void UpdateStorageVisualization(EntityUid uid, StorageComponent storageComp) + { + if (!TryComp(uid, out var appearance)) + return; + + _appearance.SetData(uid, StorageVisuals.Open, storageComp.IsUiOpen, appearance); + _appearance.SetData(uid, SharedBagOpenVisuals.BagState, storageComp.IsUiOpen ? SharedBagState.Open : SharedBagState.Closed); + + if (HasComp(uid)) + _appearance.SetData(uid, StackVisuals.Hide, !storageComp.IsUiOpen); + } + + public void RecalculateStorageUsed(StorageComponent storageComp) + { + storageComp.StorageUsed = 0; + + foreach (var entity in storageComp.Container.ContainedEntities) + { + if (!_itemQuery.TryGetComponent(entity, out var itemComp)) + continue; + + var size = itemComp.Size; + storageComp.StorageUsed += size; + } + } + + public int GetAvailableSpace(EntityUid uid, StorageComponent? component = null) + { + if (!Resolve(uid, ref component)) + return 0; + + return component.StorageCapacityMax - component.StorageUsed; + } + + /// + /// Move entities from one storage to another. + /// + public void TransferEntities(EntityUid source, EntityUid target, EntityUid? user = null, + StorageComponent? sourceComp = null, LockComponent? sourceLock = null, + StorageComponent? targetComp = null, LockComponent? targetLock = null) + { + if (!Resolve(source, ref sourceComp) || !Resolve(target, ref targetComp)) + return; + + var entities = sourceComp.Container.ContainedEntities; + if (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.ToArray()) + { + Insert(target, entity, user, targetComp, playSound: false); + } + + Audio.PlayPredicted(sourceComp.StorageInsertSound, target, user); + } + + /// + /// Verifies if an entity can be stored and if it fits + /// + /// The entity to check + /// If returning false, the reason displayed to the player + /// true if it can be inserted, false otherwise + public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, StorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp)) + { + reason = null; + return false; + } + + if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored) + { + reason = "comp-storage-anchored-failure"; + 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 StorageComponent? 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; + } + + reason = null; + return true; + } + + /// + /// Inserts into the storage container + /// + /// true if the entity was inserted, false otherwise + public bool Insert(EntityUid uid, EntityUid insertEnt, EntityUid? user = null, StorageComponent? storageComp = null, bool playSound = true) + { + if (!Resolve(uid, ref storageComp) || !CanInsert(uid, insertEnt, out _, storageComp)) + return false; + + /* + * 1. If the inserted thing is stackable then try to stack it to existing stacks + * 2. If anything remains insert whatever is possible. + * 3. If insertion is not possible then leave the stack as is. + * At either rate still play the insertion sound + * + * For now we just treat items as always being the same size regardless of stack count. + */ + + // If it's stackable then prefer to stack it + if (_stackQuery.TryGetComponent(insertEnt, out var insertStack)) + { + var toInsertCount = insertStack.Count; + + foreach (var ent in storageComp.Container.ContainedEntities) + { + if (!_stackQuery.TryGetComponent(ent, out var containedStack) || !insertStack.StackTypeId.Equals(containedStack.StackTypeId)) + continue; + + if (!_stack.TryAdd(insertEnt, ent, insertStack, containedStack)) + continue; + + var remaining = insertStack.Count; + toInsertCount -= toInsertCount - remaining; + + if (remaining > 0) + continue; + + break; + } + + // Still stackable remaining + if (insertStack.Count > 0) + { + // Try to insert it as a new stack. + if (TryComp(insertEnt, out ItemComponent? itemComp) && + itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed || + !storageComp.Container.Insert(insertEnt)) + { + // If we also didn't do any stack fills above then just end + // otherwise play sound and update UI anyway. + if (toInsertCount == insertStack.Count) + return false; + } + } + } + // Non-stackable but no insertion for reasons. + else if (!storageComp.Container.Insert(insertEnt)) + { + return false; + } + + if (playSound && storageComp.StorageInsertSound is not null) + Audio.PlayPredicted(storageComp.StorageInsertSound, uid, user); + + return true; + } + + /// + /// Inserts an entity into storage from the player's active hand + /// + /// The player to insert an entity from + /// true if inserted, false otherwise + public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, StorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp) || !TryComp(player, out HandsComponent? hands) || hands.ActiveHandEntity == null) + return false; + + var toInsert = hands.ActiveHandEntity; + + if (!CanInsert(uid, toInsert.Value, out var reason, storageComp)) + { + _popupSystem.PopupClient(reason ?? Loc.GetString("comp-storage-cant-insert"), uid, player); + return false; + } + + if (!_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands)) + { + _popupSystem.PopupClient(Loc.GetString("comp-storage-cant-drop"), uid, player); + return false; + } + + return PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp); + } + + /// + /// Inserts an Entity () in the world into storage, informing if it fails. + /// is *NOT* held, see . + /// + /// The player to insert an entity with + /// true if inserted, false otherwise + public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, StorageComponent? storageComp = null) + { + if (!Resolve(uid, ref storageComp) || !_sharedInteractionSystem.InRangeUnobstructed(player, uid)) + return false; + + if (!Insert(uid, toInsert, player, storageComp)) + { + _popupSystem.PopupClient(Loc.GetString("comp-storage-cant-insert"), uid, player); + return false; + } + return true; + } +} diff --git a/Content.Shared/Storage/SharedStorageComponent.cs b/Content.Shared/Storage/SharedStorageComponent.cs deleted file mode 100644 index 4573af6863..0000000000 --- a/Content.Shared/Storage/SharedStorageComponent.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Robust.Shared.GameStates; -using Robust.Shared.Map; -using Robust.Shared.Serialization; - -namespace Content.Shared.Storage -{ - [NetworkedComponent()] - public abstract partial class SharedStorageComponent : Component - { - [Serializable, NetSerializable] - public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState - { - public readonly List StoredEntities; - public readonly int StorageSizeUsed; - public readonly int StorageCapacityMax; - - public StorageBoundUserInterfaceState(List storedEntities, int storageSizeUsed, int storageCapacityMax) - { - StoredEntities = storedEntities; - StorageSizeUsed = storageSizeUsed; - StorageCapacityMax = storageCapacityMax; - } - } - - [Serializable, NetSerializable] - public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage - { - } - - [Serializable, NetSerializable] - public sealed class StorageInteractWithItemEvent : BoundUserInterfaceMessage - { - public readonly NetEntity InteractedItemUID; - public StorageInteractWithItemEvent(NetEntity interactedItemUID) - { - InteractedItemUID = interactedItemUID; - } - } - - [Serializable, NetSerializable] - public enum StorageUiKey - { - Key, - } - - public abstract IReadOnlyList? StoredEntities { get; } - - /// - /// Removes from the storage container and updates the stored value - /// - /// The entity to remove - /// True if no longer in storage, false otherwise - public abstract bool Remove(EntityUid entity); - } - - /// - /// Network event for displaying an animation of entities flying into a storage entity - /// - [Serializable, NetSerializable] - public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs - { - public readonly NetEntity Storage; - public readonly List StoredEntities; - public readonly List EntityPositions; - public readonly List EntityAngles; - - public AnimateInsertingEntitiesEvent(NetEntity storage, List storedEntities, List entityPositions, List entityAngles) - { - Storage = storage; - StoredEntities = storedEntities; - EntityPositions = entityPositions; - EntityAngles = entityAngles; - } - } - - [NetSerializable] - [Serializable] - public enum StorageVisuals : byte - { - Open, - HasContents, - CanLock, - Locked - } -} diff --git a/Content.Shared/Storage/StorageComponent.cs b/Content.Shared/Storage/StorageComponent.cs new file mode 100644 index 0000000000..0a924365a4 --- /dev/null +++ b/Content.Shared/Storage/StorageComponent.cs @@ -0,0 +1,135 @@ +using Content.Shared.Whitelist; +using Robust.Shared.Audio; +using Robust.Shared.Containers; +using Robust.Shared.GameStates; +using Robust.Shared.Map; +using Robust.Shared.Serialization; + +namespace Content.Shared.Storage +{ + /// + /// Handles generic storage with window, such as backpacks. + /// + [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] + public sealed partial class StorageComponent : Component + { + // TODO: This fucking sucks + [ViewVariables(VVAccess.ReadWrite), DataField("isOpen"), AutoNetworkedField] + public bool IsUiOpen; + + [ViewVariables] + public Container Container = default!; + + // TODO: Make area insert its own component. + [DataField("quickInsert")] + public bool QuickInsert; // Can insert storables by "attacking" them with the storage entity + + [DataField("clickInsert")] + public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it + + [DataField("areaInsert")] + public bool AreaInsert; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay + + [DataField("areaInsertRadius")] + public int AreaInsertRadius = 1; + + /// + /// Whitelist for entities that can go into the storage. + /// + [DataField("whitelist")] + public EntityWhitelist? Whitelist; + + /// + /// Blacklist for entities that can go into storage. + /// + [DataField("blacklist")] + public EntityWhitelist? Blacklist; + + /// + /// How much storage is currently being used by contained entities. + /// + [ViewVariables, DataField("storageUsed"), AutoNetworkedField] + public int StorageUsed; + + /// + /// Maximum capacity for storage. + /// + [DataField("capacity"), AutoNetworkedField] + public int StorageCapacityMax = 10000; + + /// + /// Sound played whenever an entity is inserted into storage. + /// + [DataField("storageInsertSound")] + public SoundSpecifier? StorageInsertSound = new SoundCollectionSpecifier("storageRustle"); + + /// + /// Sound played whenever an entity is removed from storage. + /// + [DataField("storageRemoveSound")] + public SoundSpecifier? StorageRemoveSound; + + /// + /// Sound played whenever the storage window is opened. + /// + [DataField("storageOpenSound")] + public SoundSpecifier? StorageOpenSound = new SoundCollectionSpecifier("storageRustle"); + + /// + /// Sound played whenever the storage window is closed. + /// + [DataField("storageCloseSound")] + public SoundSpecifier? StorageCloseSound; + + [Serializable, NetSerializable] + public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage + { + } + + [Serializable, NetSerializable] + public enum StorageUiKey + { + Key, + } + } + + [Serializable, NetSerializable] + public sealed class StorageInteractWithItemEvent : BoundUserInterfaceMessage + { + public readonly NetEntity InteractedItemUID; + public StorageInteractWithItemEvent(NetEntity interactedItemUID) + { + InteractedItemUID = interactedItemUID; + } + } + + /// + /// Network event for displaying an animation of entities flying into a storage entity + /// + [Serializable, NetSerializable] + public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs + { + public readonly NetEntity Storage; + public readonly List StoredEntities; + public readonly List EntityPositions; + public readonly List EntityAngles; + + public AnimateInsertingEntitiesEvent(NetEntity storage, List storedEntities, List entityPositions, List entityAngles) + { + Storage = storage; + StoredEntities = storedEntities; + EntityPositions = entityPositions; + EntityAngles = entityAngles; + } + } + + [NetSerializable] + [Serializable] + public enum StorageVisuals : byte + { + Open, + HasContents, + CanLock, + Locked + } +} diff --git a/Resources/Prototypes/Catalog/Fills/Lockers/service.yml b/Resources/Prototypes/Catalog/Fills/Lockers/service.yml index 1f669944e1..e86c09de2a 100644 --- a/Resources/Prototypes/Catalog/Fills/Lockers/service.yml +++ b/Resources/Prototypes/Catalog/Fills/Lockers/service.yml @@ -18,7 +18,7 @@ - id: BoxBeanbag amount: 2 - id: RagItem - amound: 2 + amount: 2 #- type: entity # id: LockerFormalFilled diff --git a/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml b/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml index 0c400828d8..b37d3fd974 100644 --- a/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml +++ b/Resources/Prototypes/Entities/Clothing/Belt/base_clothingbelt.yml @@ -23,8 +23,6 @@ components: - type: Storage capacity: 40 - equipSound: - path: /Audio/Items/belt_equip.ogg - type: ContainerContainer containers: storagebase: !type:Container diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/space.yml b/Resources/Prototypes/Entities/Mobs/NPCs/space.yml index aaff696c56..62366e0b14 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/space.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/space.yml @@ -183,9 +183,6 @@ interfaces: - key: enum.StrippingUiKey.Key type: StrippableBoundUserInterface - radius: 1.2 - energy: 2 - color: "#4faffb" - type: GhostRole prob: 0.25 name: ghost-role-information-space-kangaroo-name diff --git a/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml b/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml index cac3e0ac58..8c3b5aea8b 100644 --- a/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml +++ b/Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml @@ -19,7 +19,6 @@ - type: Item - type: Storage capacity: 18 - size: 5 whitelist: tags: - Dice diff --git a/Resources/Prototypes/Entities/Objects/Misc/paper.yml b/Resources/Prototypes/Entities/Objects/Misc/paper.yml index 621018d7f7..6a2d569bf4 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/paper.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/paper.yml @@ -338,7 +338,6 @@ size: 5 - type: Storage capacity: 10 - size: 10 whitelist: tags: - Document diff --git a/Resources/Prototypes/Entities/Objects/Specific/Kitchen/foodcarts.yml b/Resources/Prototypes/Entities/Objects/Specific/Kitchen/foodcarts.yml index be69667c3d..22faf499f1 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Kitchen/foodcarts.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Kitchen/foodcarts.yml @@ -47,7 +47,6 @@ - key: enum.StorageUiKey.Key type: StorageBoundUserInterface - type: Storage - popup: false capacity: 30 - type: TileFrictionModifier modifier: 0.4 # makes it slide