PreventCollision with strap component while buckled to it (#2694)

* AvoidCollision if collided entity is the one that the character is buckled to

* Attempt to PreventCollision after the player is unbuckled but still colliding with StrapComponent

* Moved PreventCollide to the Shared script.

* Add WakeBody to keep updating the physics collision while being on a collidable strap component.

* Addressed some of metalgearsloth's suggestions:
- Made EntityBuckledTo,IsOnStrapEntityThisFrame and DontCollide not virtual
-Made EntityBuckledTo nullable
-Don't call update on Paused BuckleComponents
-Removed EntityBuckledTo variable declaration in BuckleComponent because it's not needed anymore
-Call TryUnbuckle if (!IsOnStrapEntityThisFrame && DontCollide) to set BuckledTo entity to null.

* Formatting

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* Formatting

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* Formatting again :P

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* Formatting

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* Formatting

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>

* Renamed variable EntityBuckledTo to LastEntityBuckledTo

* As per DrSmugLeaf suggestion: Added [ComponentDependency] to the Body variable.

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Morshu32
2020-12-18 20:12:53 +01:00
committed by GitHub
parent 9c381dc174
commit 19bd739b0d
4 changed files with 67 additions and 7 deletions

View File

@@ -27,6 +27,7 @@ using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
@@ -49,7 +50,6 @@ namespace Content.Server.GameObjects.Components.Buckle
/// </summary>
[ViewVariables]
private float _range;
/// <summary>
/// The amount of time that must pass for this entity to
/// be able to unbuckle after recently buckling.
@@ -69,6 +69,7 @@ namespace Content.Server.GameObjects.Components.Buckle
public Vector2 BuckleOffset { get; private set; }
private StrapComponent? _buckledTo;
/// <summary>
/// The strap that this component is buckled to.
@@ -266,6 +267,8 @@ namespace Content.Server.GameObjects.Components.Buckle
AppearanceComponent?.SetData(BuckleVisuals.Buckled, true);
BuckledTo = strap;
LastEntityBuckledTo = BuckledTo.Owner.Uid;
DontCollide = true;
ReAttach(strap);
UpdateBuckleStatus();
@@ -418,8 +421,9 @@ namespace Content.Server.GameObjects.Components.Buckle
{
drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1;
}
return new BuckleComponentState(Buckled, drawDepth);
return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
@@ -427,6 +431,24 @@ namespace Content.Server.GameObjects.Components.Buckle
return TryUnbuckle(eventArgs.User);
}
public void Update()
{
if (!DontCollide || Body == null)
return;
Body.WakeBody();
if (!IsOnStrapEntityThisFrame && DontCollide)
{
DontCollide = false;
TryUnbuckle(Owner);
Dirty();
}
IsOnStrapEntityThisFrame = false;
}
/// <summary>
/// Allows the unbuckling of the owning entity through a verb if
/// anyone right clicks them.