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:
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Strap;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Utility;
|
||||
@@ -21,6 +22,7 @@ using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -58,6 +60,8 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
[ViewVariables]
|
||||
private TimeSpan _buckleTime;
|
||||
|
||||
public Vector2? BuckleOffset { get; private set; }
|
||||
|
||||
private StrapComponent? _buckledTo;
|
||||
|
||||
/// <summary>
|
||||
@@ -116,7 +120,6 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
var ownTransform = Owner.Transform;
|
||||
var strapTransform = strap.Owner.Transform;
|
||||
|
||||
ownTransform.GridPosition = strapTransform.GridPosition;
|
||||
ownTransform.AttachParent(strapTransform);
|
||||
|
||||
switch (strap.Position)
|
||||
@@ -129,14 +132,21 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
ownTransform.WorldRotation = strapTransform.WorldRotation;
|
||||
break;
|
||||
case StrapPosition.Down:
|
||||
StandingStateHelper.Down(Owner);
|
||||
StandingStateHelper.Down(Owner, force: true);
|
||||
ownTransform.WorldRotation = Angle.South;
|
||||
break;
|
||||
}
|
||||
|
||||
// Assign BuckleOffset first, before causing a MoveEvent to fire
|
||||
if (strapTransform.WorldRotation.GetCardinalDir() == Direction.North)
|
||||
{
|
||||
ownTransform.WorldPosition += (0, 0.15f);
|
||||
BuckleOffset = (0, 0.15f);
|
||||
ownTransform.WorldPosition = strapTransform.WorldPosition + BuckleOffset!.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
BuckleOffset = Vector2.Zero;
|
||||
ownTransform.WorldPosition = strapTransform.WorldPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,9 +267,9 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
appearance.SetData(BuckleVisuals.Buckled, true);
|
||||
}
|
||||
|
||||
ReAttach(strap);
|
||||
|
||||
BuckledTo = strap;
|
||||
|
||||
ReAttach(strap);
|
||||
BuckleStatus();
|
||||
|
||||
return true;
|
||||
@@ -315,8 +325,8 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
|
||||
if (Owner.Transform.Parent == BuckledTo.Owner.Transform)
|
||||
{
|
||||
Owner.Transform.DetachParent();
|
||||
Owner.Transform.WorldRotation = BuckledTo.Owner.Transform.WorldRotation;
|
||||
Owner.Transform.DetachParent();
|
||||
}
|
||||
|
||||
BuckledTo = null;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -17,11 +17,16 @@ namespace Content.Server.Mobs
|
||||
/// <param name="entity">The mob in question</param>
|
||||
/// <param name="playSound">Whether to play a sound when falling down or not</param>
|
||||
/// <param name="dropItems">Whether to make the mob drop all the items on his hands</param>
|
||||
/// <param name="force">Whether or not to check if the entity can fall.</param>
|
||||
/// <returns>False if the mob was already downed or couldn't set the state</returns>
|
||||
public static bool Down(IEntity entity, bool playSound = true, bool dropItems = true)
|
||||
public static bool Down(IEntity entity, bool playSound = true, bool dropItems = true, bool force = false)
|
||||
{
|
||||
if (!EffectBlockerSystem.CanFall(entity) ||
|
||||
!entity.TryGetComponent(out AppearanceComponent appearance))
|
||||
if (!force && !EffectBlockerSystem.CanFall(entity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user