diff --git a/Content.Client/Weapons/Ranged/FlyBySoundSystem.cs b/Content.Client/Weapons/Ranged/FlyBySoundSystem.cs new file mode 100644 index 0000000000..0a0beb08a8 --- /dev/null +++ b/Content.Client/Weapons/Ranged/FlyBySoundSystem.cs @@ -0,0 +1,37 @@ +using Content.Client.Projectiles; +using Content.Shared.Weapons.Ranged; +using Robust.Client.Player; +using Robust.Shared.Audio; +using Robust.Shared.Physics.Dynamics; +using Robust.Shared.Player; +using Robust.Shared.Random; + +namespace Content.Client.Weapons.Ranged; + +public sealed class FlyBySoundSystem : SharedFlyBySoundSystem +{ + [Dependency] private readonly IPlayerManager _player = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnCollide); + } + + private void OnCollide(EntityUid uid, FlyBySoundComponent component, StartCollideEvent args) + { + var attachedEnt = _player.LocalPlayer?.ControlledEntity; + + // If it's not our ent or we shot it. + if (attachedEnt == null || + args.OtherFixture.Body.Owner != attachedEnt || + TryComp(args.OurFixture.Body.Owner, out var projectile) && + projectile.Shooter == attachedEnt) return; + + if (args.OurFixture.ID != FlyByFixture || + !_random.Prob(component.Prob)) return; + + SoundSystem.Play(Filter.Local(), component.Sound.GetSound(), uid, component.Sound.Params); + } +} diff --git a/Content.Server/Projectiles/ProjectileSystem.cs b/Content.Server/Projectiles/SharedProjectileSystem.cs similarity index 92% rename from Content.Server/Projectiles/ProjectileSystem.cs rename to Content.Server/Projectiles/SharedProjectileSystem.cs index 9227ab939b..f1da327f5a 100644 --- a/Content.Server/Projectiles/ProjectileSystem.cs +++ b/Content.Server/Projectiles/SharedProjectileSystem.cs @@ -4,6 +4,7 @@ using Content.Shared.Body.Components; using Content.Shared.Camera; using Content.Shared.Damage; using Content.Shared.Database; +using Content.Shared.Projectiles; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Shared.Audio; @@ -13,7 +14,7 @@ using Robust.Shared.Player; namespace Content.Server.Projectiles { [UsedImplicitly] - internal sealed class ProjectileSystem : EntitySystem + public sealed class ProjectileSystem : SharedProjectileSystem { [Dependency] private readonly DamageableSystem _damageableSystem = default!; [Dependency] private readonly AdminLogSystem _adminLogSystem = default!; @@ -28,7 +29,7 @@ namespace Content.Server.Projectiles private void HandleCollide(EntityUid uid, ProjectileComponent component, StartCollideEvent args) { // This is so entities that shouldn't get a collision are ignored. - if (!args.OtherFixture.Hard || component.DamagedEntity) + if (args.OurFixture.ID != ProjectileFixture || !args.OtherFixture.Hard || component.DamagedEntity) { return; } @@ -36,7 +37,7 @@ namespace Content.Server.Projectiles var otherEntity = args.OtherFixture.Body.Owner; var coordinates = EntityManager.GetComponent(args.OtherFixture.Body.Owner).Coordinates; - var playerFilter = Filter.Pvs(coordinates); + var playerFilter = Filter.Pvs(coordinates, entityMan: EntityManager); if (!EntityManager.GetComponent(otherEntity).EntityDeleted && component.SoundHitSpecies != null && EntityManager.HasComponent(otherEntity)) diff --git a/Content.Server/Stunnable/Components/StunOnCollideComponent.cs b/Content.Server/Stunnable/Components/StunOnCollideComponent.cs index 447b030e9b..c12f9e269e 100644 --- a/Content.Server/Stunnable/Components/StunOnCollideComponent.cs +++ b/Content.Server/Stunnable/Components/StunOnCollideComponent.cs @@ -23,5 +23,10 @@ namespace Content.Server.Stunnable.Components [DataField("runSpeedMultiplier")] public float RunSpeedMultiplier = 1f; + + /// + /// Fixture we track for the collision. + /// + [ViewVariables, DataField("fixture")] public string FixtureID = "projectile"; } } diff --git a/Content.Server/Stunnable/StunOnCollideSystem.cs b/Content.Server/Stunnable/StunOnCollideSystem.cs index f0c095f7d7..d078156abd 100644 --- a/Content.Server/Stunnable/StunOnCollideSystem.cs +++ b/Content.Server/Stunnable/StunOnCollideSystem.cs @@ -41,6 +41,8 @@ namespace Content.Server.Stunnable } private void HandleCollide(EntityUid uid, StunOnCollideComponent component, StartCollideEvent args) { + if (args.OurFixture.ID != component.FixtureID) return; + TryDoCollideStun(uid, component, args.OtherFixture.Body.Owner); } diff --git a/Content.Server/Weapon/Ranged/FlyBySoundSystem.cs b/Content.Server/Weapon/Ranged/FlyBySoundSystem.cs new file mode 100644 index 0000000000..79e425e2e4 --- /dev/null +++ b/Content.Server/Weapon/Ranged/FlyBySoundSystem.cs @@ -0,0 +1,5 @@ +using Content.Shared.Weapons.Ranged; + +namespace Content.Server.Weapon.Ranged; + +public sealed class FlyBySoundSystem : SharedFlyBySoundSystem {} diff --git a/Content.Shared/Projectiles/ProjectileSystem.cs b/Content.Shared/Projectiles/SharedProjectileSystem.cs similarity index 82% rename from Content.Shared/Projectiles/ProjectileSystem.cs rename to Content.Shared/Projectiles/SharedProjectileSystem.cs index 8b29a471cf..52b322302e 100644 --- a/Content.Shared/Projectiles/ProjectileSystem.cs +++ b/Content.Shared/Projectiles/SharedProjectileSystem.cs @@ -2,8 +2,10 @@ using Robust.Shared.Physics.Dynamics; namespace Content.Shared.Projectiles { - public sealed class ProjectileSystem : EntitySystem + public abstract class SharedProjectileSystem : EntitySystem { + public const string ProjectileFixture = "projectile"; + public override void Initialize() { base.Initialize(); diff --git a/Content.Shared/Weapons/Ranged/FlyBySoundComponent.cs b/Content.Shared/Weapons/Ranged/FlyBySoundComponent.cs new file mode 100644 index 0000000000..4d10fbc817 --- /dev/null +++ b/Content.Shared/Weapons/Ranged/FlyBySoundComponent.cs @@ -0,0 +1,26 @@ +using Content.Shared.Sound; +using Robust.Shared.Audio; +using Robust.Shared.GameStates; + +namespace Content.Shared.Weapons.Ranged; + +/// +/// Plays a sound when its non-hard fixture collides with a player. +/// +[RegisterComponent, NetworkedComponent] +public sealed class FlyBySoundComponent : Component +{ + /// + /// Probability that the sound plays + /// + [ViewVariables(VVAccess.ReadWrite), DataField("prob")] + public float Prob = 0.75f; + + [ViewVariables(VVAccess.ReadWrite), DataField("sound")] + public SoundSpecifier Sound = new SoundCollectionSpecifier("BulletMiss") + { + Params = AudioParams.Default.WithVolume(5f), + }; + + [ViewVariables, DataField("range")] public float Range = 1.5f; +} diff --git a/Content.Shared/Weapons/Ranged/SharedFlyBySoundSystem.cs b/Content.Shared/Weapons/Ranged/SharedFlyBySoundSystem.cs new file mode 100644 index 0000000000..eefc23f314 --- /dev/null +++ b/Content.Shared/Weapons/Ranged/SharedFlyBySoundSystem.cs @@ -0,0 +1,75 @@ +using Content.Shared.Physics; +using Content.Shared.Sound; +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; + +public abstract class SharedFlyBySoundSystem : EntitySystem +{ + [Dependency] private readonly FixtureSystem _fixtures = default!; + + public const string FlyByFixture = "fly-by"; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnHandleState); + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); + } + + private void OnStartup(EntityUid uid, FlyBySoundComponent component, ComponentStartup args) + { + if (!TryComp(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(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; + } +} diff --git a/Resources/Audio/Weapons/Guns/Miss/bullet_miss1.ogg b/Resources/Audio/Weapons/Guns/Miss/bullet_miss1.ogg new file mode 100644 index 0000000000..ae3e7a4b66 Binary files /dev/null and b/Resources/Audio/Weapons/Guns/Miss/bullet_miss1.ogg differ diff --git a/Resources/Audio/Weapons/Guns/Miss/bullet_miss2.ogg b/Resources/Audio/Weapons/Guns/Miss/bullet_miss2.ogg new file mode 100644 index 0000000000..8ae5417ab0 Binary files /dev/null and b/Resources/Audio/Weapons/Guns/Miss/bullet_miss2.ogg differ diff --git a/Resources/Audio/Weapons/Guns/Miss/bullet_miss3.ogg b/Resources/Audio/Weapons/Guns/Miss/bullet_miss3.ogg new file mode 100644 index 0000000000..340a1a2faf Binary files /dev/null and b/Resources/Audio/Weapons/Guns/Miss/bullet_miss3.ogg differ diff --git a/Resources/Audio/Weapons/Guns/Miss/bullet_miss4.ogg b/Resources/Audio/Weapons/Guns/Miss/bullet_miss4.ogg new file mode 100644 index 0000000000..ba8cb80e40 Binary files /dev/null and b/Resources/Audio/Weapons/Guns/Miss/bullet_miss4.ogg differ diff --git a/Resources/Audio/Weapons/Guns/Miss/energy_miss1.ogg b/Resources/Audio/Weapons/Guns/Miss/energy_miss1.ogg new file mode 100644 index 0000000000..55839b14d3 Binary files /dev/null and b/Resources/Audio/Weapons/Guns/Miss/energy_miss1.ogg differ diff --git a/Resources/Audio/Weapons/Guns/Miss/licenses.txt b/Resources/Audio/Weapons/Guns/Miss/licenses.txt new file mode 100644 index 0000000000..1f6cdc1735 --- /dev/null +++ b/Resources/Audio/Weapons/Guns/Miss/licenses.txt @@ -0,0 +1,2 @@ +bullet_miss oggs taken from https://github.com/cmss13-devs/cmss13/tree/0535055a7abcd3016123f2be2cd3db428c122dac/sound/bullets under CC BY-SA 3.0 +energy_miss ogg taken from https://github.com/cmss13-devs/cmss13/tree/0535055a7abcd3016123f2be2cd3db428c122dac/sound/bullets under CC BY-SA 3.0 \ No newline at end of file diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml index fc11e2d2ac..927bd14281 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml @@ -5,6 +5,7 @@ description: If you can see this you're probably dead! abstract: true components: + - type: FlyBySound - type: Clickable - type: Sprite netsync: false @@ -21,6 +22,7 @@ !type:PhysShapeAabb bounds: "-0.1,-0.1,0.1,0.1" hard: false + id: projectile mask: - Impassable - BulletImpassable @@ -47,6 +49,7 @@ !type:PhysShapeAabb bounds: "-0.15,-0.45,0.15,0.15" hard: false + id: projectile mask: - Impassable - BulletImpassable @@ -111,6 +114,11 @@ parent: BulletBase noSpawn: true components: + - type: FlyBySound + sound: + collection: EnergyMiss + params: + volume: 5 - type: Sprite noRot: true sprite: Objects/Weapons/Guns/Projectiles/spark.rsi @@ -125,6 +133,7 @@ !type:PhysShapeAabb bounds: "-0.2,-0.2,0.2,0.2" hard: false + id: projectile mask: - Impassable - BulletImpassable @@ -159,6 +168,7 @@ !type:PhysShapeAabb bounds: "-0.2,-0.2,0.2,0.2" hard: false + id: projectile mask: - Impassable - Opaque diff --git a/Resources/Prototypes/SoundCollections/gun_sounds.yml b/Resources/Prototypes/SoundCollections/gun_sounds.yml new file mode 100644 index 0000000000..2225f809a9 --- /dev/null +++ b/Resources/Prototypes/SoundCollections/gun_sounds.yml @@ -0,0 +1,12 @@ +- type: soundCollection + id: BulletMiss + files: + - /Audio/Weapons/Guns/Miss/bullet_miss1.ogg + - /Audio/Weapons/Guns/Miss/bullet_miss2.ogg + - /Audio/Weapons/Guns/Miss/bullet_miss3.ogg + - /Audio/Weapons/Guns/Miss/bullet_miss4.ogg + +- type: soundCollection + id: EnergyMiss + files: + - /Audio/Weapons/Guns/Miss/energy_miss1.ogg