Gun refactor (#8301)
Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: T-Stalker <le0nel_1van@hotmail.com> Co-authored-by: T-Stalker <43253663+DogZeroX@users.noreply.github.com> Co-authored-by: ElectroJr <leonsfriedrich@gmail.com> Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
38
Content.Client/Weapons/Ranged/Systems/FlyBySoundSystem.cs
Normal file
38
Content.Client/Weapons/Ranged/Systems/FlyBySoundSystem.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Client.Projectiles;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Client.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed class FlyBySoundSystem : SharedFlyBySoundSystem
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<FlyBySoundComponent, StartCollideEvent>(OnCollide);
|
||||
}
|
||||
|
||||
private void OnCollide(EntityUid uid, FlyBySoundComponent component, StartCollideEvent args)
|
||||
{
|
||||
var attachedEnt = _player.LocalPlayer?.ControlledEntity;
|
||||
|
||||
// If it's not our ent or we shot it.
|
||||
if (attachedEnt == null ||
|
||||
args.OtherFixture.Body.Owner != attachedEnt ||
|
||||
TryComp<ProjectileComponent>(args.OurFixture.Body.Owner, out var projectile) &&
|
||||
projectile.Shooter == attachedEnt) return;
|
||||
|
||||
if (args.OurFixture.ID != FlyByFixture ||
|
||||
!_random.Prob(component.Prob)) return;
|
||||
|
||||
SoundSystem.Play(Filter.Local(), component.Sound.GetSound(), uid, component.Sound.Params);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user