Add unbuckling entities that are moved away from their straps (#1437)

* Add unbuckling entities that move away from their straps

* Remove range constraint from movement unbuckling check

* Fix setting the wrong positions when buckling

* Fix beds making you sleep for the rest of your life
This commit is contained in:
DrSmugleaf
2020-07-24 14:22:28 +02:00
committed by GitHub
parent be3db34d1c
commit 5e2109a2d6
3 changed files with 59 additions and 10 deletions

View File

@@ -1,14 +1,46 @@
using Content.Server.GameObjects.Components.Buckle;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems.Click;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class BuckleSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager;
#pragma warning restore 649
/// <summary>
/// Checks if a buckled entity should be unbuckled from moving
/// too far from its strap.
/// </summary>
/// <param name="moveEvent">The move event of a buckled entity.</param>
private void MoveEvent(MoveEvent moveEvent)
{
if (!moveEvent.Sender.TryGetComponent(out BuckleComponent buckle) ||
buckle.BuckledTo == null ||
!buckle.BuckleOffset.HasValue)
{
return;
}
var bucklePosition = buckle.BuckledTo.Owner.Transform.GridPosition.Offset(buckle.BuckleOffset.Value);
if (moveEvent.NewPosition.InRange(_mapManager, bucklePosition, 0.2f))
{
return;
}
buckle.TryUnbuckle(buckle.Owner, true);
}
public override void Initialize()
{
base.Initialize();
@@ -17,6 +49,8 @@ namespace Content.Server.GameObjects.EntitySystems
UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem));
SubscribeLocalEvent<MoveEvent>(MoveEvent);
}
public override void Update(float frameTime)