From 3f74141c932ffe1e9cf56e64fa7a6d223ffe5924 Mon Sep 17 00:00:00 2001 From: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Date: Thu, 11 Aug 2022 22:49:46 -0400 Subject: [PATCH] Makes projectile speed configurable in gun system (#10535) --- Content.Server/Weapon/Ranged/Systems/GunSystem.cs | 12 ++++++------ .../Weapons/Ranged/Components/GunComponent.cs | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Content.Server/Weapon/Ranged/Systems/GunSystem.cs b/Content.Server/Weapon/Ranged/Systems/GunSystem.cs index 1e2bb3f55a..513273effa 100644 --- a/Content.Server/Weapon/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapon/Ranged/Systems/GunSystem.cs @@ -58,14 +58,14 @@ public sealed partial class GunSystem : SharedGunSystem for (var i = 0; i < cartridge.Count; i++) { var uid = Spawn(cartridge.Prototype, fromCoordinates); - ShootProjectile(uid, angles[i].ToVec(), user); + ShootProjectile(uid, angles[i].ToVec(), user, gun.ProjectileSpeed); shotProjectiles.Add(uid); } } else { var uid = Spawn(cartridge.Prototype, fromCoordinates); - ShootProjectile(uid, mapDirection, user); + ShootProjectile(uid, mapDirection, user, gun.ProjectileSpeed); shotProjectiles.Add(uid); } @@ -98,11 +98,11 @@ public sealed partial class GunSystem : SharedGunSystem { RemComp(newAmmo.Owner); // TODO: Someone can probably yeet this a billion miles so need to pre-validate input somewhere up the call stack. - ThrowingSystem.TryThrow(newAmmo.Owner, mapDirection, 20f, user); + ThrowingSystem.TryThrow(newAmmo.Owner, mapDirection, gun.ProjectileSpeed, user); break; } - ShootProjectile(newAmmo.Owner, mapDirection, user); + ShootProjectile(newAmmo.Owner, mapDirection, user, gun.ProjectileSpeed); break; case HitscanPrototype hitscan: var ray = new CollisionRay(fromMap.Position, mapDirection.Normalized, hitscan.CollisionMask); @@ -155,11 +155,11 @@ public sealed partial class GunSystem : SharedGunSystem }, false); } - public void ShootProjectile(EntityUid uid, Vector2 direction, EntityUid? user = null) + public void ShootProjectile(EntityUid uid, Vector2 direction, EntityUid? user = null, float speed = 20f) { var physics = EnsureComp(uid); physics.BodyStatus = BodyStatus.InAir; - physics.LinearVelocity = direction.Normalized * 20f; + physics.LinearVelocity = direction.Normalized * speed; if (user != null) { diff --git a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs index a903caf767..23212f7b57 100644 --- a/Content.Shared/Weapons/Ranged/Components/GunComponent.cs +++ b/Content.Shared/Weapons/Ranged/Components/GunComponent.cs @@ -85,6 +85,12 @@ public class GunComponent : Component [ViewVariables(VVAccess.ReadWrite), DataField("fireRate")] public float FireRate = 8f; + /// + /// How fast the projectile moves. + /// + [ViewVariables(VVAccess.ReadWrite), DataField("projectileSpeed")] + public float ProjectileSpeed = 20f; + /// /// When the gun is next available to be shot. /// Can be set multiple times in a single tick due to guns firing faster than a single tick time.