Files
crystall-punk-14/Content.Client/Weapons/Ranged/Systems/FlyBySoundSystem.cs

48 lines
1.5 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
2022-05-21 18:04:47 +10:00
using Robust.Client.Player;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Physics.Events;
2022-05-21 18:04:47 +10:00
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Client.Weapons.Ranged.Systems;
2022-05-21 18:04:47 +10:00
public sealed class FlyBySoundSystem : SharedFlyBySoundSystem
{
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IRobustRandom _random = default!;
2022-08-18 12:32:39 +10:00
[Dependency] private readonly SharedAudioSystem _audio = default!;
2022-05-21 18:04:47 +10:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FlyBySoundComponent, StartCollideEvent>(OnCollide);
}
private void OnCollide(EntityUid uid, FlyBySoundComponent component, ref StartCollideEvent args)
2022-05-21 18:04:47 +10:00
{
var attachedEnt = _player.LocalEntity;
2022-05-21 18:04:47 +10:00
// If it's not our ent or we shot it.
if (attachedEnt == null ||
args.OtherEntity != attachedEnt ||
TryComp<ProjectileComponent>(uid, out var projectile) &&
2022-08-18 12:32:39 +10:00
projectile.Shooter == attachedEnt)
{
return;
}
2022-05-21 18:04:47 +10:00
2023-08-23 18:55:58 +10:00
if (args.OurFixtureId != FlyByFixture ||
2022-08-18 12:32:39 +10:00
!_random.Prob(component.Prob))
{
return;
}
2022-05-21 18:04:47 +10:00
2022-08-18 12:32:39 +10:00
// Play attached to our entity because the projectile may immediately delete or the likes.
2023-04-03 00:08:15 +10:00
_audio.PlayPredicted(component.Sound, attachedEnt.Value, attachedEnt.Value);
2022-05-21 18:04:47 +10:00
}
}