Files
OldThink/Content.Server/Standing/StandingStateSystem.cs

62 lines
2.0 KiB
C#
Raw Normal View History

2022-03-17 20:13:31 +13:00
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Standing;
2022-03-24 02:33:01 +13:00
using Content.Shared.Throwing;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;
namespace Content.Server.Standing;
public sealed class StandingStateSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
2022-03-17 20:13:31 +13:00
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
2022-03-24 02:33:01 +13:00
[Dependency] private readonly ThrowingSystem _throwingSystem = 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);
2022-04-23 21:05:02 -04:00
var fellEvent = new FellDownEvent(uid);
RaiseLocalEvent(uid, fellEvent, false);
if (!TryComp(uid, out HandsComponent? handsComp))
2021-12-05 18:09:01 +01:00
return;
2022-03-17 20:13:31 +13:00
var worldRotation = EntityManager.GetComponent<TransformComponent>(uid).WorldRotation.ToVec();
foreach (var hand in handsComp.Hands.Values)
{
2022-03-17 20:13:31 +13:00
if (hand.HeldEntity is not EntityUid held)
2021-12-05 18:09:01 +01:00
continue;
2022-03-17 20:13:31 +13:00
if (!_handsSystem.TryDrop(uid, hand, null, checkActionBlocker: false, handsComp: handsComp))
continue;
2022-03-24 02:33:01 +13:00
_throwingSystem.TryThrow(held,
2021-12-05 18:09:01 +01:00
_random.NextAngle().RotateVec(direction / dropAngle + worldRotation / 50),
0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f),
uid, 0);
}
}
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StandingStateComponent, DropHandItemsEvent>(FallOver);
}
}
2022-04-23 21:05:02 -04:00
/// <summary>
/// Raised after an entity falls down.
/// </summary>
2022-04-23 21:05:02 -04:00
public sealed class FellDownEvent : EntityEventArgs
{
public EntityUid Uid { get; }
public FellDownEvent(EntityUid uid)
{
Uid = uid;
}
}