]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make projectiles not hit crit mobs unless clicked on (#27905)
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Sat, 11 May 2024 15:42:11 +0000 (08:42 -0700)
committerGitHub <noreply@github.com>
Sat, 11 May 2024 15:42:11 +0000 (11:42 -0400)
Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Content.Shared/Weapons/Ranged/Components/GunComponent.cs
Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs [new file with mode: 0644]
Content.Shared/Weapons/Ranged/Events/RequestShootEvent.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs

index 5aba04bdf8a826d35e647a49fa6cdcb0d42ad02b..4a7711032e4ecc60a12fee8b7d7b40166847cb88 100644 (file)
@@ -1,5 +1,6 @@
 using System.Numerics;
 using Content.Client.Animations;
+using Content.Client.Gameplay;
 using Content.Client.Items;
 using Content.Client.Weapons.Ranged.Components;
 using Content.Shared.Camera;
@@ -13,6 +14,7 @@ using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
 using Robust.Client.Input;
 using Robust.Client.Player;
+using Robust.Client.State;
 using Robust.Shared.Animations;
 using Robust.Shared.Input;
 using Robust.Shared.Map;
@@ -30,6 +32,7 @@ public sealed partial class GunSystem : SharedGunSystem
     [Dependency] private readonly IEyeManager _eyeManager = default!;
     [Dependency] private readonly IInputManager _inputManager = default!;
     [Dependency] private readonly IPlayerManager _player = default!;
+    [Dependency] private readonly IStateManager _state = default!;
     [Dependency] private readonly AnimationPlayerSystem _animPlayer = default!;
     [Dependency] private readonly InputSystem _inputSystem = default!;
     [Dependency] private readonly SharedCameraRecoilSystem _recoil = default!;
@@ -174,10 +177,15 @@ public sealed partial class GunSystem : SharedGunSystem
         // Define target coordinates relative to gun entity, so that network latency on moving grids doesn't fuck up the target location.
         var coordinates = EntityCoordinates.FromMap(entity, mousePos, TransformSystem, EntityManager);
 
+        NetEntity? target = null;
+        if (_state.CurrentState is GameplayStateBase screen)
+            target = GetNetEntity(screen.GetClickedEntity(mousePos));
+
         Log.Debug($"Sending shoot request tick {Timing.CurTick} / {Timing.CurTime}");
 
         EntityManager.RaisePredictiveEvent(new RequestShootEvent
         {
+            Target = target,
             Coordinates = GetNetCoordinates(coordinates),
             Gun = GetNetEntity(gunUid),
         });
index f495f29e4aebf970acc527060f95a2a840b9d474..986cac98ddf4b748e6bd021e7e4fbf677cd027b3 100644 (file)
@@ -278,6 +278,13 @@ public sealed partial class GunSystem : SharedGunSystem
 
     private void ShootOrThrow(EntityUid uid, Vector2 mapDirection, Vector2 gunVelocity, GunComponent gun, EntityUid gunUid, EntityUid? user)
     {
+        if (gun.Target is { } target && !TerminatingOrDeleted(target))
+        {
+            var targeted = EnsureComp<TargetedProjectileComponent>(uid);
+            targeted.Target = target;
+            Dirty(uid, targeted);
+        }
+
         // Do a throw
         if (!HasComp<ProjectileComponent>(uid))
         {
index 0c2fcc057945eca93c1cc97ef9ac710a5b2b7d4c..ee747554e14bdc70db441e8adc8f97d3bb7d0374 100644 (file)
@@ -10,12 +10,15 @@ using Content.Shared.Item;
 using Content.Shared.Mobs.Components;
 using Content.Shared.Movement.Events;
 using Content.Shared.Pointing;
+using Content.Shared.Projectiles;
 using Content.Shared.Pulling.Events;
 using Content.Shared.Speech;
 using Content.Shared.Standing;
 using Content.Shared.Strip.Components;
 using Content.Shared.Throwing;
+using Content.Shared.Weapons.Ranged.Components;
 using Robust.Shared.Physics.Components;
+using Robust.Shared.Physics.Events;
 
 namespace Content.Shared.Mobs.Systems;
 
@@ -43,6 +46,7 @@ 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)
@@ -175,5 +179,21 @@ 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 5a335e7e5c72e862ee5319ea02364ff7554537fd..b404221abfc731473ac7a0b8c00e3532a6061857 100644 (file)
@@ -1,5 +1,3 @@
-using Content.Shared.Damage;
-using Content.Shared.Tag;
 using Content.Shared.Weapons.Ranged.Events;
 using Content.Shared.Weapons.Ranged.Systems;
 using Robust.Shared.Audio;
@@ -139,6 +137,12 @@ public sealed partial class GunComponent : Component
     [ViewVariables]
     public EntityCoordinates? ShootCoordinates = null;
 
+    /// <summary>
+    /// Who the gun is being requested to shoot at directly.
+    /// </summary>
+    [ViewVariables]
+    public EntityUid? Target = null;
+
     /// <summary>
     ///     The base value for how many shots to fire per burst.
     /// </summary>
diff --git a/Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs b/Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs
new file mode 100644 (file)
index 0000000..b804176
--- /dev/null
@@ -0,0 +1,12 @@
+using Content.Shared.Weapons.Ranged.Systems;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Weapons.Ranged.Components;
+
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(SharedGunSystem))]
+public sealed partial class TargetedProjectileComponent : Component
+{
+    [DataField, AutoNetworkedField]
+    public EntityUid Target;
+}
index 21e90b2108b920356c72ef5329b5ed2c89f7c05a..f5c4dd72b4f977e2870cfc693a3973efd49b6eef 100644 (file)
@@ -11,4 +11,5 @@ public sealed class RequestShootEvent : EntityEventArgs
 {
     public NetEntity Gun;
     public NetCoordinates Coordinates;
+    public NetEntity? Target;
 }
index 51e2e1358fdb6b3b411a7ee5bfa46cd074760458..4e51ca2b62dcb17a695bae56984d37b38e2e3f7c 100644 (file)
@@ -136,6 +136,7 @@ public abstract partial class SharedGunSystem : EntitySystem
             return;
 
         gun.ShootCoordinates = GetCoordinates(msg.Coordinates);
+        gun.Target = GetEntity(msg.Target);
         AttemptShoot(user.Value, ent, gun);
     }
 
@@ -196,6 +197,7 @@ public abstract partial class SharedGunSystem : EntitySystem
 
         gun.ShotCounter = 0;
         gun.ShootCoordinates = null;
+        gun.Target = null;
         Dirty(uid, gun);
     }