Adds force-gun (#16561)

This commit is contained in:
metalgearsloth
2023-05-19 17:10:31 +10:00
committed by GitHub
parent eb94a785f9
commit 4efb41aa58
26 changed files with 373 additions and 76 deletions

View File

@@ -3,6 +3,7 @@ using Content.Shared.Interaction;
using Content.Shared.Movement.Components;
using Content.Shared.Projectiles;
using Content.Shared.Tag;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
@@ -25,9 +26,27 @@ public sealed class ThrowingSystem : EntitySystem
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly ThrownItemSystem _thrownSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
public void TryThrow(
EntityUid uid,
EntityCoordinates coordinates,
float strength = 1.0f,
EntityUid? user = null,
float pushbackRatio = PushbackDefault,
bool playSound = true)
{
var thrownPos = Transform(uid).MapPosition;
var mapPos = coordinates.ToMap(EntityManager, _transform);
if (mapPos.MapId != thrownPos.MapId)
return;
TryThrow(uid, mapPos.Position - thrownPos.Position, strength, user, pushbackRatio, playSound);
}
/// <summary>
/// Tries to throw the entity if it has a physics component, otherwise does nothing.
/// </summary>
@@ -39,7 +58,8 @@ public sealed class ThrowingSystem : EntitySystem
Vector2 direction,
float strength = 1.0f,
EntityUid? user = null,
float pushbackRatio = PushbackDefault)
float pushbackRatio = PushbackDefault,
bool playSound = true)
{
var physicsQuery = GetEntityQuery<PhysicsComponent>();
if (!physicsQuery.TryGetComponent(uid, out var physics))
@@ -57,7 +77,8 @@ public sealed class ThrowingSystem : EntitySystem
tagQuery,
strength,
user,
pushbackRatio);
pushbackRatio,
playSound);
}
/// <summary>
@@ -75,7 +96,8 @@ public sealed class ThrowingSystem : EntitySystem
EntityQuery<TagComponent> tagQuery,
float strength = 1.0f,
EntityUid? user = null,
float pushbackRatio = PushbackDefault)
float pushbackRatio = PushbackDefault,
bool playSound = true)
{
if (strength <= 0 || direction == Vector2.Infinity || direction == Vector2.NaN || direction == Vector2.Zero)
return;
@@ -105,11 +127,11 @@ public sealed class ThrowingSystem : EntitySystem
_physics.ApplyLinearImpulse(uid, impulseVector, body: physics);
// Estimate time to arrival so we can apply OnGround status and slow it much faster.
var time = (direction / strength).Length;
var time = direction.Length / strength;
if (time < FlyTime)
{
_thrownSystem.LandComponent(uid, comp, physics);
_thrownSystem.LandComponent(uid, comp, physics, playSound);
}
else
{
@@ -120,7 +142,7 @@ public sealed class ThrowingSystem : EntitySystem
if (physics.Deleted)
return;
_thrownSystem.LandComponent(uid, comp, physics);
_thrownSystem.LandComponent(uid, comp, physics, playSound);
});
}