Add client pulling prediction (#2041)

* WIP changes

* Merge conflict fixes

* Bring pull controlelr to current year

* Sync and predict PullController on the client

* Clean imports

* Slow down pullers and make pulling tighter

* Stop pulls on pullable or puller component removals

* Make pulling not occur when moving towards the pulled entity
This commit is contained in:
DrSmugleaf
2020-10-16 20:35:09 +02:00
committed by GitHub
parent 0345fbbd22
commit b1fe4bad01
24 changed files with 734 additions and 341 deletions

View File

@@ -1,78 +0,0 @@
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Physics.Pull;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.GlobalVerbs
{
/// <summary>
/// Global verb that pulls an entity.
/// </summary>
[GlobalVerb]
public class PullingVerb : GlobalVerb
{
public override bool RequireInteractionRange => false;
public override void GetData(IEntity user, IEntity target, VerbData data)
{
data.Visibility = VerbVisibility.Invisible;
if (user == target ||
!user.HasComponent<IActorComponent>() ||
!target.HasComponent<PullableComponent>())
{
return;
}
var dist = user.Transform.Coordinates.Position - target.Transform.Coordinates.Position;
if (dist.LengthSquared > SharedInteractionSystem.InteractionRangeSquared)
{
return;
}
if (!user.HasComponent<ISharedHandsComponent>() ||
!user.TryGetComponent(out IPhysicsComponent userPhysics) ||
!target.TryGetComponent(out IPhysicsComponent targetPhysics) ||
targetPhysics.Anchored)
{
return;
}
var controller = targetPhysics.EnsureController<PullController>();
data.Visibility = VerbVisibility.Visible;
data.Text = controller.Puller == userPhysics
? Loc.GetString("Stop pulling")
: Loc.GetString("Pull");
}
public override void Activate(IEntity user, IEntity target)
{
if (!user.TryGetComponent(out IPhysicsComponent userPhysics) ||
!target.TryGetComponent(out IPhysicsComponent targetPhysics) ||
targetPhysics.Anchored ||
!target.TryGetComponent(out PullableComponent pullable) ||
!user.TryGetComponent(out HandsComponent hands))
{
return;
}
var controller = targetPhysics.EnsureController<PullController>();
if (controller.Puller == userPhysics)
{
hands.StopPull();
}
else
{
hands.StartPull(pullable);
}
}
}
}