Gun refactor (#8301)
Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: T-Stalker <le0nel_1van@hotmail.com> Co-authored-by: T-Stalker <43253663+DogZeroX@users.noreply.github.com> Co-authored-by: ElectroJr <leonsfriedrich@gmail.com> Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Weapons.Ranged.Systems;
|
||||
|
||||
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, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<FlyBySoundComponent, ComponentHandleState>(OnHandleState);
|
||||
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;
|
||||
|
||||
var shape = new PhysShapeCircle()
|
||||
{
|
||||
Radius = component.Range,
|
||||
};
|
||||
|
||||
var fixture = new Fixture(body, shape)
|
||||
{
|
||||
Hard = false,
|
||||
ID = FlyByFixture,
|
||||
CollisionLayer = (int) CollisionGroup.MobMask,
|
||||
};
|
||||
|
||||
_fixtures.TryCreateFixture(body, fixture);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, FlyBySoundComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (!TryComp<PhysicsComponent>(uid, out var body)) return;
|
||||
|
||||
_fixtures.DestroyFixture(body, FlyByFixture);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, FlyBySoundComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not FlyBySoundComponentState state) return;
|
||||
|
||||
component.Sound = state.Sound;
|
||||
component.Range = state.Range;
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, FlyBySoundComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new FlyBySoundComponentState()
|
||||
{
|
||||
Sound = component.Sound,
|
||||
Range = component.Range,
|
||||
};
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class FlyBySoundComponentState : ComponentState
|
||||
{
|
||||
public SoundSpecifier Sound = default!;
|
||||
public float Range;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user