mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-18 14:07:53 +03:00
* Cluster grenade refactor * oopsies on the name * Solve client-side errors * reviews addressed * filling scattering grenades is now predicted * reviews addressed (cherry picked from commit a4d6f09a4fc11c2cd7cdacc390f4c42995757ff6)
74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using Content.Shared.Movement.Components;
|
|
using Content.Shared.Movement.Systems;
|
|
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;
|
|
|
|
// WWDP edit no bullets passing if you move
|
|
if (TryComp<InputMoverComponent>(ent, out var mover) && mover.CanMove &&
|
|
(mover.HeldMoveButtons & MoveButtons.AnyDirection) != MoveButtons.None)
|
|
return;
|
|
// WWDP edit end
|
|
|
|
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);
|
|
}
|
|
}
|