Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the ability to shoot out of crates #28961

Merged
merged 14 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<RequireProjectileTargetComponent>(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<RequireProjectileTargetComponent>(collide.HitEntity)?.Active == true)
{
continue;
}

result = collide;
break;
}

result = collide;
break;
}

var hit = result.HitEntity;
Expand Down
13 changes: 11 additions & 2 deletions Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequireProjectileTargetComponent, PreventCollideEvent>(PreventCollide);
Expand All @@ -23,10 +26,16 @@ private void PreventCollide(Entity<RequireProjectileTargetComponent> ent, ref Pr
return;

var other = args.OtherEntity;
if (HasComp<ProjectileComponent>(other) &&
if (TryComp(other, out ProjectileComponent? projectile) &&
CompOrNull<TargetedProjectileComponent>(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;
}
}

Expand Down
Loading