Files
wwdpublic/Content.Shared/Damage/Systems/RequireProjectileTargetSystem.cs
VMSolidus 40d411bbbc Cherrypick "Shoot Over Bodies" And Related PRs (#479)
# Description
This is a manual cherry-pick of the following PRs:
https://github.com/space-wizards/space-station-14/pull/27905
https://github.com/space-wizards/space-station-14/pull/28072
https://github.com/space-wizards/space-station-14/pull/28571

I REQUIRE these for my work in PR #11 , and cannot complete said PR
without these cherry-picks. This set of PRs from Wizden adds a feature
where entities can selectively opt-out of being shot at unless a player
intentionally targets them, which I can use as a simple and elegant
solution to one of the largest glaring issues for Segmented Entities. I
could simply give Lamia segments the new
RequireProjectileTargetComponent, which adds them to the system. Future
segmented entities such as the hypothetical "Heretic Worm" may or may
not use this feature, depending on their intended implementation.

---------

Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com>
2024-06-23 01:00:32 -04:00

52 lines
1.5 KiB
C#

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);
}
}