Fix the ability to shoot out of crates (#28961)

* Fix the ability to shoot out of crates

* Makes it check what inventory the player is in

* use IsEntityOrParentInContainer

* Fix Issues Github had

* gaahhh... Prevents lasers from being shot out of crates

* gaahhh... Prevents lasers from being shot out of crates

* Fix laser?

* hmmm... this is better looking I think?

* Uncook indentation

* Rerun tests?
This commit is contained in:
Cojoke
2024-07-11 00:14:49 -05:00
committed by GitHub
parent 6371a04621
commit 19a06b6cc0
2 changed files with 25 additions and 10 deletions

View File

@@ -2,11 +2,14 @@ using Content.Shared.Projectiles;
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);
@@ -23,10 +26,16 @@ public sealed class RequireProjectileTargetSystem : EntitySystem
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;
}
}