Add back pull moving (#3635)

* Add back pull moving

* Make pull moving event-based, use map coordinates, slow down moving when getting closer and stop moving when very close, add max range and add compensation for overshooting

* Remove compensation

* Prevent pull move from pulling you

* acruid did this

* Add unsubscriptions to shutdown

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
DrSmugleaf
2021-04-05 14:08:45 +02:00
committed by GitHub
parent 8f561b7d10
commit 4c47cd4fe2
8 changed files with 243 additions and 33 deletions

View File

@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Pulling;
using Content.Shared.GameObjects.EntitySystemMessages.Pulling;
using Content.Shared.GameTicking;
using Content.Shared.Input;
using Content.Shared.Physics.Pull;
using JetBrains.Annotations;
@@ -16,7 +18,7 @@ using Robust.Shared.Players;
namespace Content.Shared.GameObjects.EntitySystems
{
[UsedImplicitly]
public class SharedPullingSystem : EntitySystem
public abstract class SharedPullingSystem : EntitySystem, IResettingEntitySystem
{
/// <summary>
/// A mapping of pullers to the entity that they are pulling.
@@ -24,6 +26,11 @@ namespace Content.Shared.GameObjects.EntitySystems
private readonly Dictionary<IEntity, IEntity> _pullers =
new();
private readonly HashSet<SharedPullableComponent> _moving = new();
private readonly HashSet<SharedPullableComponent> _stoppedMoving = new();
public IReadOnlySet<SharedPullableComponent> Moving => _moving;
public override void Initialize()
{
base.Initialize();
@@ -39,6 +46,21 @@ namespace Content.Shared.GameObjects.EntitySystems
.Register<SharedPullingSystem>();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_moving.ExceptWith(_stoppedMoving);
_stoppedMoving.Clear();
}
public void Reset()
{
_pullers.Clear();
_moving.Clear();
_stoppedMoving.Clear();
}
private void OnPullStarted(PullStartedMessage message)
{
if (_pullers.TryGetValue(message.Puller.Owner, out var pulled) &&
@@ -55,6 +77,16 @@ namespace Content.Shared.GameObjects.EntitySystems
RemovePuller(message.Puller.Owner);
}
protected void OnPullableMove(EntityUid uid, SharedPullableComponent component, PullableMoveMessage args)
{
_moving.Add(component);
}
protected void OnPullableStopMove(EntityUid uid, SharedPullableComponent component, PullableStopMovingMessage args)
{
_stoppedMoving.Add(component);
}
private void PullerMoved(MoveEvent ev)
{
if (!TryGetPulled(ev.Sender, out var pulled))
@@ -68,6 +100,11 @@ namespace Content.Shared.GameObjects.EntitySystems
}
physics.WakeBody();
if (pulled.TryGetComponent(out SharedPullableComponent? pullable))
{
pullable.MovingTo = null;
}
}
// TODO: When Joint networking is less shitcodey fix this to use a dedicated joints message.
@@ -110,7 +147,7 @@ namespace Content.Shared.GameObjects.EntitySystems
return false;
}
pullable.TryMoveTo(coords);
pullable.TryMoveTo(coords.ToMap(EntityManager));
return false;
}