2021-03-26 01:51:26 +00:00
|
|
|
#nullable enable
|
2021-02-27 04:12:09 +01:00
|
|
|
using System;
|
2020-12-20 04:26:21 +01:00
|
|
|
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
2020-08-19 18:13:22 -04:00
|
|
|
using Content.Shared.Physics;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-02-28 18:49:48 +01:00
|
|
|
using Robust.Shared.Physics;
|
2020-08-19 18:13:22 -04:00
|
|
|
using Robust.Shared.Serialization;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
|
|
|
namespace Content.Shared.GameObjects.Components.Movement
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
public abstract class SharedClimbingComponent : Component, IActionBlocker
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
|
|
|
|
public sealed override string Name => "Climbing";
|
|
|
|
|
public sealed override uint? NetID => ContentNetIDs.CLIMBING;
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
protected bool IsOnClimbableThisFrame
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
if (Body == null) return false;
|
|
|
|
|
|
|
|
|
|
foreach (var entity in Body.GetBodiesIntersecting())
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-03-26 01:51:26 +00:00
|
|
|
if ((entity.CollisionLayer & (int) CollisionGroup.SmallImpassable) != 0) return true;
|
2020-08-19 18:13:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 18:49:48 +01:00
|
|
|
bool IActionBlocker.CanMove() => !OwnerIsTransitioning;
|
2021-03-01 03:11:29 +11:00
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
[ViewVariables]
|
|
|
|
|
protected virtual bool OwnerIsTransitioning
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
get => _ownerIsTransitioning;
|
|
|
|
|
set
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
if (_ownerIsTransitioning == value) return;
|
|
|
|
|
_ownerIsTransitioning = value;
|
|
|
|
|
if (Body == null) return;
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
Body.BodyType = BodyType.Dynamic;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Body.BodyType = BodyType.KinematicController;
|
|
|
|
|
}
|
2021-03-01 03:11:29 +11:00
|
|
|
}
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _ownerIsTransitioning = false;
|
|
|
|
|
|
|
|
|
|
[ComponentDependency] protected PhysicsComponent? Body;
|
|
|
|
|
|
|
|
|
|
protected TimeSpan StartClimbTime = TimeSpan.Zero;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// We'll launch the mob onto the table and give them at least this amount of time to be on it.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected const float BufferTime = 0.3f;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
public virtual bool IsClimbing
|
|
|
|
|
{
|
|
|
|
|
get => _isClimbing;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_isClimbing == value) return;
|
|
|
|
|
_isClimbing = value;
|
|
|
|
|
|
2021-03-26 01:51:26 +00:00
|
|
|
ToggleSmallPassable(value);
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
2021-02-28 18:49:48 +01:00
|
|
|
}
|
2021-03-01 03:11:29 +11:00
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
protected bool _isClimbing;
|
|
|
|
|
|
|
|
|
|
// TODO: Layers need a re-work
|
2021-03-26 01:51:26 +00:00
|
|
|
private void ToggleSmallPassable(bool value)
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
// Hope the mob has one fixture
|
|
|
|
|
if (Body == null || Body.Deleted) return;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
foreach (var fixture in Body.Fixtures)
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
2021-03-26 01:51:26 +00:00
|
|
|
fixture.CollisionMask &= ~(int) CollisionGroup.SmallImpassable;
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-26 01:51:26 +00:00
|
|
|
fixture.CollisionMask |= (int) CollisionGroup.SmallImpassable;
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
}
|
2020-08-19 18:13:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
protected sealed class ClimbModeComponentState : ComponentState
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
public ClimbModeComponentState(bool climbing, bool isTransitioning) : base(ContentNetIDs.CLIMBING)
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
|
|
|
|
Climbing = climbing;
|
2021-03-08 04:09:59 +11:00
|
|
|
IsTransitioning = isTransitioning;
|
2020-08-19 18:13:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Climbing { get; }
|
2021-03-08 04:09:59 +11:00
|
|
|
public bool IsTransitioning { get; }
|
2020-08-19 18:13:22 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|