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
{
SendMessage(new AirAlarmUpdateDeviceDataMessage(address, data));
}
-
+
private void OnDeviceDataCopied(IAtmosDeviceData data)
{
SendMessage(new AirAlarmCopyDeviceDataMessage(data));
[ViewVariables]
private float _maxTemp = 0.0f;
-
+
[ViewVariables]
private bool _isHeater = true;
-using Content.Client.Storage;
using Content.Shared.Interaction;
+using Content.Shared.Storage;
using Robust.Shared.Containers;
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.
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;
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;
if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
return;
var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot,
- HasComp<ClientStorageComponent>(args.Equipment));
+ HasComp<StorageComponent>(args.Equipment));
OnSpriteUpdate?.Invoke(update);
}
+++ /dev/null
-using Content.Client.Animations;
-using Content.Shared.DragDrop;
-using Content.Shared.Storage;
-
-namespace Content.Client.Storage
-{
- /// <summary>
- /// Client version of item storage containers, contains a UI which displays stored entities and their size
- /// </summary>
- [RegisterComponent]
- [ComponentReference(typeof(SharedStorageComponent))]
- public sealed partial class ClientStorageComponent : SharedStorageComponent
- {
- private List<EntityUid> _storedEntities = new();
- public override IReadOnlyList<EntityUid> StoredEntities => _storedEntities;
-
- public override bool Remove(EntityUid entity)
- {
- return false;
- }
- }
-}
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
{
[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()
if (_window == null)
{
- _window = new StorageWindow(EntMan)
- {
- Title = EntMan.GetComponent<MetaDataComponent>(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<IUserInterfaceManager>().GetUIController<StorageUIController>();
+ _window = controller.EnsureStorageWindow(Owner);
+ _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_window.EntityList.GenerateItem += _window.GenerateButton;
_window.EntityList.ItemPressed += InteractWithItem;
_window.StorageContainerButton.OnPressed += TouchedContainerButton;
_window.OnClose += Close;
- _window.OpenCenteredLeft();
+
+ if (EntMan.TryGetComponent<StorageComponent>(Owner, out var storageComp))
+ {
+ BuildEntityList(Owner, storageComp);
+ }
+
}
else
{
}
}
+ 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 })
if (args.Event.Function == EngineKeyFunctions.UIClick)
{
- SendMessage(new StorageInteractWithItemEvent(EntMan.GetNetEntity(entity)));
+ SendPredictedMessage(new StorageInteractWithItemEvent(_entManager.GetNetEntity(entity)));
}
else if (EntMan.EntityExists(entity))
{
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)
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;
}
}
}
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<EntityUid, StorageComponent>? StorageUpdated;
+
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities);
}
+ public override void UpdateUI(EntityUid uid, StorageComponent component)
+ {
+ // Should we wrap this in some prediction call maybe?
+ StorageUpdated?.Invoke(uid, component);
+ }
+
/// <summary>
/// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
/// </summary>
/// <param name="msg"></param>
public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg)
{
- var store = GetEntity(msg.Storage);
-
- if (!HasComp<ClientStorageComponent>(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)
{
--- /dev/null
+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<StorageSystem>
+{
+ // This is mainly to keep legacy functionality for now.
+ private readonly Dictionary<EntityUid, StorageWindow> _storageWindows = new();
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ EntityManager.EventBus.SubscribeLocalEvent<StorageComponent, ComponentShutdown>(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<UserInterfaceComponent>(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;
+ }
+}
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;
/// <summary>
/// GUI class for client storage component
/// </summary>
- 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;
MouseFilter = MouseFilterMode.Pass,
};
- Contents.AddChild(StorageContainerButton);
+ ContentsContainer.AddChild(StorageContainerButton);
var innerContainerButton = new PanelContainer
{
{
Orientation = LayoutOrientation.Vertical,
MouseFilter = MouseFilterMode.Ignore,
+ Margin = new Thickness(5),
};
StorageContainerButton.AddChild(vBox);
/// <summary>
/// Loops through stored entities creating buttons for each, updates information labels
/// </summary>
- 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<EntityListData>(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));
}
}
using Content.Shared.Inventory.Events;
using Content.Shared.Strip;
using Content.Shared.Strip.Components;
-using Robust.Client.GameObjects;
namespace Content.Client.Strip;
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)
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;
container.AddButton(button);
}
- var showStorage = _entities.HasComponent<ClientStorageComponent>(data.HeldEntity);
+ var showStorage = _entities.HasComponent<StorageComponent>(data.HeldEntity);
var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
SpriteUpdated(update);
}
_strippingWindow!.InventoryButtons.AddButton(button, data.ButtonOffset);
}
- var showStorage = _entities.HasComponent<ClientStorageComponent>(data.HeldEntity);
+ var showStorage = _entities.HasComponent<StorageComponent>(data.HeldEntity);
var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
SpriteUpdated(update);
}
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;
return false;
}
- var clientTarget = CEntMan.GetEntity(target);
-
- if (!CEntMan.TryGetComponent<ClientUserInterfaceComponent>(clientTarget, out var ui))
+ if (!CEntMan.TryGetComponent<UserInterfaceComponent>(CEntMan.GetEntity(target), out var ui))
{
if (shouldSucceed)
Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have a bui component");
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;
{
foreach (var proto in protoManager.EnumeratePrototypes<EntityPrototype>())
{
- if (!proto.TryGetComponent<ServerStorageComponent>("Storage", out var storage) ||
+ if (!proto.TryGetComponent<StorageComponent>("Storage", out var storage) ||
storage.Whitelist != null ||
!proto.TryGetComponent<ItemComponent>("Item", out var item)) continue;
int capacity;
var isEntStorage = false;
- if (proto.TryGetComponent<ServerStorageComponent>("Storage", out var storage))
+ if (proto.TryGetComponent<StorageComponent>("Storage", out var storage))
{
capacity = storage.StorageCapacityMax;
}
using Content.Shared.Wires;
using Content.Server.Wires;
using Content.Shared.Prototypes;
+using Content.Shared.Storage.Components;
namespace Content.IntegrationTests.Tests
{
}
}
- 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;
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;
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;
public void UpdateBountyConsoles()
{
- var query = EntityQueryEnumerator<CargoBountyConsoleComponent, ServerUserInterfaceComponent>();
+ var query = EntityQueryEnumerator<CargoBountyConsoleComponent, UserInterfaceComponent>();
while (query.MoveNext(out var uid, out _, out var ui))
{
if (_station.GetOwningStation(uid) is not { } station ||
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;
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;
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
}
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);
}
}
- if (!TryComp(container, out ServerStorageComponent? storage))
+ if (!TryComp(container, out StorageComponent? storage))
return null;
- var pills = storage.Storage?.ContainedEntities.Select((Func<EntityUid, (string, FixedPoint2 quantity)>) (pill =>
+ var pills = storage.Container?.ContainedEntities.Select((Func<EntityUid, (string, FixedPoint2 quantity)>) (pill =>
{
_solutionContainerSystem.TryGetSolution(pill, SharedChemMaster.PillSolutionName, out var solution);
var quantity = solution?.Volume ?? FixedPoint2.Zero;
[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);
}
}
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;
[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.
{
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;
}
{
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;
}
continue;
// Dump out any stored entities in used entity
- if (TryComp<ServerStorageComponent>(entity, out var storage) && storage.StoredEntities != null)
+ if (TryComp<StorageComponent>(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))
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;
if (args.Handled || args.Args.Target == null)
return;
- if (!TryComp<ServerStorageComponent>(uid, out var storage) || storage.Storage == null)
+ if (!TryComp<StorageComponent>(uid, out var storage) || storage.Container == null)
return; //the parts are stored in here
var machinePartQuery = GetEntityQuery<MachinePartComponent>();
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));
//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);
}
//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);
}
}
[DataField("deleteEmpty")]
public bool DeleteEmpty = true;
- [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
+ [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
}
}
if (uiList == null)
return;
- Queue<BoundUserInterface> closeList = new(); // foreach collection modified moment
+ Queue<PlayerBoundUserInterface> closeList = new(); // foreach collection modified moment
foreach (var ui in uiList)
{
+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;
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;
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!;
return;
if (!_inventorySystem.TryGetSlotEntity(plyEnt, equipmentSlot, out var slotEntity) ||
- !TryComp(slotEntity, out ServerStorageComponent? storageComponent))
+ !TryComp(slotEntity, out StorageComponent? storageComponent))
{
if (_inventorySystem.HasSlot(plyEnt, equipmentSlot))
{
{
_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);
}
_entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser
?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession;
- [ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
+ [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
}
[RegisterComponent]
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;
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
-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
{
if (args.SenderSession.AttachedEntity is not { Valid: true } uid)
return;
- if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp<ServerStorageComponent>(entityUid, out var storageComponent))
+ if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp<StorageComponent>(entityUid, out var storageComponent))
{
_storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent);
}
-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;
base.OnStackCountChanged(uid, component, args);
if (!Container.TryGetContainingContainer(uid, out var container) ||
- !TryComp<ServerStorageComponent>(container.Owner, out var storage))
+ !TryComp<StorageComponent>(container.Owner, out var storage))
+ {
return;
+ }
+
_storage.RecalculateStorageUsed(storage);
- _storage.UpdateStorageUI(container.Owner, storage);
+ _storage.UpdateUI(container.Owner, storage);
}
}
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;
if (TryComp<LightBulbComponent>(usedUid, out var bulb))
eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb);
// add bulbs from storage?
- else if (TryComp<ServerStorageComponent>(usedUid, out var storage))
+ else if (TryComp<StorageComponent>(usedUid, out var storage))
eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage);
}
/// which was successfully inserted inside light replacer
/// </returns>
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<LightBulbComponent>(ent, out var bulb) &&
TryInsertBulb(replacerUid, ent, userUid, false, replacer, bulb))
+ {
insertedBulbs++;
+ }
}
// show some message if success
[DataField("scanDelay")]
public float ScanDelay = 0.8f;
- public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
+ public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
/// <summary>
/// Sound played on scanning begin
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
{
}
// Check for used storage on the food item
- if (TryComp<ServerStorageComponent>(food, out var storageState) && storageState.StorageUsed != 0)
+ if (TryComp<StorageComponent>(food, out var storageState) && storageState.StorageUsed != 0)
{
_popupSystem.PopupEntity(Loc.GetString("food-has-used-storage", ("food", food)), user, user);
return (false, true);
{
base.OnComponentInit(uid, pda, args);
- if (!HasComp<ServerUserInterfaceComponent>(uid))
+ if (!HasComp<UserInterfaceComponent>(uid))
return;
UpdateAlertLevel(uid, pda);
public override void Update(float deltaTime)
{
- var query = EntityQueryEnumerator<ApcComponent, PowerNetworkBatteryComponent, ServerUserInterfaceComponent>();
+ var query = EntityQueryEnumerator<ApcComponent, PowerNetworkBatteryComponent, UserInterfaceComponent>();
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);
}
}
}
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;
}
// Uncontested
- if (HasComp<SharedStorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) || HasComp<SecretStashComponent>(container.Owner))
+ if (HasComp<StorageComponent>(container.Owner) || HasComp<InventoryComponent>(container.Owner) || HasComp<SecretStashComponent>(container.Owner))
AttemptEscape(uid, container.Owner, component);
}
using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
-using Robust.Server.GameObjects;
namespace Content.Server.Salvage;
{
var state = GetState(component);
- foreach (var (console, xform, uiComp) in EntityQuery<SalvageExpeditionConsoleComponent, TransformComponent, ServerUserInterfaceComponent>(true))
+ foreach (var (console, xform, uiComp) in EntityQuery<SalvageExpeditionConsoleComponent, TransformComponent, UserInterfaceComponent>(true))
{
var station = _station.GetOwningStation(console.Owner, xform);
using Content.Shared.SensorMonitoring;
using Robust.Server.Player;
using Robust.Shared.Collections;
+using Robust.Shared.Players;
namespace Content.Server.SensorMonitoring;
public TimeSpan RetentionTime = TimeSpan.FromMinutes(1);
// UI update tracking stuff.
- public HashSet<IPlayerSession> InitialUIStateSent = new();
+ public HashSet<ICommonSession> InitialUIStateSent = new();
public TimeSpan LastUIUpdate;
public ValueList<int> RemovedSensors;
{
_updateTimer -= 1;
var state = new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun);
- var query = EntityQueryEnumerator<SolarControlConsoleComponent, ServerUserInterfaceComponent>();
+ var query = EntityQueryEnumerator<SolarControlConsoleComponent, UserInterfaceComponent>();
while (query.MoveNext(out var uid, out var _, out var uiComp))
{
_uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp);
-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;
return;
if (_container.TryGetContainingContainer(uid, out var container) &&
- TryComp<ServerStorageComponent>(container.Owner, out var storage))
+ TryComp<StorageComponent>(container.Owner, out var storage))
{
- _storage.UpdateStorageUI(container.Owner, storage);
+ _storage.UpdateUI(container.Owner, storage);
}
Hands.PickupOrDrop(userUid, split);
+++ /dev/null
-using Content.Shared.Storage;
-using Content.Shared.Whitelist;
-using Robust.Shared.Audio;
-using Robust.Shared.Containers;
-using System.Threading;
-
-namespace Content.Server.Storage.Components
-{
- /// <summary>
- /// Storage component for containing entities within this one, matches a UI on the client which shows stored entities
- /// </summary>
- [RegisterComponent]
- [ComponentReference(typeof(SharedStorageComponent))]
- public sealed partial class ServerStorageComponent : SharedStorageComponent
- {
- public string LoggerName = "Storage";
-
- public Container? Storage;
-
- public readonly Dictionary<EntityUid, int> 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;
-
- /// <summary>
- /// If true, storage will show popup messages to the player after failed interactions.
- /// Usually this is message that item doesn't fit inside container.
- /// </summary>
- [DataField("popup")]
- public bool ShowPopup = true;
-
- /// <summary>
- /// This storage has an open UI
- /// </summary>
- 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<EntityUid>? 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;
- }
- }
-}
+++ /dev/null
-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<EntitySpawnEntry> Contents = new();
- }
-}
-using Content.Server.Storage.Components;
+using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems;
using JetBrains.Annotations;
{
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;
using Robust.Shared.Containers;
using Robust.Shared.Random;
using System.Linq;
+using Content.Shared.Storage;
namespace Content.Server.Storage.EntitySystems;
private void OnGetAlternativeVerbs(EntityUid uid, PickRandomComponent comp, GetVerbsEvent<AlternativeVerb> args)
{
- if (!args.CanAccess || !args.CanInteract || !TryComp<ServerStorageComponent>(uid, out var storage))
+ if (!args.CanAccess || !args.CanInteract || !TryComp<StorageComponent>(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,
});
}
- 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));
-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;
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))
using Content.Server.Storage.Components;
using Content.Shared.Storage;
+using Content.Shared.Storage.Components;
namespace Content.Server.Storage.EntitySystems;
{
private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args)
{
- if (component.Contents.Count == 0) return;
+ if (component.Contents.Count == 0)
+ return;
- TryComp<ServerStorageComponent>(uid, out var serverStorageComp);
+ TryComp<StorageComponent>(uid, out var storageComp);
TryComp<EntityStorageComponent>(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 (entityStorageComp != null && EntityStorage.Insert(ent, uid))
+ continue;
- if (serverStorageComp != null && Insert(uid, ent, serverStorageComp, false))
+ if (storageComp != null && Insert(uid, ent, storageComp: storageComp, playSound: false))
continue;
- Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
+ Log.Error($"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
EntityManager.DeleteEntity(ent);
}
}
-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
-{
- public sealed partial class StorageSystem : EntitySystem
- {
- [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!;
-
- /// <inheritdoc />
- public override void Initialize()
- {
- base.Initialize();
-
- SubscribeLocalEvent<ServerStorageComponent, ComponentInit>(OnComponentInit);
- SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
- SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
- SubscribeLocalEvent<ServerStorageComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) });
- SubscribeLocalEvent<ServerStorageComponent, ActivateInWorldEvent>(OnActivate);
- SubscribeLocalEvent<ServerStorageComponent, OpenStorageImplantEvent>(OnImplantActivate);
- SubscribeLocalEvent<ServerStorageComponent, AfterInteractEvent>(AfterInteract);
- SubscribeLocalEvent<ServerStorageComponent, DestructionEventArgs>(OnDestroy);
- SubscribeLocalEvent<ServerStorageComponent, StorageInteractWithItemEvent>(OnInteractWithItem);
- SubscribeLocalEvent<ServerStorageComponent, StorageInsertItemMessage>(OnInsertItemMessage);
- SubscribeLocalEvent<ServerStorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
- SubscribeLocalEvent<ServerStorageComponent, BoundUIClosedEvent>(OnBoundUIClosed);
- SubscribeLocalEvent<ServerStorageComponent, EntRemovedFromContainerMessage>(OnStorageItemRemoved);
-
- SubscribeLocalEvent<ServerStorageComponent, AreaPickupDoAfterEvent>(OnDoAfter);
-
- SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
- }
-
- private void OnComponentInit(EntityUid uid, ServerStorageComponent storageComp, ComponentInit args)
- {
- base.Initialize();
-
- // ReSharper disable once StringLiteralTypo
- storageComp.Storage = _containerSystem.EnsureContainer<Container>(uid, "storagebase");
- storageComp.Storage.OccludesLight = storageComp.OccludesLight;
- UpdateStorageVisualization(uid, storageComp);
- RecalculateStorageUsed(storageComp);
- UpdateStorageUI(uid, storageComp);
- }
-
- private void AddOpenUiVerb(EntityUid uid, ServerStorageComponent component, GetVerbsEvent<ActivationVerb> args)
- {
- var silent = false;
- if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
- {
- // we allow admins to open the storage anyways
- if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin))
- return;
-
- silent = true;
- }
-
- silent |= HasComp<GhostComponent>(args.User);
-
- // Get the session for the user
- if (!TryComp<ActorComponent>(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<UtilityVerb> args)
- {
- if (!args.CanAccess || !args.CanInteract)
- return;
+namespace Content.Server.Storage.EntitySystems;
- var entities = component.Storage?.ContainedEntities;
- if (entities == null || entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
- return;
+public sealed partial class StorageSystem : SharedStorageSystem
+{
+ [Dependency] private readonly IAdminManager _admin = default!;
+ [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
- // 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)
- };
+ public override void Initialize()
+ {
+ base.Initialize();
+ SubscribeLocalEvent<StorageComponent, GetVerbsEvent<ActivationVerb>>(AddUiVerb);
+ SubscribeLocalEvent<StorageComponent, BoundUIClosedEvent>(OnBoundUIClosed);
- args.Verbs.Add(verb);
- }
- }
+ SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
+ }
- /// <summary>
- /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user
- /// </summary>
- /// <returns>true if inserted, false otherwise</returns>
- private void OnInteractUsing(EntityUid uid, ServerStorageComponent storageComp, InteractUsingEvent args)
+ private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<ActivationVerb> args)
+ {
+ var silent = false;
+ if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
{
- 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<PlaceableSurfaceComponent>(uid))
+ // we allow admins to open the storage anyways
+ if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin))
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;
+ silent = true;
}
- /// <summary>
- /// Sends a message to open the storage UI
- /// </summary>
- /// <returns></returns>
- 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);
- }
+ silent |= HasComp<GhostComponent>(args.User);
- /// <summary>
- /// Specifically for storage implants.
- /// </summary>
- private void OnImplantActivate(EntityUid uid, ServerStorageComponent storageComp, OpenStorageImplantEvent args)
- {
- if (args.Handled || !TryComp<TransformComponent>(uid, out var xform))
- return;
+ // Get the session for the user
+ if (!TryComp<ActorComponent>(args.User, out var actor))
+ return;
- OpenStorageUI(uid, xform.ParentUid, storageComp);
- }
+ // Does this player currently have the storage UI open?
+ var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
- /// <summary>
- /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius
- /// around a click.
- /// </summary>
- /// <returns></returns>
- private async void AfterInteract(EntityUid uid, ServerStorageComponent storageComp, AfterInteractEvent args)
+ ActivationVerb verb = new()
{
- 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<ItemComponent>(args.Target.Value)))
+ Act = () =>
{
- var validStorables = new List<NetEntity>();
- var itemQuery = GetEntityQuery<ItemComponent>();
-
- foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries))
+ if (uiOpen)
{
- if (entity == args.User
- || !itemQuery.HasComponent(entity)
- || !CanInsert(uid, entity, out _, storageComp)
- || !_interactionSystem.InRangeUnobstructed(args.User, entity))
- {
- continue;
- }
-
- validStorables.Add(GetNetEntity(entity));
+ _uiSystem.TryClose(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
}
-
- //If there's only one then let's be generous
- if (validStorables.Count > 1)
+ else
{
- 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);
+ OpenStorageUI(uid, args.User, component, silent);
}
-
- 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<ItemComponent>(target))
- return;
-
- if (TryComp<TransformComponent>(uid, out var transformOwner) && TryComp<TransformComponent>(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<NetEntity> { GetNetEntity(target) },
- new List<NetCoordinates> { GetNetCoordinates(position) },
- new List<Angle> { transformOwner.LocalRotation }));
- }
- }
- }
- }
-
- private void OnDoAfter(EntityUid uid, ServerStorageComponent component, AreaPickupDoAfterEvent args)
+ };
+ if (uiOpen)
{
- if (args.Handled || args.Cancelled)
- return;
-
- var successfullyInserted = new List<EntityUid>();
- var successfullyInsertedPositions = new List<EntityCoordinates>();
- var successfullyInsertedAngles = new List<Angle>();
- var itemQuery = GetEntityQuery<ItemComponent>();
- var xformQuery = GetEntityQuery<TransformComponent>();
- 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;
+ verb.Text = Loc.GetString("verb-common-close-ui");
+ verb.Icon = new SpriteSpecifier.Texture(
+ new("/Textures/Interface/VerbIcons/close.svg.192dpi.png"));
}
-
- private void OnDestroy(EntityUid uid, ServerStorageComponent storageComp, DestructionEventArgs args)
+ else
{
- var storedEntities = storageComp.StoredEntities?.ToList();
-
- if (storedEntities == null)
- return;
-
- foreach (var entity in storedEntities)
- {
- RemoveAndDrop(uid, entity, storageComp);
- }
+ 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);
+ }
- /// <summary>
- /// 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.
- /// </summary>
- 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<ActorComponent>(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<AppearanceComponent>(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<ItemCounterComponent>(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<ItemComponent>();
-
- 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;
- }
-
- /// <summary>
- /// Move entities from one storage to another.
- /// </summary>
- public void TransferEntities(EntityUid source, EntityUid target,
- ServerStorageComponent? sourceComp = null, LockComponent? sourceLock = null,
- ServerStorageComponent? targetComp = null, LockComponent? targetLock = null)
- {
- if (!Resolve(source, ref sourceComp) || !Resolve(target, ref targetComp))
- return;
-
- var entities = sourceComp.Storage?.ContainedEntities;
- if (entities == null || entities.Count == 0)
- return;
-
- if (Resolve(source, ref sourceLock, false) && sourceLock.Locked
- || Resolve(target, ref targetLock, false) && targetLock.Locked)
- return;
-
- foreach (var entity in entities.ToList())
- {
- Insert(target, entity, targetComp);
- }
- RecalculateStorageUsed(sourceComp);
- UpdateStorageUI(source, sourceComp);
- }
-
- /// <summary>
- /// Verifies if an entity can be stored and if it fits
- /// </summary>
- /// <param name="uid">The entity to check</param>
- /// <param name="reason">If returning false, the reason displayed to the player</param>
- /// <returns>true if it can be inserted, false otherwise</returns>
- public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, ServerStorageComponent? storageComp = null)
- {
- if (!Resolve(uid, ref storageComp))
- {
- reason = null;
- return false;
- }
-
- if (TryComp(insertEnt, out 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;
- }
-
- /// <summary>
- /// Inserts into the storage container
- /// </summary>
- /// <returns>true if the entity was inserted, false otherwise</returns>
- 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<StackComponent>();
-
- 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;
- }
+ private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundUIClosedEvent args)
+ {
+ if (TryComp<ActorComponent>(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null)
+ CloseNestedInterfaces(uid, actor.PlayerSession, storageComp);
- // REMOVE: remove and drop on the ground
- public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null)
+ // If UI is closed for everyone
+ if (!_uiSystem.IsUiOpen(uid, args.UiKey))
{
- if (!Resolve(uid, ref storageComp))
- return false;
-
- var itemRemoved = storageComp.Storage?.Remove(removeEnt) == true;
- if (itemRemoved)
- RecalculateStorageUsed(storageComp);
+ storageComp.IsUiOpen = false;
+ UpdateStorageVisualization(uid, storageComp);
- return itemRemoved;
+ if (storageComp.StorageCloseSound is not null)
+ Audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params);
}
+ }
- /// <summary>
- /// Inserts an entity into storage from the player's active hand
- /// </summary>
- /// <param name="player">The player to insert an entity from</param>
- /// <returns>true if inserted, false otherwise</returns>
- public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, ServerStorageComponent? storageComp = null)
- {
- if (!Resolve(uid, ref storageComp) || !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);
- }
+ /// <summary>
+ /// Opens the storage UI for an entity
+ /// </summary>
+ /// <param name="entity">The entity to open the UI for</param>
+ 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;
- /// <summary>
- /// Inserts an Entity (<paramref name="toInsert"/>) in the world into storage, informing <paramref name="player"/> if it fails.
- /// <paramref name="toInsert"/> is *NOT* held, see <see cref="PlayerInsertHeldEntity(Robust.Shared.GameObjects.EntityUid)"/>.
- /// </summary>
- /// <param name="player">The player to insert an entity with</param>
- /// <returns>true if inserted, false otherwise</returns>
- public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, ServerStorageComponent? storageComp = null)
+ // prevent spamming bag open / honkerton honk sound
+ silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && UseDelay.ActiveDelay(uid, useDelay);
+ if (!silent)
{
- 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;
+ Audio.PlayPvs(storageComp.StorageOpenSound, uid);
+ if (useDelay != null)
+ UseDelay.BeginDelay(uid, useDelay);
}
- /// <summary>
- /// Opens the storage UI for an entity
- /// </summary>
- /// <param name="entity">The entity to open the UI for</param>
- public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent? storageComp = null, bool silent = false)
- {
- if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player))
- return;
-
- // prevent spamming bag open / honkerton honk sound
- silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && _useDelay.ActiveDelay(uid, useDelay);
- if (!silent)
- {
- _audio.PlayPvs(storageComp.StorageOpenSound, uid);
- if (useDelay != null)
- _useDelay.BeginDelay(uid, useDelay);
- }
+ Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
- _logManager.GetSawmill(storageComp.LoggerName)
- .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);
+ }
- var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key);
- if (bui != null)
- _uiSystem.OpenUi(bui, player.PlayerSession);
- }
+ /// <summary>
+ /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
+ /// </summary>
+ /// <param name="session"></param>
+ public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, StorageComponent? storageComp = null)
+ {
+ if (!Resolve(uid, ref storageComp))
+ return;
- /// <summary>
- /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
- /// </summary>
- /// <param name="session"></param>
- public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent? storageComp = null)
+ // 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)
{
- if (!Resolve(uid, ref storageComp) || storageComp.StoredEntities == null)
- return;
+ if (!TryComp(entity, out UserInterfaceComponent? ui))
+ continue;
- // 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)
+ foreach (var bui in ui.Interfaces.Values)
{
- 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);
- }
+ _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);
- }
}
}
/// <param name="store">The store entity itself</param>
/// <param name="component">The store component being refreshed.</param>
/// <param name="ui"></param>
- 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;
[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")]
SubscribeLocalEvent<ActivatableUIComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
- SubscribeLocalEvent<ServerUserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
+ SubscribeLocalEvent<UserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
InitializePower();
}
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;
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;
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<IEntitySystemManager>().GetEntitySystem<UserInterfaceSystem>().GetUiOrNull(entity, uiKey);
}
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;
}
/// <summary>
- /// Key representing which <see cref="BoundUserInterface"/> is currently open.
+ /// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
/// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary>
[Serializable, NetSerializable]
namespace Content.Shared.Atmos.Piping.Binary.Components
{
/// <summary>
- /// Key representing which <see cref="BoundUserInterface"/> is currently open.
+ /// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
/// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary>
[Serializable, NetSerializable]
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<SharedStorageComponent>(args.Container.Owner) && component.BuckledEntities.Count != 0)
+ if (HasComp<StorageComponent>(args.Container.Owner) && component.BuckledEntities.Count != 0)
args.Cancel();
}
namespace Content.Shared.Labels
{
/// <summary>
- /// Key representing which <see cref="BoundUserInterface"/> is currently open.
+ /// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
/// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary>
[Serializable, NetSerializable]
}
/// <summary>
-/// Key representing which <see cref="BoundUserInterface"/> is currently open.
+/// Key representing which <see cref="PlayerBoundUserInterface"/> is currently open.
/// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary>
[Serializable, NetSerializable]
--- /dev/null
+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<EntitySpawnEntry> Contents = new();
+}
+using System.Linq;
using Content.Shared.Disposal;
-using Content.Shared.Disposal.Components;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Placeable;
if (!args.CanAccess || !args.CanInteract)
return;
- if (!TryComp<SharedStorageComponent>(uid, out var storage) || storage.StoredEntities == null || storage.StoredEntities.Count == 0)
+ if (!TryComp<StorageComponent>(uid, out var storage) || !storage.Container.ContainedEntities.Any())
return;
AlternativeVerb verb = new()
if (!args.CanAccess || !args.CanInteract)
return;
- if (!TryComp<SharedStorageComponent>(uid, out var storage) || storage.StoredEntities == null || storage.StoredEntities.Count == 0)
+ if (!TryComp<StorageComponent>(uid, out var storage) || !storage.Container.ContainedEntities.Any())
return;
if (_disposalUnitSystem.HasDisposals(args.Target))
public void StartDoAfter(EntityUid storageUid, EntityUid? targetUid, EntityUid userUid, DumpableComponent dumpable)
{
- if (!TryComp<SharedStorageComponent>(storageUid, out var storage) || storage.StoredEntities == null)
+ if (!TryComp<StorageComponent>(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)
{
private void OnDoAfter(EntityUid uid, DumpableComponent component, DoAfterEvent args)
{
- if (args.Handled || args.Cancelled || !TryComp<SharedStorageComponent>(uid, out var storage) || storage.StoredEntities == null)
+ if (args.Handled || args.Cancelled || !TryComp<StorageComponent>(uid, out var storage))
return;
Queue<EntityUid> dumpQueue = new();
- foreach (var entity in storage.StoredEntities)
+ foreach (var entity in storage.Container.ContainedEntities)
{
dumpQueue.Enqueue(entity);
}
--- /dev/null
+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<ItemComponent> _itemQuery;
+ private EntityQuery<StackComponent> _stackQuery;
+ private EntityQuery<TransformComponent> _xformQuery;
+
+ /// <inheritdoc />
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ _itemQuery = GetEntityQuery<ItemComponent>();
+ _stackQuery = GetEntityQuery<StackComponent>();
+ _xformQuery = GetEntityQuery<TransformComponent>();
+
+ SubscribeLocalEvent<StorageComponent, ComponentInit>(OnComponentInit, before: new[] { typeof(SharedContainerSystem) });
+ SubscribeLocalEvent<StorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
+ SubscribeLocalEvent<StorageComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(ItemSlotsSystem) });
+ SubscribeLocalEvent<StorageComponent, ActivateInWorldEvent>(OnActivate);
+ SubscribeLocalEvent<StorageComponent, OpenStorageImplantEvent>(OnImplantActivate);
+ SubscribeLocalEvent<StorageComponent, AfterInteractEvent>(AfterInteract);
+ SubscribeLocalEvent<StorageComponent, DestructionEventArgs>(OnDestroy);
+ SubscribeLocalEvent<StorageComponent, StorageComponent.StorageInsertItemMessage>(OnInsertItemMessage);
+ SubscribeLocalEvent<StorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
+
+ SubscribeLocalEvent<StorageComponent, EntInsertedIntoContainerMessage>(OnStorageItemInserted);
+ SubscribeLocalEvent<StorageComponent, EntRemovedFromContainerMessage>(OnStorageItemRemoved);
+
+ SubscribeLocalEvent<StorageComponent, AreaPickupDoAfterEvent>(OnDoAfter);
+
+ SubscribeLocalEvent<StorageComponent, StorageInteractWithItemEvent>(OnInteractWithItem);
+ }
+
+ private void OnComponentInit(EntityUid uid, StorageComponent storageComp, ComponentInit args)
+ {
+ // ReSharper disable once StringLiteralTypo
+ storageComp.Container = _containerSystem.EnsureContainer<Container>(uid, "storagebase");
+ UpdateStorage(uid, storageComp);
+ }
+
+ /// <summary>
+ /// Updates the storage UI, visualizer, etc.
+ /// </summary>
+ /// <param name="uid"></param>
+ /// <param name="component"></param>
+ 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<UtilityVerb> 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);
+ }
+ }
+
+ /// <summary>
+ /// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user
+ /// </summary>
+ /// <returns>true if inserted, false otherwise</returns>
+ 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<PlaceableSurfaceComponent>(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;
+ }
+
+ /// <summary>
+ /// Sends a message to open the storage UI
+ /// </summary>
+ 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);
+ }
+
+ /// <summary>
+ /// Specifically for storage implants.
+ /// </summary>
+ 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);
+ }
+
+ /// <summary>
+ /// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius
+ /// around a click.
+ /// </summary>
+ /// <returns></returns>
+ 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<ItemComponent>(args.Target.Value)))
+ {
+ var validStorables = new List<EntityUid>();
+
+ 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<ItemComponent>(target))
+ {
+ return;
+ }
+
+ if (TryComp<TransformComponent>(uid, out var transformOwner) && TryComp<TransformComponent>(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<NetEntity> { GetNetEntity(target) },
+ new List<NetCoordinates> { GetNetCoordinates(position) },
+ new List<Angle> { transformOwner.LocalRotation }));
+ }
+ }
+ }
+ }
+
+ private void OnDoAfter(EntityUid uid, StorageComponent component, AreaPickupDoAfterEvent args)
+ {
+ if (args.Handled || args.Cancelled)
+ return;
+
+ var successfullyInserted = new List<EntityUid>();
+ var successfullyInsertedPositions = new List<EntityCoordinates>();
+ var successfullyInsertedAngles = new List<Angle>();
+ _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);
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ 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<AppearanceComponent>(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<ItemCounterComponent>(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;
+ }
+
+ /// <summary>
+ /// Move entities from one storage to another.
+ /// </summary>
+ 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);
+ }
+
+ /// <summary>
+ /// Verifies if an entity can be stored and if it fits
+ /// </summary>
+ /// <param name="uid">The entity to check</param>
+ /// <param name="reason">If returning false, the reason displayed to the player</param>
+ /// <returns>true if it can be inserted, false otherwise</returns>
+ public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, 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;
+ }
+
+ /// <summary>
+ /// Inserts into the storage container
+ /// </summary>
+ /// <returns>true if the entity was inserted, false otherwise</returns>
+ 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;
+ }
+
+ /// <summary>
+ /// Inserts an entity into storage from the player's active hand
+ /// </summary>
+ /// <param name="player">The player to insert an entity from</param>
+ /// <returns>true if inserted, false otherwise</returns>
+ public bool PlayerInsertHeldEntity(EntityUid uid, EntityUid player, 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);
+ }
+
+ /// <summary>
+ /// Inserts an Entity (<paramref name="toInsert"/>) in the world into storage, informing <paramref name="player"/> if it fails.
+ /// <paramref name="toInsert"/> is *NOT* held, see <see cref="PlayerInsertHeldEntity(Robust.Shared.GameObjects.EntityUid)"/>.
+ /// </summary>
+ /// <param name="player">The player to insert an entity with</param>
+ /// <returns>true if inserted, false otherwise</returns>
+ public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, 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;
+ }
+}
+++ /dev/null
-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<NetEntity> StoredEntities;
- public readonly int StorageSizeUsed;
- public readonly int StorageCapacityMax;
-
- public StorageBoundUserInterfaceState(List<NetEntity> 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<EntityUid>? StoredEntities { get; }
-
- /// <summary>
- /// Removes from the storage container and updates the stored value
- /// </summary>
- /// <param name="entity">The entity to remove</param>
- /// <returns>True if no longer in storage, false otherwise</returns>
- public abstract bool Remove(EntityUid entity);
- }
-
- /// <summary>
- /// Network event for displaying an animation of entities flying into a storage entity
- /// </summary>
- [Serializable, NetSerializable]
- public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs
- {
- public readonly NetEntity Storage;
- public readonly List<NetEntity> StoredEntities;
- public readonly List<NetCoordinates> EntityPositions;
- public readonly List<Angle> EntityAngles;
-
- public AnimateInsertingEntitiesEvent(NetEntity storage, List<NetEntity> storedEntities, List<NetCoordinates> entityPositions, List<Angle> entityAngles)
- {
- Storage = storage;
- StoredEntities = storedEntities;
- EntityPositions = entityPositions;
- EntityAngles = entityAngles;
- }
- }
-
- [NetSerializable]
- [Serializable]
- public enum StorageVisuals : byte
- {
- Open,
- HasContents,
- CanLock,
- Locked
- }
-}
--- /dev/null
+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
+{
+ /// <summary>
+ /// Handles generic storage with window, such as backpacks.
+ /// </summary>
+ [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;
+
+ /// <summary>
+ /// Whitelist for entities that can go into the storage.
+ /// </summary>
+ [DataField("whitelist")]
+ public EntityWhitelist? Whitelist;
+
+ /// <summary>
+ /// Blacklist for entities that can go into storage.
+ /// </summary>
+ [DataField("blacklist")]
+ public EntityWhitelist? Blacklist;
+
+ /// <summary>
+ /// How much storage is currently being used by contained entities.
+ /// </summary>
+ [ViewVariables, DataField("storageUsed"), AutoNetworkedField]
+ public int StorageUsed;
+
+ /// <summary>
+ /// Maximum capacity for storage.
+ /// </summary>
+ [DataField("capacity"), AutoNetworkedField]
+ public int StorageCapacityMax = 10000;
+
+ /// <summary>
+ /// Sound played whenever an entity is inserted into storage.
+ /// </summary>
+ [DataField("storageInsertSound")]
+ public SoundSpecifier? StorageInsertSound = new SoundCollectionSpecifier("storageRustle");
+
+ /// <summary>
+ /// Sound played whenever an entity is removed from storage.
+ /// </summary>
+ [DataField("storageRemoveSound")]
+ public SoundSpecifier? StorageRemoveSound;
+
+ /// <summary>
+ /// Sound played whenever the storage window is opened.
+ /// </summary>
+ [DataField("storageOpenSound")]
+ public SoundSpecifier? StorageOpenSound = new SoundCollectionSpecifier("storageRustle");
+
+ /// <summary>
+ /// Sound played whenever the storage window is closed.
+ /// </summary>
+ [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;
+ }
+ }
+
+ /// <summary>
+ /// Network event for displaying an animation of entities flying into a storage entity
+ /// </summary>
+ [Serializable, NetSerializable]
+ public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs
+ {
+ public readonly NetEntity Storage;
+ public readonly List<NetEntity> StoredEntities;
+ public readonly List<NetCoordinates> EntityPositions;
+ public readonly List<Angle> EntityAngles;
+
+ public AnimateInsertingEntitiesEvent(NetEntity storage, List<NetEntity> storedEntities, List<NetCoordinates> entityPositions, List<Angle> entityAngles)
+ {
+ Storage = storage;
+ StoredEntities = storedEntities;
+ EntityPositions = entityPositions;
+ EntityAngles = entityAngles;
+ }
+ }
+
+ [NetSerializable]
+ [Serializable]
+ public enum StorageVisuals : byte
+ {
+ Open,
+ HasContents,
+ CanLock,
+ Locked
+ }
+}
- id: BoxBeanbag
amount: 2
- id: RagItem
- amound: 2
+ amount: 2
#- type: entity
# id: LockerFormalFilled
components:
- type: Storage
capacity: 40
- equipSound:
- path: /Audio/Items/belt_equip.ogg
- type: ContainerContainer
containers:
storagebase: !type:Container
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
- type: Item
- type: Storage
capacity: 18
- size: 5
whitelist:
tags:
- Dice
size: 5
- type: Storage
capacity: 10
- size: 10
whitelist:
tags:
- Document
- key: enum.StorageUiKey.Key
type: StorageBoundUserInterface
- type: Storage
- popup: false
capacity: 30
- type: TileFrictionModifier
modifier: 0.4 # makes it slide