mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Content.Shared.Projectiles;
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
using Content.Shared.Weapons.Ranged.Systems;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Physics.Events;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Client.Weapons.Ranged.Systems;
|
|
|
|
public sealed partial class FlyBySoundSystem : SharedFlyBySoundSystem
|
|
{
|
|
[Dependency] private IPlayerManager _player = default!;
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private SharedAudioSystem _audio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<FlyBySoundComponent, StartCollideEvent>(OnCollide);
|
|
}
|
|
|
|
private void OnCollide(Entity<FlyBySoundComponent> ent, ref StartCollideEvent args)
|
|
{
|
|
var attachedEnt = _player.LocalEntity;
|
|
|
|
// If it's not our ent or we shot it.
|
|
if (attachedEnt == null ||
|
|
args.OtherEntity != attachedEnt ||
|
|
TryComp<ProjectileComponent>(ent, out var projectile) &&
|
|
projectile.Shooter == attachedEnt)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (args.OurFixtureId != FlyByFixture ||
|
|
!_random.Prob(ent.Comp.Prob))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Play attached to our entity because the projectile may immediately delete or the likes.
|
|
_audio.PlayPredicted(ent.Comp.Sound, attachedEnt.Value, attachedEnt.Value);
|
|
}
|
|
}
|