* Migrate lots of pulling logic out of the components and clean it up * It's buggy, but move more code out of the pullable component * Pulling system now throws less errors than it did before the refactor * Finally finish the big parts of refactoring pullability * Pulling: Handle disconnect properly if the pull joint has been removed by physics shutdown * Port2b68449328to this branch * Changes as per PR reviews * Porte801ffac45(SharedJointSystem) and fix issues encountered during testing SharedJointSystem. Also, MinLength and Stiffness appear to have suddenly gained enough meaning that pulling is broken unless they're set.
64 lines
2.3 KiB
C#
64 lines
2.3 KiB
C#
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Pulling.Components;
|
|
using Content.Shared.Pulling;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Physics;
|
|
|
|
namespace Content.Server.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 IPhysBody? userPhysics) ||
|
|
!component.Owner.TryGetComponent(out IPhysBody? targetPhysics) ||
|
|
targetPhysics.BodyType == BodyType.Static)
|
|
{
|
|
return;
|
|
}
|
|
|
|
data.Visibility = VerbVisibility.Visible;
|
|
data.Text = component.Puller == userPhysics.Owner
|
|
? Loc.GetString("pulling-verb-get-data-text-stop-pulling")
|
|
: Loc.GetString("pulling-verb-get-data-text");
|
|
}
|
|
|
|
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)
|
|
{
|
|
EntitySystem.Get<SharedPullingSystem>().TryStopPull(component);
|
|
}
|
|
else
|
|
{
|
|
EntitySystem.Get<SharedPullingSystem>().TryStartPull(component.Owner, user);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|