diff --git a/Content.Client/Storage/ClientStorageComponent.cs b/Content.Client/Storage/ClientStorageComponent.cs index 4625056e28..e5eab84e3e 100644 --- a/Content.Client/Storage/ClientStorageComponent.cs +++ b/Content.Client/Storage/ClientStorageComponent.cs @@ -14,13 +14,7 @@ using Robust.Client.Player; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; -using Robust.Shared.GameObjects; using Robust.Shared.Input; -using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Maths; -using Robust.Shared.Network; -using Robust.Shared.Players; using static Robust.Client.UserInterface.Control; using static Robust.Client.UserInterface.Controls.BaseButton; using static Robust.Client.UserInterface.Controls.BoxContainer; @@ -86,35 +80,11 @@ namespace Content.Client.Storage _storedEntities = state.StoredEntities.ToList(); } - [Obsolete("Component Messages are deprecated, use Entity Events instead.")] - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) - { - base.HandleNetworkMessage(message, channel, session); - - switch (message) - { - //Updates what we are storing for the UI - case StorageHeldItemsMessage msg: - HandleStorageMessage(msg); - break; - //Opens the UI - case OpenStorageUIMessage _: - ToggleUI(); - break; - case CloseStorageUIMessage _: - CloseUI(); - break; - case AnimateInsertingEntitiesMessage msg: - HandleAnimatingInsertingEntities(msg); - break; - } - } - /// /// Copies received values from server about contents of storage container /// /// - private void HandleStorageMessage(StorageHeldItemsMessage storageState) + public void HandleStorageMessage(StorageHeldItemsEvent storageState) { _storedEntities = storageState.StoredEntities.ToList(); StorageSizeUsed = storageState.StorageSizeUsed; @@ -126,7 +96,7 @@ namespace Content.Client.Storage /// Animate the newly stored entities in flying towards this storage's position /// /// - private void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesMessage msg) + public void HandleAnimatingInsertingEntities(AnimateInsertingEntitiesEvent msg) { for (var i = 0; msg.StoredEntities.Count > i; i++) { @@ -143,7 +113,7 @@ namespace Content.Client.Storage /// /// Opens the storage UI if closed. Closes it if opened. /// - private void ToggleUI() + public void ToggleUI() { var window = GetOrCreateWindow(); @@ -153,7 +123,7 @@ namespace Content.Client.Storage window.OpenCentered(); } - private void CloseUI() + public void CloseUI() { _window?.Close(); } @@ -162,13 +132,11 @@ namespace Content.Client.Storage /// Function for clicking one of the stored entity buttons in the UI, tells server to remove that entity /// /// - private void Interact(ButtonEventArgs args, EntityUid entity) + public void Interact(ButtonEventArgs args, EntityUid entity) { if (args.Event.Function == EngineKeyFunctions.UIClick) { -#pragma warning disable 618 - SendNetworkMessage(new RemoveEntityMessage(entity)); -#pragma warning restore 618 + _entityManager.EntityNetManager?.SendSystemNetworkMessage(new RemoveEntityEvent(Owner, entity)); args.Event.Handle(); } else if (_entityManager.EntityExists(entity)) @@ -191,7 +159,7 @@ namespace Content.Client.Storage /// /// Button created for each entity that represents that item in the storage UI, with a texture, and name and size label /// - private void GenerateButton(EntityUid entity, EntityContainerButton button) + public void GenerateButton(EntityUid entity, EntityContainerButton button) { if (!_entityManager.EntityExists(entity)) return; @@ -269,9 +237,7 @@ namespace Content.Client.Storage if (entities.HasComponent(controlledEntity)) { -#pragma warning disable 618 - StorageEntity.SendNetworkMessage(new InsertEntityMessage()); -#pragma warning restore 618 + entities.EntityNetManager?.SendSystemNetworkMessage(new InsertEntityEvent(storageEntity.Owner)); } }; @@ -306,9 +272,7 @@ namespace Content.Client.Storage public override void Close() { -#pragma warning disable 618 - StorageEntity.SendNetworkMessage(new CloseStorageUIMessage()); -#pragma warning restore 618 + IoCManager.Resolve().EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(StorageEntity.Owner)); base.Close(); } diff --git a/Content.Client/Storage/StorageSystem.cs b/Content.Client/Storage/StorageSystem.cs new file mode 100644 index 0000000000..75ce2fa8c3 --- /dev/null +++ b/Content.Client/Storage/StorageSystem.cs @@ -0,0 +1,49 @@ +using Content.Shared.Storage; + +namespace Content.Client.Storage; + +// TODO kill this is all horrid. +public sealed class StorageSystem : EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + + SubscribeNetworkEvent(OnStorageHeldItems); + SubscribeNetworkEvent(OnOpenStorageUI); + SubscribeNetworkEvent(OnCloseStorageUI); + SubscribeNetworkEvent(OnAnimateInsertingEntities); + } + + private void OnStorageHeldItems(StorageHeldItemsEvent ev) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.HandleStorageMessage(ev); + } + } + + private void OnOpenStorageUI(OpenStorageUIEvent ev) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.ToggleUI(); + } + } + + private void OnCloseStorageUI(CloseStorageUIEvent ev) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.CloseUI(); + } + } + + private void OnAnimateInsertingEntities(AnimateInsertingEntitiesEvent ev) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.HandleAnimatingInsertingEntities(ev); + } + } +} diff --git a/Content.Server/Storage/Components/ServerStorageComponent.cs b/Content.Server/Storage/Components/ServerStorageComponent.cs index 58dbd27db9..971f9b11af 100644 --- a/Content.Server/Storage/Components/ServerStorageComponent.cs +++ b/Content.Server/Storage/Components/ServerStorageComponent.cs @@ -302,9 +302,7 @@ namespace Content.Server.Storage.Components Logger.DebugS(LoggerName, $"Storage (UID {Owner}) \"used\" by player session (UID {userSession.AttachedEntity})."); SubscribeSession(userSession); -#pragma warning disable 618 - SendNetworkMessage(new OpenStorageUIMessage(), userSession.ConnectedClient); -#pragma warning restore 618 + _entityManager.EntityNetManager?.SendSystemNetworkMessage(new OpenStorageUIEvent(Owner), userSession.ConnectedClient); UpdateClientInventory(userSession); } @@ -349,9 +347,7 @@ namespace Content.Server.Storage.Components var stored = StoredEntities.Select(e => e).ToArray(); -#pragma warning disable 618 - SendNetworkMessage(new StorageHeldItemsMessage(stored, StorageUsed, StorageCapacityMax), session.ConnectedClient); -#pragma warning restore 618 + _entityManager.EntityNetManager?.SendSystemNetworkMessage(new StorageHeldItemsEvent(Owner, StorageCapacityMax,StorageUsed, stored), session.ConnectedClient); } /// @@ -385,9 +381,8 @@ namespace Content.Server.Storage.Components Logger.DebugS(LoggerName, $"Storage (UID {Owner}) unsubscribed player session (UID {session.AttachedEntity})."); SubscribedSessions.Remove(session); -#pragma warning disable 618 - SendNetworkMessage(new CloseStorageUIMessage(), session.ConnectedClient); -#pragma warning restore 618 + _entityManager.EntityNetManager?.SendSystemNetworkMessage(new CloseStorageUIEvent(Owner), + session.ConnectedClient); } CloseNestedInterfaces(session); @@ -444,73 +439,57 @@ namespace Content.Server.Storage.Components EnsureInitialCalculated(); } - [Obsolete("Component Messages are deprecated, use Entity Events instead.")] - public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null) + public void HandleRemoveEntity(RemoveEntityEvent remove, ICommonSession session) { - base.HandleNetworkMessage(message, channel, session); + EnsureInitialCalculated(); - if (session == null) + if (session.AttachedEntity is not {Valid: true} player) { - throw new ArgumentException(nameof(session)); + return; } - switch (message) + var ownerTransform = _entityManager.GetComponent(Owner); + var playerTransform = _entityManager.GetComponent(player); + + if (!playerTransform.Coordinates.InRange(_entityManager, ownerTransform.Coordinates, 2) || + Owner.IsInContainer() && !playerTransform.ContainsEntity(ownerTransform)) { - case RemoveEntityMessage remove: - { - EnsureInitialCalculated(); - - if (session.AttachedEntity is not {Valid: true} player) - { - break; - } - - var ownerTransform = _entityManager.GetComponent(Owner); - var playerTransform = _entityManager.GetComponent(player); - - if (!playerTransform.Coordinates.InRange(_entityManager, ownerTransform.Coordinates, 2) || - Owner.IsInContainer() && !playerTransform.ContainsEntity(ownerTransform)) - { - break; - } - - if (!remove.EntityUid.Valid || Storage?.Contains(remove.EntityUid) == false) - { - break; - } - - _sysMan.GetEntitySystem().TryPickupAnyHand(player, remove.EntityUid); - break; - } - case InsertEntityMessage _: - { - EnsureInitialCalculated(); - - if (session.AttachedEntity is not {Valid: true} player) - { - break; - } - - if (!EntitySystem.Get().InRangeUnobstructed(player, Owner, popup: true)) - { - break; - } - - PlayerInsertHeldEntity(player); - - break; - } - case CloseStorageUIMessage _: - { - if (session is not IPlayerSession playerSession) - { - break; - } - - UnsubscribeSession(playerSession); - break; - } + return; } + + if (!remove.EntityUid.Valid || Storage?.Contains(remove.EntityUid) == false) + { + return; + } + + _sysMan.GetEntitySystem().TryPickupAnyHand(player, remove.EntityUid); + } + + public void HandleInsertEntity(ICommonSession session) + { + EnsureInitialCalculated(); + + if (session.AttachedEntity is not {Valid: true} player) + { + return; + } + + if (!EntitySystem.Get().InRangeUnobstructed(player, Owner, popup: true)) + { + return; + } + + PlayerInsertHeldEntity(player); + } + + public void HandleCloseUI(ICommonSession session) + { + if (session is not IPlayerSession playerSession) + { + return; + } + + UnsubscribeSession(playerSession); } /// @@ -604,14 +583,8 @@ namespace Content.Server.Storage.Components if (successfullyInserted.Count > 0) { PlaySoundCollection(); -#pragma warning disable 618 - SendNetworkMessage( -#pragma warning restore 618 - new AnimateInsertingEntitiesMessage( - successfullyInserted, - successfullyInsertedPositions - ) - ); + _entityManager.EntityNetManager?.SendSystemNetworkMessage( + new AnimateInsertingEntitiesEvent(Owner, successfullyInserted, successfullyInsertedPositions)); } return true; } @@ -632,12 +605,9 @@ namespace Content.Server.Storage.Components _entityManager.GetComponent(target).MapPosition); if (PlayerInsertEntityInWorld(eventArgs.User, target)) { -#pragma warning disable 618 - SendNetworkMessage(new AnimateInsertingEntitiesMessage( -#pragma warning restore 618 - new List {target}, - new List {position} - )); + _entityManager.EntityNetManager?.SendSystemNetworkMessage(new AnimateInsertingEntitiesEvent(Owner, + new List { target }, + new List { position })); return true; } return true; diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 270a6e83dc..44602bbae0 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Linq; using Content.Server.Disposal.Unit.Components; using Content.Server.Disposal.Unit.EntitySystems; @@ -6,6 +5,7 @@ using Content.Server.Hands.Components; using Content.Server.Storage.Components; using Content.Shared.Interaction; using Content.Shared.Movement; +using Content.Shared.Storage; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -40,6 +40,34 @@ namespace Content.Server.Storage.EntitySystems SubscribeLocalEvent>(AddTransferVerbs); SubscribeLocalEvent(OnStorageFillMapInit); + + SubscribeNetworkEvent(OnRemoveEntity); + SubscribeNetworkEvent(OnInsertEntity); + SubscribeNetworkEvent(OnCloseStorageUI); + } + + private void OnRemoveEntity(RemoveEntityEvent ev, EntitySessionEventArgs args) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.HandleRemoveEntity(ev, args.SenderSession); + } + } + + private void OnInsertEntity(InsertEntityEvent ev, EntitySessionEventArgs args) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.HandleInsertEntity(args.SenderSession); + } + } + + private void OnCloseStorageUI(CloseStorageUIEvent ev, EntitySessionEventArgs args) + { + if (TryComp(ev.Storage, out var storage)) + { + storage.HandleCloseUI(args.SenderSession); + } } private void OnRelayMovement(EntityUid uid, EntityStorageComponent component, RelayMovementEntityEvent args) diff --git a/Content.Shared/Storage/SharedStorageComponent.cs b/Content.Shared/Storage/SharedStorageComponent.cs index dbc6f93fc3..24a3ff9197 100644 --- a/Content.Shared/Storage/SharedStorageComponent.cs +++ b/Content.Shared/Storage/SharedStorageComponent.cs @@ -74,98 +74,96 @@ namespace Content.Shared.Storage /// Updates the client component about what entities this storage is holding /// [Serializable, NetSerializable] -#pragma warning disable 618 - public sealed class StorageHeldItemsMessage : ComponentMessage -#pragma warning restore 618 + public sealed class StorageHeldItemsEvent : EntityEventArgs { + public readonly EntityUid Storage; public readonly int StorageSizeMax; public readonly int StorageSizeUsed; public readonly EntityUid[] StoredEntities; - public StorageHeldItemsMessage(EntityUid[] storedEntities, int storageUsed, int storageMaxSize) + public StorageHeldItemsEvent(EntityUid storage, int storageSizeMax, int storageSizeUsed, EntityUid[] storedEntities) { - Directed = true; - StorageSizeMax = storageMaxSize; - StorageSizeUsed = storageUsed; + Storage = storage; + StorageSizeMax = storageSizeMax; + StorageSizeUsed = storageSizeUsed; StoredEntities = storedEntities; } } /// - /// Component message for adding an entity to the storage entity. + /// Network event for adding an entity to the storage entity. /// [Serializable, NetSerializable] -#pragma warning disable 618 - public sealed class InsertEntityMessage : ComponentMessage -#pragma warning restore 618 + public sealed class InsertEntityEvent : EntityEventArgs { - public InsertEntityMessage() + public readonly EntityUid Storage; + + public InsertEntityEvent(EntityUid storage) { - Directed = true; + Storage = storage; } } /// - /// Component message for displaying an animation of entities flying into a storage entity + /// Network event for displaying an animation of entities flying into a storage entity /// [Serializable, NetSerializable] -#pragma warning disable 618 - public sealed class AnimateInsertingEntitiesMessage : ComponentMessage -#pragma warning restore 618 + public sealed class AnimateInsertingEntitiesEvent : EntityEventArgs { + public readonly EntityUid Storage; public readonly List StoredEntities; public readonly List EntityPositions; - public AnimateInsertingEntitiesMessage(List storedEntities, List entityPositions) + + public AnimateInsertingEntitiesEvent(EntityUid storage, List storedEntities, List entityPositions) { - Directed = true; + Storage = storage; StoredEntities = storedEntities; EntityPositions = entityPositions; } } /// - /// Component message for removing a contained entity from the storage entity + /// Network event for removing a contained entity from the storage entity /// [Serializable, NetSerializable] -#pragma warning disable 618 - public sealed class RemoveEntityMessage : ComponentMessage -#pragma warning restore 618 + public sealed class RemoveEntityEvent : EntityEventArgs { + public EntityUid Storage; public EntityUid EntityUid; - public RemoveEntityMessage(EntityUid entityuid) + public RemoveEntityEvent(EntityUid storage, EntityUid entityUid) { - Directed = true; - EntityUid = entityuid; + Storage = storage; + EntityUid = entityUid; } } /// - /// Component message for opening the storage UI + /// Network event for opening the storage UI /// [Serializable, NetSerializable] -#pragma warning disable 618 - public sealed class OpenStorageUIMessage : ComponentMessage -#pragma warning restore 618 + public sealed class OpenStorageUIEvent : EntityEventArgs { - public OpenStorageUIMessage() + public readonly EntityUid Storage; + + public OpenStorageUIEvent(EntityUid storage) { - Directed = true; + Storage = storage; } } /// - /// Component message for closing the storage UI. + /// Network event for closing the storage UI. /// E.g when the player moves too far away from the container. /// [Serializable, NetSerializable] -#pragma warning disable 618 - public sealed class CloseStorageUIMessage : ComponentMessage -#pragma warning restore 618 + public sealed class CloseStorageUIEvent : EntityEventArgs { - public CloseStorageUIMessage() + public readonly EntityUid Storage; + + public CloseStorageUIEvent(EntityUid storage) { - Directed = true; + Storage = storage; } }