Break pulling on container insertion (#3602)

* Break pulling on container insertion

* Paul's review

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-03-13 14:24:06 +11:00
committed by GitHub
parent 8b225ec68f
commit fcf4b403d6

View File

@@ -1,14 +1,16 @@
#nullable enable
#nullable enable
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Pulling;
using Content.Shared.Input;
using Content.Shared.Physics.Pull;
using JetBrains.Annotations;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics.Joints;
using Robust.Shared.Players;
namespace Content.Shared.GameObjects.EntitySystems
@@ -29,6 +31,7 @@ namespace Content.Shared.GameObjects.EntitySystems
SubscribeLocalEvent<PullStartedMessage>(OnPullStarted);
SubscribeLocalEvent<PullStoppedMessage>(OnPullStopped);
SubscribeLocalEvent<MoveEvent>(PullerMoved);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleContainerInsert);
CommandBinds.Builder
.Bind(ContentKeyFunctions.MovePulledObject, new PointerInputCmdHandler(HandleMovePulledObject))
@@ -67,6 +70,27 @@ namespace Content.Shared.GameObjects.EntitySystems
physics.WakeBody();
}
// TODO: When Joint networking is less shitcodey fix this to use a dedicated joints message.
private void HandleContainerInsert(EntInsertedIntoContainerMessage message)
{
if (message.Entity.TryGetComponent(out SharedPullableComponent? pullable))
{
pullable.TryStopPull();
}
if (message.Entity.TryGetComponent(out SharedPullerComponent? puller))
{
if (puller.Pulling == null) return;
if (!puller.Pulling.TryGetComponent(out SharedPullableComponent? pulling))
{
return;
}
pulling.TryStopPull();
}
}
private bool HandleMovePulledObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
var player = session?.AttachedEntity;