diff --git a/Content.Server/_CorvaxNext/Weapons/Ranged/Systems/FireOnDropSystem.cs b/Content.Server/_CorvaxNext/Weapons/Ranged/Systems/FireOnDropSystem.cs new file mode 100644 index 00000000000..a6112ad49cf --- /dev/null +++ b/Content.Server/_CorvaxNext/Weapons/Ranged/Systems/FireOnDropSystem.cs @@ -0,0 +1,27 @@ +using Content.Shared.Throwing; +using Content.Shared.Weapons.Ranged.Components; +using Content.Shared.Weapons.Ranged.Systems; +using Robust.Shared.Random; + +namespace Content.Server.Weapons.Ranged.Systems; + +public sealed class FireOnDropSystem : EntitySystem +{ + [Dependency] private readonly SharedGunSystem _gun = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(HandleLand); + } + + + private void HandleLand(EntityUid uid, GunComponent component, ref ThrowDoHitEvent args) + { + if (_random.Prob(component.FireOnDropChance)) + _gun.AttemptShoot(uid, uid, component, Transform(uid).Coordinates.Offset(Transform(uid).LocalRotation.ToVec())); + } +} diff --git a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs index 98b1d2fe2a4..bcc56c28ab1 100644 --- a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs @@ -263,6 +263,12 @@ public sealed partial class GunComponent : Component /// [DataField] public Vector2 DefaultDirection = new Vector2(0, -1); + + /// + /// Corvax-Next. The percentage chance of a given gun to accidentally discharge if violently thrown into a wall or person + /// + [DataField] + public float FireOnDropChance = 0.1f; } [Flags] diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/base_pka.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/base_pka.yml index a661323c7c3..03dc3a2dc0b 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/base_pka.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Basic/base_pka.yml @@ -22,6 +22,7 @@ - SemiAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/kinetic_accel.ogg + fireOnDropChance: 1 # Corvax-Next-FireOnDrop - type: AmmoCounter - type: Appearance - type: GenericVisualizer diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml index 55499a0a979..7dbb328e42c 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml @@ -20,6 +20,7 @@ - SemiAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/laser.ogg + fireOnDropChance: 0.15 # Corvax-Next-FireOnDrop - type: Battery maxCharge: 1000 startingCharge: 1000 diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml index 167e21e15f2..7cf0f06ccde 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml @@ -33,6 +33,7 @@ - FullAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/pistol.ogg + fireOnDropChance: 0.3 # Corvax-Next-FireOnDrop - type: ChamberMagazineAmmoProvider soundRack: path: /Audio/Weapons/Guns/Cock/pistol_cock.ogg diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml index a34d0a4fe0a..e0aa5057f45 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml @@ -29,6 +29,7 @@ - SemiAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/revolver.ogg + fireOnDropChance: 0.6 # Corvax-Next-FireOnDrop - type: UseDelay delay: 0.66 - type: ContainerContainer diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index 44b8944592e..d51e95088e8 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -22,6 +22,7 @@ - FullAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/batrifle.ogg + fireOnDropChance: 0.5 # Corvax-Next-FireOnDrop - type: ChamberMagazineAmmoProvider soundRack: path: /Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml index bccb514c63f..cca78cb4ffe 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml @@ -29,6 +29,7 @@ soundGunshot: path: /Audio/Weapons/Guns/Gunshots/smg.ogg defaultDirection: 1, 0 + fireOnDropChance: 0.3 # Corvax-Next-FireOnDrop - type: ChamberMagazineAmmoProvider soundRack: path: /Audio/Weapons/Guns/Cock/smg_cock.ogg diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml index 02f6b5c03de..5887669fd0e 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml @@ -28,6 +28,7 @@ path: /Audio/Weapons/Guns/Gunshots/shotgun.ogg soundEmpty: path: /Audio/Weapons/Guns/Empty/empty.ogg + fireOnDropChance: 0.3 # Corvax-Next-FireOnDrop - type: BallisticAmmoProvider whitelist: tags: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml index 9cb0b630b7e..7e2586f485e 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml @@ -25,6 +25,7 @@ - SemiAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/sniper.ogg + fireOnDropChance: 0.9 # Corvax-Next-FireOnDrop - type: BallisticAmmoProvider capacity: 10 proto: CartridgeLightRifle