Predict StorageComponent (#19682)

This commit is contained in:
metalgearsloth
2023-09-11 21:20:46 +10:00
committed by GitHub
parent 99b77bc2d3
commit d5bd1c6f86
68 changed files with 1124 additions and 1121 deletions

View File

@@ -5,6 +5,7 @@ using Content.Shared.CrewManifest;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.IdCardConsoleComponent; using static Content.Shared.Access.Components.IdCardConsoleComponent;
namespace Content.Client.Access.UI namespace Content.Client.Access.UI
{ {
public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface

View File

@@ -1,5 +1,5 @@
using Content.Client.Storage;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Storage;
using Robust.Shared.Containers; using Robust.Shared.Containers;
namespace Content.Client.Interactable namespace Content.Client.Interactable
@@ -14,7 +14,7 @@ namespace Content.Client.Interactable
if (!target.TryGetContainer(out var container)) if (!target.TryGetContainer(out var container))
return false; return false;
if (!TryComp(container.Owner, out ClientStorageComponent? storage)) if (!TryComp(container.Owner, out StorageComponent? storage))
return false; return false;
// we don't check if the user can access the storage entity itself. This should be handed by the UI system. // we don't check if the user can access the storage entity itself. This should be handed by the UI system.

View File

@@ -1,6 +1,5 @@
using Content.Client.Clothing; using Content.Client.Clothing;
using Content.Client.Examine; using Content.Client.Examine;
using Content.Client.Storage;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Client.Verbs.UI; using Content.Client.Verbs.UI;
using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Components;
@@ -9,6 +8,7 @@ using Content.Shared.Interaction;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Inventory; using Content.Shared.Inventory;
using Content.Shared.Inventory.Events; using Content.Shared.Inventory.Events;
using Content.Shared.Storage;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Player; using Robust.Client.Player;
@@ -101,7 +101,7 @@ namespace Content.Client.Inventory
if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity) if (args.Equipee != _playerManager.LocalPlayer?.ControlledEntity)
return; return;
var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot, var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot,
HasComp<ClientStorageComponent>(args.Equipment)); HasComp<StorageComponent>(args.Equipment));
OnSpriteUpdate?.Invoke(update); OnSpriteUpdate?.Invoke(update);
} }

View File

@@ -1,22 +0,0 @@
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;
}
}
}

View File

@@ -4,12 +4,13 @@ using Content.Client.UserInterface.Controls;
using Content.Client.Verbs.UI; using Content.Client.Verbs.UI;
using Content.Shared.Input; using Content.Shared.Input;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Storage;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input; using Robust.Shared.Input;
using static Content.Shared.Storage.SharedStorageComponent; using static Content.Shared.Storage.StorageComponent;
namespace Content.Client.Storage namespace Content.Client.Storage
{ {
@@ -19,8 +20,11 @@ namespace Content.Client.Storage
[ViewVariables] [ViewVariables]
private StorageWindow? _window; private StorageWindow? _window;
[Dependency] private readonly IEntityManager _entManager = default!;
public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public StorageBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
IoCManager.InjectDependencies(this);
} }
protected override void Open() protected override void Open()
@@ -29,17 +33,22 @@ namespace Content.Client.Storage
if (_window == null) if (_window == null)
{ {
_window = new StorageWindow(EntMan) // 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>();
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName _window = controller.EnsureStorageWindow(Owner);
}; _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
_window.EntityList.GenerateItem += _window.GenerateButton; _window.EntityList.GenerateItem += _window.GenerateButton;
_window.EntityList.ItemPressed += InteractWithItem; _window.EntityList.ItemPressed += InteractWithItem;
_window.StorageContainerButton.OnPressed += TouchedContainerButton; _window.StorageContainerButton.OnPressed += TouchedContainerButton;
_window.OnClose += Close; _window.OnClose += Close;
_window.OpenCenteredLeft();
if (EntMan.TryGetComponent<StorageComponent>(Owner, out var storageComp))
{
BuildEntityList(Owner, storageComp);
}
} }
else else
{ {
@@ -47,6 +56,11 @@ namespace Content.Client.Storage
} }
} }
public void BuildEntityList(EntityUid uid, StorageComponent component)
{
_window?.BuildEntityList(uid, component);
}
public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData) public void InteractWithItem(BaseButton.ButtonEventArgs args, ListData cData)
{ {
if (cData is not EntityListData { Uid: var entity }) if (cData is not EntityListData { Uid: var entity })
@@ -54,7 +68,7 @@ namespace Content.Client.Storage
if (args.Event.Function == EngineKeyFunctions.UIClick) if (args.Event.Function == EngineKeyFunctions.UIClick)
{ {
SendMessage(new StorageInteractWithItemEvent(EntMan.GetNetEntity(entity))); SendPredictedMessage(new StorageInteractWithItemEvent(_entManager.GetNetEntity(entity)));
} }
else if (EntMan.EntityExists(entity)) else if (EntMan.EntityExists(entity))
{ {
@@ -92,17 +106,7 @@ namespace Content.Client.Storage
public void TouchedContainerButton(BaseButton.ButtonEventArgs args) public void TouchedContainerButton(BaseButton.ButtonEventArgs args)
{ {
SendMessage(new StorageInsertItemMessage()); SendPredictedMessage(new StorageInsertItemMessage());
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_window == null || state is not StorageBoundUserInterfaceState cast)
return;
_window?.BuildEntityList(cast);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
@@ -113,14 +117,13 @@ namespace Content.Client.Storage
if (_window != null) if (_window != null)
{ {
_window.Orphan();
_window.EntityList.GenerateItem -= _window.GenerateButton; _window.EntityList.GenerateItem -= _window.GenerateButton;
_window.EntityList.ItemPressed -= InteractWithItem; _window.EntityList.ItemPressed -= InteractWithItem;
_window.StorageContainerButton.OnPressed -= TouchedContainerButton; _window.StorageContainerButton.OnPressed -= TouchedContainerButton;
_window.OnClose -= Close; _window.OnClose -= Close;
}
_window?.Dispose();
_window = null; _window = null;
} }
} }
} }
}

View File

@@ -1,11 +1,17 @@
using Content.Client.Animations; using Content.Client.Animations;
using Content.Shared.Storage; using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Robust.Shared.Timing;
namespace Content.Client.Storage.Systems; namespace Content.Client.Storage.Systems;
// TODO kill this is all horrid. // 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() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -13,22 +19,24 @@ public sealed class StorageSystem : EntitySystem
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities); 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> /// <summary>
/// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position /// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
/// </summary> /// </summary>
/// <param name="msg"></param> /// <param name="msg"></param>
public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg) public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg)
{ {
var store = GetEntity(msg.Storage); TryComp(GetEntity(msg.Storage), out TransformComponent? transformComp);
if (!HasComp<ClientStorageComponent>(store))
return;
TryComp(store, out TransformComponent? transformComp);
for (var i = 0; msg.StoredEntities.Count > i; i++) for (var i = 0; msg.StoredEntities.Count > i; i++)
{ {
var entity = GetEntity(msg.StoredEntities[i]); var entity = GetEntity(msg.StoredEntities[i]);
var initialPosition = msg.EntityPositions[i]; var initialPosition = msg.EntityPositions[i];
if (EntityManager.EntityExists(entity) && transformComp != null) if (EntityManager.EntityExists(entity) && transformComp != null)
{ {

View File

@@ -0,0 +1,60 @@
using Content.Client.Storage.Systems;
using Content.Shared.Storage;
using Robust.Client.UserInterface.Controllers;
namespace Content.Client.Storage.UI;
public sealed class StorageUIController : UIController, IOnSystemChanged<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;
}
}

View File

@@ -8,7 +8,9 @@ using Content.Client.UserInterface.Controls;
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Content.Shared.Storage;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Shared.Containers;
using static Robust.Client.UserInterface.Controls.BoxContainer; using static Robust.Client.UserInterface.Controls.BoxContainer;
using static Content.Shared.Storage.SharedStorageComponent; using static Content.Shared.Storage.SharedStorageComponent;
using Direction = Robust.Shared.Maths.Direction; using Direction = Robust.Shared.Maths.Direction;
@@ -18,9 +20,9 @@ namespace Content.Client.Storage.UI
/// <summary> /// <summary>
/// GUI class for client storage component /// GUI class for client storage component
/// </summary> /// </summary>
public sealed class StorageWindow : DefaultWindow public sealed class StorageWindow : FancyWindow
{ {
private IEntityManager _entityManager; private readonly IEntityManager _entityManager;
private readonly Label _information; private readonly Label _information;
public readonly ContainerButton StorageContainerButton; public readonly ContainerButton StorageContainerButton;
@@ -41,7 +43,7 @@ namespace Content.Client.Storage.UI
MouseFilter = MouseFilterMode.Pass, MouseFilter = MouseFilterMode.Pass,
}; };
Contents.AddChild(StorageContainerButton); ContentsContainer.AddChild(StorageContainerButton);
var innerContainerButton = new PanelContainer var innerContainerButton = new PanelContainer
{ {
@@ -54,6 +56,7 @@ namespace Content.Client.Storage.UI
{ {
Orientation = LayoutOrientation.Vertical, Orientation = LayoutOrientation.Vertical,
MouseFilter = MouseFilterMode.Ignore, MouseFilter = MouseFilterMode.Ignore,
Margin = new Thickness(5),
}; };
StorageContainerButton.AddChild(vBox); StorageContainerButton.AddChild(vBox);
@@ -87,20 +90,27 @@ namespace Content.Client.Storage.UI
/// <summary> /// <summary>
/// Loops through stored entities creating buttons for each, updates information labels /// Loops through stored entities creating buttons for each, updates information labels
/// </summary> /// </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); EntityList.PopulateList(list);
// Sets information about entire storage container current capacity // Sets information about entire storage container current capacity
if (state.StorageCapacityMax != 0) if (component.StorageCapacityMax != 0)
{ {
_information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", state.StoredEntities.Count), _information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", storedCount),
("usedVolume", state.StorageSizeUsed), ("maxVolume", state.StorageCapacityMax)); ("usedVolume", component.StorageUsed), ("maxVolume", component.StorageCapacityMax));
} }
else 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));
} }
} }

View File

@@ -5,7 +5,6 @@ using Content.Shared.Hands;
using Content.Shared.Inventory.Events; using Content.Shared.Inventory.Events;
using Content.Shared.Strip; using Content.Shared.Strip;
using Content.Shared.Strip.Components; using Content.Shared.Strip.Components;
using Robust.Client.GameObjects;
namespace Content.Client.Strip; namespace Content.Client.Strip;
@@ -33,7 +32,7 @@ public sealed class StrippableSystem : SharedStrippableSystem
public void UpdateUi(EntityUid uid, StrippableComponent? component = null, EntityEventArgs? args = null) public void UpdateUi(EntityUid uid, StrippableComponent? component = null, EntityEventArgs? args = null)
{ {
if (!TryComp(uid, out ClientUserInterfaceComponent? uiComp)) if (!TryComp(uid, out UserInterfaceComponent? uiComp))
return; return;
foreach (var ui in uiComp.OpenInterfaces.Values) foreach (var ui in uiComp.OpenInterfaces.Values)

View File

@@ -1,12 +1,12 @@
using Content.Client.Gameplay; using Content.Client.Gameplay;
using Content.Client.Hands.Systems; using Content.Client.Hands.Systems;
using Content.Client.Inventory; using Content.Client.Inventory;
using Content.Client.Storage;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.Inventory.Controls; using Content.Client.UserInterface.Systems.Inventory.Controls;
using Content.Client.UserInterface.Systems.Inventory.Windows; using Content.Client.UserInterface.Systems.Inventory.Windows;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Input; using Content.Shared.Input;
using Content.Shared.Storage;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers; using Robust.Client.UserInterface.Controllers;
@@ -126,7 +126,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
container.AddButton(button); 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); var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
SpriteUpdated(update); SpriteUpdated(update);
} }
@@ -151,7 +151,7 @@ public sealed class InventoryUIController : UIController, IOnStateEntered<Gamepl
_strippingWindow!.InventoryButtons.AddButton(button, data.ButtonOffset); _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); var update = new SlotSpriteUpdate(data.HeldEntity, data.SlotGroup, data.SlotName, showStorage);
SpriteUpdated(update); SpriteUpdated(update);
} }

View File

@@ -18,7 +18,6 @@ using Content.Shared.Construction.Prototypes;
using Content.Shared.DoAfter; using Content.Shared.DoAfter;
using Content.Shared.Gravity; using Content.Shared.Gravity;
using Content.Shared.Item; using Content.Shared.Item;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -785,9 +784,7 @@ public abstract partial class InteractionTest
return false; return false;
} }
var clientTarget = CEntMan.GetEntity(target); if (!CEntMan.TryGetComponent<UserInterfaceComponent>(CEntMan.GetEntity(target), out var ui))
if (!CEntMan.TryGetComponent<ClientUserInterfaceComponent>(clientTarget, out var ui))
{ {
if (shouldSucceed) if (shouldSucceed)
Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have a bui component"); Assert.Fail($"Entity {SEntMan.ToPrettyString(SEntMan.GetEntity(target.Value))} does not have a bui component");

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Content.Server.Storage.Components; using Content.Server.Storage.Components;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Storage; using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.UnitTesting; using Robust.UnitTesting;
@@ -29,7 +30,7 @@ namespace Content.IntegrationTests.Tests
{ {
foreach (var proto in protoManager.EnumeratePrototypes<EntityPrototype>()) 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 || storage.Whitelist != null ||
!proto.TryGetComponent<ItemComponent>("Item", out var item)) continue; !proto.TryGetComponent<ItemComponent>("Item", out var item)) continue;
@@ -84,7 +85,7 @@ namespace Content.IntegrationTests.Tests
int capacity; int capacity;
var isEntStorage = false; var isEntStorage = false;
if (proto.TryGetComponent<ServerStorageComponent>("Storage", out var storage)) if (proto.TryGetComponent<StorageComponent>("Storage", out var storage))
{ {
capacity = storage.StorageCapacityMax; capacity = storage.StorageCapacityMax;
} }

View File

@@ -12,6 +12,7 @@ using Content.Shared.VendingMachines;
using Content.Shared.Wires; using Content.Shared.Wires;
using Content.Server.Wires; using Content.Server.Wires;
using Content.Shared.Prototypes; using Content.Shared.Prototypes;
using Content.Shared.Storage.Components;
namespace Content.IntegrationTests.Tests namespace Content.IntegrationTests.Tests
{ {

View File

@@ -30,7 +30,7 @@ public sealed class BlockGameArcadeSystem : EntitySystem
} }
} }
private void UpdatePlayerStatus(EntityUid uid, IPlayerSession session, BoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null) private void UpdatePlayerStatus(EntityUid uid, IPlayerSession session, PlayerBoundUserInterface? bui = null, BlockGameArcadeComponent? blockGame = null)
{ {
if (!Resolve(uid, ref blockGame)) if (!Resolve(uid, ref blockGame))
return; return;

View File

@@ -150,7 +150,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
DirtyUI(uid, thermoMachine); 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)) if (!Resolve(uid, ref thermoMachine, ref ui, false))
return; return;

View File

@@ -9,7 +9,6 @@ using Content.Shared.Cargo.Prototypes;
using Content.Shared.Database; using Content.Shared.Database;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Containers; using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Collections; using Robust.Shared.Collections;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -314,7 +313,7 @@ public sealed partial class CargoSystem
public void UpdateBountyConsoles() public void UpdateBountyConsoles()
{ {
var query = EntityQueryEnumerator<CargoBountyConsoleComponent, ServerUserInterfaceComponent>(); var query = EntityQueryEnumerator<CargoBountyConsoleComponent, UserInterfaceComponent>();
while (query.MoveNext(out var uid, out _, out var ui)) while (query.MoveNext(out var uid, out _, out var ui))
{ {
if (_station.GetOwningStation(uid) is not { } station || if (_station.GetOwningStation(uid) is not { } station ||

View File

@@ -3,7 +3,6 @@ using System.Linq;
using Content.Server.Chemistry.Components; using Content.Server.Chemistry.Components;
using Content.Server.Labels; using Content.Server.Labels;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems; using Content.Server.Storage.EntitySystems;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
@@ -12,6 +11,7 @@ using Content.Shared.Chemistry.Reagent;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Storage;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -174,8 +174,8 @@ namespace Content.Server.Chemistry.EntitySystems
var user = message.Session.AttachedEntity; var user = message.Session.AttachedEntity;
var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName); var maybeContainer = _itemSlotsSystem.GetItemOrNull(chemMaster.Owner, SharedChemMaster.OutputSlotName);
if (maybeContainer is not { Valid: true } container if (maybeContainer is not { Valid: true } container
|| !TryComp(container, out ServerStorageComponent? storage) || !TryComp(container, out StorageComponent? storage)
|| storage.Storage is null) || storage.Container is null)
{ {
return; // output can't fit pills return; // output can't fit pills
} }
@@ -201,7 +201,7 @@ namespace Content.Server.Chemistry.EntitySystems
for (var i = 0; i < message.Number; i++) for (var i = 0; i < message.Number; i++)
{ {
var item = Spawn(PillPrototypeId, Transform(container).Coordinates); var item = Spawn(PillPrototypeId, Transform(container).Coordinates);
_storageSystem.Insert(container, item, storage); _storageSystem.Insert(container, item, user, storage);
_labelSystem.Label(item, message.Label); _labelSystem.Label(item, message.Label);
var itemSolution = _solutionContainerSystem.EnsureSolution(item, SharedChemMaster.PillSolutionName); var itemSolution = _solutionContainerSystem.EnsureSolution(item, SharedChemMaster.PillSolutionName);
@@ -340,10 +340,10 @@ namespace Content.Server.Chemistry.EntitySystems
} }
} }
if (!TryComp(container, out ServerStorageComponent? storage)) if (!TryComp(container, out StorageComponent? storage))
return null; 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); _solutionContainerSystem.TryGetSolution(pill, SharedChemMaster.PillSolutionName, out var solution);
var quantity = solution?.Volume ?? FixedPoint2.Zero; var quantity = solution?.Volume ?? FixedPoint2.Zero;

View File

@@ -57,6 +57,6 @@ namespace Content.Server.Communications
[DataField("sound")] [DataField("sound")]
public SoundSpecifier AnnouncementSound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg"); public SoundSpecifier AnnouncementSound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg");
public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key); public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CommunicationsConsoleUiKey.Key);
} }
} }

View File

@@ -2,7 +2,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Server.Construction.Components; using Content.Server.Construction.Components;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems; using Content.Server.Storage.EntitySystems;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Construction; using Content.Shared.Construction;
@@ -30,7 +29,6 @@ namespace Content.Server.Construction
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!; [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookupSystem = default!; [Dependency] private readonly EntityLookupSystem _lookupSystem = default!;
[Dependency] private readonly StorageSystem _storageSystem = default!;
// --- WARNING! LEGACY CODE AHEAD! --- // --- WARNING! LEGACY CODE AHEAD! ---
// This entire file contains the legacy code for initial construction. // This entire file contains the legacy code for initial construction.
@@ -51,9 +49,9 @@ namespace Content.Server.Construction
{ {
foreach (var item in _handsSystem.EnumerateHeld(user)) 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; yield return storedEntity;
} }
@@ -66,10 +64,12 @@ namespace Content.Server.Construction
{ {
while (containerSlotEnumerator.MoveNext(out var containerSlot)) while (containerSlotEnumerator.MoveNext(out var containerSlot))
{ {
if(!containerSlot.ContainedEntity.HasValue) continue; if(!containerSlot.ContainedEntity.HasValue)
if (EntityManager.TryGetComponent(containerSlot.ContainedEntity.Value, out ServerStorageComponent? storage)) 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; yield return storedEntity;
} }
@@ -207,12 +207,9 @@ namespace Content.Server.Construction
continue; continue;
// Dump out any stored entities in used entity // 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()) _container.EmptyContainer(storage.Container);
{
_storageSystem.RemoveAndDrop(entity, storedEntity, storage);
}
} }
if (string.IsNullOrEmpty(arbitraryStep.Store)) if (string.IsNullOrEmpty(arbitraryStep.Store))

View File

@@ -1,12 +1,12 @@
using System.Linq; using System.Linq;
using Content.Server.Construction.Components; using Content.Server.Construction.Components;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems; using Content.Server.Storage.EntitySystems;
using Content.Shared.DoAfter; using Content.Shared.DoAfter;
using Content.Shared.Construction.Components; using Content.Shared.Construction.Components;
using Content.Shared.Exchanger; using Content.Shared.Exchanger;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Storage;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Content.Shared.Wires; using Content.Shared.Wires;
@@ -41,13 +41,13 @@ public sealed class PartExchangerSystem : EntitySystem
if (args.Handled || args.Args.Target == null) if (args.Handled || args.Args.Target == null)
return; 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 return; //the parts are stored in here
var machinePartQuery = GetEntityQuery<MachinePartComponent>(); var machinePartQuery = GetEntityQuery<MachinePartComponent>();
var machineParts = new List<(EntityUid, 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)) if (machinePartQuery.TryGetComponent(item, out var part))
machineParts.Add((item, part)); machineParts.Add((item, part));
@@ -96,7 +96,7 @@ public sealed class PartExchangerSystem : EntitySystem
//put the unused parts back into rped. (this also does the "swapping") //put the unused parts back into rped. (this also does the "swapping")
foreach (var (unused, _) in machineParts) foreach (var (unused, _) in machineParts)
{ {
_storage.Insert(storageUid, unused, null, false); _storage.Insert(storageUid, unused, playSound: false);
} }
_construction.RefreshParts(uid, machine); _construction.RefreshParts(uid, machine);
} }
@@ -146,7 +146,7 @@ public sealed class PartExchangerSystem : EntitySystem
//put the unused parts back into rped. (this also does the "swapping") //put the unused parts back into rped. (this also does the "swapping")
foreach (var (unused, _) in machineParts) foreach (var (unused, _) in machineParts)
{ {
_storage.Insert(storageEnt, unused, null, false); _storage.Insert(storageEnt, unused, playSound: false);
} }
} }

View File

@@ -25,6 +25,6 @@ namespace Content.Server.Crayon
[DataField("deleteEmpty")] [DataField("deleteEmpty")]
public bool DeleteEmpty = true; public bool DeleteEmpty = true;
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key); [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(CrayonUiKey.Key);
} }
} }

View File

@@ -44,7 +44,7 @@ public sealed class ActivatableUIRequiresVisionSystem : EntitySystem
if (uiList == null) if (uiList == null)
return; return;
Queue<BoundUserInterface> closeList = new(); // foreach collection modified moment Queue<PlayerBoundUserInterface> closeList = new(); // foreach collection modified moment
foreach (var ui in uiList) foreach (var ui in uiList)
{ {

View File

@@ -1,8 +1,8 @@
using System.Linq;
using System.Numerics; using System.Numerics;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Pulling; using Content.Server.Pulling;
using Content.Server.Stack; using Content.Server.Stack;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems; using Content.Server.Storage.EntitySystems;
using Content.Server.Stunnable; using Content.Server.Stunnable;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
@@ -16,6 +16,7 @@ using Content.Shared.Inventory;
using Content.Shared.Physics.Pull; using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components; using Content.Shared.Pulling.Components;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Player; using Robust.Server.Player;
@@ -30,8 +31,7 @@ using Robust.Shared.Utility;
namespace Content.Server.Hands.Systems namespace Content.Server.Hands.Systems
{ {
[UsedImplicitly] public sealed class HandsSystem : SharedHandsSystem
internal sealed class HandsSystem : SharedHandsSystem
{ {
[Dependency] private readonly InventorySystem _inventorySystem = default!; [Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly StackSystem _stackSystem = default!; [Dependency] private readonly StackSystem _stackSystem = default!;
@@ -252,7 +252,7 @@ namespace Content.Server.Hands.Systems
return; return;
if (!_inventorySystem.TryGetSlotEntity(plyEnt, equipmentSlot, out var slotEntity) || if (!_inventorySystem.TryGetSlotEntity(plyEnt, equipmentSlot, out var slotEntity) ||
!TryComp(slotEntity, out ServerStorageComponent? storageComponent)) !TryComp(slotEntity, out StorageComponent? storageComponent))
{ {
if (_inventorySystem.HasSlot(plyEnt, equipmentSlot)) if (_inventorySystem.HasSlot(plyEnt, equipmentSlot))
{ {
@@ -287,16 +287,17 @@ namespace Content.Server.Hands.Systems
{ {
_storageSystem.PlayerInsertHeldEntity(slotEntity.Value, plyEnt, storageComponent); _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); _popupSystem.PopupEntity(Loc.GetString("hands-system-empty-equipment-slot", ("slotName", equipmentSlot)), plyEnt, session);
} }
else else
{ {
var lastStoredEntity = storageComponent.StoredEntities[^1]; var lastStoredEntity = storageComponent.Container.ContainedEntities[^1];
if (storageComponent.Remove(lastStoredEntity))
if (storageComponent.Container.Remove(lastStoredEntity))
{ {
PickupOrDrop(plyEnt, lastStoredEntity, animateUser: true, handsComp: hands); PickupOrDrop(plyEnt, lastStoredEntity, animateUser: true, handsComp: hands);
} }

View File

@@ -21,7 +21,7 @@ public sealed partial class InstrumentComponent : SharedInstrumentComponent
_entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser _entMan.GetComponentOrNull<ActivatableUIComponent>(Owner)?.CurrentSingleUser
?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession; ?? _entMan.GetComponentOrNull<ActorComponent>(Owner)?.PlayerSession;
[ViewVariables] public BoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key); [ViewVariables] public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(InstrumentUiKey.Key);
} }
[RegisterComponent] [RegisterComponent]

View File

@@ -2,7 +2,6 @@
using Content.Server.Administration.Logs; using Content.Server.Administration.Logs;
using Content.Server.Pulling; using Content.Server.Pulling;
using Content.Server.Storage.Components;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.DragDrop; using Content.Shared.DragDrop;
using Content.Shared.Input; using Content.Shared.Input;
@@ -46,17 +45,17 @@ namespace Content.Server.Interaction
if (!_container.TryGetContainingContainer(target, out var container)) if (!_container.TryGetContainingContainer(target, out var container))
return false; return false;
if (!TryComp(container.Owner, out ServerStorageComponent? storage)) if (!TryComp(container.Owner, out StorageComponent? storage))
return false; return false;
if (storage.Storage?.ID != container.ID) if (storage.Container?.ID != container.ID)
return false; return false;
if (!TryComp(user, out ActorComponent? actor)) if (!TryComp(user, out ActorComponent? actor))
return false; return false;
// we don't check if the user can access the storage entity itself. This should be handed by the UI system. // 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 #region Drag drop

View File

@@ -1,9 +1,9 @@
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems; using Content.Server.Storage.EntitySystems;
using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Components;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Inventory; using Content.Shared.Inventory;
using Content.Shared.Inventory.Events; using Content.Shared.Inventory.Events;
using Content.Shared.Storage;
namespace Content.Server.Inventory namespace Content.Server.Inventory
{ {
@@ -33,7 +33,7 @@ namespace Content.Server.Inventory
if (args.SenderSession.AttachedEntity is not { Valid: true } uid) if (args.SenderSession.AttachedEntity is not { Valid: true } uid)
return; 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); _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent);
} }

View File

@@ -1,7 +1,7 @@
using Content.Server.Storage.Components; using Content.Server.Storage.EntitySystems;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Content.Shared.Storage;
namespace Content.Server.Item; namespace Content.Server.Item;
@@ -14,9 +14,12 @@ public sealed class ItemSystem : SharedItemSystem
base.OnStackCountChanged(uid, component, args); base.OnStackCountChanged(uid, component, args);
if (!Container.TryGetContainingContainer(uid, out var container) || if (!Container.TryGetContainingContainer(uid, out var container) ||
!TryComp<ServerStorageComponent>(container.Owner, out var storage)) !TryComp<StorageComponent>(container.Owner, out var storage))
{
return; return;
}
_storage.RecalculateStorageUsed(storage); _storage.RecalculateStorageUsed(storage);
_storage.UpdateStorageUI(container.Owner, storage); _storage.UpdateUI(container.Owner, storage);
} }
} }

View File

@@ -1,6 +1,5 @@
using System.Linq; using System.Linq;
using Content.Server.Light.Components; using Content.Server.Light.Components;
using Content.Server.Storage.Components;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Light.Components; using Content.Shared.Light.Components;
@@ -101,7 +100,7 @@ public sealed class LightReplacerSystem : EntitySystem
if (TryComp<LightBulbComponent>(usedUid, out var bulb)) if (TryComp<LightBulbComponent>(usedUid, out var bulb))
eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb); eventArgs.Handled = TryInsertBulb(uid, usedUid, eventArgs.User, true, component, bulb);
// add bulbs from storage? // 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); eventArgs.Handled = TryInsertBulbsFromStorage(uid, usedUid, eventArgs.User, component, storage);
} }
@@ -205,24 +204,24 @@ public sealed class LightReplacerSystem : EntitySystem
/// which was successfully inserted inside light replacer /// which was successfully inserted inside light replacer
/// </returns> /// </returns>
public bool TryInsertBulbsFromStorage(EntityUid replacerUid, EntityUid storageUid, EntityUid? userUid = null, 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)) if (!Resolve(replacerUid, ref replacer))
return false; return false;
if (!Resolve(storageUid, ref storage)) if (!Resolve(storageUid, ref storage))
return false; return false;
if (storage.StoredEntities == null)
return false;
var insertedBulbs = 0; var insertedBulbs = 0;
var storagedEnts = storage.StoredEntities.ToArray(); var storagedEnts = storage.Container.ContainedEntities.ToArray();
foreach (var ent in storagedEnts) foreach (var ent in storagedEnts)
{ {
if (TryComp<LightBulbComponent>(ent, out var bulb) && if (TryComp<LightBulbComponent>(ent, out var bulb) &&
TryInsertBulb(replacerUid, ent, userUid, false, replacer, bulb)) TryInsertBulb(replacerUid, ent, userUid, false, replacer, bulb))
{
insertedBulbs++; insertedBulbs++;
} }
}
// show some message if success // show some message if success
if (insertedBulbs > 0 && userUid != null) if (insertedBulbs > 0 && userUid != null)

View File

@@ -17,7 +17,7 @@ namespace Content.Server.Medical.Components
[DataField("scanDelay")] [DataField("scanDelay")]
public float ScanDelay = 0.8f; public float ScanDelay = 0.8f;
public BoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key); public PlayerBoundUserInterface? UserInterface => Owner.GetUIOrNull(HealthAnalyzerUiKey.Key);
/// <summary> /// <summary>
/// Sound played on scanning begin /// Sound played on scanning begin

View File

@@ -28,7 +28,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Content.Shared.Tag; using Content.Shared.Tag;
using Content.Server.Storage.Components; using Content.Shared.Storage;
namespace Content.Server.Nutrition.EntitySystems namespace Content.Server.Nutrition.EntitySystems
{ {
@@ -120,7 +120,7 @@ namespace Content.Server.Nutrition.EntitySystems
} }
// Check for used storage on the food item // 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); _popupSystem.PopupEntity(Loc.GetString("food-has-used-storage", ("food", food)), user, user);
return (false, true); return (false, true);

View File

@@ -53,7 +53,7 @@ namespace Content.Server.PDA
{ {
base.OnComponentInit(uid, pda, args); base.OnComponentInit(uid, pda, args);
if (!HasComp<ServerUserInterfaceComponent>(uid)) if (!HasComp<UserInterfaceComponent>(uid))
return; return;
UpdateAlertLevel(uid, pda); UpdateAlertLevel(uid, pda);

View File

@@ -40,13 +40,13 @@ public sealed class ApcSystem : EntitySystem
public override void Update(float deltaTime) 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)) while (query.MoveNext(out var uid, out var apc, out var battery, out var ui))
{ {
if (apc.LastUiUpdate + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime) if (apc.LastUiUpdate + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime)
{ {
apc.LastUiUpdate = _gameTiming.CurTime; apc.LastUiUpdate = _gameTiming.CurTime;
UpdateUIState(uid, apc, battery, ui); UpdateUIState(uid, apc, battery);
} }
} }
} }
@@ -146,7 +146,7 @@ public sealed class ApcSystem : EntitySystem
public void UpdateUIState(EntityUid uid, public void UpdateUIState(EntityUid uid,
ApcComponent? apc = null, ApcComponent? apc = null,
PowerNetworkBatteryComponent? netBat = null, PowerNetworkBatteryComponent? netBat = null,
ServerUserInterfaceComponent? ui = null) UserInterfaceComponent? ui = null)
{ {
if (!Resolve(uid, ref apc, ref netBat, ref ui)) if (!Resolve(uid, ref apc, ref netBat, ref ui))
return; return;

View File

@@ -60,7 +60,7 @@ public sealed class EscapeInventorySystem : EntitySystem
} }
// Uncontested // 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); AttemptEscape(uid, container.Owner, component);
} }

View File

@@ -1,6 +1,5 @@
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions; using Content.Shared.Salvage.Expeditions;
using Robust.Server.GameObjects;
namespace Content.Server.Salvage; namespace Content.Server.Salvage;
@@ -38,7 +37,7 @@ public sealed partial class SalvageSystem
{ {
var state = GetState(component); 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); var station = _station.GetOwningStation(console.Owner, xform);

View File

@@ -1,6 +1,7 @@
using Content.Shared.SensorMonitoring; using Content.Shared.SensorMonitoring;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Collections; using Robust.Shared.Collections;
using Robust.Shared.Players;
namespace Content.Server.SensorMonitoring; namespace Content.Server.SensorMonitoring;
@@ -26,7 +27,7 @@ public sealed partial class SensorMonitoringConsoleComponent : Component
public TimeSpan RetentionTime = TimeSpan.FromMinutes(1); public TimeSpan RetentionTime = TimeSpan.FromMinutes(1);
// UI update tracking stuff. // UI update tracking stuff.
public HashSet<IPlayerSession> InitialUIStateSent = new(); public HashSet<ICommonSession> InitialUIStateSent = new();
public TimeSpan LastUIUpdate; public TimeSpan LastUIUpdate;
public ValueList<int> RemovedSensors; public ValueList<int> RemovedSensors;

View File

@@ -34,7 +34,7 @@ namespace Content.Server.Solar.EntitySystems
{ {
_updateTimer -= 1; _updateTimer -= 1;
var state = new SolarControlConsoleBoundInterfaceState(_powerSolarSystem.TargetPanelRotation, _powerSolarSystem.TargetPanelVelocity, _powerSolarSystem.TotalPanelPower, _powerSolarSystem.TowardsSun); 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)) while (query.MoveNext(out var uid, out var _, out var uiComp))
{ {
_uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp); _uiSystem.TrySetUiState(uid, SolarControlConsoleUiKey.Key, state, ui: uiComp);

View File

@@ -1,7 +1,7 @@
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems; using Content.Server.Storage.EntitySystems;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.Containers; using Robust.Server.Containers;
@@ -163,9 +163,9 @@ namespace Content.Server.Stack
return; return;
if (_container.TryGetContainingContainer(uid, out var container) && 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); Hands.PickupOrDrop(userUid, split);

View File

@@ -1,88 +0,0 @@
using Content.Shared.Storage;
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using System.Threading;
namespace Content.Server.Storage.Components
{
/// <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;
}
}
}

View File

@@ -1,11 +0,0 @@
using Content.Server.Storage.EntitySystems;
using Content.Shared.Storage;
namespace Content.Server.Storage.Components
{
[RegisterComponent, Access(typeof(StorageSystem))]
public sealed partial class StorageFillComponent : Component
{
[DataField("contents")] public List<EntitySpawnEntry> Contents = new();
}
}

View File

@@ -1,4 +1,4 @@
using Content.Server.Storage.Components; using Content.Shared.Storage;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems; using Content.Shared.Storage.EntitySystems;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -11,16 +11,16 @@ namespace Content.Server.Storage.EntitySystems
{ {
protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter) protected override int? GetCount(ContainerModifiedMessage msg, ItemCounterComponent itemCounter)
{ {
if (!EntityManager.TryGetComponent(msg.Container.Owner, out ServerStorageComponent? component) if (!EntityManager.TryGetComponent(msg.Container.Owner, out StorageComponent? component))
|| component.StoredEntities == null)
{ {
return null; return null;
} }
var count = 0; 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; return count;

View File

@@ -5,6 +5,7 @@ using Content.Shared.Verbs;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Random; using Robust.Shared.Random;
using System.Linq; using System.Linq;
using Content.Shared.Storage;
namespace Content.Server.Storage.EntitySystems; namespace Content.Server.Storage.EntitySystems;
@@ -24,21 +25,20 @@ public sealed class PickRandomSystem : EntitySystem
private void OnGetAlternativeVerbs(EntityUid uid, PickRandomComponent comp, GetVerbsEvent<AlternativeVerb> args) 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; return;
var user = args.User; var user = args.User;
var enabled = false; var enabled = storage.Container.ContainedEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
if (storage.StoredEntities != null)
enabled = storage.StoredEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
// alt-click / alt-z to pick an item // alt-click / alt-z to pick an item
args.Verbs.Add(new AlternativeVerb args.Verbs.Add(new AlternativeVerb
{ {
Act = (() => { Act = () =>
{
TryPick(uid, comp, storage, user); TryPick(uid, comp, storage, user);
}), },
Impact = LogImpact.Low, Impact = LogImpact.Low,
Text = Loc.GetString(comp.VerbText), Text = Loc.GetString(comp.VerbText),
Disabled = !enabled, Disabled = !enabled,
@@ -46,16 +46,14 @@ public sealed class PickRandomSystem : EntitySystem
}); });
} }
private void TryPick(EntityUid uid, PickRandomComponent comp, ServerStorageComponent storage, EntityUid user) private void TryPick(EntityUid uid, PickRandomComponent comp, StorageComponent storage, EntityUid user)
{ {
if (storage.StoredEntities == null) var entities = storage.Container.ContainedEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true).ToArray();
return;
var entities = storage.StoredEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
if (!entities.Any()) if (!entities.Any())
return; 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 // if it fails to go into a hand of the user, will be on the storage
_container.AttachParentToContainerOrGrid(Transform(picked)); _container.AttachParentToContainerOrGrid(Transform(picked));

View File

@@ -1,5 +1,5 @@
using Content.Server.Storage.Components; using Content.Shared.Rounding;
using Content.Shared.Rounding; using Content.Shared.Storage;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Containers; using Robust.Shared.Containers;
@@ -33,7 +33,7 @@ public sealed class StorageFillVisualizerSystem : EntitySystem
UpdateAppearance(uid, component: component); 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) StorageFillVisualizerComponent? component = null)
{ {
if (!Resolve(uid, ref storage, ref appearance, ref component, false)) if (!Resolve(uid, ref storage, ref appearance, ref component, false))

View File

@@ -1,5 +1,6 @@
using Content.Server.Storage.Components; using Content.Server.Storage.Components;
using Content.Shared.Storage; using Content.Shared.Storage;
using Content.Shared.Storage.Components;
namespace Content.Server.Storage.EntitySystems; namespace Content.Server.Storage.EntitySystems;
@@ -7,32 +8,33 @@ public sealed partial class StorageSystem
{ {
private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args) 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); 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; return;
} }
var coordinates = Transform(uid).Coordinates; var coordinates = Transform(uid).Coordinates;
var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, _random); var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, Random);
foreach (var item in spawnItems) foreach (var item in spawnItems)
{ {
var ent = EntityManager.SpawnEntity(item, coordinates); var ent = EntityManager.SpawnEntity(item, coordinates);
// handle depending on storage component, again this should be unified after ECS // handle depending on storage component, again this should be unified after ECS
if (entityStorageComp != null && _entityStorage.Insert(ent, uid)) if (entityStorageComp != null && EntityStorage.Insert(ent, uid))
continue; continue;
if (serverStorageComp != null && Insert(uid, ent, serverStorageComp, false)) if (storageComp != null && Insert(uid, ent, storageComp: storageComp, playSound: false))
continue; 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); EntityManager.DeleteEntity(ent);
} }
} }

View File

@@ -1,101 +1,35 @@
using System.Linq;
using Content.Server.Administration.Managers; 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.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.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.Lock;
using Content.Shared.Placeable;
using Content.Shared.Stacks;
using Content.Shared.Storage; using Content.Shared.Storage;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems;
using Content.Shared.Timing; using Content.Shared.Timing;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Server.Containers;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Server.Player; 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.Player;
using Robust.Shared.Random; using Robust.Shared.Players;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using static Content.Shared.Storage.SharedStorageComponent;
namespace Content.Server.Storage.EntitySystems namespace Content.Server.Storage.EntitySystems;
public sealed partial class StorageSystem : SharedStorageSystem
{ {
public sealed partial class StorageSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAdminManager _admin = 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 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() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<StorageComponent, GetVerbsEvent<ActivationVerb>>(AddUiVerb);
SubscribeLocalEvent<ServerStorageComponent, ComponentInit>(OnComponentInit); SubscribeLocalEvent<StorageComponent, BoundUIClosedEvent>(OnBoundUIClosed);
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); SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
} }
private void OnComponentInit(EntityUid uid, ServerStorageComponent storageComp, ComponentInit args) private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<ActivationVerb> 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; var silent = false;
if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked) if (!args.CanAccess || !args.CanInteract || TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
@@ -114,11 +48,21 @@ namespace Content.Server.Storage.EntitySystems
return; return;
// Does this player currently have the storage UI open? // Does this player currently have the storage UI open?
var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession); var uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
ActivationVerb verb = new() ActivationVerb verb = new()
{ {
Act = () => OpenStorageUI(uid, args.User, component, silent) Act = () =>
{
if (uiOpen)
{
_uiSystem.TryClose(uid, StorageComponent.StorageUiKey.Key, actor.PlayerSession);
}
else
{
OpenStorageUI(uid, args.User, component, silent);
}
}
}; };
if (uiOpen) if (uiOpen)
{ {
@@ -135,279 +79,7 @@ namespace Content.Server.Storage.EntitySystems
args.Verbs.Add(verb); args.Verbs.Add(verb);
} }
private void AddTransferVerbs(EntityUid uid, ServerStorageComponent component, GetVerbsEvent<UtilityVerb> args) private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundUIClosedEvent args)
{
if (!args.CanAccess || !args.CanInteract)
return;
var entities = component.Storage?.ContainedEntities;
if (entities == null || entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked)
return;
// if the target is storage, add a verb to transfer storage.
if (TryComp(args.Target, out ServerStorageComponent? targetStorage)
&& (!TryComp(uid, out LockComponent? targetLock) || !targetLock.Locked))
{
UtilityVerb verb = new()
{
Text = Loc.GetString("storage-component-transfer-verb"),
IconEntity = GetNetEntity(args.Using),
Act = () => TransferEntities(uid, args.Target, component, lockComponent, targetStorage, targetLock)
};
args.Verbs.Add(verb);
}
}
/// <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)
{
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))
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>
/// <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);
}
/// <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;
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 async void AfterInteract(EntityUid uid, ServerStorageComponent storageComp, AfterInteractEvent args)
{
if (!args.CanReach)
return;
// Pick up all entities in a radius around the clicked location.
// The last half of the if is because carpets exist and this is terrible
if (storageComp.AreaInsert && (args.Target == null || !HasComp<ItemComponent>(args.Target.Value)))
{
var validStorables = new List<NetEntity>();
var itemQuery = GetEntityQuery<ItemComponent>();
foreach (var entity in _entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.Dynamic | LookupFlags.Sundries))
{
if (entity == args.User
|| !itemQuery.HasComponent(entity)
|| !CanInsert(uid, entity, out _, storageComp)
|| !_interactionSystem.InRangeUnobstructed(args.User, entity))
{
continue;
}
validStorables.Add(GetNetEntity(entity));
}
//If there's only one then let's be generous
if (validStorables.Count > 1)
{
var doAfterArgs = new DoAfterArgs(EntityManager, args.User, 0.2f * validStorables.Count, new AreaPickupDoAfterEvent(validStorables), uid, target: uid)
{
BreakOnDamage = true,
BreakOnUserMove = true,
NeedHand = true
};
_doAfterSystem.TryStartDoAfter(doAfterArgs);
}
return;
}
// Pick up the clicked entity
if (storageComp.QuickInsert)
{
if (args.Target is not { Valid: true } target)
return;
if (_containerSystem.IsEntityInContainer(target)
|| target == args.User
|| !HasComp<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 (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;
}
private void OnDestroy(EntityUid uid, ServerStorageComponent storageComp, DestructionEventArgs args)
{
var storedEntities = storageComp.StoredEntities?.ToList();
if (storedEntities == null)
return;
foreach (var entity in storedEntities)
{
RemoveAndDrop(uid, entity, storageComp);
}
}
/// <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) if (TryComp<ActorComponent>(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null)
CloseNestedInterfaces(uid, actor.PlayerSession, storageComp); CloseNestedInterfaces(uid, actor.PlayerSession, storageComp);
@@ -415,289 +87,35 @@ namespace Content.Server.Storage.EntitySystems
// If UI is closed for everyone // If UI is closed for everyone
if (!_uiSystem.IsUiOpen(uid, args.UiKey)) if (!_uiSystem.IsUiOpen(uid, args.UiKey))
{ {
storageComp.IsOpen = false; storageComp.IsUiOpen = false;
UpdateStorageVisualization(uid, storageComp); UpdateStorageVisualization(uid, storageComp);
if (storageComp.StorageCloseSound is not null) if (storageComp.StorageCloseSound is not null)
_audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params); 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;
}
// REMOVE: remove and drop on the ground
public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null)
{
if (!Resolve(uid, ref storageComp))
return false;
var itemRemoved = storageComp.Storage?.Remove(removeEnt) == true;
if (itemRemoved)
RecalculateStorageUsed(storageComp);
return itemRemoved;
}
/// <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>
/// Inserts an Entity (<paramref name="toInsert"/>) in the world into storage, informing <paramref name="player"/> if it fails.
/// <paramref name="toInsert"/> is *NOT* held, see <see cref="PlayerInsertHeldEntity(Robust.Shared.GameObjects.EntityUid)"/>.
/// </summary>
/// <param name="player">The player to insert an entity with</param>
/// <returns>true if inserted, false otherwise</returns>
public bool PlayerInsertEntityInWorld(EntityUid uid, EntityUid player, EntityUid toInsert, ServerStorageComponent? storageComp = null)
{
if (!Resolve(uid, ref storageComp) || !_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;
}
/// <summary> /// <summary>
/// Opens the storage UI for an entity /// Opens the storage UI for an entity
/// </summary> /// </summary>
/// <param name="entity">The entity to open the UI for</param> /// <param name="entity">The entity to open the UI for</param>
public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent? storageComp = null, bool silent = false) public override void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false)
{ {
if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player)) if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player))
return; return;
// prevent spamming bag open / honkerton honk sound // prevent spamming bag open / honkerton honk sound
silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && _useDelay.ActiveDelay(uid, useDelay); silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && UseDelay.ActiveDelay(uid, useDelay);
if (!silent) if (!silent)
{ {
_audio.PlayPvs(storageComp.StorageOpenSound, uid); Audio.PlayPvs(storageComp.StorageOpenSound, uid);
if (useDelay != null) if (useDelay != null)
_useDelay.BeginDelay(uid, useDelay); UseDelay.BeginDelay(uid, useDelay);
} }
_logManager.GetSawmill(storageComp.LoggerName) Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
var bui = _uiSystem.GetUiOrNull(uid, StorageUiKey.Key); var bui = _uiSystem.GetUiOrNull(uid, StorageComponent.StorageUiKey.Key);
if (bui != null) if (bui != null)
_uiSystem.OpenUi(bui, player.PlayerSession); _uiSystem.OpenUi(bui, player.PlayerSession);
} }
@@ -706,9 +124,9 @@ namespace Content.Server.Storage.EntitySystems
/// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them. /// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
/// </summary> /// </summary>
/// <param name="session"></param> /// <param name="session"></param>
public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent? storageComp = null) public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, StorageComponent? storageComp = null)
{ {
if (!Resolve(uid, ref storageComp) || storageComp.StoredEntities == null) if (!Resolve(uid, ref storageComp))
return; return;
// for each containing thing // for each containing thing
@@ -716,12 +134,9 @@ namespace Content.Server.Storage.EntitySystems
// ensure unsubscribe from session // ensure unsubscribe from session
// if it has a ui component // if it has a ui component
// close ui // close ui
foreach (var entity in storageComp.StoredEntities) foreach (var entity in storageComp.Container.ContainedEntities)
{ {
if (TryComp(entity, out ServerStorageComponent? storedStorageComp)) if (!TryComp(entity, out UserInterfaceComponent? ui))
DebugTools.Assert(storedStorageComp != storageComp, $"Storage component contains itself!? Entity: {uid}");
if (!TryComp(entity, out ServerUserInterfaceComponent? ui))
continue; continue;
foreach (var bui in ui.Interfaces.Values) foreach (var bui in ui.Interfaces.Values)
@@ -730,33 +145,4 @@ namespace Content.Server.Storage.EntitySystems
} }
} }
} }
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);
}
}
} }

View File

@@ -67,7 +67,7 @@ public sealed partial class StoreSystem
/// <param name="store">The store entity itself</param> /// <param name="store">The store entity itself</param>
/// <param name="component">The store component being refreshed.</param> /// <param name="component">The store component being refreshed.</param>
/// <param name="ui"></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)) if (!Resolve(store, ref component))
return; return;

View File

@@ -12,7 +12,7 @@ namespace Content.Server.UserInterface
[ViewVariables] [ViewVariables]
public Enum? Key { get; set; } 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)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("inHandsOnly")] [DataField("inHandsOnly")]

View File

@@ -33,7 +33,7 @@ public sealed partial class ActivatableUISystem : EntitySystem
SubscribeLocalEvent<ActivatableUIComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb); SubscribeLocalEvent<ActivatableUIComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
SubscribeLocalEvent<ServerUserInterfaceComponent, OpenUiActionEvent>(OnActionPerform); SubscribeLocalEvent<UserInterfaceComponent, OpenUiActionEvent>(OnActionPerform);
InitializePower(); InitializePower();
} }
@@ -50,7 +50,7 @@ public sealed partial class ActivatableUISystem : EntitySystem
ev.Cancel(); 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) if (args.Handled || args.Key == null)
return; return;

View File

@@ -59,7 +59,7 @@ public sealed class IntrinsicUISystem : EntitySystem
return true; 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)) if (!Resolve(uid, ref component))
return null; return null;

View File

@@ -5,7 +5,7 @@ namespace Content.Server.UserInterface
public static class UserInterfaceHelpers public static class UserInterfaceHelpers
{ {
[Obsolete("Use UserInterfaceSystem")] [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); return IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<UserInterfaceSystem>().GetUiOrNull(entity, uiKey);
} }

View File

@@ -565,7 +565,7 @@ public sealed class WiresSystem : SharedWiresSystem
UpdateUserInterface(uid); 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 if (!Resolve(uid, ref wires, ref ui, false)) // logging this means that we get a bunch of errors
return; return;

View File

@@ -8,7 +8,7 @@ namespace Content.Shared.Access.Systems
} }
/// <summary> /// <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. /// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary> /// </summary>
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -3,7 +3,7 @@
namespace Content.Shared.Atmos.Piping.Binary.Components namespace Content.Shared.Atmos.Piping.Binary.Components
{ {
/// <summary> /// <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. /// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary> /// </summary>
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -108,7 +108,7 @@ public abstract partial class SharedBuckleSystem
private void OnStrapContainerGettingInsertedAttempt(EntityUid uid, StrapComponent component, ContainerGettingInsertedAttemptEvent args) 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 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(); args.Cancel();
} }

View File

@@ -3,7 +3,7 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Labels namespace Content.Shared.Labels
{ {
/// <summary> /// <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. /// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary> /// </summary>
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -37,7 +37,7 @@ public sealed partial class MeleeSpeechComponent : Component
} }
/// <summary> /// <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. /// Useful when there are multiple UI for an object. Here it's future-proofing only.
/// </summary> /// </summary>
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -0,0 +1,12 @@
using Content.Shared.Storage.EntitySystems;
using Robust.Shared.GameStates;
namespace Content.Shared.Storage.Components;
// TODO:
// REPLACE THIS WITH CONTAINERFILL
[RegisterComponent, NetworkedComponent, Access(typeof(SharedStorageSystem))]
public sealed partial class StorageFillComponent : Component
{
[DataField("contents")] public List<EntitySpawnEntry> Contents = new();
}

View File

@@ -1,5 +1,5 @@
using System.Linq;
using Content.Shared.Disposal; using Content.Shared.Disposal;
using Content.Shared.Disposal.Components;
using Content.Shared.DoAfter; using Content.Shared.DoAfter;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Placeable; using Content.Shared.Placeable;
@@ -49,7 +49,7 @@ public sealed class DumpableSystem : EntitySystem
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; 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; return;
AlternativeVerb verb = new() AlternativeVerb verb = new()
@@ -69,7 +69,7 @@ public sealed class DumpableSystem : EntitySystem
if (!args.CanAccess || !args.CanInteract) if (!args.CanAccess || !args.CanInteract)
return; 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; return;
if (_disposalUnitSystem.HasDisposals(args.Target)) if (_disposalUnitSystem.HasDisposals(args.Target))
@@ -103,10 +103,10 @@ public sealed class DumpableSystem : EntitySystem
public void StartDoAfter(EntityUid storageUid, EntityUid? targetUid, EntityUid userUid, DumpableComponent dumpable) 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; 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) _doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, userUid, delay, new DumpableDoAfterEvent(), storageUid, target: targetUid, used: storageUid)
{ {
@@ -118,11 +118,11 @@ public sealed class DumpableSystem : EntitySystem
private void OnDoAfter(EntityUid uid, DumpableComponent component, DoAfterEvent args) 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; return;
Queue<EntityUid> dumpQueue = new(); Queue<EntityUid> dumpQueue = new();
foreach (var entity in storage.StoredEntities) foreach (var entity in storage.Container.ContainedEntities)
{ {
dumpQueue.Enqueue(entity); dumpQueue.Enqueue(entity);
} }

View File

@@ -0,0 +1,606 @@
using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.CombatMode;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Destructible;
using Content.Shared.DoAfter;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Lock;
using Content.Shared.Placeable;
using Content.Shared.Popups;
using Content.Shared.Stacks;
using Content.Shared.Storage.Components;
using Content.Shared.Timing;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Random;
namespace Content.Shared.Storage.EntitySystems;
public abstract class SharedStorageSystem : EntitySystem
{
[Dependency] protected readonly IRobustRandom Random = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!;
[Dependency] protected readonly SharedEntityStorageSystem EntityStorage = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
[Dependency] private readonly SharedInteractionSystem _sharedInteractionSystem = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedStackSystem _stack = default!;
[Dependency] protected readonly UseDelaySystem UseDelay = default!;
private EntityQuery<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;
}
}

View File

@@ -1,85 +0,0 @@
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.Storage
{
[NetworkedComponent()]
public abstract partial class SharedStorageComponent : Component
{
[Serializable, NetSerializable]
public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState
{
public readonly List<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
}
}

View File

@@ -0,0 +1,135 @@
using Content.Shared.Whitelist;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
using Robust.Shared.Serialization;
namespace Content.Shared.Storage
{
/// <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
}
}

View File

@@ -18,7 +18,7 @@
- id: BoxBeanbag - id: BoxBeanbag
amount: 2 amount: 2
- id: RagItem - id: RagItem
amound: 2 amount: 2
#- type: entity #- type: entity
# id: LockerFormalFilled # id: LockerFormalFilled

View File

@@ -23,8 +23,6 @@
components: components:
- type: Storage - type: Storage
capacity: 40 capacity: 40
equipSound:
path: /Audio/Items/belt_equip.ogg
- type: ContainerContainer - type: ContainerContainer
containers: containers:
storagebase: !type:Container storagebase: !type:Container

View File

@@ -183,9 +183,6 @@
interfaces: interfaces:
- key: enum.StrippingUiKey.Key - key: enum.StrippingUiKey.Key
type: StrippableBoundUserInterface type: StrippableBoundUserInterface
radius: 1.2
energy: 2
color: "#4faffb"
- type: GhostRole - type: GhostRole
prob: 0.25 prob: 0.25
name: ghost-role-information-space-kangaroo-name name: ghost-role-information-space-kangaroo-name

View File

@@ -19,7 +19,6 @@
- type: Item - type: Item
- type: Storage - type: Storage
capacity: 18 capacity: 18
size: 5
whitelist: whitelist:
tags: tags:
- Dice - Dice

View File

@@ -338,7 +338,6 @@
size: 5 size: 5
- type: Storage - type: Storage
capacity: 10 capacity: 10
size: 10
whitelist: whitelist:
tags: tags:
- Document - Document

View File

@@ -47,7 +47,6 @@
- key: enum.StorageUiKey.Key - key: enum.StorageUiKey.Key
type: StorageBoundUserInterface type: StorageBoundUserInterface
- type: Storage - type: Storage
popup: false
capacity: 30 capacity: 30
- type: TileFrictionModifier - type: TileFrictionModifier
modifier: 0.4 # makes it slide modifier: 0.4 # makes it slide