Make projectiles not hit crates unless clicked on (#28072)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.Physics.Events;
|
||||
|
||||
namespace Content.Shared.Damage.Components;
|
||||
|
||||
public sealed class RequireProjectileTargetSystem : EntitySystem
|
||||
{
|
||||
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 (HasComp<ProjectileComponent>(other) &&
|
||||
CompOrNull<TargetedProjectileComponent>(other)?.Target != ent)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user