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

@@ -5,10 +5,8 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Movement;
using Content.Server.GameObjects.EntitySystems.Click;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Body.Part;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Mobs;
@@ -25,10 +23,11 @@ using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
using Content.Server.GameObjects.Components.Pulling;
using Robust.Shared.Map;
namespace Content.Server.GameObjects.Components.GUI
{
@@ -516,77 +515,6 @@ namespace Content.Server.GameObjects.Components.GUI
return false;
}
public void StartPull(PullableComponent pullable)
{
if (Owner == pullable.Owner)
{
return;
}
if (!Owner.IsInSameOrNoContainer(pullable.Owner))
{
return;
}
if (IsPulling)
{
StopPull();
}
PulledObject = pullable.Owner.GetComponent<IPhysicsComponent>();
var controller = PulledObject.EnsureController<PullController>();
controller.StartPull(Owner.GetComponent<IPhysicsComponent>());
}
public void MovePulledObject(EntityCoordinates puller, EntityCoordinates to)
{
if (PulledObject != null &&
PulledObject.TryGetController(out PullController controller))
{
controller.TryMoveTo(puller, to);
}
}
private void MoveEvent(MoveEvent moveEvent)
{
if (moveEvent.Sender != Owner)
{
return;
}
if (!IsPulling)
{
return;
}
PulledObject!.WakeBody();
}
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:
Owner.EntityManager.EventBus.SubscribeEvent<MoveEvent>(EventSource.Local, this, MoveEvent);
AddPullingStatuses(msg.Pulled.Owner);
break;
case PullStoppedMessage msg:
Owner.EntityManager.EventBus.UnsubscribeEvent<MoveEvent>(EventSource.Local, this);
RemovePullingStatuses(msg.Pulled.Owner);
break;
}
}
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
{
base.HandleNetworkMessage(message, channel, session);

View File

@@ -1,38 +1,15 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Body;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameObjects;
using Content.Server.Utility;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Power;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Kitchen;
using Content.Shared.Prototypes.Kitchen;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Timers;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Kitchen
{
@@ -49,11 +26,9 @@ namespace Content.Server.GameObjects.Components.Kitchen
void IActivate.Activate(ActivateEventArgs eventArgs)
{
var victim = eventArgs.User.GetComponent<HandsComponent>().PulledObject?.Owner;
SpriteComponent? sprite;
var sprite = Owner.GetComponent<SpriteComponent>();
if (victim == null)
if (!EntitySystem.Get<SharedPullingSystem>().TryGetPulled(eventArgs.User, out var victim))
{
if (_meatParts == 0)
{
@@ -72,12 +47,18 @@ namespace Content.Server.GameObjects.Components.Kitchen
}
else
{
sprite.LayerSetState(0, "spike");
if (Owner.TryGetComponent(out sprite))
{
sprite.LayerSetState(0, "spike");
}
eventArgs.User.PopupMessage(_meatSource0);
}
return;
}
else if (_meatParts > 0)
if (_meatParts > 0)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("The spike already has something on it, finish collecting its meat first!"));
return;
@@ -94,7 +75,10 @@ namespace Content.Server.GameObjects.Components.Kitchen
_meatSource1p = Loc.GetString("You remove some meat from {0:theName}.", victim);
_meatSource0 = Loc.GetString("You remove the last piece of meat from {0:theName}!", victim);
sprite.LayerSetState(0, "spikebloody");
if (Owner.TryGetComponent(out sprite))
{
sprite.LayerSetState(0, "spikebloody");
}
Owner.PopupMessageEveryone(Loc.GetString("{0:theName} has forced {1:theName} onto the spike, killing them instantly!", eventArgs.User, victim));
victim.Delete();

View File

@@ -5,8 +5,11 @@ using Content.Server.GameObjects.Components.Buckle;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Movement;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Pulling;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.Players;
using Robust.Shared.ViewVariables;
@@ -25,7 +28,7 @@ namespace Content.Server.GameObjects.Components.Mobs
return new StatusEffectComponentState(_statusEffects);
}
public void ChangeStatusEffectIcon(StatusEffect effect, string icon)
public override void ChangeStatusEffectIcon(StatusEffect effect, string icon)
{
if (_statusEffects.TryGetValue(effect, out var value) && value.Icon == icon)
{
@@ -60,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Mobs
Dirty();
}
public void RemoveStatusEffect(StatusEffect effect)
public override void RemoveStatusEffect(StatusEffect effect)
{
if (!_statusEffects.Remove(effect))
{
@@ -106,19 +109,19 @@ namespace Content.Server.GameObjects.Components.Mobs
controller.RemoveController();
break;
case StatusEffect.Pulling:
if (!player.TryGetComponent(out HandsComponent hands))
break;
EntitySystem
.Get<SharedPullingSystem>()
.GetPulled(player)?
.GetComponentOrNull<SharedPullableComponent>()?
.TryStopPull();
hands.StopPull();
break;
case StatusEffect.Fire:
if (!player.TryGetComponent(out FlammableComponent flammable))
break;
flammable.Resist();
break;
default:
player.PopupMessage(msg.Effect.ToString());
break;

View File

@@ -1,10 +0,0 @@
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Movement
{
[RegisterComponent]
public class PullableComponent: Component
{
public override string Name => "Pullable";
}
}

View File

@@ -0,0 +1,74 @@
#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;
}
var controller = targetPhysics.EnsureController<PullController>();
data.Visibility = VerbVisibility.Visible;
data.Text = controller.Puller == userPhysics
? Loc.GetString("Stop pulling")
: Loc.GetString("Pull");
}
protected override void Activate(IEntity user, PullableComponent component)
{
if (!user.TryGetComponent(out IPhysicsComponent? userCollidable) ||
!component.Owner.TryGetComponent(out IPhysicsComponent? targetCollidable) ||
targetCollidable.Anchored)
{
return;
}
var controller = targetCollidable.EnsureController<PullController>();
if (controller.Puller == userCollidable)
{
component.TryStopPull();
}
else
{
component.TryStartPull(user);
}
}
}
}
}