* Update DamageableSystem to modern standards * DamageContainerId -> DamageContainerID with lint flag * Replace strings with protoids * Make CVar subscription declarations all consistently whitespaced * ChangeDamage -> TryChangeDamage, cope with C# jank * Revert event signature changes * Restore a comment * Re-add two queries * Init the queries * Use appearanceQuery in DamageChanged * Use damageableQuery in TryChangeDamage * Use damageableQuery in SetDamageModifierSetId * Final cleanup, fix sandboxing * Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage * Re-organize DamageableSystem * first big fuck you breaking change. * THATS A LOT OF DAMAGE!!! * Fix test fails * test fixes 2 * push it --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using Content.Shared.Damage.Components;
|
|
using Content.Shared.Projectiles;
|
|
using Content.Shared.Standing;
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Physics.Events;
|
|
|
|
namespace Content.Shared.Damage.Systems;
|
|
|
|
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;
|
|
|
|
// ProjectileGrenades delete the entity that's shooting the projectile,
|
|
// so it's impossible to check if the entity is in a container
|
|
if (TerminatingOrDeleted(shooter.Value))
|
|
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);
|
|
}
|
|
}
|