Storage Component ECS (#7530)
Co-authored-by: fishfish458 <fishfish458> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using Content.Client.Storage;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.Interactable
|
||||
{
|
||||
@@ -15,11 +14,12 @@ namespace Content.Client.Interactable
|
||||
if (!target.TryGetContainer(out var container))
|
||||
return false;
|
||||
|
||||
if (!EntityManager.TryGetComponent(container.Owner, out ClientStorageComponent storage))
|
||||
if (!TryComp(container.Owner, out ClientStorageComponent? storage))
|
||||
return false;
|
||||
|
||||
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
||||
return storage.UIOpen;
|
||||
// Need to return if UI is open or not
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.Animations;
|
||||
using Content.Client.Hands;
|
||||
using Content.Client.Items.Components;
|
||||
using Content.Client.Items.Managers;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Input;
|
||||
using static Robust.Client.UserInterface.Control;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.Storage
|
||||
{
|
||||
@@ -27,71 +10,10 @@ namespace Content.Client.Storage
|
||||
[RegisterComponent]
|
||||
public sealed class ClientStorageComponent : SharedStorageComponent, IDraggable
|
||||
{
|
||||
[Dependency] private readonly IItemSlotManager _itemSlotManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private List<EntityUid> _storedEntities = new();
|
||||
private int StorageSizeUsed;
|
||||
private int StorageCapacityMax;
|
||||
private StorageWindow? _window;
|
||||
public bool UIOpen => _window?.IsOpen ?? false;
|
||||
|
||||
public override IReadOnlyList<EntityUid> StoredEntities => _storedEntities;
|
||||
|
||||
private StorageWindow GetOrCreateWindow()
|
||||
{
|
||||
if (_window == null)
|
||||
{
|
||||
_window = new StorageWindow(this, _playerManager, _entityManager)
|
||||
{
|
||||
Title = _entityManager.GetComponent<MetaDataComponent>(Owner).EntityName
|
||||
};
|
||||
|
||||
_window.EntityList.GenerateItem += GenerateButton;
|
||||
_window.EntityList.ItemPressed += Interact;
|
||||
}
|
||||
|
||||
return _window;
|
||||
}
|
||||
|
||||
protected override void OnRemove()
|
||||
{
|
||||
if (_window is { Disposed: false })
|
||||
{
|
||||
_window.EntityList.GenerateItem -= GenerateButton;
|
||||
_window.EntityList.ItemPressed -= Interact;
|
||||
_window.Dispose();
|
||||
}
|
||||
|
||||
_window = null;
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not StorageComponentState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storedEntities = state.StoredEntities.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies received values from server about contents of storage container
|
||||
/// </summary>
|
||||
/// <param name="storageState"></param>
|
||||
public void HandleStorageMessage(StorageHeldItemsEvent storageState)
|
||||
{
|
||||
_storedEntities = storageState.StoredEntities.ToList();
|
||||
StorageSizeUsed = storageState.StorageSizeUsed;
|
||||
StorageCapacityMax = storageState.StorageSizeMax;
|
||||
GetOrCreateWindow().BuildEntityList(storageState.StoredEntities.ToList());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
|
||||
/// </summary>
|
||||
@@ -110,190 +32,9 @@ namespace Content.Client.Storage
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the storage UI if closed. Closes it if opened.
|
||||
/// </summary>
|
||||
public void ToggleUI()
|
||||
{
|
||||
var window = GetOrCreateWindow();
|
||||
|
||||
if (window.IsOpen)
|
||||
window.Close();
|
||||
else
|
||||
window.OpenCentered();
|
||||
}
|
||||
|
||||
public void CloseUI()
|
||||
{
|
||||
_window?.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
public void Interact(ButtonEventArgs args, EntityUid entity)
|
||||
{
|
||||
if (args.Event.Function == EngineKeyFunctions.UIClick)
|
||||
{
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new RemoveEntityEvent(Owner, entity));
|
||||
args.Event.Handle();
|
||||
}
|
||||
else if (_entityManager.EntityExists(entity))
|
||||
{
|
||||
_itemSlotManager.OnButtonPressed(args.Event, entity);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Remove(EntityUid entity)
|
||||
{
|
||||
if (_storedEntities.Remove(entity))
|
||||
{
|
||||
Dirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label
|
||||
/// </summary>
|
||||
public void GenerateButton(EntityUid entity, EntityContainerButton button)
|
||||
{
|
||||
if (!_entityManager.EntityExists(entity))
|
||||
return;
|
||||
|
||||
_entityManager.TryGetComponent(entity, out ISpriteComponent? sprite);
|
||||
_entityManager.TryGetComponent(entity, out ItemComponent? item);
|
||||
|
||||
button.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 2,
|
||||
Children =
|
||||
{
|
||||
new SpriteView
|
||||
{
|
||||
HorizontalAlignment = HAlignment.Left,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
MinSize = new Vector2(32.0f, 32.0f),
|
||||
OverrideDirection = Direction.South,
|
||||
Sprite = sprite
|
||||
},
|
||||
new Label
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
ClipText = true,
|
||||
Text = _entityManager.GetComponent<MetaDataComponent>(entity).EntityName
|
||||
},
|
||||
new Label
|
||||
{
|
||||
Align = Label.AlignMode.Right,
|
||||
Text = item?.Size.ToString() ?? Loc.GetString("no-item-size")
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
button.EnableAllKeybinds = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GUI class for client storage component
|
||||
/// </summary>
|
||||
private sealed class StorageWindow : DefaultWindow
|
||||
{
|
||||
private Control _vBox;
|
||||
private readonly Label _information;
|
||||
public readonly EntityListDisplay EntityList;
|
||||
public readonly ClientStorageComponent StorageEntity;
|
||||
|
||||
private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) };
|
||||
private readonly StyleBoxFlat _unHoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.0f) };
|
||||
|
||||
public StorageWindow(ClientStorageComponent storageEntity, IPlayerManager players, IEntityManager entities)
|
||||
{
|
||||
StorageEntity = storageEntity;
|
||||
SetSize = (200, 320);
|
||||
Title = Loc.GetString("comp-storage-window-title");
|
||||
RectClipContent = true;
|
||||
|
||||
var containerButton = new ContainerButton
|
||||
{
|
||||
Name = "StorageContainerButton",
|
||||
MouseFilter = MouseFilterMode.Pass,
|
||||
};
|
||||
Contents.AddChild(containerButton);
|
||||
|
||||
var innerContainerButton = new PanelContainer
|
||||
{
|
||||
PanelOverride = _unHoveredBox,
|
||||
};
|
||||
|
||||
containerButton.AddChild(innerContainerButton);
|
||||
containerButton.OnPressed += args =>
|
||||
{
|
||||
var controlledEntity = players.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (entities.HasComponent<HandsComponent>(controlledEntity))
|
||||
{
|
||||
entities.EntityNetManager?.SendSystemNetworkMessage(new InsertEntityEvent(storageEntity.Owner));
|
||||
}
|
||||
};
|
||||
|
||||
_vBox = new BoxContainer()
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
MouseFilter = MouseFilterMode.Ignore,
|
||||
};
|
||||
containerButton.AddChild(_vBox);
|
||||
_information = new Label
|
||||
{
|
||||
Text = Loc.GetString("comp-storage-window-volume", ("itemCount", 0), ("usedVolume", 0), ("maxVolume", 0)),
|
||||
VerticalAlignment = VAlignment.Center
|
||||
};
|
||||
_vBox.AddChild(_information);
|
||||
|
||||
EntityList = new EntityListDisplay
|
||||
{
|
||||
Name = "EntityListContainer",
|
||||
};
|
||||
_vBox.AddChild(EntityList);
|
||||
EntityList.OnMouseEntered += _ =>
|
||||
{
|
||||
innerContainerButton.PanelOverride = _hoveredBox;
|
||||
};
|
||||
|
||||
EntityList.OnMouseExited += _ =>
|
||||
{
|
||||
innerContainerButton.PanelOverride = _unHoveredBox;
|
||||
};
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(StorageEntity.Owner));
|
||||
base.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loops through stored entities creating buttons for each, updates information labels
|
||||
/// </summary>
|
||||
public void BuildEntityList(List<EntityUid> entityUids)
|
||||
{
|
||||
EntityList.PopulateList(entityUids);
|
||||
|
||||
//Sets information about entire storage container current capacity
|
||||
if (StorageEntity.StorageCapacityMax != 0)
|
||||
{
|
||||
_information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", entityUids.Count),
|
||||
("usedVolume", StorageEntity.StorageSizeUsed), ("maxVolume", StorageEntity.StorageCapacityMax));
|
||||
}
|
||||
else
|
||||
{
|
||||
_information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", entityUids.Count));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
87
Content.Client/Storage/StorageBoundUserInterface.cs
Normal file
87
Content.Client/Storage/StorageBoundUserInterface.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using Content.Client.Storage.UI;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Input;
|
||||
using Content.Client.Items.Managers;
|
||||
using JetBrains.Annotations;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
|
||||
namespace Content.Client.Storage
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class StorageBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
[ViewVariables] private StorageWindow? _window;
|
||||
|
||||
public StorageBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
|
||||
if (_window == null)
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
_window = new StorageWindow(entMan) {Title = entMan.GetComponent<MetaDataComponent>(Owner.Owner).EntityName};
|
||||
|
||||
_window.EntityList.GenerateItem += _window.GenerateButton;
|
||||
_window.EntityList.ItemPressed += InteractWithItem;
|
||||
_window.StorageContainerButton.OnPressed += TouchedContainerButton;
|
||||
|
||||
_window.OnClose += Close;
|
||||
_window.OpenCentered();
|
||||
}
|
||||
else
|
||||
{
|
||||
_window.Open();
|
||||
}
|
||||
}
|
||||
|
||||
public void InteractWithItem(BaseButton.ButtonEventArgs args, EntityUid entity)
|
||||
{
|
||||
if (args.Event.Function == EngineKeyFunctions.UIClick)
|
||||
{
|
||||
SendMessage(new StorageRemoveItemMessage(entity));
|
||||
}
|
||||
else if (IoCManager.Resolve<IEntityManager>().EntityExists(entity))
|
||||
{
|
||||
IoCManager.Resolve<IItemSlotManager>().OnButtonPressed(args.Event, entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void TouchedContainerButton(BaseButton.ButtonEventArgs args)
|
||||
{
|
||||
SendMessage(new StorageInsertItemMessage());
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
|
||||
if (_window == null || state is not StorageBoundUserInterfaceState cast)
|
||||
return;
|
||||
|
||||
_window?.BuildEntityList(cast);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (!disposing)
|
||||
return;
|
||||
|
||||
if (_window != null)
|
||||
{
|
||||
_window.EntityList.GenerateItem -= _window.GenerateButton;
|
||||
_window.EntityList.ItemPressed -= InteractWithItem;
|
||||
_window.StorageContainerButton.OnPressed -= TouchedContainerButton;
|
||||
_window.OnClose -= Close;
|
||||
}
|
||||
|
||||
_window?.Dispose();
|
||||
_window = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Storage;
|
||||
using Content.Client.Animations;
|
||||
|
||||
namespace Content.Client.Storage;
|
||||
|
||||
@@ -9,41 +10,28 @@ public sealed class StorageSystem : EntitySystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<StorageHeldItemsEvent>(OnStorageHeldItems);
|
||||
SubscribeNetworkEvent<OpenStorageUIEvent>(OnOpenStorageUI);
|
||||
SubscribeNetworkEvent<CloseStorageUIEvent>(OnCloseStorageUI);
|
||||
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(OnAnimateInsertingEntities);
|
||||
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities);
|
||||
}
|
||||
|
||||
private void OnStorageHeldItems(StorageHeldItemsEvent ev)
|
||||
/// <summary>
|
||||
/// Animate the newly stored entities in <paramref name="msg"/> flying towards this storage's position
|
||||
/// </summary>
|
||||
/// <param name="msg"></param>
|
||||
public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleStorageMessage(ev);
|
||||
}
|
||||
}
|
||||
if (!TryComp(msg.Storage, out ClientStorageComponent? storage))
|
||||
return;
|
||||
|
||||
private void OnOpenStorageUI(OpenStorageUIEvent ev)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.ToggleUI();
|
||||
}
|
||||
}
|
||||
TryComp(msg.Storage, out TransformComponent? transformComp);
|
||||
|
||||
private void OnCloseStorageUI(CloseStorageUIEvent ev)
|
||||
for (var i = 0; msg.StoredEntities.Count > i; i++)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
var entity = msg.StoredEntities[i];
|
||||
var initialPosition = msg.EntityPositions[i];
|
||||
if (EntityManager.EntityExists(entity) && transformComp != null)
|
||||
{
|
||||
storage.CloseUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAnimateInsertingEntities(AnimateInsertingEntitiesEvent ev)
|
||||
{
|
||||
if (TryComp<ClientStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleAnimatingInsertingEntities(ev);
|
||||
ReusableAnimations.AnimateEntityPickup(entity, initialPosition, transformComp.LocalPosition, EntityManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
142
Content.Client/Storage/UI/StorageWindow.cs
Normal file
142
Content.Client/Storage/UI/StorageWindow.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Content.Client.Items.Components;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
|
||||
namespace Content.Client.Storage.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// GUI class for client storage component
|
||||
/// </summary>
|
||||
public sealed class StorageWindow : DefaultWindow
|
||||
{
|
||||
private IEntityManager _entityManager;
|
||||
|
||||
private readonly Label _information;
|
||||
public readonly ContainerButton StorageContainerButton;
|
||||
public readonly EntityListDisplay EntityList;
|
||||
private readonly StyleBoxFlat _hoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.35f) };
|
||||
private readonly StyleBoxFlat _unHoveredBox = new() { BackgroundColor = Color.Black.WithAlpha(0.0f) };
|
||||
|
||||
public StorageWindow(IEntityManager entityManager)
|
||||
{
|
||||
_entityManager = entityManager;
|
||||
SetSize = (200, 320);
|
||||
Title = Loc.GetString("comp-storage-window-title");
|
||||
RectClipContent = true;
|
||||
|
||||
StorageContainerButton = new ContainerButton
|
||||
{
|
||||
Name = "StorageContainerButton",
|
||||
MouseFilter = MouseFilterMode.Pass,
|
||||
};
|
||||
|
||||
Contents.AddChild(StorageContainerButton);
|
||||
|
||||
var innerContainerButton = new PanelContainer
|
||||
{
|
||||
PanelOverride = _unHoveredBox,
|
||||
};
|
||||
|
||||
StorageContainerButton.AddChild(innerContainerButton);
|
||||
|
||||
Control vBox = new BoxContainer()
|
||||
{
|
||||
Orientation = LayoutOrientation.Vertical,
|
||||
MouseFilter = MouseFilterMode.Ignore,
|
||||
};
|
||||
|
||||
StorageContainerButton.AddChild(vBox);
|
||||
|
||||
_information = new Label
|
||||
{
|
||||
Text = Loc.GetString("comp-storage-window-volume", ("itemCount", 0), ("usedVolume", 0), ("maxVolume", 0)),
|
||||
VerticalAlignment = VAlignment.Center
|
||||
};
|
||||
|
||||
vBox.AddChild(_information);
|
||||
|
||||
EntityList = new EntityListDisplay
|
||||
{
|
||||
Name = "EntityListContainer",
|
||||
};
|
||||
|
||||
vBox.AddChild(EntityList);
|
||||
|
||||
EntityList.OnMouseEntered += _ =>
|
||||
{
|
||||
innerContainerButton.PanelOverride = _hoveredBox;
|
||||
};
|
||||
|
||||
EntityList.OnMouseExited += _ =>
|
||||
{
|
||||
innerContainerButton.PanelOverride = _unHoveredBox;
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loops through stored entities creating buttons for each, updates information labels
|
||||
/// </summary>
|
||||
public void BuildEntityList(StorageBoundUserInterfaceState state)
|
||||
{
|
||||
EntityList.PopulateList(state.StoredEntities);
|
||||
|
||||
//Sets information about entire storage container current capacity
|
||||
if (state.StorageCapacityMax != 0)
|
||||
{
|
||||
_information.Text = Loc.GetString("comp-storage-window-volume", ("itemCount", state.StoredEntities.Count),
|
||||
("usedVolume", state.StorageSizeUsed), ("maxVolume", state.StorageCapacityMax));
|
||||
}
|
||||
else
|
||||
{
|
||||
_information.Text = Loc.GetString("comp-storage-window-volume-unlimited", ("itemCount", state.StoredEntities.Count));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label
|
||||
/// </summary>
|
||||
public void GenerateButton(EntityUid entity, EntityContainerButton button)
|
||||
{
|
||||
if (!_entityManager.EntityExists(entity))
|
||||
return;
|
||||
|
||||
_entityManager.TryGetComponent(entity, out ISpriteComponent? sprite);
|
||||
_entityManager.TryGetComponent(entity, out ItemComponent? item);
|
||||
|
||||
button.AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
SeparationOverride = 2,
|
||||
Children =
|
||||
{
|
||||
new SpriteView
|
||||
{
|
||||
HorizontalAlignment = HAlignment.Left,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
MinSize = new Vector2(32.0f, 32.0f),
|
||||
OverrideDirection = Direction.South,
|
||||
Sprite = sprite
|
||||
},
|
||||
new Label
|
||||
{
|
||||
HorizontalExpand = true,
|
||||
ClipText = true,
|
||||
Text = _entityManager.GetComponent<MetaDataComponent>(entity).EntityName
|
||||
},
|
||||
new Label
|
||||
{
|
||||
Align = Label.AlignMode.Right,
|
||||
Text = item?.Size.ToString() ?? Loc.GetString("no-item-size")
|
||||
}
|
||||
}
|
||||
});
|
||||
button.EnableAllKeybinds = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Content.Server.Hands.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Stack;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Server.Strip;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Shared.ActionBlocker;
|
||||
@@ -47,6 +48,7 @@ namespace Content.Server.Hands.Systems
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] private readonly PullingSystem _pullingSystem = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
||||
[Dependency] private readonly StorageSystem _storageSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -262,7 +264,7 @@ namespace Content.Server.Hands.Systems
|
||||
|
||||
if (hands.ActiveHand?.HeldEntity != null)
|
||||
{
|
||||
storageComponent.PlayerInsertHeldEntity(plyEnt);
|
||||
_storageSystem.PlayerInsertHeldEntity(slotEntity.Value, plyEnt, storageComponent);
|
||||
}
|
||||
else if (storageComponent.StoredEntities != null)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.CombatMode;
|
||||
using Content.Server.Hands.Components;
|
||||
@@ -12,7 +10,6 @@ using Content.Shared.Input;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Timing;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -20,6 +17,7 @@ using Robust.Shared.Containers;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Players;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
|
||||
namespace Content.Server.Interaction
|
||||
{
|
||||
@@ -32,6 +30,7 @@ namespace Content.Server.Interaction
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
||||
[Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -71,7 +70,7 @@ namespace Content.Server.Interaction
|
||||
return false;
|
||||
|
||||
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
|
||||
return storage.SubscribedSessions.Contains(actor.PlayerSession);
|
||||
return _uiSystem.SessionHasOpenUi(container.Owner, StorageUiKey.Key, actor.PlayerSession);
|
||||
}
|
||||
|
||||
#region Drag drop
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Server.Atmos;
|
||||
using Content.Server.Clothing.Components;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Server.Temperature.Systems;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Inventory;
|
||||
@@ -9,8 +9,10 @@ using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
|
||||
|
||||
namespace Content.Server.Inventory
|
||||
{
|
||||
sealed class ServerInventorySystem : InventorySystem
|
||||
public sealed class ServerInventorySystem : InventorySystem
|
||||
{
|
||||
[Dependency] private readonly StorageSystem _storageSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -37,7 +39,7 @@ namespace Content.Server.Inventory
|
||||
|
||||
if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp<ServerStorageComponent>(entityUid, out var storageComponent))
|
||||
{
|
||||
storageComponent.OpenStorageUI(uid);
|
||||
_storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Linq;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Nutrition.Components;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Server.Storage.Components;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Shared.Camera;
|
||||
@@ -31,6 +32,7 @@ namespace Content.Server.PneumaticCannon
|
||||
[Dependency] private readonly CameraRecoilSystem _cameraRecoil = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
||||
[Dependency] private readonly StorageSystem _storageSystem = default!;
|
||||
|
||||
private HashSet<PneumaticCannonComponent> _currentlyFiring = new();
|
||||
|
||||
@@ -133,9 +135,9 @@ namespace Content.Server.PneumaticCannon
|
||||
if (EntityManager.TryGetComponent<SharedItemComponent?>(args.Used, out var item)
|
||||
&& EntityManager.TryGetComponent<ServerStorageComponent?>(component.Owner, out var storage))
|
||||
{
|
||||
if (storage.CanInsert(args.Used))
|
||||
if (_storageSystem.CanInsert(component.Owner, args.Used, storage))
|
||||
{
|
||||
storage.Insert(args.Used);
|
||||
_storageSystem.Insert(component.Owner, args.Used, storage);
|
||||
args.User.PopupMessage(Loc.GetString("pneumatic-cannon-component-insert-item-success",
|
||||
("item", args.Used), ("cannon", component.Owner)));
|
||||
}
|
||||
|
||||
@@ -1,39 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Coordinates;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Placeable;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System.Threading;
|
||||
|
||||
namespace Content.Server.Storage.Components
|
||||
{
|
||||
@@ -41,36 +10,36 @@ namespace Content.Server.Storage.Components
|
||||
/// Storage component for containing entities within this one, matches a UI on the client which shows stored entities
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
[ComponentReference(typeof(SharedStorageComponent))]
|
||||
public sealed class ServerStorageComponent : SharedStorageComponent, IInteractUsing, IActivate, IStorageComponent, IDestroyAct, IAfterInteract
|
||||
public sealed class ServerStorageComponent : SharedStorageComponent
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
|
||||
|
||||
private const string LoggerName = "Storage";
|
||||
public string LoggerName = "Storage";
|
||||
|
||||
public Container? Storage;
|
||||
|
||||
private readonly Dictionary<EntityUid, int> _sizeCache = new();
|
||||
public readonly Dictionary<EntityUid, int> SizeCache = new();
|
||||
|
||||
[DataField("occludesLight")]
|
||||
private bool _occludesLight = true;
|
||||
|
||||
[DataField("quickInsert")]
|
||||
private bool _quickInsert = false; // Can insert storables by "attacking" them with the storage entity
|
||||
public bool QuickInsert = false; // Can insert storables by "attacking" them with the storage entity
|
||||
|
||||
[DataField("clickInsert")]
|
||||
private bool _clickInsert = true; // Can insert stuff by clicking the storage entity with it
|
||||
public bool ClickInsert = true; // Can insert stuff by clicking the storage entity with it
|
||||
|
||||
[DataField("areaInsert")]
|
||||
private bool _areaInsert = false; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay
|
||||
public bool AreaInsert = false; // "Attacking" with the storage entity causes it to insert all nearby storables after a delay
|
||||
|
||||
/// <summary>
|
||||
/// Token for interrupting area insert do after.
|
||||
/// </summary>
|
||||
public CancellationTokenSource? CancelToken;
|
||||
|
||||
[DataField("areaInsertRadius")]
|
||||
private int _areaInsertRadius = 1;
|
||||
public int AreaInsertRadius = 1;
|
||||
|
||||
[DataField("whitelist")]
|
||||
private EntityWhitelist? _whitelist = null;
|
||||
public EntityWhitelist? Whitelist = null;
|
||||
[DataField("blacklist")]
|
||||
public EntityWhitelist? Blacklist = null;
|
||||
|
||||
@@ -81,19 +50,30 @@ namespace Content.Server.Storage.Components
|
||||
[DataField("popup")]
|
||||
public bool ShowPopup = true;
|
||||
|
||||
private bool _storageInitialCalculated;
|
||||
/// <summary>
|
||||
/// This storage has an open UI
|
||||
/// </summary>
|
||||
public bool IsOpen = false;
|
||||
public int StorageUsed;
|
||||
[DataField("capacity")]
|
||||
public int StorageCapacityMax = 10000;
|
||||
public readonly HashSet<IPlayerSession> SubscribedSessions = new();
|
||||
|
||||
[DataField("storageSoundCollection")]
|
||||
public SoundSpecifier StorageSoundCollection { get; set; } = new SoundCollectionSpecifier("storageRustle");
|
||||
[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;
|
||||
@@ -104,567 +84,10 @@ namespace Content.Server.Storage.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStorageVisualization()
|
||||
{
|
||||
if (!_entityManager.TryGetComponent(Owner, out AppearanceComponent appearance))
|
||||
return;
|
||||
|
||||
bool open = SubscribedSessions.Count != 0;
|
||||
|
||||
appearance.SetData(StorageVisuals.Open, open);
|
||||
appearance.SetData(SharedBagOpenVisuals.BagState, open ? SharedBagState.Open : SharedBagState.Closed);
|
||||
|
||||
if (_entityManager.HasComponent<ItemCounterComponent>(Owner))
|
||||
appearance.SetData(StackVisuals.Hide, !open);
|
||||
}
|
||||
|
||||
private void EnsureInitialCalculated()
|
||||
{
|
||||
if (_storageInitialCalculated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RecalculateStorageUsed();
|
||||
|
||||
_storageInitialCalculated = true;
|
||||
}
|
||||
|
||||
private void RecalculateStorageUsed()
|
||||
{
|
||||
StorageUsed = 0;
|
||||
_sizeCache.Clear();
|
||||
|
||||
if (Storage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var entity in Storage.ContainedEntities)
|
||||
{
|
||||
var item = _entityManager.GetComponent<SharedItemComponent>(entity);
|
||||
StorageUsed += item.Size;
|
||||
_sizeCache.Add(entity, item.Size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if an entity can be stored and if it fits
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to check</param>
|
||||
/// <returns>true if it can be inserted, false otherwise</returns>
|
||||
public bool CanInsert(EntityUid entity)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (_entityManager.TryGetComponent(entity, out ServerStorageComponent? storage) &&
|
||||
storage.StorageCapacityMax >= StorageCapacityMax)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_entityManager.TryGetComponent(entity, out SharedItemComponent? store) &&
|
||||
store.Size > StorageCapacityMax - StorageUsed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_whitelist != null && !_whitelist.IsValid(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Blacklist != null && Blacklist.IsValid(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_entityManager.GetComponent<TransformComponent>(entity).Anchored)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts into the storage container
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to insert</param>
|
||||
/// <returns>true if the entity was inserted, false otherwise</returns>
|
||||
public bool Insert(EntityUid entity)
|
||||
{
|
||||
return CanInsert(entity) && Storage?.Insert(entity) == true;
|
||||
}
|
||||
|
||||
// neccesary for abstraction, should be deleted on complete storage ECS
|
||||
public override bool Remove(EntityUid entity)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
return Storage?.Remove(entity) == true;
|
||||
}
|
||||
|
||||
public void HandleEntityMaybeInserted(EntInsertedIntoContainerMessage message)
|
||||
{
|
||||
if (message.Container != Storage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PlaySoundCollection();
|
||||
EnsureInitialCalculated();
|
||||
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) had entity (UID {message.Entity}) inserted into it.");
|
||||
|
||||
var size = 0;
|
||||
if (_entityManager.TryGetComponent(message.Entity, out SharedItemComponent? storable))
|
||||
size = storable.Size;
|
||||
|
||||
StorageUsed += size;
|
||||
_sizeCache[message.Entity] = size;
|
||||
|
||||
UpdateClientInventories();
|
||||
}
|
||||
|
||||
public void HandleEntityMaybeRemoved(EntRemovedFromContainerMessage message)
|
||||
{
|
||||
if (message.Container != Storage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureInitialCalculated();
|
||||
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) had entity (UID {message.Entity}) removed from it.");
|
||||
|
||||
if (!_sizeCache.TryGetValue(message.Entity, out var size))
|
||||
{
|
||||
Logger.WarningS(LoggerName, $"Removed entity {_entityManager.ToPrettyString(message.Entity)} without a cached size from storage {_entityManager.ToPrettyString(Owner)} at {_entityManager.GetComponent<TransformComponent>(Owner).MapPosition}");
|
||||
|
||||
RecalculateStorageUsed();
|
||||
return;
|
||||
}
|
||||
|
||||
StorageUsed -= size;
|
||||
|
||||
UpdateClientInventories();
|
||||
}
|
||||
|
||||
/// <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 player)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (!_entityManager.TryGetComponent(player, out HandsComponent? hands) ||
|
||||
hands.ActiveHandEntity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var toInsert = hands.ActiveHandEntity;
|
||||
|
||||
var handSys = _sysMan.GetEntitySystem<SharedHandsSystem>();
|
||||
|
||||
if (!handSys.TryDrop(player, toInsert.Value, handsComp: hands))
|
||||
{
|
||||
Popup(player, "comp-storage-cant-insert");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Insert(toInsert.Value))
|
||||
{
|
||||
handSys.PickupOrDrop(player, toInsert.Value, handsComp: hands);
|
||||
Popup(player, "comp-storage-cant-insert");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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 player, EntityUid toInsert)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (!Insert(toInsert))
|
||||
{
|
||||
Popup(player, "comp-storage-cant-insert");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the storage UI for an entity
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to open the UI for</param>
|
||||
public void OpenStorageUI(EntityUid entity)
|
||||
{
|
||||
PlaySoundCollection();
|
||||
EnsureInitialCalculated();
|
||||
|
||||
var userSession = _entityManager.GetComponent<ActorComponent>(entity).PlayerSession;
|
||||
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) \"used\" by player session (UID {userSession.AttachedEntity}).");
|
||||
|
||||
SubscribeSession(userSession);
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new OpenStorageUIEvent(Owner), userSession.ConnectedClient);
|
||||
UpdateClientInventory(userSession);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the storage UI on all subscribed actors, informing them of the state of the container.
|
||||
/// </summary>
|
||||
private void UpdateClientInventories()
|
||||
{
|
||||
foreach (var session in SubscribedSessions)
|
||||
{
|
||||
UpdateClientInventory(session);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates storage UI on a client, informing them of the state of the container.
|
||||
/// </summary>
|
||||
/// <param name="session">The client to be updated</param>
|
||||
private void UpdateClientInventory(IPlayerSession session)
|
||||
{
|
||||
if (session.AttachedEntity == null)
|
||||
{
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) detected no attached entity in player session (UID {session.AttachedEntity}).");
|
||||
|
||||
UnsubscribeSession(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage == null)
|
||||
{
|
||||
Logger.WarningS(LoggerName, $"{nameof(UpdateClientInventory)} called with null {nameof(Storage)}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (StoredEntities == null)
|
||||
{
|
||||
Logger.WarningS(LoggerName, $"{nameof(UpdateClientInventory)} called with null {nameof(StoredEntities)}");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var stored = StoredEntities.Select(e => e).ToArray();
|
||||
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new StorageHeldItemsEvent(Owner, StorageCapacityMax,StorageUsed, stored), session.ConnectedClient);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a session to the update list.
|
||||
/// </summary>
|
||||
/// <param name="session">The session to add</param>
|
||||
private void SubscribeSession(IPlayerSession session)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (!SubscribedSessions.Contains(session))
|
||||
{
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) subscribed player session (UID {session.AttachedEntity}).");
|
||||
|
||||
session.PlayerStatusChanged += HandlePlayerSessionChangeEvent;
|
||||
SubscribedSessions.Add(session);
|
||||
}
|
||||
|
||||
_entityManager.EnsureComponent<ActiveStorageComponent>(Owner);
|
||||
if (SubscribedSessions.Count == 1)
|
||||
UpdateStorageVisualization();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a session from the update list.
|
||||
/// </summary>
|
||||
/// <param name="session">The session to remove</param>
|
||||
public void UnsubscribeSession(IPlayerSession session)
|
||||
{
|
||||
if (SubscribedSessions.Contains(session))
|
||||
{
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) unsubscribed player session (UID {session.AttachedEntity}).");
|
||||
|
||||
SubscribedSessions.Remove(session);
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(Owner),
|
||||
session.ConnectedClient);
|
||||
}
|
||||
|
||||
CloseNestedInterfaces(session);
|
||||
|
||||
if (SubscribedSessions.Count == 0)
|
||||
{
|
||||
UpdateStorageVisualization();
|
||||
|
||||
if (_entityManager.HasComponent<ActiveStorageComponent>(Owner))
|
||||
{
|
||||
_entityManager.RemoveComponent<ActiveStorageComponent>(Owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
|
||||
/// </summary>
|
||||
/// <param name="session"></param>
|
||||
public void CloseNestedInterfaces(IPlayerSession session)
|
||||
{
|
||||
if (StoredEntities == null)
|
||||
return;
|
||||
|
||||
foreach (var entity in StoredEntities)
|
||||
{
|
||||
if (_entityManager.TryGetComponent(entity, out ServerStorageComponent storageComponent))
|
||||
{
|
||||
DebugTools.Assert(storageComponent != this, $"Storage component contains itself!? Entity: {Owner}");
|
||||
storageComponent.UnsubscribeSession(session);
|
||||
}
|
||||
|
||||
if (_entityManager.TryGetComponent(entity, out ServerUserInterfaceComponent uiComponent))
|
||||
{
|
||||
foreach (var ui in uiComponent.Interfaces)
|
||||
{
|
||||
ui.Close(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePlayerSessionChangeEvent(object? obj, SessionStatusEventArgs sessionStatus)
|
||||
{
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) handled a status change in player session (UID {sessionStatus.Session.AttachedEntity}).");
|
||||
|
||||
if (sessionStatus.NewStatus != SessionStatus.InGame)
|
||||
{
|
||||
UnsubscribeSession(sessionStatus.Session);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
// ReSharper disable once StringLiteralTypo
|
||||
Storage = Owner.EnsureContainer<Container>("storagebase");
|
||||
Storage.OccludesLight = _occludesLight;
|
||||
UpdateStorageVisualization();
|
||||
EnsureInitialCalculated();
|
||||
}
|
||||
|
||||
public void HandleRemoveEntity(RemoveEntityEvent remove, ICommonSession session)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var ownerTransform = _entityManager.GetComponent<TransformComponent>(Owner);
|
||||
var playerTransform = _entityManager.GetComponent<TransformComponent>(player);
|
||||
|
||||
if (!playerTransform.Coordinates.InRange(_entityManager, ownerTransform.Coordinates, 2) ||
|
||||
Owner.IsInContainer() && !playerTransform.ContainsEntity(ownerTransform))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!remove.EntityUid.Valid || Storage?.Contains(remove.EntityUid) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_sysMan.GetEntitySystem<SharedHandsSystem>().TryPickupAnyHand(player, remove.EntityUid);
|
||||
}
|
||||
|
||||
public void HandleInsertEntity(ICommonSession session)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
|
||||
if (session.AttachedEntity is not {Valid: true} player)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(player, Owner, popup: ShowPopup))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInsertHeldEntity(player);
|
||||
}
|
||||
|
||||
public void HandleCloseUI(ICommonSession session)
|
||||
{
|
||||
if (session is not IPlayerSession playerSession)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UnsubscribeSession(playerSession);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inserts storable entities into this storage container if possible, otherwise return to the hand of the user
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
/// <returns>true if inserted, false otherwise</returns>
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!_clickInsert)
|
||||
return false;
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner}) attacked by user (UID {eventArgs.User}) with entity (UID {eventArgs.Using}).");
|
||||
|
||||
if (_entityManager.HasComponent<PlaceableSurfaceComponent>(Owner))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return PlayerInsertHeldEntity(eventArgs.User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message to open the storage UI
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
/// <returns></returns>
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
EnsureInitialCalculated();
|
||||
OpenStorageUI(eventArgs.User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows a user to pick up entities by clicking them, or pick up all entities in a certain radius
|
||||
/// arround a click.
|
||||
/// </summary>
|
||||
/// <param name="eventArgs"></param>
|
||||
/// <returns></returns>
|
||||
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.CanReach) return false;
|
||||
|
||||
// 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 (_areaInsert && (eventArgs.Target == null || !_entityManager.HasComponent<SharedItemComponent>(eventArgs.Target.Value)))
|
||||
{
|
||||
var validStorables = new List<EntityUid>();
|
||||
foreach (var entity in EntitySystem.Get<EntityLookupSystem>().GetEntitiesInRange(eventArgs.ClickLocation, _areaInsertRadius, LookupFlags.None))
|
||||
{
|
||||
if (entity.IsInContainer()
|
||||
|| entity == eventArgs.User
|
||||
|| !_entityManager.HasComponent<SharedItemComponent>(entity)
|
||||
|| !EntitySystem.Get<InteractionSystem>().InRangeUnobstructed(eventArgs.User, entity))
|
||||
continue;
|
||||
validStorables.Add(entity);
|
||||
}
|
||||
|
||||
//If there's only one then let's be generous
|
||||
if (validStorables.Count > 1)
|
||||
{
|
||||
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, 0.2f * validStorables.Count, CancellationToken.None, Owner)
|
||||
{
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = true,
|
||||
};
|
||||
var result = await doAfterSystem.WaitDoAfter(doAfterArgs);
|
||||
if (result != DoAfterStatus.Finished) return true;
|
||||
}
|
||||
|
||||
var successfullyInserted = new List<EntityUid>();
|
||||
var successfullyInsertedPositions = new List<EntityCoordinates>();
|
||||
foreach (var entity in validStorables)
|
||||
{
|
||||
// Check again, situation may have changed for some entities, but we'll still pick up any that are valid
|
||||
if (entity.IsInContainer()
|
||||
|| entity == eventArgs.User
|
||||
|| !_entityManager.HasComponent<SharedItemComponent>(entity))
|
||||
continue;
|
||||
var position = EntityCoordinates.FromMap(_entityManager.GetComponent<TransformComponent>(Owner).Parent?.Owner ?? Owner, _entityManager.GetComponent<TransformComponent>(entity).MapPosition);
|
||||
if (PlayerInsertEntityInWorld(eventArgs.User, entity))
|
||||
{
|
||||
successfullyInserted.Add(entity);
|
||||
successfullyInsertedPositions.Add(position);
|
||||
}
|
||||
}
|
||||
|
||||
// If we picked up atleast one thing, play a sound and do a cool animation!
|
||||
if (successfullyInserted.Count > 0)
|
||||
{
|
||||
PlaySoundCollection();
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(
|
||||
new AnimateInsertingEntitiesEvent(Owner, successfullyInserted, successfullyInsertedPositions));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Pick up the clicked entity
|
||||
else if (_quickInsert)
|
||||
{
|
||||
if (eventArgs.Target is not {Valid: true} target)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.IsInContainer()
|
||||
|| target == eventArgs.User
|
||||
|| !_entityManager.HasComponent<SharedItemComponent>(target))
|
||||
return false;
|
||||
var position = EntityCoordinates.FromMap(
|
||||
_entityManager.GetComponent<TransformComponent>(Owner).Parent?.Owner ?? Owner,
|
||||
_entityManager.GetComponent<TransformComponent>(target).MapPosition);
|
||||
if (PlayerInsertEntityInWorld(eventArgs.User, target))
|
||||
{
|
||||
_entityManager.EntityNetManager?.SendSystemNetworkMessage(new AnimateInsertingEntitiesEvent(Owner,
|
||||
new List<EntityUid> { target },
|
||||
new List<EntityCoordinates> { position }));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
|
||||
{
|
||||
var storedEntities = StoredEntities?.ToList();
|
||||
|
||||
if (storedEntities == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var entity in storedEntities)
|
||||
{
|
||||
Remove(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void Popup(EntityUid player, string message)
|
||||
{
|
||||
if (!ShowPopup) return;
|
||||
|
||||
Owner.PopupMessage(player, Loc.GetString(message));
|
||||
}
|
||||
|
||||
private void PlaySoundCollection()
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), StorageSoundCollection.GetSound(), Owner, AudioParams.Default);
|
||||
}
|
||||
}
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveStorageComponent : Component {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Content.Server.Storage.Components;
|
||||
using Robust.Shared.Random;
|
||||
using System.Linq;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems;
|
||||
@@ -10,8 +8,10 @@ public sealed partial class StorageSystem
|
||||
private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.Contents.Count == 0) return;
|
||||
|
||||
if (!TryComp<IStorageComponent>(uid, out var storage))
|
||||
// ServerStorageComponent needs to rejoin IStorageComponent when other storage components are ECS'd
|
||||
TryComp<IStorageComponent>(uid, out var storage);
|
||||
TryComp<ServerStorageComponent>(uid, out var serverStorageComp);
|
||||
if (storage == null && serverStorageComp == null)
|
||||
{
|
||||
Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})");
|
||||
return;
|
||||
@@ -24,7 +24,12 @@ public sealed partial class StorageSystem
|
||||
{
|
||||
var ent = EntityManager.SpawnEntity(item, coordinates);
|
||||
|
||||
if (storage.Insert(ent)) continue;
|
||||
// handle depending on storage component, again this should be unified after ECS
|
||||
if (storage != null && storage.Insert(ent))
|
||||
continue;
|
||||
|
||||
if (serverStorageComp != null && Insert(uid, ent, serverStorageComp))
|
||||
continue;
|
||||
|
||||
Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {uid} but can't.");
|
||||
EntityManager.DeleteEntity(ent);
|
||||
|
||||
@@ -14,6 +14,21 @@ using Robust.Shared.Containers;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Threading;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Placeable;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Server.Containers;
|
||||
using Content.Server.Popups;
|
||||
using static Content.Shared.Storage.SharedStorageComponent;
|
||||
|
||||
namespace Content.Server.Storage.EntitySystems
|
||||
{
|
||||
@@ -22,51 +37,50 @@ namespace Content.Server.Storage.EntitySystems
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly DisposalUnitSystem _disposalSystem = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
|
||||
[Dependency] private readonly EntityLookupSystem _entityLookupSystem = 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!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
|
||||
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
|
||||
SubscribeLocalEvent<ServerStorageComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
|
||||
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
|
||||
SubscribeLocalEvent<ServerStorageComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<ServerStorageComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<ServerStorageComponent, AfterInteractEvent>(AfterInteract);
|
||||
SubscribeLocalEvent<ServerStorageComponent, DestructionEventArgs>(OnDestroy);
|
||||
SubscribeLocalEvent<ServerStorageComponent, StorageRemoveItemMessage>(OnRemoveItemMessage);
|
||||
SubscribeLocalEvent<ServerStorageComponent, StorageInsertItemMessage>(OnInsertItemMessage);
|
||||
SubscribeLocalEvent<ServerStorageComponent, BoundUIOpenedEvent>(OnBoundUIOpen);
|
||||
SubscribeLocalEvent<ServerStorageComponent, BoundUIClosedEvent>(OnBoundUIClosed);
|
||||
SubscribeLocalEvent<ServerStorageComponent, EntRemovedFromContainerMessage>(OnStorageItemRemoved);
|
||||
|
||||
SubscribeLocalEvent<EntityStorageComponent, GetVerbsEvent<InteractionVerb>>(AddToggleOpenVerb);
|
||||
SubscribeLocalEvent<EntityStorageComponent, RelayMovementEntityEvent>(OnRelayMovement);
|
||||
|
||||
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<ActivationVerb>>(AddOpenUiVerb);
|
||||
SubscribeLocalEvent<ServerStorageComponent, GetVerbsEvent<UtilityVerb>>(AddTransferVerbs);
|
||||
|
||||
SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
|
||||
|
||||
SubscribeNetworkEvent<RemoveEntityEvent>(OnRemoveEntity);
|
||||
SubscribeNetworkEvent<InsertEntityEvent>(OnInsertEntity);
|
||||
SubscribeNetworkEvent<CloseStorageUIEvent>(OnCloseStorageUI);
|
||||
}
|
||||
|
||||
private void OnRemoveEntity(RemoveEntityEvent ev, EntitySessionEventArgs args)
|
||||
private void OnComponentInit(EntityUid uid, ServerStorageComponent storageComp, ComponentInit args)
|
||||
{
|
||||
if (TryComp<ServerStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleRemoveEntity(ev, args.SenderSession);
|
||||
}
|
||||
}
|
||||
base.Initialize();
|
||||
|
||||
private void OnInsertEntity(InsertEntityEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
if (TryComp<ServerStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleInsertEntity(args.SenderSession);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCloseStorageUI(CloseStorageUIEvent ev, EntitySessionEventArgs args)
|
||||
{
|
||||
if (TryComp<ServerStorageComponent>(ev.Storage, out var storage))
|
||||
{
|
||||
storage.HandleCloseUI(args.SenderSession);
|
||||
}
|
||||
// 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 OnRelayMovement(EntityUid uid, EntityStorageComponent component, RelayMovementEntityEvent args)
|
||||
@@ -76,22 +90,12 @@ namespace Content.Server.Storage.EntitySystems
|
||||
|
||||
if (_gameTiming.CurTime <
|
||||
component.LastInternalOpenAttempt + EntityStorageComponent.InternalOpenAttemptDelay)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
component.LastInternalOpenAttempt = _gameTiming.CurTime;
|
||||
component.TryOpenStorage(args.Entity);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var (_, component) in EntityManager.EntityQuery<ActiveStorageComponent, ServerStorageComponent>())
|
||||
{
|
||||
CheckSubscribedEntities(component);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToggleOpenVerb(EntityUid uid, EntityStorageComponent component, GetVerbsEvent<InteractionVerb> args)
|
||||
{
|
||||
@@ -121,19 +125,18 @@ namespace Content.Server.Storage.EntitySystems
|
||||
if (!args.CanAccess || !args.CanInteract)
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out LockComponent? lockComponent) && lockComponent.Locked)
|
||||
if (TryComp<LockComponent>(uid, out var lockComponent) && lockComponent.Locked)
|
||||
return;
|
||||
|
||||
// Get the session for the user
|
||||
var session = EntityManager.GetComponentOrNull<ActorComponent>(args.User)?.PlayerSession;
|
||||
if (session == null)
|
||||
if (!TryComp<ActorComponent>(args.User, out var actor) || actor?.PlayerSession == null)
|
||||
return;
|
||||
|
||||
// Does this player currently have the storage UI open?
|
||||
var uiOpen = component.SubscribedSessions.Contains(session);
|
||||
bool uiOpen = _uiSystem.SessionHasOpenUi(uid, StorageUiKey.Key, actor.PlayerSession);
|
||||
|
||||
ActivationVerb verb = new();
|
||||
verb.Act = () => component.OpenStorageUI(args.User);
|
||||
verb.Act = () => OpenStorageUI(uid, args.User, component);
|
||||
if (uiOpen)
|
||||
{
|
||||
verb.Text = Loc.GetString("verb-common-close-ui");
|
||||
@@ -187,6 +190,236 @@ namespace Content.Server.Storage.EntitySystems
|
||||
args.Verbs.Add(dispose);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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 (!storageComp.ClickInsert)
|
||||
return;
|
||||
|
||||
Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) attacked by user (UID {args.User}) with entity (UID {args.Used}).");
|
||||
|
||||
if (HasComp<PlaceableSurfaceComponent>(uid))
|
||||
return;
|
||||
|
||||
PlayerInsertHeldEntity(uid, args.User, storageComp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message to open the storage UI
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void OnActivate(EntityUid uid, ServerStorageComponent storageComp, ActivateInWorldEvent args)
|
||||
{
|
||||
if (!TryComp<ActorComponent>(args.User, out var actor))
|
||||
return;
|
||||
|
||||
OpenStorageUI(uid, args.User, 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 eventArgs)
|
||||
{
|
||||
if (!eventArgs.CanReach) return;
|
||||
|
||||
if (storageComp.CancelToken != null)
|
||||
{
|
||||
storageComp.CancelToken.Cancel();
|
||||
storageComp.CancelToken = null;
|
||||
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 && (eventArgs.Target == null || !HasComp<SharedItemComponent>(eventArgs.Target.Value)))
|
||||
{
|
||||
var validStorables = new List<EntityUid>();
|
||||
foreach (var entity in _entityLookupSystem.GetEntitiesInRange(eventArgs.ClickLocation, storageComp.AreaInsertRadius, LookupFlags.None))
|
||||
{
|
||||
if (entity == eventArgs.User
|
||||
|| !HasComp<SharedItemComponent>(entity)
|
||||
|| !_interactionSystem.InRangeUnobstructed(eventArgs.User, entity))
|
||||
continue;
|
||||
|
||||
validStorables.Add(entity);
|
||||
}
|
||||
|
||||
//If there's only one then let's be generous
|
||||
if (validStorables.Count > 1)
|
||||
{
|
||||
storageComp.CancelToken = new CancellationTokenSource();
|
||||
var doAfterArgs = new DoAfterEventArgs(eventArgs.User, 0.2f * validStorables.Count, storageComp.CancelToken.Token, uid)
|
||||
{
|
||||
BreakOnStun = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnUserMove = true,
|
||||
NeedHand = true,
|
||||
};
|
||||
|
||||
await _doAfterSystem.WaitDoAfter(doAfterArgs);
|
||||
}
|
||||
|
||||
// TODO: Make it use the event DoAfter
|
||||
var successfullyInserted = new List<EntityUid>();
|
||||
var successfullyInsertedPositions = new List<EntityCoordinates>();
|
||||
foreach (var entity in validStorables)
|
||||
{
|
||||
// Check again, situation may have changed for some entities, but we'll still pick up any that are valid
|
||||
if (_containerSystem.IsEntityInContainer(entity)
|
||||
|| entity == eventArgs.User
|
||||
|| !HasComp<SharedItemComponent>(entity))
|
||||
continue;
|
||||
|
||||
if (TryComp<TransformComponent>(uid, out var transformOwner) && TryComp<TransformComponent>(entity, out var transformEnt))
|
||||
{
|
||||
var position = EntityCoordinates.FromMap(transformOwner.Parent?.Owner ?? uid, transformEnt.MapPosition);
|
||||
|
||||
if (PlayerInsertEntityInWorld(uid, eventArgs.User, entity, storageComp))
|
||||
{
|
||||
successfullyInserted.Add(entity);
|
||||
successfullyInsertedPositions.Add(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we picked up atleast one thing, play a sound and do a cool animation!
|
||||
if (successfullyInserted.Count > 0)
|
||||
{
|
||||
if (storageComp.StorageInsertSound is not null)
|
||||
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageInsertSound.GetSound(), uid, AudioParams.Default);
|
||||
RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid, successfullyInserted, successfullyInsertedPositions));
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Pick up the clicked entity
|
||||
else if (storageComp.QuickInsert)
|
||||
{
|
||||
if (eventArgs.Target is not {Valid: true} target)
|
||||
return;
|
||||
|
||||
if (_containerSystem.IsEntityInContainer(target)
|
||||
|| target == eventArgs.User
|
||||
|| !HasComp<SharedItemComponent>(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);
|
||||
if (PlayerInsertEntityInWorld(uid, eventArgs.User, target, storageComp))
|
||||
{
|
||||
RaiseNetworkEvent(new AnimateInsertingEntitiesEvent(uid,
|
||||
new List<EntityUid> { target },
|
||||
new List<EntityCoordinates> { position }));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemoveItemMessage(EntityUid uid, ServerStorageComponent storageComp, StorageRemoveItemMessage args)
|
||||
{
|
||||
if (args.Session.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
HandleRemoveEntity(uid, args.Session.AttachedEntity.Value, args.InteractedItemUID, storageComp);
|
||||
}
|
||||
|
||||
private void OnInsertItemMessage(EntityUid uid, ServerStorageComponent storageComp, StorageInsertItemMessage args)
|
||||
{
|
||||
if (args.Session.AttachedEntity == null)
|
||||
return;
|
||||
|
||||
PlayerInsertHeldEntity(uid, args.Session.AttachedEntity.Value, storageComp);
|
||||
}
|
||||
|
||||
private void OnBoundUIOpen(EntityUid uid, ServerStorageComponent storageComp, BoundUIOpenedEvent args)
|
||||
{
|
||||
if (!storageComp.IsOpen)
|
||||
{
|
||||
storageComp.IsOpen = true;
|
||||
UpdateStorageVisualization(uid, storageComp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBoundUIClosed(EntityUid uid, ServerStorageComponent storageComp, BoundUIClosedEvent args)
|
||||
{
|
||||
if (TryComp<ActorComponent>(args.Session.AttachedEntity, out var actor) && actor?.PlayerSession != null)
|
||||
CloseNestedInterfaces(uid, actor.PlayerSession, storageComp);
|
||||
|
||||
// If UI is closed for everyone
|
||||
if (!_uiSystem.IsUiOpen(uid, args.UiKey))
|
||||
{
|
||||
storageComp.IsOpen = false;
|
||||
UpdateStorageVisualization(uid, storageComp);
|
||||
|
||||
if (storageComp.StorageCloseSound is not null)
|
||||
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageCloseSound.GetSound(), uid, AudioParams.Default);
|
||||
}
|
||||
}
|
||||
|
||||
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(StorageVisuals.Open, storageComp.IsOpen);
|
||||
appearance.SetData(SharedBagOpenVisuals.BagState, storageComp.IsOpen ? SharedBagState.Open : SharedBagState.Closed);
|
||||
|
||||
if (HasComp<ItemCounterComponent>(uid))
|
||||
appearance.SetData(StackVisuals.Hide, !storageComp.IsOpen);
|
||||
}
|
||||
|
||||
private void RecalculateStorageUsed(ServerStorageComponent storageComp)
|
||||
{
|
||||
storageComp.StorageUsed = 0;
|
||||
storageComp.SizeCache.Clear();
|
||||
|
||||
if (storageComp.Storage == null)
|
||||
return;
|
||||
|
||||
var itemQuery = GetEntityQuery<SharedItemComponent>();
|
||||
|
||||
foreach (var entity in storageComp.Storage.ContainedEntities)
|
||||
{
|
||||
if (!itemQuery.TryGetComponent(entity, out var itemComp))
|
||||
continue;
|
||||
|
||||
storageComp.StorageUsed += itemComp.Size;
|
||||
storageComp.SizeCache.Add(entity, itemComp.Size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move entities from one storage to another.
|
||||
/// </summary>
|
||||
@@ -207,8 +440,10 @@ namespace Content.Server.Storage.EntitySystems
|
||||
|
||||
foreach (var entity in entities.ToList())
|
||||
{
|
||||
targetComp.Insert(entity);
|
||||
Insert(target, entity, targetComp);
|
||||
}
|
||||
RecalculateStorageUsed(sourceComp);
|
||||
UpdateStorageUI(source, sourceComp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -236,57 +471,207 @@ namespace Content.Server.Storage.EntitySystems
|
||||
_disposalSystem.AfterInsert(disposalComp, entity);
|
||||
}
|
||||
}
|
||||
RecalculateStorageUsed(sourceComp);
|
||||
UpdateStorageUI(source, sourceComp);
|
||||
}
|
||||
|
||||
private void HandleEntityRemovedFromContainer(EntRemovedFromContainerMessage message)
|
||||
public void HandleRemoveEntity(EntityUid uid, EntityUid player, EntityUid itemToRemove, ServerStorageComponent? storageComp = null)
|
||||
{
|
||||
var oldParentEntity = message.Container.Owner;
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return;
|
||||
|
||||
if (EntityManager.TryGetComponent(oldParentEntity, out ServerStorageComponent? storageComp))
|
||||
if (!_containerSystem.ContainsEntity(uid, itemToRemove))
|
||||
return;
|
||||
|
||||
// succeeded, remove entity and update UI
|
||||
_containerSystem.RemoveEntity(uid, itemToRemove, false);
|
||||
|
||||
if (storageComp.StorageRemoveSound is not null)
|
||||
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageRemoveSound.GetSound(), uid, AudioParams.Default);
|
||||
|
||||
_sharedHandsSystem.TryPickupAnyHand(player, itemToRemove);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if an entity can be stored and if it fits
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to check</param>
|
||||
/// <returns>true if it can be inserted, false otherwise</returns>
|
||||
public bool CanInsert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? storageComp = null)
|
||||
{
|
||||
storageComp.HandleEntityMaybeRemoved(message);
|
||||
}
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return false;
|
||||
|
||||
if (TryComp(insertEnt, out ServerStorageComponent? storage) &&
|
||||
storage.StorageCapacityMax >= storageComp.StorageCapacityMax)
|
||||
return false;
|
||||
|
||||
if (TryComp(insertEnt, out SharedItemComponent? itemComp) &&
|
||||
itemComp.Size > storageComp.StorageCapacityMax - storageComp.StorageUsed)
|
||||
return false;
|
||||
|
||||
if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false)
|
||||
return false;
|
||||
|
||||
if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true)
|
||||
return false;
|
||||
|
||||
if (TryComp(insertEnt, out TransformComponent? transformComp) && transformComp.Anchored)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void HandleEntityInsertedIntoContainer(EntInsertedIntoContainerMessage message)
|
||||
/// <summary>
|
||||
/// Inserts into the storage container
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to insert</param>
|
||||
/// <returns>true if the entity was inserted, false otherwise</returns>
|
||||
public bool Insert(EntityUid uid, EntityUid insertEnt, ServerStorageComponent? storageComp = null)
|
||||
{
|
||||
var oldParentEntity = message.Container.Owner;
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return false;
|
||||
|
||||
if (EntityManager.TryGetComponent(oldParentEntity, out ServerStorageComponent? storageComp))
|
||||
if (!CanInsert(uid, insertEnt, storageComp) || storageComp.Storage?.Insert(insertEnt) == false)
|
||||
return false;
|
||||
|
||||
if (storageComp.StorageInsertSound is not null)
|
||||
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageInsertSound.GetSound(), uid, AudioParams.Default);
|
||||
|
||||
RecalculateStorageUsed(storageComp);
|
||||
UpdateStorageUI(uid, storageComp);
|
||||
return true;
|
||||
}
|
||||
|
||||
// REMOVE: remove and drop on the ground
|
||||
public bool RemoveAndDrop(EntityUid uid, EntityUid removeEnt, ServerStorageComponent? storageComp = null)
|
||||
{
|
||||
storageComp.HandleEntityMaybeInserted(message);
|
||||
}
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return false;
|
||||
|
||||
var itemRemoved = storageComp.Storage?.Remove(removeEnt) == true;
|
||||
if (itemRemoved)
|
||||
RecalculateStorageUsed(storageComp);
|
||||
|
||||
return itemRemoved;
|
||||
}
|
||||
|
||||
private void CheckSubscribedEntities(ServerStorageComponent storageComp)
|
||||
/// <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)
|
||||
{
|
||||
var xform = Transform(storageComp.Owner);
|
||||
var storagePos = xform.WorldPosition;
|
||||
var storageMap = xform.MapID;
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return false;
|
||||
|
||||
var remove = new RemQueue<IPlayerSession>();
|
||||
if (!TryComp(player, out HandsComponent? hands) ||
|
||||
hands.ActiveHandEntity == null)
|
||||
return false;
|
||||
|
||||
foreach (var session in storageComp.SubscribedSessions)
|
||||
var toInsert = hands.ActiveHandEntity;
|
||||
|
||||
if (!_sharedHandsSystem.TryDrop(player, toInsert.Value, handsComp: hands))
|
||||
{
|
||||
// The component manages the set of sessions, so this invalid session should be removed soon.
|
||||
if (session.AttachedEntity is not {} attachedEntity || !EntityManager.EntityExists(attachedEntity))
|
||||
continue;
|
||||
Popup(uid, player, "comp-storage-cant-insert", storageComp);
|
||||
return false;
|
||||
}
|
||||
|
||||
var attachedXform = Transform(attachedEntity);
|
||||
if (storageMap != attachedXform.MapID)
|
||||
continue;
|
||||
return PlayerInsertEntityInWorld(uid, player, toInsert.Value, storageComp);
|
||||
}
|
||||
|
||||
var distanceSquared = (storagePos - attachedXform.WorldPosition).LengthSquared;
|
||||
if (distanceSquared > SharedInteractionSystem.InteractionRangeSquared)
|
||||
/// <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)
|
||||
{
|
||||
remove.Add(session);
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return false;
|
||||
|
||||
if (!_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>
|
||||
/// Opens the storage UI for an entity
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity to open the UI for</param>
|
||||
public void OpenStorageUI(EntityUid uid, EntityUid entity, ServerStorageComponent? storageComp = null)
|
||||
{
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return;
|
||||
|
||||
if (!TryComp(entity, out ActorComponent? player))
|
||||
return;
|
||||
|
||||
if (storageComp.StorageOpenSound is not null)
|
||||
SoundSystem.Play(Filter.Pvs(uid, entityManager: EntityManager), storageComp.StorageOpenSound.GetSound(), uid, AudioParams.Default);
|
||||
|
||||
Logger.DebugS(storageComp.LoggerName, $"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
|
||||
|
||||
_uiSystem.GetUiOrNull(uid, StorageUiKey.Key)?.Open(player.PlayerSession);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the user has nested-UIs open (e.g., PDA UI open when pda is in a backpack), close them.
|
||||
/// </summary>
|
||||
/// <param name="session"></param>
|
||||
public void CloseNestedInterfaces(EntityUid uid, IPlayerSession session, ServerStorageComponent? storageComp = null)
|
||||
{
|
||||
if (!Resolve(uid, ref storageComp))
|
||||
return;
|
||||
|
||||
if (storageComp.StoredEntities == null)
|
||||
return;
|
||||
|
||||
// for each containing thing
|
||||
// if it has a storage comp
|
||||
// ensure unsubscribe from session
|
||||
// if it has a ui component
|
||||
// close ui
|
||||
foreach (var entity in storageComp.StoredEntities)
|
||||
{
|
||||
if (TryComp(entity, out ServerStorageComponent? storedStorageComp))
|
||||
{
|
||||
DebugTools.Assert(storedStorageComp != storageComp, $"Storage component contains itself!? Entity: {uid}");
|
||||
}
|
||||
|
||||
if (TryComp(entity, out ServerUserInterfaceComponent? uiComponent))
|
||||
{
|
||||
foreach (var ui in uiComponent.Interfaces)
|
||||
{
|
||||
ui.Close(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var session in remove)
|
||||
private void UpdateStorageUI(EntityUid uid, ServerStorageComponent storageComp)
|
||||
{
|
||||
storageComp.UnsubscribeSession(session);
|
||||
}
|
||||
if (storageComp.Storage == null)
|
||||
return;
|
||||
|
||||
var state = new StorageBoundUserInterfaceState((List<EntityUid>) storageComp.Storage.ContainedEntities, storageComp.StorageUsed, storageComp.StorageCapacityMax);
|
||||
|
||||
_uiSystem.GetUiOrNull(uid, StorageUiKey.Key)?.SetState(state);
|
||||
}
|
||||
|
||||
private void Popup(EntityUid uid, EntityUid player, string message, ServerStorageComponent storageComp)
|
||||
{
|
||||
if (!storageComp.ShowPopup) return;
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString(message), player, Filter.Entities(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Placeable;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -16,6 +11,42 @@ namespace Content.Shared.Storage
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedStorageComponent : Component, IDraggable
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
public readonly List<EntityUid> StoredEntities;
|
||||
public readonly int StorageSizeUsed;
|
||||
public readonly int StorageCapacityMax;
|
||||
|
||||
public StorageBoundUserInterfaceState(List<EntityUid> storedEntities, int storageSizeUsed, int storageCapacityMax)
|
||||
{
|
||||
StoredEntities = storedEntities;
|
||||
StorageSizeUsed = storageSizeUsed;
|
||||
StorageCapacityMax = storageCapacityMax;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageInsertItemMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageRemoveItemMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly EntityUid InteractedItemUID;
|
||||
public StorageRemoveItemMessage(EntityUid interactedItemUID)
|
||||
{
|
||||
InteractedItemUID = interactedItemUID;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum StorageUiKey
|
||||
{
|
||||
Key,
|
||||
}
|
||||
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
public abstract IReadOnlyList<EntityUid>? StoredEntities { get; }
|
||||
|
||||
@@ -35,75 +66,24 @@ namespace Content.Shared.Storage
|
||||
bool IDraggable.Drop(DragDropEvent eventArgs)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User, eventArgs.Target))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var storedEntities = StoredEntities?.ToArray();
|
||||
|
||||
if (storedEntities == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// empty everything out
|
||||
foreach (var storedEntity in storedEntities)
|
||||
{
|
||||
if (Remove(storedEntity))
|
||||
{
|
||||
_entMan.GetComponent<TransformComponent>(storedEntity).WorldPosition = eventArgs.DropLocation.Position;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageComponentState : ComponentState
|
||||
{
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageComponentState(EntityUid[] storedEntities)
|
||||
{
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the client component about what entities this storage is holding
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StorageHeldItemsEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
public readonly int StorageSizeMax;
|
||||
public readonly int StorageSizeUsed;
|
||||
public readonly EntityUid[] StoredEntities;
|
||||
|
||||
public StorageHeldItemsEvent(EntityUid storage, int storageSizeMax, int storageSizeUsed, EntityUid[] storedEntities)
|
||||
{
|
||||
Storage = storage;
|
||||
StorageSizeMax = storageSizeMax;
|
||||
StorageSizeUsed = storageSizeUsed;
|
||||
StoredEntities = storedEntities;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for adding an entity to the storage entity.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InsertEntityEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public InsertEntityEvent(EntityUid storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for displaying an animation of entities flying into a storage entity
|
||||
/// </summary>
|
||||
@@ -122,51 +102,6 @@ namespace Content.Shared.Storage
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for removing a contained entity from the storage entity
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class RemoveEntityEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Storage;
|
||||
public EntityUid EntityUid;
|
||||
|
||||
public RemoveEntityEvent(EntityUid storage, EntityUid entityUid)
|
||||
{
|
||||
Storage = storage;
|
||||
EntityUid = entityUid;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for opening the storage UI
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class OpenStorageUIEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public OpenStorageUIEvent(EntityUid storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Network event for closing the storage UI.
|
||||
/// E.g when the player moves too far away from the container.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class CloseStorageUIEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Storage;
|
||||
|
||||
public CloseStorageUIEvent(EntityUid storage)
|
||||
{
|
||||
Storage = storage;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable]
|
||||
[Serializable]
|
||||
public enum StorageVisuals
|
||||
|
||||
@@ -5,8 +5,7 @@
|
||||
description: A cardboard box for storing things.
|
||||
components:
|
||||
- type: Sprite
|
||||
layers:
|
||||
- state: box
|
||||
state: box
|
||||
|
||||
- type: entity
|
||||
name: lightbulb box
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
sprite: Clothing/Back/Backpacks/backpack.rsi
|
||||
- type: Storage
|
||||
capacity: 100
|
||||
storageSoundCollection:
|
||||
collection: storageRustle
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
- type: entity
|
||||
parent: ClothingBackpack
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
- back
|
||||
- type: Storage
|
||||
capacity: 100
|
||||
storageSoundCollection:
|
||||
collection: storageRustle
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
- type: entity
|
||||
parent: ClothingBackpackDuffel
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
sprite: Clothing/Back/Satchels/satchel.rsi
|
||||
- type: Storage
|
||||
capacity: 100
|
||||
storageSoundCollection:
|
||||
collection: storageRustle
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
- type: entity
|
||||
parent: ClothingBackpackSatchel
|
||||
|
||||
@@ -62,6 +62,10 @@
|
||||
visuals:
|
||||
- type: MappedItemVisualizer
|
||||
sprite: Clothing/Belt/belt_overlay.rsi
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
- type: entity
|
||||
parent: ClothingBeltBase
|
||||
|
||||
@@ -9,6 +9,18 @@
|
||||
- type: Sprite
|
||||
state: icon
|
||||
|
||||
- type: entity
|
||||
abstract: true
|
||||
parent: ClothingOuterBase
|
||||
id: ClothingOuterStorageBase
|
||||
components:
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
- type: entity
|
||||
abstract: true
|
||||
parent: ClothingOuterBase
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatBomber
|
||||
name: bomber jacket
|
||||
description: A thick, well-worn WW2 leather bomber jacket.
|
||||
@@ -8,11 +8,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/bomber.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/bomber.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatDetective
|
||||
name: detective trenchcoat
|
||||
description: A rugged canvas trenchcoat, designed and created by TX Fabrication Corp. The coat is externally impact resistant - perfect for your next act of autodefenestration!
|
||||
@@ -21,8 +19,6 @@
|
||||
sprite: Clothing/OuterClothing/Coats/detective.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/detective.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
- type: Armor
|
||||
modifiers:
|
||||
coefficients:
|
||||
@@ -32,7 +28,7 @@
|
||||
Heat: 0.9
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatGentle
|
||||
name: gentle coat
|
||||
description: A gentle coat for a gentle man, or woman.
|
||||
@@ -41,11 +37,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/gentlecoat.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/gentlecoat.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatHoSTrench
|
||||
name: head of security's trenchcoat
|
||||
description: This trenchcoat was specifically designed for asserting superior authority.
|
||||
@@ -54,8 +48,6 @@
|
||||
sprite: Clothing/OuterClothing/Coats/hos_trenchcoat.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/hos_trenchcoat.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
- type: Armor
|
||||
modifiers:
|
||||
coefficients:
|
||||
@@ -65,7 +57,7 @@
|
||||
Heat: 0.7
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatInspector
|
||||
name: inspectors coat
|
||||
description: A strict inspector coat for being intimidating during inspections.
|
||||
@@ -74,11 +66,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/insp_coat.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/insp_coat.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatJensen
|
||||
name: jensen coat
|
||||
description: A jensen coat.
|
||||
@@ -87,11 +77,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/jensencoat.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/jensencoat.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatLab
|
||||
name: lab coat
|
||||
description: A suit that protects against minor chemical spills.
|
||||
@@ -100,11 +88,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/labcoat.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/labcoat.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatLabChem
|
||||
name: lab coat (chem)
|
||||
description: A suit that protects against minor chemical spills. Has an orange stripe on the shoulder.
|
||||
@@ -113,11 +99,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/labcoat_chem.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/labcoat_chem.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatLabCmo
|
||||
name: chief medical officer's lab coat
|
||||
description: Bluer than the standard model.
|
||||
@@ -126,11 +110,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/labcoat_cmo.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/labcoat_cmo.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatPirate
|
||||
name: pirate garb
|
||||
description: Yarr.
|
||||
@@ -139,11 +121,9 @@
|
||||
sprite: Clothing/OuterClothing/Coats/pirate.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/pirate.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
|
||||
- type: entity
|
||||
parent: ClothingOuterBase
|
||||
parent: ClothingOuterStorageBase
|
||||
id: ClothingOuterCoatWarden
|
||||
name: warden's armored jacket
|
||||
description: A sturdy, utilitarian jacket designed to protect a warden from any brig-bound threats.
|
||||
@@ -152,8 +132,6 @@
|
||||
sprite: Clothing/OuterClothing/Coats/warden.rsi
|
||||
- type: Clothing
|
||||
sprite: Clothing/OuterClothing/Coats/warden.rsi
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
- type: Armor
|
||||
modifiers:
|
||||
coefficients:
|
||||
|
||||
@@ -307,7 +307,7 @@
|
||||
|
||||
- type: entity
|
||||
id: DrinkCanPack
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
name: 6pack
|
||||
components:
|
||||
- type: Sprite
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# an alpha color which -Y- said he would implement.
|
||||
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BoxCardboard
|
||||
id: FoodBoxDonut
|
||||
name: donut box
|
||||
description: Mmm, Donuts.
|
||||
@@ -50,7 +50,7 @@
|
||||
# Egg
|
||||
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BoxCardboard
|
||||
id: FoodContainerEgg
|
||||
name: egg carton
|
||||
description: Don't drop 'em!
|
||||
@@ -66,6 +66,7 @@
|
||||
- Egg
|
||||
- type: Item
|
||||
sprite: Objects/Consumable/Food/egg.rsi
|
||||
state: box-closed
|
||||
size: 12
|
||||
- type: StorageFill
|
||||
contents:
|
||||
@@ -138,7 +139,7 @@
|
||||
# Since you could open pizza boxes in the stack.
|
||||
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BoxCardboard
|
||||
id: FoodBoxPizza
|
||||
name: pizza box
|
||||
components:
|
||||
@@ -219,7 +220,7 @@
|
||||
# Nugget
|
||||
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BoxCardboard
|
||||
id: FoodBoxNugget
|
||||
name: chicken nuggets
|
||||
description: You suddenly have an urge to trade on the intergalactic stock market.
|
||||
@@ -258,7 +259,7 @@
|
||||
# Donkpocket
|
||||
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BoxCardboard
|
||||
id: FoodBoxDonkpocket
|
||||
name: box of donk-pockets
|
||||
description: 'Instructions: Heat in microwave. Product will cool if not eaten within seven minutes.'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: entity
|
||||
id: CigPackBase
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
name: cigarette pack
|
||||
abstract: true
|
||||
components:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
name: pack of rolling paper
|
||||
id: PackPaperRolling
|
||||
description: A pack of thin pieces of paper used to make fine smokeables.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: entity
|
||||
id: CigarCase
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
name: cigar case
|
||||
description: A case for holding your cigars when you are not smoking them.
|
||||
components:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
id: DiceBag
|
||||
name: bag of dice
|
||||
description: Contains all the luck you'll ever need.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: entity
|
||||
id: BoxBase
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
abstract: true
|
||||
components:
|
||||
- type: Sprite
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- type: entity
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
abstract: true
|
||||
id: BriefcaseBase
|
||||
description: Useful for carrying items in your hands.
|
||||
@@ -8,8 +8,6 @@
|
||||
size: 60
|
||||
- type: Storage
|
||||
capacity: 60
|
||||
storageSoundCollection:
|
||||
collection: storageRustle
|
||||
|
||||
- type: entity
|
||||
name: brown briefcase
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- type: entity
|
||||
name: bible
|
||||
description: New Interstellar Version 2340
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
id: Bible
|
||||
components:
|
||||
- type: Bible
|
||||
@@ -31,8 +31,10 @@
|
||||
- Belt
|
||||
- type: Storage
|
||||
capacity: 10
|
||||
storageSoundCollection:
|
||||
collection: storageRustle
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
- type: entity
|
||||
parent: Bible
|
||||
|
||||
@@ -109,7 +109,7 @@
|
||||
- type: entity
|
||||
name: plant bag
|
||||
id: PlantBag
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
description: A bag for botanists to easily move their huge harvests.
|
||||
components:
|
||||
- type: Sprite
|
||||
|
||||
@@ -205,6 +205,10 @@
|
||||
maxFillLevels: 3
|
||||
fillBaseName: cart_water_
|
||||
changeColor: false
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
|
||||
- type: entity
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- type: entity
|
||||
name: trash bag
|
||||
id: TrashBag
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
components:
|
||||
- type: Sprite
|
||||
netSync: false
|
||||
@@ -16,7 +16,9 @@
|
||||
capacity: 125
|
||||
quickInsert: true
|
||||
areaInsert: true
|
||||
storageSoundCollection:
|
||||
storageOpenSound:
|
||||
collection: trashBagRustle
|
||||
storageInsertSound:
|
||||
collection: trashBagRustle
|
||||
whitelist:
|
||||
tags:
|
||||
@@ -55,5 +57,3 @@
|
||||
quickInsert: true
|
||||
areaInsert: true
|
||||
areaInsertRadius: 1000
|
||||
storageSoundCollection:
|
||||
collection: trashBagRustle
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- type: entity
|
||||
name: first aid kit
|
||||
description: It's an emergency medical kit for those serious boo-boos.
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
id: Medkit
|
||||
components:
|
||||
- type: Sprite
|
||||
|
||||
@@ -279,7 +279,7 @@
|
||||
- type: entity
|
||||
name: pill canister
|
||||
id: PillCanister
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
description: Holds up to 12 pills.
|
||||
components:
|
||||
- type: Sprite
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: entity
|
||||
id: SmallboxItem
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
abstract: true
|
||||
components:
|
||||
- type: Storage
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: entity
|
||||
id: ToolboxBase
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
abstract: true
|
||||
components:
|
||||
- type: Sprite
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- type: entity
|
||||
name: improvised pneumatic cannon
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
id: ImprovisedPneumaticCannon
|
||||
description: Improvised using nothing but a pipe, some zipties, and a pneumatic cannon.
|
||||
components:
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
- type: entity
|
||||
name: pie cannon
|
||||
parent: BaseItem
|
||||
parent: BaseStorageItem
|
||||
id: LauncherCreamPie
|
||||
description: Load cream pie for optimal results.
|
||||
components:
|
||||
@@ -43,7 +43,9 @@
|
||||
components:
|
||||
- CreamPie
|
||||
clickInsert: false
|
||||
storageSoundCollection:
|
||||
storageOpenSound:
|
||||
collection: BikeHorn
|
||||
storageInsertSound:
|
||||
collection: BikeHorn
|
||||
capacity: 40
|
||||
- type: PneumaticCannon
|
||||
|
||||
@@ -35,3 +35,15 @@
|
||||
drawdepth: Items
|
||||
noRot: false
|
||||
- type: Pullable
|
||||
|
||||
- type: entity
|
||||
name: "storage item"
|
||||
id: BaseStorageItem
|
||||
parent: BaseItem
|
||||
abstract: true
|
||||
components:
|
||||
- type: Storage
|
||||
- type: UserInterface
|
||||
interfaces:
|
||||
- key: enum.StorageUiKey.Key
|
||||
type: StorageBoundUserInterface
|
||||
|
||||
Reference in New Issue
Block a user