2021-02-27 04:12:09 +01:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.ActionBlocker;
|
2020-08-19 18:13:22 -04:00
|
|
|
using Content.Shared.Physics;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
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
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Climbing
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2021-10-21 13:03:14 +11:00
|
|
|
public abstract class SharedClimbingComponent : Component
|
2020-08-19 18:13:22 -04:00
|
|
|
{
|
|
|
|
|
public sealed override string Name => "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-03-08 04:09:59 +11:00
|
|
|
[ViewVariables]
|
2021-08-10 10:34:01 +10:00
|
|
|
public 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>
|
2021-11-20 01:03:09 +00:00
|
|
|
public 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-07-12 01:32:10 -07:00
|
|
|
public ClimbModeComponentState(bool climbing, bool isTransitioning)
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|