Files
tbd-station-14/Content.Shared/Physics/ThrowController.cs

53 lines
1.4 KiB
C#

using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.Physics;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Timers;
namespace Content.Shared.Physics
{
public class ThrowController: VirtualController
{
private float _throwTime;
private PhysicsComponent _component;
public const float DefaultThrowTime = 0.25f;
public float ThrowTime
{
get => _throwTime;
set => _throwTime = value;
}
public override PhysicsComponent ControlledComponent
{
set => _component = value;
}
public void StartThrow(Vector2 initialImpulse)
{
_component.Momentum = initialImpulse;
_component.Status = BodyStatus.InAir;
Timer.Spawn((int) (ThrowTime * 1000), StopThrow);
}
public void StopThrow()
{
if (_component == null || _component.Owner.Deleted) return;
if (IoCManager.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition))
{
Timer.Spawn((int) (ThrowTime * 1000), StopThrow);
return;
}
_component.Status = BodyStatus.OnGround;
_component.LinearVelocity = Vector2.Zero;
}
public ThrowController()
{
ThrowTime = DefaultThrowTime;
}
}
}