2022-05-21 18:04:47 +10:00
|
|
|
using Content.Shared.Physics;
|
2022-06-01 19:59:58 +10:00
|
|
|
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;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Components;
|
2022-05-21 18:04:47 +10:00
|
|
|
using Robust.Shared.Physics.Dynamics;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Systems;
|
2022-05-21 18:04:47 +10:00
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
2022-06-01 19:59:58 +10:00
|
|
|
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)
|
|
|
|
|
{
|
2023-01-15 15:38:59 +11:00
|
|
|
if (!TryComp<PhysicsComponent>(uid, out var body))
|
|
|
|
|
return;
|
2022-05-21 18:04:47 +10:00
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
var shape = new PhysShapeCircle(component.Range);
|
2022-05-21 18:04:47 +10:00
|
|
|
|
2023-01-15 15:38:59 +11: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)
|
|
|
|
|
{
|
2022-10-27 23:37:55 +11:00
|
|
|
if (!TryComp<PhysicsComponent>(uid, out var body) ||
|
|
|
|
|
MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-21 18:04:47 +10:00
|
|
|
|
2023-01-15 15:38:59 +11:00
|
|
|
_fixtures.DestroyFixture(uid, FlyByFixture, body: body);
|
2022-05-21 18:04:47 +10:00
|
|
|
}
|
|
|
|
|
}
|