2020-09-13 14:23:52 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components.Movement;
|
|
|
|
|
|
using Content.Shared.Physics;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Movement
|
|
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
2020-10-14 15:24:07 +02:00
|
|
|
|
public class ClimbingComponent : SharedClimbingComponent
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
|
|
|
|
|
private bool _isClimbing = false;
|
|
|
|
|
|
private ClimbController _climbController = default;
|
|
|
|
|
|
|
|
|
|
|
|
public override bool IsClimbing
|
|
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
get => _isClimbing;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (_isClimbing == value)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (!value)
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
Body?.TryRemoveController<ClimbController>();
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_isClimbing = value;
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Make the owner climb from one point to another
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void TryMoveTo(Vector2 from, Vector2 to)
|
|
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (Body == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
_climbController = Body.EnsureController<ClimbController>();
|
|
|
|
|
|
_climbController.TryMoveTo(from, to);
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-12 02:12:46 +11:00
|
|
|
|
public void Update()
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (!IsClimbing || Body == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (_climbController != null && (_climbController.IsBlocked || !_climbController.IsActive))
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (Body.TryRemoveController<ClimbController>())
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
_climbController = null;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
2020-10-12 02:12:46 +11:00
|
|
|
|
}
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (IsClimbing)
|
|
|
|
|
|
Body.WakeBody();
|
2020-08-19 20:21:15 -04:00
|
|
|
|
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (!IsOnClimbableThisFrame && IsClimbing && _climbController == null)
|
|
|
|
|
|
IsClimbing = false;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
2020-10-12 02:12:46 +11:00
|
|
|
|
IsOnClimbableThisFrame = false;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override ComponentState GetComponentState()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ClimbModeComponentState(_isClimbing);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|