[Feat&Fix] Система лежания (#288)

* лежать

* лучше так сделать

* - remove: Gravity is fine.

* - add: Hit moving lying targets.

* - tweak: Lie down insted of stun on FTL.

* - fix: Fix double component.

* - remove: Disable recoil.

---------

Co-authored-by: Aviu00 <aviu00@protonmail.com>
This commit is contained in:
Remuchi
2024-04-22 22:14:23 +07:00
committed by GitHub
parent 026ab3b445
commit 9565de0262
30 changed files with 237 additions and 139 deletions

View File

@@ -4,46 +4,17 @@ using Content.Shared.Hands.EntitySystems;
using Content.Shared.Standing;
using Content.Shared.Throwing;
using Content.Shared._White.MagGloves;
using Content.Shared.Standing.Systems;
using Robust.Server.GameObjects;
using Robust.Shared.Physics.Components;
using Robust.Shared.Random;
namespace Content.Server.Standing;
public sealed class StandingStateSystem : EntitySystem
public sealed class StandingStateSystem : SharedStandingStateSystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[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);
var fellEvent = new FellDownEvent(uid);
RaiseLocalEvent(uid, fellEvent, false);
if (!TryComp(uid, out HandsComponent? handsComp))
return;
var worldRotation = EntityManager.GetComponent<TransformComponent>(uid).WorldRotation.ToVec();
foreach (var hand in handsComp.Hands.Values)
{
if (hand.HeldEntity is not EntityUid held)
continue;
if (!HasComp<KeepItemsOnFallComponent>(uid))
{
if (!_handsSystem.TryDrop(uid, hand, null, checkActionBlocker: false, handsComp: handsComp))
continue;
}
_throwingSystem.TryThrow(held,
_random.NextAngle().RotateVec(direction / dropAngle + worldRotation / 50),
0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f),
uid, 0);
}
}
[Dependency] private readonly TransformSystem _transform = default!;
public override void Initialize()
{
@@ -51,16 +22,43 @@ public sealed class StandingStateSystem : EntitySystem
SubscribeLocalEvent<StandingStateComponent, DropHandItemsEvent>(FallOver);
}
}
/// <summary>
/// Raised after an entity falls down.
/// </summary>
public sealed class FellDownEvent : EntityEventArgs
private void FallOver(EntityUid uid, StandingStateComponent component, DropHandItemsEvent args)
{
public EntityUid Uid { get; }
public FellDownEvent(EntityUid uid)
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);
if (!TryComp(uid, out HandsComponent? handsComp))
return;
var worldRotation = _transform.GetWorldRotation(uid).ToVec();
foreach (var hand in handsComp.Hands.Values)
{
Uid = uid;
if (hand.HeldEntity is not { } held)
continue;
if (!HasComp<KeepItemsOnFallComponent>(uid))
{
if (!_handsSystem.TryDrop(uid, hand, checkActionBlocker: false, handsComp: handsComp))
continue;
}
_throwingSystem.TryThrow(held,
Random.NextAngle().RotateVec(direction / dropAngle + worldRotation / 50),
0.5f * dropAngle * Random.NextFloat(-0.9f, 1.1f),
uid, 0);
}
}
}
/// <summary>
/// Raised after an entity falls down.
/// </summary>
public sealed class FellDownEvent(EntityUid uid) : EntityEventArgs
{
public EntityUid Uid { get; } = uid;
}