* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
48 lines
1.5 KiB
C#
48 lines
1.5 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;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Physics.Events;
|
|
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!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<FlyBySoundComponent, StartCollideEvent>(OnCollide);
|
|
}
|
|
|
|
private void OnCollide(EntityUid uid, FlyBySoundComponent component, 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>(uid, out var projectile) &&
|
|
projectile.Shooter == attachedEnt)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (args.OurFixtureId != FlyByFixture ||
|
|
!_random.Prob(component.Prob))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Play attached to our entity because the projectile may immediately delete or the likes.
|
|
_audio.PlayPredicted(component.Sound, attachedEnt.Value, attachedEnt.Value);
|
|
}
|
|
}
|