Files
tbd-station-14/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs
Cojoke 19a06b6cc0 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?
2024-07-11 15:14:49 +10:00

61 lines
1.9 KiB
C#

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);
SubscribeLocalEvent<RequireProjectileTargetComponent, StoodEvent>(StandingBulletHit);
SubscribeLocalEvent<RequireProjectileTargetComponent, DownedEvent>(LayingBulletPass);
}
private void PreventCollide(Entity<RequireProjectileTargetComponent> ent, ref PreventCollideEvent args)
{
if (args.Cancelled)
return;
if (!ent.Comp.Active)
return;
var other = args.OtherEntity;
if (TryComp(other, out ProjectileComponent? projectile) &&
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
{
// Prevents shooting out of while inside of crates
var shooter = projectile.Shooter;
if (!shooter.HasValue)
return;
if (!_container.IsEntityOrParentInContainer(shooter.Value))
args.Cancelled = true;
}
}
private void SetActive(Entity<RequireProjectileTargetComponent> ent, bool value)
{
if (ent.Comp.Active == value)
return;
ent.Comp.Active = value;
Dirty(ent);
}
private void StandingBulletHit(Entity<RequireProjectileTargetComponent> ent, ref StoodEvent args)
{
SetActive(ent, false);
}
private void LayingBulletPass(Entity<RequireProjectileTargetComponent> ent, ref DownedEvent args)
{
SetActive(ent, true);
}
}