Adds grappling gun (#16662)

This commit is contained in:
metalgearsloth
2023-05-27 14:15:15 +10:00
committed by GitHub
parent 9eb4d4edb0
commit 552fbb0585
48 changed files with 753 additions and 35 deletions

View File

@@ -1,6 +1,9 @@
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Events;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Serialization;
namespace Content.Shared.Projectiles
@@ -9,10 +12,26 @@ namespace Content.Shared.Projectiles
{
public const string ProjectileFixture = "projectile";
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ProjectileComponent, PreventCollideEvent>(PreventCollision);
SubscribeLocalEvent<EmbeddableProjectileComponent, StartCollideEvent>(OnEmbedCollide);
}
private void OnEmbedCollide(EntityUid uid, EmbeddableProjectileComponent component, ref StartCollideEvent args)
{
if (!TryComp<ProjectileComponent>(uid, out var projectile))
return;
_physics.SetLinearVelocity(uid, Vector2.Zero, body: args.OurBody);
_physics.SetBodyType(uid, BodyType.Static, body: args.OurBody);
_transform.SetParent(uid, args.OtherEntity);
var ev = new ProjectileEmbedEvent(projectile.Shooter, projectile.Weapon, args.OtherEntity);
RaiseLocalEvent(uid, ref ev);
}
private void PreventCollision(EntityUid uid, ProjectileComponent component, ref PreventCollideEvent args)
@@ -25,7 +44,8 @@ namespace Content.Shared.Projectiles
public void SetShooter(ProjectileComponent component, EntityUid uid)
{
if (component.Shooter == uid) return;
if (component.Shooter == uid)
return;
component.Shooter = uid;
Dirty(component);