diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index 7f7c7ba8557403..29f91988182f11 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -24,6 +24,7 @@ using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Utility; +using Robust.Shared.Containers; namespace Content.Server.Weapons.Ranged.Systems; @@ -38,6 +39,7 @@ public sealed partial class GunSystem : SharedGunSystem [Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly StaminaSystem _stamina = default!; [Dependency] private readonly StunSystem _stun = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; private const float DamagePitchVariation = 0.05f; public const float GunClumsyChance = 0.5f; @@ -204,17 +206,21 @@ public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid? var result = rayCastResults[0]; - // Checks if the laser should pass over unless targeted by its user - foreach (var collide in rayCastResults) + // Check if laser is shot from in a container + if (!_container.IsEntityOrParentInContainer(lastUser)) { - if (collide.HitEntity != gun.Target && - CompOrNull(collide.HitEntity)?.Active == true) + // Checks if the laser should pass over unless targeted by its user + foreach (var collide in rayCastResults) { - continue; + if (collide.HitEntity != gun.Target && + CompOrNull(collide.HitEntity)?.Active == true) + { + continue; + } + + result = collide; + break; } - - result = collide; - break; } var hit = result.HitEntity; diff --git a/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs b/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs index 79b374a60f35d0..12838eb04d9b87 100644 --- a/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs +++ b/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs @@ -2,11 +2,14 @@ using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Standing; using Robust.Shared.Physics.Events; +using Robust.Shared.Containers; namespace Content.Shared.Damage.Components; public sealed class RequireProjectileTargetSystem : EntitySystem { + [Dependency] private readonly SharedContainerSystem _container = default!; + public override void Initialize() { SubscribeLocalEvent(PreventCollide); @@ -23,10 +26,16 @@ private void PreventCollide(Entity ent, ref Pr return; var other = args.OtherEntity; - if (HasComp(other) && + if (TryComp(other, out ProjectileComponent? projectile) && CompOrNull(other)?.Target != ent) { - args.Cancelled = true; + // Prevents shooting out of while inside of crates + var shooter = projectile.Shooter; + if (!shooter.HasValue) + return; + + if (!_container.IsEntityOrParentInContainer(shooter.Value)) + args.Cancelled = true; } }