]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow PKA to gather (#16250)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Thu, 11 May 2023 13:19:08 +0000 (23:19 +1000)
committerGitHub <noreply@github.com>
Thu, 11 May 2023 13:19:08 +0000 (23:19 +1000)
Content.Server/Gatherable/Components/GatheringProjectileComponent.cs [new file with mode: 0644]
Content.Server/Gatherable/GatherableSystem.Projectile.cs [new file with mode: 0644]
Content.Server/Gatherable/GatherableSystem.cs
Content.Shared/Destructible/SharedDestructibleSystem.cs
Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml

diff --git a/Content.Server/Gatherable/Components/GatheringProjectileComponent.cs b/Content.Server/Gatherable/Components/GatheringProjectileComponent.cs
new file mode 100644 (file)
index 0000000..88388c7
--- /dev/null
@@ -0,0 +1,10 @@
+namespace Content.Server.Gatherable.Components;
+
+/// <summary>
+/// Destroys a gatherable entity when colliding with it.
+/// </summary>
+[RegisterComponent]
+public sealed class GatheringProjectileComponent : Component
+{
+
+}
diff --git a/Content.Server/Gatherable/GatherableSystem.Projectile.cs b/Content.Server/Gatherable/GatherableSystem.Projectile.cs
new file mode 100644 (file)
index 0000000..62417bc
--- /dev/null
@@ -0,0 +1,28 @@
+using Content.Server.Gatherable.Components;
+using Content.Server.Projectiles;
+using Content.Shared.Projectiles;
+using Content.Shared.Weapons.Ranged.Systems;
+using Robust.Shared.Physics.Events;
+
+namespace Content.Server.Gatherable;
+
+public sealed partial class GatherableSystem
+{
+    private void InitializeProjectile()
+    {
+        SubscribeLocalEvent<GatheringProjectileComponent, StartCollideEvent>(OnProjectileCollide);
+    }
+
+    private void OnProjectileCollide(EntityUid uid, GatheringProjectileComponent component, ref StartCollideEvent args)
+    {
+        if (!args.OtherFixture.Hard ||
+            args.OurFixture.ID != SharedProjectileSystem.ProjectileFixture ||
+            !TryComp<GatherableComponent>(args.OtherEntity, out var gatherable))
+        {
+            return;
+        }
+
+        Gather(args.OtherEntity, uid, gatherable);
+        QueueDel(uid);
+    }
+}
index 0aa8c256f857802e250d7cc9819ab644ed200587..b9a375d28466039dc3e45e0bbaaefb22a468ed8e 100644 (file)
@@ -5,18 +5,20 @@ using Content.Shared.EntityList;
 using Content.Shared.Gatherable;
 using Content.Shared.Interaction;
 using Content.Shared.Tag;
+using Robust.Shared.Audio;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
 
 namespace Content.Server.Gatherable;
 
-public sealed class GatherableSystem : EntitySystem
+public sealed partial class GatherableSystem : EntitySystem
 {
     [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly DestructibleSystem _destructible = default!;
     [Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
+    [Dependency] private readonly SharedTransformSystem _transform = default!;
     [Dependency] private readonly TagSystem _tagSystem = default!;
 
     public override void Initialize()
@@ -25,6 +27,7 @@ public sealed class GatherableSystem : EntitySystem
 
         SubscribeLocalEvent<GatherableComponent, InteractUsingEvent>(OnInteractUsing);
         SubscribeLocalEvent<GatherableComponent, GatherableDoAfterEvent>(OnDoAfter);
+        InitializeProjectile();
     }
 
     private void OnInteractUsing(EntityUid uid, GatherableComponent component, InteractUsingEvent args)
@@ -53,36 +56,44 @@ public sealed class GatherableSystem : EntitySystem
 
     private void OnDoAfter(EntityUid uid, GatherableComponent component, GatherableDoAfterEvent args)
     {
-        if(!TryComp<GatheringToolComponent>(args.Args.Used, out var tool) || args.Args.Target == null)
+        if(!TryComp<GatheringToolComponent>(args.Args.Used, out var tool))
             return;
 
-        tool.GatheringEntities.Remove(args.Args.Target.Value);
+        tool.GatheringEntities.Remove(uid);
         if (args.Handled || args.Cancelled)
             return;
 
+        Gather(uid, args.Args.Used, component, tool.GatheringSound);
+        args.Handled = true;
+    }
+
+    public void Gather(EntityUid gatheredUid, EntityUid? gatherer = null, GatherableComponent? component = null, SoundSpecifier? sound = null)
+    {
+        if (!Resolve(gatheredUid, ref component))
+            return;
+
         // Complete the gathering process
-        _destructible.DestroyEntity(args.Args.Target.Value);
-        _audio.PlayPvs(tool.GatheringSound, args.Args.Target.Value);
+        _destructible.DestroyEntity(gatheredUid);
+        _audio.PlayPvs(sound, gatheredUid);
 
         // Spawn the loot!
         if (component.MappedLoot == null)
             return;
 
-        var playerPos = Transform(args.Args.User).MapPosition;
+        var pos = Transform(gatheredUid).MapPosition;
 
         foreach (var (tag, table) in component.MappedLoot)
         {
             if (tag != "All")
             {
-                if (!_tagSystem.HasTag(tool.Owner, tag))
+                if (gatherer != null && !_tagSystem.HasTag(gatherer.Value, tag))
                     continue;
             }
             var getLoot = _prototypeManager.Index<EntityLootTablePrototype>(table);
             var spawnLoot = getLoot.GetSpawns();
-            var spawnPos = playerPos.Offset(_random.NextVector2(0.3f));
+            var spawnPos = pos.Offset(_random.NextVector2(0.3f));
             Spawn(spawnLoot[0], spawnPos);
         }
-        args.Handled = true;
     }
 }
 
index b16ededbe74fdc7e3940545c3ec1c868425ccf90..b16009e1981dde0f982d5b160d8c83f60170c0e0 100644 (file)
@@ -9,7 +9,7 @@ public abstract class SharedDestructibleSystem : EntitySystem
     {
         var eventArgs = new DestructionEventArgs();
 
-        RaiseLocalEvent(owner, eventArgs, false);
+        RaiseLocalEvent(owner, eventArgs);
         QueueDel(owner);
     }
 
@@ -19,7 +19,7 @@ public abstract class SharedDestructibleSystem : EntitySystem
     public void BreakEntity(EntityUid owner)
     {
         var eventArgs = new BreakageEventArgs();
-        RaiseLocalEvent(owner, eventArgs, false);
+        RaiseLocalEvent(owner, eventArgs);
     }
 }
 
index 642b4f8d0bd9eae288aa88ac8af5d765dc5de383..796383f0fcd938a2c830247838285f2c236c6ce5 100644 (file)
   description: Not too bad, but you still don't want to get hit by it.
   components:
   - type: Sprite
-    netsync: false
     noRot: false
     sprite: Objects/Weapons/Guns/Projectiles/magic.rsi
     layers:
     - state: chronobolt
       shader: unshaded
+  - type: GatheringProjectile
   - type: Projectile
     impactEffect: BulletImpactEffectKinetic
     damage: