Skip to content

Commit

Permalink
Port Randomly Fire Dropped Weapons (#471)
Browse files Browse the repository at this point in the history
# Description

Ports
Simple-Station/Parkstation-Friendly-Chainsaw#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.
  • Loading branch information
VMSolidus authored Jun 20, 2024
1 parent 896627d commit b353d95
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/FireOnDropSystem.cs
Original file line number Diff line number Diff line change
@@ -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<GunComponent, ThrowDoHitEvent>(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()));
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Weapons/Ranged/Components/GunComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ public sealed partial class GunComponent : Component
/// </summary>
[DataField]
public bool ClumsyProof = false;

/// <summary>
/// The percentage chance of a given gun to accidentally discharge if violently thrown into a wall or person
/// </summary>
[DataField]
public float FireOnDropChance = 0.1f;
}

[Flags]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- SemiAuto
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/kinetic_accel.ogg
fireOnDropChance: 1
- type: AmmoCounter
- type: Appearance
- type: GenericVisualizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
selectedMode: SemiAuto
availableModes:
- SemiAuto
fireOnDropChance: 0.15
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/laser.ogg
- type: Battery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -125,6 +134,7 @@
volume: -14
availableModes:
- SemiAuto
fireOnDropChance: 0.1
- type: ItemSlots
slots:
gun_magazine:
Expand Down Expand Up @@ -169,6 +179,7 @@
- SemiAuto
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/mk58.ogg
fireOnDropChance: 0.5

- type: entity
id: WeaponPistolMk58Nonlethal
Expand Down Expand Up @@ -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
Expand All @@ -219,6 +230,7 @@
- SemiAuto
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/mk58.ogg
fireOnDropChance: 0.6
- type: ItemSlots
slots:
gun_magazine:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- SemiAuto
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/revolver.ogg
fireOnDropChance: 0.5
- type: UseDelay
delay: 0.66
- type: ContainerContainer
Expand Down Expand Up @@ -127,6 +128,7 @@
path: /Audio/Weapons/Guns/Gunshots/revolver.ogg
params:
volume: 2.25
fireOnDropChance: 0.3

- type: entity
name: Python
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -159,6 +160,7 @@
- type: Gun
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/ltrifle.ogg
fireOnDropChance: 0.2
- type: ItemSlots
slots:
gun_magazine:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
fireRate: 10
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/atreides.ogg
fireOnDropChance: 0.3
- type: MagazineVisuals
magState: mag
steps: 1
Expand All @@ -96,6 +97,7 @@
- type: Gun
soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/c-20r.ogg
fireOnDropChance: 0.3
- type: ChamberMagazineAmmoProvider
autoEject: true
- type: MagazineVisuals
Expand Down Expand Up @@ -126,6 +128,7 @@
path: /Audio/Weapons/Guns/Gunshots/atreides.ogg
availableModes:
- FullAuto
fireOnDropChance: 0.2
- type: ItemSlots
slots:
gun_magazine:
Expand Down Expand Up @@ -173,6 +176,7 @@
path: /Audio/Weapons/Guns/Gunshots/atreides.ogg
availableModes:
- FullAuto
fireOnDropChance: 0.1
- type: ItemSlots
slots:
gun_magazine:
Expand Down Expand Up @@ -225,6 +229,7 @@
selectedMode: FullAuto
availableModes:
- FullAuto
fireOnDropChance: 0.1
- type: ItemSlots
slots:
gun_magazine:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -115,6 +117,7 @@
heldPrefix: db
- type: Gun
fireRate: 2
fireOnDropChance: 0.5
- type: BallisticAmmoProvider
capacity: 2
- type: Construction
Expand Down Expand Up @@ -190,6 +193,7 @@
heldPrefix: sawn
- type: Gun
fireRate: 4
fireOnDropChance: 0.5
- type: BallisticAmmoProvider
capacity: 2
- type: Construction
Expand Down Expand Up @@ -226,6 +230,7 @@
sprite: Objects/Weapons/Guns/Shotguns/hm_pistol.rsi
- type: Gun
fireRate: 4
fireOnDropChance: 1
- type: BallisticAmmoProvider
capacity: 1
- type: Construction
Expand All @@ -250,6 +255,7 @@
sprite: Objects/Weapons/Guns/Shotguns/blunderbuss.rsi
- type: Gun
fireRate: 2
fireOnDropChance: 1
- type: BallisticAmmoProvider
capacity: 1
- type: StaticPrice
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,6 +90,7 @@
selectedMode: SemiAuto
availableModes:
- SemiAuto
fireOnDropChance: 1
- type: UseDelayOnShoot
- type: UseDelay
delay: 8 #it's a musket
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b353d95

Please sign in to comment.