Change ThrownItemComponent to be removed after flytime (#20700)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Tag;
|
||||
using Robust.Shared.Map;
|
||||
@@ -24,6 +23,7 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
/// </summary>
|
||||
public const float FlyTime = 0.15f;
|
||||
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly SharedGravitySystem _gravity = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
@@ -112,6 +112,13 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
|
||||
var comp = EnsureComp<ThrownItemComponent>(uid);
|
||||
comp.Thrower = user;
|
||||
|
||||
// Estimate time to arrival so we can apply OnGround status and slow it much faster.
|
||||
var time = direction.Length() / strength;
|
||||
comp.ThrownTime = _gameTiming.CurTime;
|
||||
comp.LandTime = time < FlyTime ? default : comp.ThrownTime + TimeSpan.FromSeconds(time - FlyTime);
|
||||
comp.PlayLandSound = playSound;
|
||||
|
||||
ThrowingAngleComponent? throwingAngle = null;
|
||||
|
||||
// Give it a l'il spin.
|
||||
@@ -134,24 +141,13 @@ public sealed class ThrowingSystem : EntitySystem
|
||||
var impulseVector = direction.Normalized() * strength * physics.Mass;
|
||||
_physics.ApplyLinearImpulse(uid, impulseVector, body: physics);
|
||||
|
||||
// Estimate time to arrival so we can apply OnGround status and slow it much faster.
|
||||
var time = direction.Length() / strength;
|
||||
|
||||
if (time < FlyTime)
|
||||
if (comp.LandTime <= TimeSpan.Zero)
|
||||
{
|
||||
_thrownSystem.LandComponent(uid, comp, physics, playSound);
|
||||
}
|
||||
else
|
||||
{
|
||||
_physics.SetBodyStatus(physics, BodyStatus.InAir);
|
||||
|
||||
Timer.Spawn(TimeSpan.FromSeconds(time - FlyTime), () =>
|
||||
{
|
||||
if (physics.Deleted)
|
||||
return;
|
||||
|
||||
_thrownSystem.LandComponent(uid, comp, physics, playSound);
|
||||
});
|
||||
}
|
||||
|
||||
// Give thrower an impulse in the other direction
|
||||
|
||||
Reference in New Issue
Block a user