Files
crystall-punk-14/Content.Shared/Weapons/Ranged/Systems/SharedFlyBySoundSystem.cs

48 lines
1.5 KiB
C#
Raw Permalink Normal View History

2022-05-21 18:04:47 +10:00
using Content.Shared.Physics;
using Content.Shared.Weapons.Ranged.Components;
2022-07-29 14:13:12 +12:00
using Robust.Shared.Audio;
2022-05-21 18:04:47 +10:00
using Robust.Shared.GameStates;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
2022-05-21 18:04:47 +10:00
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Systems;
2022-05-21 18:04:47 +10:00
using Robust.Shared.Serialization;
namespace Content.Shared.Weapons.Ranged.Systems;
2022-05-21 18:04:47 +10:00
public abstract class SharedFlyBySoundSystem : EntitySystem
{
[Dependency] private readonly FixtureSystem _fixtures = default!;
public const string FlyByFixture = "fly-by";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FlyBySoundComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<FlyBySoundComponent, ComponentShutdown>(OnShutdown);
}
private void OnStartup(EntityUid uid, FlyBySoundComponent component, ComponentStartup args)
{
if (!TryComp<PhysicsComponent>(uid, out var body))
return;
2022-05-21 18:04:47 +10:00
var shape = new PhysShapeCircle(component.Range);
2022-05-21 18:04:47 +10:00
_fixtures.TryCreateFixture(uid, shape, FlyByFixture, collisionLayer: (int) CollisionGroup.MobMask, hard: false, body: body);
2022-05-21 18:04:47 +10:00
}
private void OnShutdown(EntityUid uid, FlyBySoundComponent component, ComponentShutdown args)
{
if (!TryComp<PhysicsComponent>(uid, out var body) ||
MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
{
return;
}
2022-05-21 18:04:47 +10:00
_fixtures.DestroyFixture(uid, FlyByFixture, body: body);
2022-05-21 18:04:47 +10:00
}
}