Refactor slip dropping to use throwing (#5476)

* Refactor slip dropping to use throwing

* Update Content.Server/Fluids/EntitySystems/SpillableSystem.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Uncringe

* Update Content.Server/Fluids/EntitySystems/SpillableSystem.cs

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
Clyybber
2021-11-24 00:38:39 +01:00
committed by GitHub
parent ee27c75224
commit 0e98c1c524
10 changed files with 113 additions and 121 deletions

View File

@@ -0,0 +1,41 @@
using Content.Server.Hands.Components;
using Content.Shared.Standing;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Random;
namespace Content.Server.Standing;
public class StandingStateSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
private void FallOver(EntityUid uid, StandingStateComponent component, DropHandItemsEvent args)
{
var direction = EntityManager.TryGetComponent(uid, out PhysicsComponent? comp) ? comp.LinearVelocity / 50 : Vector2.Zero;
var dropAngle = _random.NextFloat(0.8f, 1.2f);
if (EntityManager.TryGetComponent(uid, out HandsComponent? hands))
{
foreach (var heldItem in hands.GetAllHeldItems())
{
if (hands.Drop(heldItem.Owner))
{
Throwing.ThrowHelper.TryThrow(heldItem.Owner,
_random.NextAngle().RotateVec(direction / dropAngle +
EntityManager.GetEntity(uid).Transform.WorldRotation.ToVec() / 50),
0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f),
EntityManager.GetEntity(uid), 0);
}
}
}
}
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StandingStateComponent, DropHandItemsEvent>(FallOver);
}
}