]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make projectiles not hit crates unless clicked on (#28072)
authorCojoke <83733158+Cojoke-dot@users.noreply.github.com>
Mon, 3 Jun 2024 13:04:07 +0000 (08:04 -0500)
committerGitHub <noreply@github.com>
Mon, 3 Jun 2024 13:04:07 +0000 (09:04 -0400)
Content.Shared/Damage/Components/RequireProjectileTargetComponent.cs [new file with mode: 0644]
Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs [new file with mode: 0644]
Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Resources/Prototypes/Entities/Mobs/base.yml
Resources/Prototypes/Entities/Structures/Storage/Crates/base_structurecrates.yml

diff --git a/Content.Shared/Damage/Components/RequireProjectileTargetComponent.cs b/Content.Shared/Damage/Components/RequireProjectileTargetComponent.cs
new file mode 100644 (file)
index 0000000..5bd8292
--- /dev/null
@@ -0,0 +1,14 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Damage.Components;
+
+/// <summary>
+/// Prevent the object from getting hit by projetiles unless you target the object.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(RequireProjectileTargetSystem))]
+public sealed partial class RequireProjectileTargetComponent : Component
+{
+    [DataField, AutoNetworkedField]
+    public bool Active = true;
+}
diff --git a/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs b/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs
new file mode 100644 (file)
index 0000000..79b374a
--- /dev/null
@@ -0,0 +1,51 @@
+using Content.Shared.Projectiles;
+using Content.Shared.Weapons.Ranged.Components;
+using Content.Shared.Standing;
+using Robust.Shared.Physics.Events;
+
+namespace Content.Shared.Damage.Components;
+
+public sealed class RequireProjectileTargetSystem : EntitySystem
+{
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<RequireProjectileTargetComponent, PreventCollideEvent>(PreventCollide);
+        SubscribeLocalEvent<RequireProjectileTargetComponent, StoodEvent>(StandingBulletHit);
+        SubscribeLocalEvent<RequireProjectileTargetComponent, DownedEvent>(LayingBulletPass);
+    }
+
+    private void PreventCollide(Entity<RequireProjectileTargetComponent> ent, ref PreventCollideEvent args)
+    {
+        if (args.Cancelled)
+          return;
+
+        if (!ent.Comp.Active)
+            return;
+
+        var other = args.OtherEntity;
+        if (HasComp<ProjectileComponent>(other) &&
+            CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
+        {
+            args.Cancelled = true;
+        }
+    }
+
+    private void SetActive(Entity<RequireProjectileTargetComponent> ent, bool value)
+    {
+        if (ent.Comp.Active == value)
+            return;
+
+        ent.Comp.Active = value;
+        Dirty(ent);
+    }
+
+    private void StandingBulletHit(Entity<RequireProjectileTargetComponent> ent, ref StoodEvent args)
+    {
+        SetActive(ent, false);
+    }
+
+    private void LayingBulletPass(Entity<RequireProjectileTargetComponent> ent, ref DownedEvent args)
+    {
+        SetActive(ent, true);
+    }
+}
index ee747554e14bdc70db441e8adc8f97d3bb7d0374..08b351e61e85e7221dbf281bea1166d4d5e8c2a2 100644 (file)
@@ -46,7 +46,6 @@ public partial class MobStateSystem
         SubscribeLocalEvent<MobStateComponent, TryingToSleepEvent>(OnSleepAttempt);
         SubscribeLocalEvent<MobStateComponent, CombatModeShouldHandInteractEvent>(OnCombatModeShouldHandInteract);
         SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
-        SubscribeLocalEvent<MobStateComponent, PreventCollideEvent>(OnPreventCollide);
     }
 
     private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
@@ -179,21 +178,5 @@ public partial class MobStateSystem
         args.Cancelled = true;
     }
 
-    private void OnPreventCollide(Entity<MobStateComponent> ent, ref PreventCollideEvent args)
-    {
-        if (args.Cancelled)
-            return;
-
-        if (IsAlive(ent, ent))
-            return;
-
-        var other = args.OtherEntity;
-        if (HasComp<ProjectileComponent>(other) &&
-            CompOrNull<TargetedProjectileComponent>(other)?.Target != ent.Owner)
-        {
-            args.Cancelled = true;
-        }
-    }
-
     #endregion
 }
index 0a2b68d0a1dadec0fefbe711436843baa9546a38..fae47113107d8c5a98e95f47d7cebb538247eaa2 100644 (file)
@@ -1,4 +1,4 @@
-# The progenitor. This should only container the most basic components possible.
+# The progenitor. This should only container the most basic components possible.
 # Only put things on here if every mob *must* have it. This includes ghosts.
 - type: entity
   save: false
@@ -43,6 +43,8 @@
   - type: MovementSpeedModifier
   - type: Polymorphable
   - type: StatusIcon
+  - type: RequireProjectileTarget
+    active: False
 
 # Used for mobs that have health and can take damage.
 - type: entity
index 2d84541231eb3d5f0259f79e9e8f19ae7ab03f0a..01c226cb0fd064b0e3320010e9cf01b2e4bcc875 100644 (file)
@@ -89,6 +89,7 @@
     node: crategenericsteel
     containers:
       - entity_storage
+  - type: RequireProjectileTarget
 
 - type: entity
   parent: CrateGeneric