From bc818a6b6f6b3fca9c79f364fc0cfd10861eb747 Mon Sep 17 00:00:00 2001 From: Vonsant Date: Tue, 10 Dec 2024 16:19:08 +0300 Subject: [PATCH 1/2] FireOnDrop --- .../Ranged/Systems/FireOnDropSystem.cs | 27 +++++++++++++++++++ .../Weapons/Ranged/Components/GunComponent.cs | 6 +++++ .../Objects/Weapons/Guns/Basic/base_pka.yml | 1 + .../Weapons/Guns/Battery/battery_guns.yml | 1 + .../Objects/Weapons/Guns/Pistols/pistols.yml | 1 + .../Weapons/Guns/Revolvers/revolvers.yml | 1 + .../Objects/Weapons/Guns/Rifles/rifles.yml | 1 + .../Objects/Weapons/Guns/SMGs/smgs.yml | 1 + .../Weapons/Guns/Shotguns/shotguns.yml | 1 + .../Objects/Weapons/Guns/Snipers/snipers.yml | 1 + 10 files changed, 41 insertions(+) create mode 100644 Content.Server/_CorvaxNext/Weapons/Ranged/Systems/FireOnDropSystem.cs 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 f85e93b893f..81994a96748 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 6e4d3a59262..1f4e5a7382b 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 309c2c502d6..9ae534ca04c 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 e34433cb56a..eab3042df8b 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -25,6 +25,7 @@ - type: ChamberMagazineAmmoProvider soundRack: path: /Audio/Weapons/Guns/Cock/sf_rifle_cock.ogg + fireOnDropChance: 0.5 # Corvax-Next-FireOnDrop - type: ItemSlots slots: gun_magazine: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml index d23e34a1ecb..7642343fb86 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 8a7e673e208..3802255a6a4 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 4ea0061c961..32306bab7fe 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 From 20d2a1fe54f39ab77d4d6da5681e601b0ce6a55f Mon Sep 17 00:00:00 2001 From: Kill_Me_I_Noobs <118206719+Vonsant@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:29:47 +0300 Subject: [PATCH 2/2] whoopsy --- .../Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index eab3042df8b..ce5f896a16b 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -22,10 +22,10 @@ - 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 - fireOnDropChance: 0.5 # Corvax-Next-FireOnDrop - type: ItemSlots slots: gun_magazine: