From 61af74c40e2da9e4d09951f5c147a8f5761164c8 Mon Sep 17 00:00:00 2001 From: Lyndomen <49795619+Lyndomen@users.noreply.github.com> Date: Thu, 6 Feb 2025 14:57:11 -0500 Subject: [PATCH] Turrets and grenades can hit prone people [port] (#2910) * ranged ai targets crawling people properly (cherry picked from commit 8f64627c9e35b3c873a7825f25b52319ff8c8e25) * ranged ai targets crawling people properly (cherry picked from commit 8f64627c9e35b3c873a7825f25b52319ff8c8e25) * projectile grenades hit crawling/downed people (cherry picked from commit 24c3737ae83ab399add28162a65d528d44f73ea9) * change * impstation to imp * remove extra method ops --------- Co-authored-by: Darkmajia --- .../Explosion/EntitySystems/ProjectileGrenadeSystem.cs | 2 ++ Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs | 1 + .../Damage/Systems/RequireProjectileTargetSystem.cs | 8 ++++++-- .../Ranged/Components/TargetedProjectileComponent.cs | 2 +- Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs | 8 ++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Content.Server/Explosion/EntitySystems/ProjectileGrenadeSystem.cs b/Content.Server/Explosion/EntitySystems/ProjectileGrenadeSystem.cs index 555ce3399e..29aa30313b 100644 --- a/Content.Server/Explosion/EntitySystems/ProjectileGrenadeSystem.cs +++ b/Content.Server/Explosion/EntitySystems/ProjectileGrenadeSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Explosion.Components; using Content.Server.Weapons.Ranged.Systems; +using Content.Shared.Weapons.Ranged.Components; // Imp using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.Map; @@ -77,6 +78,7 @@ public sealed class ProjectileGrenadeSystem : EntitySystem // slightly uneven, doesn't really change much, but it looks better var direction = angle.ToVec().Normalized(); var velocity = _random.NextVector2(component.MinVelocity, component.MaxVelocity); + EnsureComp(contentUid); // imp - ensure projectile is a TargetedProjectile with no target to hit crawling players _gun.ShootProjectile(contentUid, direction, velocity, uid, null); } } diff --git a/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs b/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs index d7196ea73c..227ffb8afc 100644 --- a/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs +++ b/Content.Server/NPC/Systems/NPCCombatSystem.Ranged.cs @@ -202,6 +202,7 @@ public sealed partial class NPCCombatSystem return; } + _gun.SetTarget(gun, comp.Target); // Imp _gun.AttemptShoot(uid, gunUid, gun, targetCordinates); } } diff --git a/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs b/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs index 66b1de65e8..bb75cb5570 100644 --- a/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs +++ b/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs @@ -26,8 +26,12 @@ public sealed class RequireProjectileTargetSystem : EntitySystem return; var other = args.OtherEntity; - if (TryComp(other, out ProjectileComponent? projectile) && - CompOrNull(other)?.Target != ent) + + if (TryComp(other, out TargetedProjectileComponent? targeted) && // Imp + (targeted.Target == null || targeted.Target == ent)) + return; + + if (TryComp(other, out ProjectileComponent? projectile)) { // Prevents shooting out of while inside of crates var shooter = projectile.Shooter; diff --git a/Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs b/Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs index b804176497..c136aafb65 100644 --- a/Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/TargetedProjectileComponent.cs @@ -8,5 +8,5 @@ namespace Content.Shared.Weapons.Ranged.Components; public sealed partial class TargetedProjectileComponent : Component { [DataField, AutoNetworkedField] - public EntityUid Target; + public EntityUid? Target; // Imp } diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index d6abc970b1..8524916172 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -207,6 +207,14 @@ public abstract partial class SharedGunSystem : EntitySystem EntityManager.DirtyField(uid, gun, nameof(GunComponent.ShotCounter)); } + /// + /// Sets the targeted entity of the gun. Should be called before attempting to shoot to avoid shooting over the target. + /// + public void SetTarget(GunComponent gun, EntityUid target) // Imp + { + gun.Target = target; + } + /// /// Attempts to shoot at the target coordinates. Resets the shot counter after every shot. ///