diff --git a/Content.Shared/Weapons/Ranged/Components/GunSpreadModifierComponent.cs b/Content.Shared/Weapons/Ranged/Components/GunSpreadModifierComponent.cs new file mode 100644 index 0000000000..7f889f57f6 --- /dev/null +++ b/Content.Shared/Weapons/Ranged/Components/GunSpreadModifierComponent.cs @@ -0,0 +1,16 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Weapons.Ranged.Components; + +/// +/// This component modifies the spread of the gun it is attached to. +/// +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] +public sealed partial class GunSpreadModifierComponent: Component +{ + /// + /// A scalar value multiplied by the spread built into the ammo itself. + /// + [DataField, AutoNetworkedField] + public float Spread = 1; +} diff --git a/Content.Shared/Weapons/Ranged/Systems/GunSpreadModifierSystem.cs b/Content.Shared/Weapons/Ranged/Systems/GunSpreadModifierSystem.cs new file mode 100644 index 0000000000..84d8dd2cf4 --- /dev/null +++ b/Content.Shared/Weapons/Ranged/Systems/GunSpreadModifierSystem.cs @@ -0,0 +1,30 @@ +using Content.Shared.Examine; +using Content.Shared.Weapons.Ranged.Components; +using Content.Shared.Weapons.Ranged.Events; + +namespace Content.Shared.Weapons.Ranged.Systems; + + +public sealed class GunSpreadModifierSystem: EntitySystem +{ + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(OnGunGetAmmoSpread); + SubscribeLocalEvent(OnExamine); + } + + private void OnGunGetAmmoSpread(EntityUid uid, GunSpreadModifierComponent comp, ref GunGetAmmoSpreadEvent args) + { + args.Spread *= comp.Spread; + } + + private void OnExamine(EntityUid uid, GunSpreadModifierComponent comp, ExaminedEvent args) + { + var percentage = Math.Round(comp.Spread * 100); + var loc = percentage < 100 ? "examine-gun-spread-modifier-reduction" : "examine-gun-spread-modifier-increase"; + percentage = percentage < 100 ? 100 - percentage : percentage - 100; + var msg = Loc.GetString(loc, ("percentage", percentage)); + args.PushMarkup(msg); + } +} diff --git a/Resources/Locale/en-US/weapons/ranged/gun.ftl b/Resources/Locale/en-US/weapons/ranged/gun.ftl index 10bc9e6c78..18e01e31c8 100644 --- a/Resources/Locale/en-US/weapons/ranged/gun.ftl +++ b/Resources/Locale/en-US/weapons/ranged/gun.ftl @@ -50,3 +50,7 @@ gun-revolver-insert = Inserted gun-revolver-spin = Spin revolver gun-revolver-spun = Spun gun-speedloader-empty = Speedloader empty + +# GunSpreadModifier +examine-gun-spread-modifier-reduction = The spread has been reduced by [color=yellow]{$percentage}%[/color]. +examine-gun-spread-modifier-increase = The spread has been increased by [color=yellow]{$percentage}%[/color]. diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml index 4cbdb99f69..b2e8d0a14b 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Shotguns/shotguns.yml @@ -175,6 +175,8 @@ - type: GunRequiresWield #remove when inaccuracy on spreads is fixed - type: Gun fireRate: 1 + - type: GunSpreadModifier + spread: 0.6 - type: Tag tags: - WeaponShotgunKammerer