2020-11-06 01:08:24 +11:00
|
|
|
|
#nullable enable
|
2021-03-08 04:09:59 +11:00
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Server.GameObjects.EntitySystems;
|
2020-11-06 01:08:24 +11:00
|
|
|
|
using Content.Shared.GameObjects.Components.Buckle;
|
|
|
|
|
|
using Content.Shared.GameObjects.Components.Movement;
|
2020-09-13 14:23:52 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
using Robust.Shared.IoC;
|
2020-09-13 14:23:52 +02:00
|
|
|
|
using Robust.Shared.Maths;
|
2021-02-18 09:09:07 +01:00
|
|
|
|
using Robust.Shared.Players;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
using Robust.Shared.Timing;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Movement
|
|
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
2021-01-11 22:14:01 +11:00
|
|
|
|
[ComponentReference(typeof(SharedClimbingComponent))]
|
2020-10-14 15:24:07 +02:00
|
|
|
|
public class ClimbingComponent : SharedClimbingComponent
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
|
|
|
|
|
public override bool IsClimbing
|
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
get => base.IsClimbing;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2020-10-12 02:12:46 +11:00
|
|
|
|
if (_isClimbing == value)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
|
base.IsClimbing = value;
|
|
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
|
{
|
|
|
|
|
|
StartClimbTime = IoCManager.Resolve<IGameTiming>().CurTime;
|
|
|
|
|
|
EntitySystem.Get<ClimbSystem>().AddActiveClimber(this);
|
|
|
|
|
|
OwnerIsTransitioning = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
EntitySystem.Get<ClimbSystem>().RemoveActiveClimber(this);
|
|
|
|
|
|
OwnerIsTransitioning = false;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
|
Dirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool OwnerIsTransitioning
|
|
|
|
|
|
{
|
|
|
|
|
|
get => base.OwnerIsTransitioning;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value == base.OwnerIsTransitioning) return;
|
|
|
|
|
|
base.OwnerIsTransitioning = value;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
Dirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-11-06 01:08:24 +11:00
|
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.HandleMessage(message, component);
|
|
|
|
|
|
switch (message)
|
|
|
|
|
|
{
|
|
|
|
|
|
case BuckleMessage msg:
|
|
|
|
|
|
if (msg.Buckled)
|
|
|
|
|
|
IsClimbing = false;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-19 18:13:22 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Make the owner climb from one point to another
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void TryMoveTo(Vector2 from, Vector2 to)
|
|
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
if (Body == null) return;
|
2021-03-01 03:11:29 +11:00
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
|
var velocity = (to - from).Length;
|
|
|
|
|
|
|
|
|
|
|
|
if (velocity <= 0.0f) return;
|
|
|
|
|
|
|
|
|
|
|
|
Body.ApplyLinearImpulse((to - from).Normalized * velocity * 400);
|
|
|
|
|
|
OwnerIsTransitioning = true;
|
|
|
|
|
|
|
|
|
|
|
|
Owner.SpawnTimer((int) (BufferTime * 1000), () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Deleted) return;
|
|
|
|
|
|
OwnerIsTransitioning = false;
|
|
|
|
|
|
});
|
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
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
if (!IsClimbing || _gameTiming.CurTime < TimeSpan.FromSeconds(BufferTime) + StartClimbTime)
|
2021-02-28 18:49:48 +01:00
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
return;
|
2020-10-12 02:12:46 +11:00
|
|
|
|
}
|
2020-08-19 18:13:22 -04:00
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
|
if (!IsOnClimbableThisFrame && IsClimbing)
|
2020-10-12 02:12:46 +11:00
|
|
|
|
IsClimbing = false;
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-18 09:09:07 +01:00
|
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
2020-08-19 18:13:22 -04:00
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
return new ClimbModeComponentState(_isClimbing, OwnerIsTransitioning);
|
2020-08-19 18:13:22 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|