From b353d958ecb2a744db12b198a6a1e27d2a8f7809 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Thu, 20 Jun 2024 18:17:02 -0400 Subject: [PATCH] Port Randomly Fire Dropped Weapons (#471) # Description Ports https://github.com/Simple-Station/Parkstation-Friendly-Chainsaw/pull/19 I have added a new stat for firearms, the "Reliability" stat, which is a number between 0 and 1. It's used as a percentage chance for the weapon to fire itself when violently thrown into anyone. This PR differs from the original one slightly in that to get it to actually work without crashing, I set the system to listen to an event that triggers whenever the gun collides with another entity, not necessarily just the floor. This is the same event responsible for the clown's cream pie system, or for glass shards embedding in an entity. # Changelog :cl: - add: NanoTrasen has disabled the unneeded safeties on your guns- Make sure you're careful with them! - tweak: All Firearms now have a reliability stat, some are more reliable than others. The more reliable a weapon is, the less likely it is to accidentally discharge when yeeted. --- .../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 | 14 +++++++++- .../Weapons/Guns/Revolvers/revolvers.yml | 3 +++ .../Objects/Weapons/Guns/Rifles/rifles.yml | 2 ++ .../Objects/Weapons/Guns/SMGs/smgs.yml | 5 ++++ .../Weapons/Guns/Shotguns/shotguns.yml | 7 +++++ .../Objects/Weapons/Guns/Snipers/snipers.yml | 10 +++++++ 10 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Content.Server/Weapons/Ranged/Systems/FireOnDropSystem.cs diff --git a/Content.Server/Weapons/Ranged/Systems/FireOnDropSystem.cs b/Content.Server/Weapons/Ranged/Systems/FireOnDropSystem.cs new file mode 100644 index 00000000000..a6112ad49cf --- /dev/null +++ b/Content.Server/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 0183a30a73b..a18aac80abe 100644 --- a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs @@ -229,6 +229,12 @@ public sealed partial class GunComponent : Component /// [DataField] public bool ClumsyProof = false; + + /// + /// 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..93621bc3a28 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 - 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 202604b8bf0..bf0c51849a3 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml @@ -18,6 +18,7 @@ selectedMode: SemiAuto availableModes: - SemiAuto + fireOnDropChance: 0.15 soundGunshot: path: /Audio/Weapons/Guns/Gunshots/laser.ogg - type: Battery diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml index 16cacb79dfa..410664e46e4 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml @@ -99,6 +99,15 @@ containers: gun_magazine: !type:ContainerSlot gun_chamber: !type:ContainerSlot + - type: Gun + fireRate: 6 + selectedMode: SemiAuto + availableModes: + - SemiAuto + - FullAuto + soundGunshot: + path: /Audio/Weapons/Guns/Gunshots/pistol.ogg + fireOnDropChance: 0.3 - type: entity name: cobra @@ -125,6 +134,7 @@ volume: -14 availableModes: - SemiAuto + fireOnDropChance: 0.1 - type: ItemSlots slots: gun_magazine: @@ -169,6 +179,7 @@ - SemiAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/mk58.ogg + fireOnDropChance: 0.5 - type: entity id: WeaponPistolMk58Nonlethal @@ -198,7 +209,7 @@ name: N1984 parent: BaseWeaponPistol id: WeaponPistolN1984 # the spaces in description are for formatting. - description: The sidearm of any self respecting officer. Comes in .45 magnum, the lord's caliber. + description: The sidearm of any self respecting officer. Comes in .45 magnum, the lord's caliber. components: - type: Sprite sprite: Objects/Weapons/Guns/Pistols/N1984.rsi @@ -219,6 +230,7 @@ - SemiAuto soundGunshot: path: /Audio/Weapons/Guns/Gunshots/mk58.ogg + fireOnDropChance: 0.6 - type: ItemSlots slots: gun_magazine: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Revolvers/revolvers.yml index bd043c997da..c5237cdad9a 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.5 - type: UseDelay delay: 0.66 - type: ContainerContainer @@ -127,6 +128,7 @@ path: /Audio/Weapons/Guns/Gunshots/revolver.ogg params: volume: 2.25 + fireOnDropChance: 0.3 - type: entity name: Python @@ -155,6 +157,7 @@ sprite: Objects/Weapons/Guns/Revolvers/pirate_revolver.rsi - type: Gun fireRate: 1 + fireOnDropChance: 1 - type: ContainerContainer containers: revolver-ammo: !type:Container diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml index 5bc8125ebaa..c55b2b6b091 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml @@ -67,6 +67,7 @@ fireRate: 5 soundGunshot: path: /Audio/Weapons/Guns/Gunshots/rifle2.ogg + fireOnDropChance: 0.5 - type: ChamberMagazineAmmoProvider soundRack: path: /Audio/Weapons/Guns/Cock/ltrifle_cock.ogg @@ -159,6 +160,7 @@ - type: Gun soundGunshot: path: /Audio/Weapons/Guns/Gunshots/ltrifle.ogg + fireOnDropChance: 0.2 - 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 b693bdba370..2dfc833badf 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml @@ -72,6 +72,7 @@ fireRate: 10 soundGunshot: path: /Audio/Weapons/Guns/Gunshots/atreides.ogg + fireOnDropChance: 0.3 - type: MagazineVisuals magState: mag steps: 1 @@ -96,6 +97,7 @@ - type: Gun soundGunshot: path: /Audio/Weapons/Guns/Gunshots/c-20r.ogg + fireOnDropChance: 0.3 - type: ChamberMagazineAmmoProvider autoEject: true - type: MagazineVisuals @@ -126,6 +128,7 @@ path: /Audio/Weapons/Guns/Gunshots/atreides.ogg availableModes: - FullAuto + fireOnDropChance: 0.2 - type: ItemSlots slots: gun_magazine: @@ -173,6 +176,7 @@ path: /Audio/Weapons/Guns/Gunshots/atreides.ogg availableModes: - FullAuto + fireOnDropChance: 0.1 - type: ItemSlots slots: gun_magazine: @@ -225,6 +229,7 @@ selectedMode: FullAuto availableModes: - FullAuto + fireOnDropChance: 0.1 - type: ItemSlots slots: gun_magazine: diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml index a8d9f539917..52b05b6d60b 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.2 - type: BallisticAmmoProvider whitelist: tags: @@ -75,6 +76,7 @@ path: /Audio/Weapons/Guns/Gunshots/shotgun.ogg soundEmpty: path: /Audio/Weapons/Guns/Empty/empty.ogg + fireOnDropChance: 0.3 - type: ItemSlots slots: gun_magazine: @@ -115,6 +117,7 @@ heldPrefix: db - type: Gun fireRate: 2 + fireOnDropChance: 0.5 - type: BallisticAmmoProvider capacity: 2 - type: Construction @@ -190,6 +193,7 @@ heldPrefix: sawn - type: Gun fireRate: 4 + fireOnDropChance: 0.5 - type: BallisticAmmoProvider capacity: 2 - type: Construction @@ -226,6 +230,7 @@ sprite: Objects/Weapons/Guns/Shotguns/hm_pistol.rsi - type: Gun fireRate: 4 + fireOnDropChance: 1 - type: BallisticAmmoProvider capacity: 1 - type: Construction @@ -250,6 +255,7 @@ sprite: Objects/Weapons/Guns/Shotguns/blunderbuss.rsi - type: Gun fireRate: 2 + fireOnDropChance: 1 - type: BallisticAmmoProvider capacity: 1 - type: StaticPrice @@ -273,6 +279,7 @@ heldPrefix: improvised - type: Gun fireRate: 4 #No reason to stifle the firerate since you have to manually reload every time anyways. + fireOnDropChance: 1 - type: BallisticAmmoProvider capacity: 1 proto: null diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml index c97459629cf..adb8e323f4a 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Snipers/snipers.yml @@ -46,6 +46,14 @@ components: - type: Sprite sprite: Objects/Weapons/Guns/Snipers/bolt_gun_wood.rsi + - type: Gun + fireRate: 0.75 + selectedMode: SemiAuto + availableModes: + - SemiAuto + soundGunshot: + path: /Audio/Weapons/Guns/Gunshots/sniper.ogg + fireOnDropChance: 1 - type: entity name: Hristov @@ -82,6 +90,7 @@ selectedMode: SemiAuto availableModes: - SemiAuto + fireOnDropChance: 1 - type: UseDelayOnShoot - type: UseDelay delay: 8 #it's a musket @@ -111,6 +120,7 @@ - type: Gun minAngle: 0 maxAngle: 30 #miss him entirely because the barrel is smoothbore + fireOnDropChance: 1 - type: Item size: Small storedRotation: 90