2022-12-24 23:28:21 -05:00
|
|
|
using Content.Shared.Projectiles;
|
2022-06-01 19:59:58 +10:00
|
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
|
|
|
using Content.Shared.Weapons.Ranged.Systems;
|
2022-05-21 18:04:47 +10:00
|
|
|
using Robust.Client.Player;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Audio.Systems;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Events;
|
2022-05-21 18:04:47 +10:00
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
|
2022-06-01 19:59:58 +10:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 17:26:26 +10:00
|
|
|
private void OnCollide(EntityUid uid, FlyBySoundComponent component, ref StartCollideEvent args)
|
2022-05-21 18:04:47 +10:00
|
|
|
{
|
2024-02-13 22:48:39 +01: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 ||
|
2023-05-09 19:21:26 +12:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|