Fix pulling not stopping when going into a container (#1712)
This commit is contained in:
@@ -13,7 +13,7 @@ using Content.Shared.GameObjects.Components.Items;
|
|||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
using Content.Shared.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Health.BodySystem;
|
using Content.Shared.Health.BodySystem;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics.Pull;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.Components.Container;
|
using Robust.Server.GameObjects.Components.Container;
|
||||||
using Robust.Server.GameObjects.EntitySystemMessages;
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||||
@@ -547,16 +547,10 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isOwnerContained = ContainerHelpers.TryGetContainer(Owner, out var ownerContainer);
|
if (!Owner.IsInSameOrNoContainer(pullable.Owner))
|
||||||
var isPullableContained = ContainerHelpers.TryGetContainer(pullable.Owner, out var pullableContainer);
|
|
||||||
|
|
||||||
if (isOwnerContained || isPullableContained)
|
|
||||||
{
|
|
||||||
if (ownerContainer != pullableContainer)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (IsPulling)
|
if (IsPulling)
|
||||||
{
|
{
|
||||||
@@ -564,10 +558,8 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
PulledObject = pullable.Owner.GetComponent<ICollidableComponent>();
|
PulledObject = pullable.Owner.GetComponent<ICollidableComponent>();
|
||||||
var controller = PulledObject!.EnsureController<PullController>();
|
var controller = PulledObject.EnsureController<PullController>();
|
||||||
controller!.StartPull(Owner.GetComponent<ICollidableComponent>());
|
controller.StartPull(Owner.GetComponent<ICollidableComponent>());
|
||||||
|
|
||||||
AddPullingStatuses();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MovePulledObject(GridCoordinates puller, GridCoordinates to)
|
public void MovePulledObject(GridCoordinates puller, GridCoordinates to)
|
||||||
@@ -579,6 +571,27 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||||
|
{
|
||||||
|
base.HandleMessage(message, component);
|
||||||
|
|
||||||
|
if (!(message is PullMessage pullMessage) ||
|
||||||
|
pullMessage.Puller.Owner != Owner)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case PullStartedMessage msg:
|
||||||
|
AddPullingStatuses(msg.Pulled.Owner);
|
||||||
|
break;
|
||||||
|
case PullStoppedMessage msg:
|
||||||
|
RemovePullingStatuses(msg.Pulled.Owner);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
|
||||||
{
|
{
|
||||||
base.HandleNetworkMessage(message, channel, session);
|
base.HandleNetworkMessage(message, channel, session);
|
||||||
@@ -689,10 +702,9 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddPullingStatuses()
|
private void AddPullingStatuses(IEntity pulled)
|
||||||
{
|
{
|
||||||
if (PulledObject?.Owner != null &&
|
if (pulled.TryGetComponent(out ServerStatusEffectsComponent pulledStatus))
|
||||||
PulledObject.Owner.TryGetComponent(out ServerStatusEffectsComponent pulledStatus))
|
|
||||||
{
|
{
|
||||||
pulledStatus.ChangeStatusEffectIcon(StatusEffect.Pulled,
|
pulledStatus.ChangeStatusEffectIcon(StatusEffect.Pulled,
|
||||||
"/Textures/Interface/StatusEffects/Pull/pulled.png");
|
"/Textures/Interface/StatusEffects/Pull/pulled.png");
|
||||||
@@ -705,10 +717,9 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemovePullingStatuses()
|
private void RemovePullingStatuses(IEntity pulled)
|
||||||
{
|
{
|
||||||
if (PulledObject?.Owner != null &&
|
if (pulled.TryGetComponent(out ServerStatusEffectsComponent pulledStatus))
|
||||||
PulledObject.Owner.TryGetComponent(out ServerStatusEffectsComponent pulledStatus))
|
|
||||||
{
|
{
|
||||||
pulledStatus.RemoveStatusEffect(StatusEffect.Pulled);
|
pulledStatus.RemoveStatusEffect(StatusEffect.Pulled);
|
||||||
}
|
}
|
||||||
@@ -719,12 +730,6 @@ namespace Content.Server.GameObjects.Components.GUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void StopPull()
|
|
||||||
{
|
|
||||||
RemovePullingStatuses();
|
|
||||||
base.StopPull();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IBodyPartAdded.BodyPartAdded(BodyPartAddedEventArgs eventArgs)
|
void IBodyPartAdded.BodyPartAdded(BodyPartAddedEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
if (eventArgs.Part.PartType != BodyPartType.Hand)
|
if (eventArgs.Part.PartType != BodyPartType.Hand)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Content.Shared.GameObjects.EntitySystems;
|
|||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using Content.Shared.Physics.Pull;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Shared.GameObjects.Components.Items;
|
|||||||
using Content.Shared.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.GameObjects.Verbs;
|
using Content.Shared.GameObjects.Verbs;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using Content.Shared.Physics.Pull;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics.Pull;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
@@ -26,8 +27,27 @@ namespace Content.Shared.GameObjects.Components.Items
|
|||||||
{
|
{
|
||||||
controller.StopPull();
|
controller.StopPull();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||||
|
{
|
||||||
|
base.HandleMessage(message, component);
|
||||||
|
|
||||||
|
if (!(message is PullMessage pullMessage) ||
|
||||||
|
pullMessage.Puller.Owner != Owner)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case PullStartedMessage msg:
|
||||||
|
PulledObject = msg.Pulled;
|
||||||
|
break;
|
||||||
|
case PullStoppedMessage _:
|
||||||
PulledObject = null;
|
PulledObject = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
using Content.Shared.GameObjects.Components.Items;
|
using Content.Shared.GameObjects.Components.Items;
|
||||||
using Content.Shared.GameObjects.Components.Movement;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using Content.Shared.Physics.Pull;
|
||||||
using Robust.Shared.Configuration;
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using Content.Shared.GameObjects.Components.Items;
|
|
||||||
using Content.Shared.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Shared.Physics
|
namespace Content.Shared.Physics.Pull
|
||||||
{
|
{
|
||||||
public class PullController : VirtualController
|
public class PullController : VirtualController
|
||||||
{
|
{
|
||||||
@@ -25,15 +26,50 @@ namespace Content.Shared.Physics
|
|||||||
|
|
||||||
public ICollidableComponent? Puller => _puller;
|
public ICollidableComponent? Puller => _puller;
|
||||||
|
|
||||||
public void StartPull(ICollidableComponent? pull)
|
public void StartPull(ICollidableComponent puller)
|
||||||
{
|
{
|
||||||
_puller = pull;
|
DebugTools.AssertNotNull(puller);
|
||||||
|
|
||||||
|
if (_puller == puller)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_puller = puller;
|
||||||
|
|
||||||
|
if (ControlledComponent == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = new PullStartedMessage(this, _puller, ControlledComponent);
|
||||||
|
|
||||||
|
_puller.Owner.SendMessage(null, message);
|
||||||
|
ControlledComponent.Owner.SendMessage(null, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopPull()
|
public void StopPull()
|
||||||
{
|
{
|
||||||
|
var oldPuller = _puller;
|
||||||
|
|
||||||
|
if (oldPuller == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_puller = null;
|
_puller = null;
|
||||||
ControlledComponent?.TryRemoveController<PullController>();
|
|
||||||
|
if (ControlledComponent == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var message = new PullStoppedMessage(this, oldPuller, ControlledComponent);
|
||||||
|
|
||||||
|
oldPuller.Owner.SendMessage(null, message);
|
||||||
|
ControlledComponent.Owner.SendMessage(null, message);
|
||||||
|
|
||||||
|
ControlledComponent.TryRemoveController<PullController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TryMoveTo(GridCoordinates from, GridCoordinates to)
|
public void TryMoveTo(GridCoordinates from, GridCoordinates to)
|
||||||
@@ -68,12 +104,18 @@ namespace Content.Shared.Physics
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_puller.Owner.IsInSameOrNoContainer(ControlledComponent.Owner))
|
||||||
|
{
|
||||||
|
StopPull();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Are we outside of pulling range?
|
// Are we outside of pulling range?
|
||||||
var dist = _puller.Owner.Transform.WorldPosition - ControlledComponent.Owner.Transform.WorldPosition;
|
var dist = _puller.Owner.Transform.WorldPosition - ControlledComponent.Owner.Transform.WorldPosition;
|
||||||
|
|
||||||
if (dist.Length > DistBeforeStopPull)
|
if (dist.Length > DistBeforeStopPull)
|
||||||
{
|
{
|
||||||
_puller.Owner.GetComponent<ISharedHandsComponent>().StopPull();
|
StopPull();
|
||||||
}
|
}
|
||||||
else if (_movingTo.HasValue)
|
else if (_movingTo.HasValue)
|
||||||
{
|
{
|
||||||
19
Content.Shared/Physics/Pull/PullMessage.cs
Normal file
19
Content.Shared/Physics/Pull/PullMessage.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
|
||||||
|
namespace Content.Shared.Physics.Pull
|
||||||
|
{
|
||||||
|
public class PullMessage : ComponentMessage
|
||||||
|
{
|
||||||
|
public readonly PullController Controller;
|
||||||
|
public readonly ICollidableComponent Puller;
|
||||||
|
public readonly ICollidableComponent Pulled;
|
||||||
|
|
||||||
|
protected PullMessage(PullController controller, ICollidableComponent puller, ICollidableComponent pulled)
|
||||||
|
{
|
||||||
|
Controller = controller;
|
||||||
|
Puller = puller;
|
||||||
|
Pulled = pulled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Content.Shared/Physics/Pull/PullStartedMessage.cs
Normal file
12
Content.Shared/Physics/Pull/PullStartedMessage.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
|
||||||
|
namespace Content.Shared.Physics.Pull
|
||||||
|
{
|
||||||
|
public class PullStartedMessage : PullMessage
|
||||||
|
{
|
||||||
|
public PullStartedMessage(PullController controller, ICollidableComponent puller, ICollidableComponent pulled) :
|
||||||
|
base(controller, puller, pulled)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
Content.Shared/Physics/Pull/PullStoppedMessage.cs
Normal file
12
Content.Shared/Physics/Pull/PullStoppedMessage.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
|
||||||
|
namespace Content.Shared.Physics.Pull
|
||||||
|
{
|
||||||
|
public class PullStoppedMessage : PullMessage
|
||||||
|
{
|
||||||
|
public PullStoppedMessage(PullController controller, ICollidableComponent puller, ICollidableComponent pulled) :
|
||||||
|
base(controller, puller, pulled)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user