@@ -15,10 +15,12 @@ using Content.Shared.Movement.Pulling.Components;
|
||||
using Content.Shared.Movement.Pulling.Events;
|
||||
using Content.Shared.Movement.Pulling.Systems;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -53,6 +55,8 @@ namespace Content.Server.Hands.Systems
|
||||
|
||||
SubscribeLocalEvent<HandsComponent, BeforeExplodeEvent>(OnExploded);
|
||||
|
||||
SubscribeLocalEvent<HandsComponent, DropHandItemsEvent>(OnDropHandItems);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
|
||||
.Register<HandsSystem>();
|
||||
@@ -228,6 +232,36 @@ namespace Content.Server.Hands.Systems
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,15 +1,14 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Rotation;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Physics;
|
||||
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 SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
@@ -49,7 +48,8 @@ namespace Content.Shared.Standing
|
||||
// and ultimately this is just to avoid boilerplate in Down callers + keep their behavior consistent.
|
||||
if (dropHeldItems && hands != null)
|
||||
{
|
||||
RaiseLocalEvent(uid, new DropHandItemsEvent(), false);
|
||||
var ev = new DropHandItemsEvent();
|
||||
RaiseLocalEvent(uid, ref ev, false);
|
||||
}
|
||||
|
||||
if (!force)
|
||||
@@ -136,37 +136,56 @@ namespace Content.Shared.Standing
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DropHandItemsEvent : EventArgs
|
||||
{
|
||||
}
|
||||
[ByRefEvent]
|
||||
public record struct DropHandItemsEvent();
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a down attempt.
|
||||
/// </summary>
|
||||
public sealed class DownAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a down attempt.
|
||||
/// </summary>
|
||||
public sealed class DownAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a stand attempt.
|
||||
/// </summary>
|
||||
public sealed class StandAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Subscribe if you can potentially block a stand attempt.
|
||||
/// </summary>
|
||||
public sealed class StandAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an entity becomes standing
|
||||
/// </summary>
|
||||
public sealed class StoodEvent : EntityEventArgs
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Raised when an entity becomes standing
|
||||
/// </summary>
|
||||
public sealed class StoodEvent : EntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an entity is not standing
|
||||
/// </summary>
|
||||
public sealed class DownedEvent : EntityEventArgs
|
||||
/// <summary>
|
||||
/// Raised when an entity is not standing
|
||||
/// </summary>
|
||||
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