@@ -15,10 +15,12 @@ using Content.Shared.Movement.Pulling.Components;
|
|||||||
using Content.Shared.Movement.Pulling.Events;
|
using Content.Shared.Movement.Pulling.Events;
|
||||||
using Content.Shared.Movement.Pulling.Systems;
|
using Content.Shared.Movement.Pulling.Systems;
|
||||||
using Content.Shared.Stacks;
|
using Content.Shared.Stacks;
|
||||||
|
using Content.Shared.Standing;
|
||||||
using Content.Shared.Throwing;
|
using Content.Shared.Throwing;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Input.Binding;
|
using Robust.Shared.Input.Binding;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
@@ -53,6 +55,8 @@ namespace Content.Server.Hands.Systems
|
|||||||
|
|
||||||
SubscribeLocalEvent<HandsComponent, BeforeExplodeEvent>(OnExploded);
|
SubscribeLocalEvent<HandsComponent, BeforeExplodeEvent>(OnExploded);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<HandsComponent, DropHandItemsEvent>(OnDropHandItems);
|
||||||
|
|
||||||
CommandBinds.Builder
|
CommandBinds.Builder
|
||||||
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
|
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
|
||||||
.Register<HandsSystem>();
|
.Register<HandsSystem>();
|
||||||
@@ -228,6 +232,36 @@ namespace Content.Server.Hands.Systems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDropHandItems(Entity<HandsComponent> entity, ref DropHandItemsEvent args)
|
||||||
|
{
|
||||||
|
var direction = EntityManager.TryGetComponent(entity, out PhysicsComponent? comp) ? comp.LinearVelocity / 50 : Vector2.Zero;
|
||||||
|
var dropAngle = _random.NextFloat(0.8f, 1.2f);
|
||||||
|
|
||||||
|
var fellEvent = new FellDownEvent(entity);
|
||||||
|
RaiseLocalEvent(entity, fellEvent, false);
|
||||||
|
|
||||||
|
var worldRotation = TransformSystem.GetWorldRotation(entity).ToVec();
|
||||||
|
foreach (var hand in entity.Comp.Hands.Values)
|
||||||
|
{
|
||||||
|
if (hand.HeldEntity is not EntityUid held)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var throwAttempt = new FellDownThrowAttemptEvent(entity);
|
||||||
|
RaiseLocalEvent(hand.HeldEntity.Value, ref throwAttempt);
|
||||||
|
|
||||||
|
if (throwAttempt.Cancelled)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!TryDrop(entity, hand, null, checkActionBlocker: false, handsComp: entity.Comp))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
_throwingSystem.TryThrow(held,
|
||||||
|
_random.NextAngle().RotateVec(direction / dropAngle + worldRotation / 50),
|
||||||
|
0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f),
|
||||||
|
entity, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
using System.Numerics;
|
|
||||||
using Content.Shared.Hands.Components;
|
|
||||||
using Content.Shared.Hands.EntitySystems;
|
|
||||||
using Content.Shared.Standing;
|
|
||||||
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!;
|
|
||||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
|
||||||
[Dependency] private readonly ThrowingSystem _throwingSystem = default!;
|
|
||||||
[Dependency] private readonly SharedTransformSystem _transformSystem = 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 = _transformSystem.GetWorldRotation(uid).ToVec();
|
|
||||||
foreach (var hand in handsComp.Hands.Values)
|
|
||||||
{
|
|
||||||
if (hand.HeldEntity is not EntityUid held)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
SubscribeLocalEvent<StandingStateComponent, DropHandItemsEvent>(FallOver);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Raised after an entity falls down.
|
|
||||||
/// </summary>
|
|
||||||
public sealed class FellDownEvent : EntityEventArgs
|
|
||||||
{
|
|
||||||
public EntityUid Uid { get; }
|
|
||||||
public FellDownEvent(EntityUid uid)
|
|
||||||
{
|
|
||||||
Uid = uid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
using Content.Shared.Hands.Components;
|
using Content.Shared.Hands.Components;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Content.Shared.Rotation;
|
using Content.Shared.Rotation;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
|
|
||||||
namespace Content.Shared.Standing
|
namespace Content.Shared.Standing;
|
||||||
{
|
|
||||||
public sealed class StandingStateSystem : EntitySystem
|
public sealed class StandingStateSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
@@ -49,7 +48,8 @@ namespace Content.Shared.Standing
|
|||||||
// and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
|
// and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
|
||||||
if (dropHeldItems && hands != null)
|
if (dropHeldItems && hands != null)
|
||||||
{
|
{
|
||||||
RaiseLocalEvent(uid, new DropHandItemsEvent(), false);
|
var ev = new DropHandItemsEvent();
|
||||||
|
RaiseLocalEvent(uid, ref ev, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!force)
|
if (!force)
|
||||||
@@ -138,9 +138,8 @@ namespace Content.Shared.Standing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class DropHandItemsEvent : EventArgs
|
[ByRefEvent]
|
||||||
{
|
public record struct DropHandItemsEvent();
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Subscribe if you can potentially block a down attempt.
|
/// Subscribe if you can potentially block a down attempt.
|
||||||
@@ -169,4 +168,24 @@ namespace Content.Shared.Standing
|
|||||||
public sealed class DownedEvent : EntityEventArgs
|
public sealed class DownedEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised after an entity falls down.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class FellDownEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public EntityUid Uid { get; }
|
||||||
|
|
||||||
|
public FellDownEvent(EntityUid uid)
|
||||||
|
{
|
||||||
|
Uid = uid;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised on the entity being thrown due to the holder falling down.
|
||||||
|
/// </summary>
|
||||||
|
[ByRefEvent]
|
||||||
|
public record struct FellDownThrowAttemptEvent(EntityUid Thrower, bool Cancelled = false);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user