Change ThrownItemComponent to be removed after flytime (#20700)

This commit is contained in:
DrSmugleaf
2023-10-06 17:43:54 -07:00
committed by GitHub
parent 6af7c90b73
commit 783ed6f917
4 changed files with 77 additions and 35 deletions

View File

@@ -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