Remove manual container ejection checking code.

This fixes map load when something is in a storage component.
This commit is contained in:
Pieter-Jan Briers
2019-05-05 13:09:21 +02:00
parent 23d8b92f94
commit b7d30f0870
5 changed files with 82 additions and 71 deletions

View File

@@ -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
/// <inheritdoc />
public override void SubscribeEvents()
{
SubscribeEvent<EntParentChangedMessage>(HandleParented);
SubscribeEvent<EntRemovedFromContainerMessage>(HandleContainerModified);
SubscribeEvent<EntInsertedIntoContainerMessage>(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<T>(IPlayerSession session, out T component)

View File

@@ -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<EntParentChangedMessage>(HandleParentChanged);
SubscribeEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
SubscribeEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
}
/// <inheritdoc />
@@ -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);
}
}