Re-organize all projects (#4166)
This commit is contained in:
28
Content.Shared/Climbing/SharedClimbableComponent.cs
Normal file
28
Content.Shared/Climbing/SharedClimbableComponent.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
#nullable enable
|
||||
using Content.Shared.DragDrop;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Climbing
|
||||
{
|
||||
public interface IClimbable { }
|
||||
|
||||
public abstract class SharedClimbableComponent : Component, IClimbable, IDragDropOn
|
||||
{
|
||||
public sealed override string Name => "Climbable";
|
||||
|
||||
/// <summary>
|
||||
/// The range from which this entity can be climbed.
|
||||
/// </summary>
|
||||
[ViewVariables] [DataField("range")] protected float Range = SharedInteractionSystem.InteractionRange / 1.4f;
|
||||
|
||||
public virtual bool CanDragDropOn(DragDropEvent eventArgs)
|
||||
{
|
||||
return eventArgs.Dragged.HasComponent<SharedClimbingComponent>();
|
||||
}
|
||||
|
||||
public abstract bool DragDropOn(DragDropEvent eventArgs);
|
||||
}
|
||||
}
|
||||
112
Content.Shared/Climbing/SharedClimbingComponent.cs
Normal file
112
Content.Shared/Climbing/SharedClimbingComponent.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.NetIDs;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Climbing
|
||||
{
|
||||
public abstract class SharedClimbingComponent : Component, IActionBlocker
|
||||
{
|
||||
public sealed override string Name => "Climbing";
|
||||
public sealed override uint? NetID => ContentNetIDs.CLIMBING;
|
||||
|
||||
protected bool IsOnClimbableThisFrame
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Body == null) return false;
|
||||
|
||||
foreach (var entity in Body.GetBodiesIntersecting())
|
||||
{
|
||||
if ((entity.CollisionLayer & (int) CollisionGroup.SmallImpassable) != 0) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanMove() => !OwnerIsTransitioning;
|
||||
|
||||
[ViewVariables]
|
||||
protected virtual bool OwnerIsTransitioning
|
||||
{
|
||||
get => _ownerIsTransitioning;
|
||||
set
|
||||
{
|
||||
if (_ownerIsTransitioning == value) return;
|
||||
_ownerIsTransitioning = value;
|
||||
if (Body == null) return;
|
||||
if (value)
|
||||
{
|
||||
Body.BodyType = BodyType.Dynamic;
|
||||
}
|
||||
else
|
||||
{
|
||||
Body.BodyType = BodyType.KinematicController;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public virtual bool IsClimbing
|
||||
{
|
||||
get => _isClimbing;
|
||||
set
|
||||
{
|
||||
if (_isClimbing == value) return;
|
||||
_isClimbing = value;
|
||||
|
||||
ToggleSmallPassable(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected bool _isClimbing;
|
||||
|
||||
// TODO: Layers need a re-work
|
||||
private void ToggleSmallPassable(bool value)
|
||||
{
|
||||
// Hope the mob has one fixture
|
||||
if (Body == null || Body.Deleted) return;
|
||||
|
||||
foreach (var fixture in Body.Fixtures)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
fixture.CollisionMask &= ~(int) CollisionGroup.SmallImpassable;
|
||||
}
|
||||
else
|
||||
{
|
||||
fixture.CollisionMask |= (int) CollisionGroup.SmallImpassable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class ClimbModeComponentState : ComponentState
|
||||
{
|
||||
public ClimbModeComponentState(bool climbing, bool isTransitioning) : base(ContentNetIDs.CLIMBING)
|
||||
{
|
||||
Climbing = climbing;
|
||||
IsTransitioning = isTransitioning;
|
||||
}
|
||||
|
||||
public bool Climbing { get; }
|
||||
public bool IsTransitioning { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user