Adds grappling gun (#16662)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user