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

65 lines
2.1 KiB
C#
Raw Normal View History

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