Files
tbd-station-14/Content.Client/GameObjects/Components/Buckle/BuckleComponent.cs
Morshu32 19bd739b0d 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>
2020-12-18 20:12:53 +01:00

53 lines
1.5 KiB
C#

using Content.Shared.GameObjects.Components.Buckle;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Client.GameObjects.Components.Buckle
{
[RegisterComponent]
public class BuckleComponent : SharedBuckleComponent
{
private bool _buckled;
private int? _originalDrawDepth;
public override bool Buckled => _buckled;
public override bool TryBuckle(IEntity user, IEntity to)
{
// TODO: Prediction
return false;
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (curState is not BuckleComponentState buckle)
{
return;
}
_buckled = buckle.Buckled;
LastEntityBuckledTo = buckle.LastEntityBuckledTo;
DontCollide = buckle.DontCollide;
if (!Owner.TryGetComponent(out SpriteComponent ownerSprite))
{
return;
}
if (_buckled && buckle.DrawDepth.HasValue)
{
_originalDrawDepth ??= ownerSprite.DrawDepth;
ownerSprite.DrawDepth = buckle.DrawDepth.Value;
return;
}
if (!_buckled && _originalDrawDepth.HasValue)
{
ownerSprite.DrawDepth = _originalDrawDepth.Value;
_originalDrawDepth = null;
}
}
}
}