2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2022-03-17 20:13:31 +13:00
|
|
|
using Content.Shared.Hands.Components;
|
|
|
|
|
using Content.Shared.Hands.EntitySystems;
|
2021-11-24 00:38:39 +01:00
|
|
|
using Content.Shared.Standing;
|
2022-03-24 02:33:01 +13:00
|
|
|
using Content.Shared.Throwing;
|
2024-03-21 02:08:17 +02:00
|
|
|
using Content.Shared._White.MagGloves;
|
2024-04-22 22:14:23 +07:00
|
|
|
using Content.Shared.Standing.Systems;
|
|
|
|
|
using Robust.Server.GameObjects;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
2021-11-24 00:38:39 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.Standing;
|
|
|
|
|
|
2024-04-22 22:14:23 +07:00
|
|
|
public sealed class StandingStateSystem : SharedStandingStateSystem
|
2021-11-24 00:38:39 +01:00
|
|
|
{
|
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!;
|
2024-04-22 22:14:23 +07:00
|
|
|
[Dependency] private readonly TransformSystem _transform = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<StandingStateComponent, DropHandItemsEvent>(FallOver);
|
|
|
|
|
}
|
2021-11-24 00:38:39 +01:00
|
|
|
|
|
|
|
|
private void FallOver(EntityUid uid, StandingStateComponent component, DropHandItemsEvent args)
|
|
|
|
|
{
|
2024-04-22 22:14:23 +07:00
|
|
|
var direction = EntityManager.TryGetComponent(uid, out PhysicsComponent? comp)
|
|
|
|
|
? comp.LinearVelocity / 50
|
|
|
|
|
: Vector2.Zero;
|
|
|
|
|
var dropAngle = Random.NextFloat(0.8f, 1.2f);
|
2021-11-24 00:38:39 +01:00
|
|
|
|
2024-06-29 20:03:28 +00:00
|
|
|
// var fellEvent = new FellDownEvent(uid);
|
|
|
|
|
// RaiseLocalEvent(uid, fellEvent);
|
2022-04-23 21:05:02 -04:00
|
|
|
|
2023-04-07 11:21:12 -07:00
|
|
|
if (!TryComp(uid, out HandsComponent? handsComp))
|
2021-12-05 18:09:01 +01:00
|
|
|
return;
|
|
|
|
|
|
2024-04-22 22:14:23 +07:00
|
|
|
var worldRotation = _transform.GetWorldRotation(uid).ToVec();
|
2022-03-17 20:13:31 +13:00
|
|
|
foreach (var hand in handsComp.Hands.Values)
|
2021-11-24 00:38:39 +01:00
|
|
|
{
|
2024-04-22 22:14:23 +07:00
|
|
|
if (hand.HeldEntity is not { } held)
|
2021-12-05 18:09:01 +01:00
|
|
|
continue;
|
|
|
|
|
|
2024-03-21 02:08:17 +02:00
|
|
|
if (!HasComp<KeepItemsOnFallComponent>(uid))
|
|
|
|
|
{
|
2024-04-22 22:14:23 +07:00
|
|
|
if (!_handsSystem.TryDrop(uid, hand, checkActionBlocker: false, handsComp: handsComp))
|
2024-03-21 02:08:17 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-03-24 02:33:01 +13:00
|
|
|
|
|
|
|
|
_throwingSystem.TryThrow(held,
|
2024-04-22 22:14:23 +07:00
|
|
|
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);
|
2021-11-24 00:38:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-23 21:05:02 -04:00
|
|
|
|
2024-04-22 22:14:23 +07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Raised after an entity falls down.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class FellDownEvent(EntityUid uid) : EntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
public EntityUid Uid { get; } = uid;
|
2024-06-29 20:03:28 +00:00
|
|
|
}
|