diff --git a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs
index 798f2da5a5..3822f1d39a 100644
--- a/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs
+++ b/Content.Server/GameObjects/Components/GUI/ServerHandsComponent.cs
@@ -7,6 +7,7 @@ using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
+using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
@@ -91,22 +92,6 @@ namespace Content.Server.GameObjects
return false;
}
- ///
- public void RemoveHandEntity(IEntity entity)
- {
- if (entity == null)
- return;
-
- foreach (var slot in hands.Values)
- {
- if (slot.ContainedEntity == entity)
- {
- slot.Remove(entity);
- }
- }
- Dirty();
- }
-
public ItemComponent GetHand(string index)
{
var slot = hands[index];
@@ -504,5 +489,26 @@ namespace Content.Server.GameObjects
}
}
}
+
+ public void HandleSlotModifiedMaybe(ContainerModifiedMessage message)
+ {
+ foreach (var container in hands.Values)
+ {
+ if (container != message.Container)
+ {
+ continue;
+ }
+
+ Dirty();
+ if (!message.Entity.TryGetComponent(out PhysicsComponent physics))
+ {
+ return;
+ }
+
+ // set velocity to zero
+ physics.LinearVelocity = Vector2.Zero;
+ return;
+ }
+ }
}
}
diff --git a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs
index 35180c683f..1f6e50afa5 100644
--- a/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs
+++ b/Content.Server/GameObjects/Components/Items/Storage/ServerStorageComponent.cs
@@ -18,6 +18,7 @@ using Robust.Shared.GameObjects.EntitySystemMessages;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.ViewVariables;
using Content.Server.GameObjects.Components;
+using Robust.Server.GameObjects.EntitySystemMessages;
namespace Content.Server.GameObjects
{
@@ -82,14 +83,21 @@ namespace Content.Server.GameObjects
public bool Remove(IEntity toremove)
{
_ensureInitialCalculated();
- if (storage.Remove(toremove))
+ return storage.Remove(toremove);
+ }
+
+ internal void HandleEntityMaybeRemoved(EntRemovedFromContainerMessage message)
+ {
+ if (message.Container != storage)
{
- Logger.InfoS("Storage", "Storage (UID {0}) had entity (UID {1}) removed from it.", Owner.Uid, toremove.Uid);
- StorageUsed -= toremove.GetComponent().ObjectSize;
- UpdateClientInventories();
- return true;
+ return;
}
- return false;
+
+ _ensureInitialCalculated();
+ Logger.DebugS("Storage", "Storage (UID {0}) had entity (UID {1}) removed from it.", Owner.Uid,
+ message.Entity.Uid);
+ StorageUsed -= message.Entity.GetComponent().ObjectSize;
+ UpdateClientInventories();
}
///
@@ -99,14 +107,21 @@ namespace Content.Server.GameObjects
///
public bool Insert(IEntity toinsert)
{
- if (CanInsert(toinsert) && storage.Insert(toinsert))
+ return CanInsert(toinsert) && storage.Insert(toinsert);
+ }
+
+ internal void HandleEntityMaybeInserted(EntInsertedIntoContainerMessage message)
+ {
+ if (message.Container != storage)
{
- Logger.InfoS("Storage", "Storage (UID {0}) had entity (UID {1}) inserted into it.", Owner.Uid, toinsert.Uid);
- StorageUsed += toinsert.GetComponent().ObjectSize;
- UpdateClientInventories();
- return true;
+ return;
}
- return false;
+
+ _ensureInitialCalculated();
+ Logger.DebugS("Storage", "Storage (UID {0}) had entity (UID {1}) inserted into it.", Owner.Uid,
+ message.Entity.Uid);
+ StorageUsed += message.Entity.GetComponent().ObjectSize;
+ UpdateClientInventories();
}
///
@@ -328,6 +343,11 @@ namespace Content.Server.GameObjects
StorageUsed = 0;
+ if (storage == null)
+ {
+ return;
+ }
+
foreach (var entity in storage.ContainedEntities)
{
var item = entity.GetComponent();
diff --git a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs
index a2dd32a0e9..60f4476322 100644
--- a/Content.Server/GameObjects/EntitySystems/HandsSystem.cs
+++ b/Content.Server/GameObjects/EntitySystems/HandsSystem.cs
@@ -4,14 +4,14 @@ using Content.Server.GameObjects.Components.Stack;
using Content.Server.Interfaces.GameObjects;
using Content.Shared.Input;
using Content.Shared.Physics;
+using JetBrains.Annotations;
using Robust.Server.GameObjects;
+using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
-using Robust.Shared.GameObjects.EntitySystemMessages;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Input;
-using Robust.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
@@ -21,7 +21,8 @@ using Robust.Shared.Players;
namespace Content.Server.GameObjects.EntitySystems
{
- internal class HandsSystem : EntitySystem
+ [UsedImplicitly]
+ internal sealed class HandsSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager;
@@ -58,31 +59,16 @@ namespace Content.Server.GameObjects.EntitySystems
///
public override void SubscribeEvents()
{
- SubscribeEvent(HandleParented);
+ SubscribeEvent(HandleContainerModified);
+ SubscribeEvent(HandleContainerModified);
}
- private static void HandleParented(object sender, EntitySystemMessage args)
+ private static void HandleContainerModified(object sender, ContainerModifiedMessage args)
{
- var msg = (EntParentChangedMessage) args;
-
- // entity is no longer a child of OldParent, therefore it cannot be in the hand of the parent
- if (msg.OldParent != null && msg.OldParent.IsValid() && msg.OldParent.Transform != msg.Entity.Transform.Parent && msg.OldParent.TryGetComponent(out IHandsComponent handsComp))
+ if (args.Container.Owner.TryGetComponent(out IHandsComponent handsComponent))
{
- handsComp.RemoveHandEntity(msg.Entity);
+ handsComponent.HandleSlotModifiedMaybe(args);
}
-
- if (msg.Entity.Deleted)
- return;
-
- // if item is in a container
- if (msg.Entity.Transform.IsMapTransform)
- return;
-
- if (!msg.Entity.TryGetComponent(out PhysicsComponent physics))
- return;
-
- // set velocity to zero
- physics.LinearVelocity = Vector2.Zero;
}
private static bool TryGetAttachedComponent(IPlayerSession session, out T component)
diff --git a/Content.Server/GameObjects/EntitySystems/StorageSystem.cs b/Content.Server/GameObjects/EntitySystems/StorageSystem.cs
index 8db8cb6bd3..1cbc59cd6c 100644
--- a/Content.Server/GameObjects/EntitySystems/StorageSystem.cs
+++ b/Content.Server/GameObjects/EntitySystems/StorageSystem.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
+using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
-using Robust.Shared.GameObjects.EntitySystemMessages;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -22,7 +22,8 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.SubscribeEvents();
- SubscribeEvent(HandleParentChanged);
+ SubscribeEvent(HandleEntityRemovedFromContainer);
+ SubscribeEvent(HandleEntityInsertedIntoContainer);
}
///
@@ -34,22 +35,23 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
- private static void HandleParentChanged(object sender, EntitySystemMessage message)
+ private static void HandleEntityRemovedFromContainer(object sender, EntRemovedFromContainerMessage message)
{
- if(!(sender is IEntity childEntity))
- return;
-
- if(!(message is EntParentChangedMessage msg))
- return;
-
- var oldParentEntity = msg.OldParent;
-
- if(oldParentEntity == null || !oldParentEntity.IsValid())
- return;
+ var oldParentEntity = message.Container.Owner;
if (oldParentEntity.TryGetComponent(out ServerStorageComponent storageComp))
{
- storageComp.Remove(childEntity);
+ storageComp.HandleEntityMaybeRemoved(message);
+ }
+ }
+
+ private static void HandleEntityInsertedIntoContainer(object sender, EntInsertedIntoContainerMessage message)
+ {
+ var oldParentEntity = message.Container.Owner;
+
+ if (oldParentEntity.TryGetComponent(out ServerStorageComponent storageComp))
+ {
+ storageComp.HandleEntityMaybeInserted(message);
}
}
diff --git a/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs b/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs
index 66a2b6d81d..df102d2cdc 100644
--- a/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs
+++ b/Content.Server/Interfaces/GameObjects/Components/Items/IHandsComponent.cs
@@ -3,6 +3,7 @@ using Content.Server.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using System.Collections.Generic;
using Robust.Server.GameObjects.Components.Container;
+using Robust.Server.GameObjects.EntitySystemMessages;
using Robust.Shared.Map;
namespace Content.Server.Interfaces.GameObjects
@@ -26,12 +27,6 @@ namespace Content.Server.Interfaces.GameObjects
/// The item in the held, null if no item is held
ItemComponent GetHand(string index);
- ///
- /// If any hands are holding this entity, immediately remove the entity without dropping it.
- ///
- /// Entity to be removed.
- void RemoveHandEntity(IEntity entity);
-
///
/// Gets item held by the current active hand
///
@@ -195,5 +190,7 @@ namespace Content.Server.Interfaces.GameObjects
/// The hand name to check.
/// True if the hand exists, false otherwise.
bool HasHand(string index);
+
+ void HandleSlotModifiedMaybe(ContainerModifiedMessage message);
}
}