Files
tbd-station-14/Content.Server/GameObjects/Components/Pulling/PullableComponent.cs
20kdc 380d76f4cd Migrate pulling logic into SharedPullableComponent from PullController (#2627)
* Pulling: Migrate critical pull state from PullController to SharedPullableComponent, fixing two bugs in the process

Bug 1: PullController can be just summoned for no reason when the verb is queried
Bug 2: PullController keeps it's own independent pull state which can (and will) go out of sync (See https://github.com/space-wizards/space-station-14/issues/2619 )

* Pulling: Fix issues with previous commit (or possibly in general?) causing transferring a pull to cause alerts to go wrong

The primary problem is that there is one "pulling slot" for a puller, so SharedPullableComponent needs to stop the existing pull.

* Pulling: Remove debug logs (whoops)
2020-11-27 00:48:10 +11:00

66 lines
2.3 KiB
C#

#nullable enable
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Pulling;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Physics.Pull;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.GameObjects.Components.Pulling
{
[RegisterComponent]
[ComponentReference(typeof(SharedPullableComponent))]
public class PullableComponent : SharedPullableComponent
{
[Verb]
public class PullingVerb : Verb<PullableComponent>
{
protected override void GetData(IEntity user, PullableComponent component, VerbData data)
{
data.Visibility = VerbVisibility.Invisible;
if (user == component.Owner)
{
return;
}
if (!user.Transform.Coordinates.TryDistance(user.EntityManager, component.Owner.Transform.Coordinates, out var distance) ||
distance > SharedInteractionSystem.InteractionRange)
{
return;
}
if (!user.HasComponent<ISharedHandsComponent>() ||
!user.TryGetComponent(out IPhysicsComponent? userPhysics) ||
!component.Owner.TryGetComponent(out IPhysicsComponent? targetPhysics) ||
targetPhysics.Anchored)
{
return;
}
data.Visibility = VerbVisibility.Visible;
data.Text = component.Puller == userPhysics
? Loc.GetString("Stop pulling")
: Loc.GetString("Pull");
}
protected override void Activate(IEntity user, PullableComponent component)
{
// There used to be sanity checks here for no reason.
// Why no reason? Because they're supposed to be performed in TryStartPull.
if (component.Puller == user)
{
component.TryStopPull();
}
else
{
component.TryStartPull(user);
}
}
}
}
}