Changes to "Burst" firemode; Drozd, WT550 and C20-r (#31292)

* Initial commit

* Change burst fire variable to be a set value rather than a multiplier
This commit is contained in:
SlamBamActionman
2024-11-06 15:39:16 +01:00
committed by GitHub
parent e72d63e8a9
commit b15d5a7f27
5 changed files with 104 additions and 23 deletions

View File

@@ -157,7 +157,7 @@ public sealed partial class GunSystem : SharedGunSystem
var useKey = gun.UseKey ? EngineKeyFunctions.Use : EngineKeyFunctions.UseSecondary; var useKey = gun.UseKey ? EngineKeyFunctions.Use : EngineKeyFunctions.UseSecondary;
if (_inputSystem.CmdStates.GetState(useKey) != BoundKeyState.Down) if (_inputSystem.CmdStates.GetState(useKey) != BoundKeyState.Down && !gun.BurstActivated)
{ {
if (gun.ShotCounter != 0) if (gun.ShotCounter != 0)
EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = GetNetEntity(gunUid) }); EntityManager.RaisePredictiveEvent(new RequestStopShootEvent { Gun = GetNetEntity(gunUid) });

View File

@@ -1,4 +1,6 @@
using Content.Shared.Damage;
using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Map;
namespace Content.Server.Weapons.Ranged.Systems; namespace Content.Server.Weapons.Ranged.Systems;
@@ -13,17 +15,28 @@ public sealed partial class GunSystem
*/ */
// Automatic firing without stopping if the AutoShootGunComponent component is exist and enabled // Automatic firing without stopping if the AutoShootGunComponent component is exist and enabled
var query = EntityQueryEnumerator<AutoShootGunComponent, GunComponent>(); var query = EntityQueryEnumerator<GunComponent>();
while (query.MoveNext(out var uid, out var autoShoot, out var gun)) while (query.MoveNext(out var uid, out var gun))
{ {
if (!autoShoot.Enabled)
continue;
if (gun.NextFire > Timing.CurTime) if (gun.NextFire > Timing.CurTime)
continue; continue;
AttemptShoot(uid, gun); if (TryComp(uid, out AutoShootGunComponent? autoShoot))
{
if (!autoShoot.Enabled)
continue;
AttemptShoot(uid, gun);
}
else if (gun.BurstActivated)
{
var parent = _transform.GetParentUid(uid);
if (HasComp<DamageableComponent>(parent))
AttemptShoot(parent, uid, gun, gun.ShootCoordinates ?? new EntityCoordinates(uid, gun.DefaultDirection));
else
AttemptShoot(uid, gun);
}
} }
} }
} }

View File

@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Shared.Weapons.Ranged.Events; using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems; using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -156,6 +157,30 @@ public sealed partial class GunComponent : Component
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)] [AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public int ShotsPerBurstModified = 3; public int ShotsPerBurstModified = 3;
/// <summary>
/// How long time must pass between burstfire shots.
/// </summary>
[DataField, AutoNetworkedField]
public float BurstCooldown = 0.25f;
/// <summary>
/// The fire rate of the weapon in burst fire mode.
/// </summary>
[DataField, AutoNetworkedField]
public float BurstFireRate = 8f;
/// <summary>
/// Whether the burst fire mode has been activated.
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public bool BurstActivated = false;
/// <summary>
/// The burst fire bullet count.
/// </summary>
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
public int BurstShotsCount = 0;
/// <summary> /// <summary>
/// Used for tracking semi-auto / burst /// Used for tracking semi-auto / burst
/// </summary> /// </summary>
@@ -232,6 +257,12 @@ public sealed partial class GunComponent : Component
/// </summary> /// </summary>
[DataField] [DataField]
public bool ClumsyProof = false; public bool ClumsyProof = false;
/// <summary>
/// Firing direction for an item not being held (e.g. shuttle cannons, thrown guns still firing).
/// </summary>
[DataField]
public Vector2 DefaultDirection = new Vector2(0, -1);
} }
[Flags] [Flags]

View File

@@ -218,7 +218,7 @@ public abstract partial class SharedGunSystem : EntitySystem
/// </summary> /// </summary>
public void AttemptShoot(EntityUid gunUid, GunComponent gun) public void AttemptShoot(EntityUid gunUid, GunComponent gun)
{ {
var coordinates = new EntityCoordinates(gunUid, new Vector2(0, -1)); var coordinates = new EntityCoordinates(gunUid, gun.DefaultDirection);
gun.ShootCoordinates = coordinates; gun.ShootCoordinates = coordinates;
AttemptShoot(gunUid, gunUid, gun); AttemptShoot(gunUid, gunUid, gun);
gun.ShotCounter = 0; gun.ShotCounter = 0;
@@ -258,6 +258,9 @@ public abstract partial class SharedGunSystem : EntitySystem
var fireRate = TimeSpan.FromSeconds(1f / gun.FireRateModified); var fireRate = TimeSpan.FromSeconds(1f / gun.FireRateModified);
if (gun.SelectedMode == SelectiveFire.Burst || gun.BurstActivated)
fireRate = TimeSpan.FromSeconds(1f / gun.BurstFireRate);
// First shot // First shot
// Previously we checked shotcounter but in some cases all the bullets got dumped at once // Previously we checked shotcounter but in some cases all the bullets got dumped at once
// curTime - fireRate is insufficient because if you time it just right you can get a 3rd shot out slightly quicker. // curTime - fireRate is insufficient because if you time it just right you can get a 3rd shot out slightly quicker.
@@ -278,18 +281,24 @@ public abstract partial class SharedGunSystem : EntitySystem
// Get how many shots we're actually allowed to make, due to clip size or otherwise. // Get how many shots we're actually allowed to make, due to clip size or otherwise.
// Don't do this in the loop so we still reset NextFire. // Don't do this in the loop so we still reset NextFire.
switch (gun.SelectedMode) if (!gun.BurstActivated)
{ {
case SelectiveFire.SemiAuto: switch (gun.SelectedMode)
shots = Math.Min(shots, 1 - gun.ShotCounter); {
break; case SelectiveFire.SemiAuto:
case SelectiveFire.Burst: shots = Math.Min(shots, 1 - gun.ShotCounter);
shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter); break;
break; case SelectiveFire.Burst:
case SelectiveFire.FullAuto: shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter);
break; break;
default: case SelectiveFire.FullAuto:
throw new ArgumentOutOfRangeException($"No implemented shooting behavior for {gun.SelectedMode}!"); break;
default:
throw new ArgumentOutOfRangeException($"No implemented shooting behavior for {gun.SelectedMode}!");
}
} else
{
shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter);
} }
var attemptEv = new AttemptShootEvent(user, null); var attemptEv = new AttemptShootEvent(user, null);
@@ -301,7 +310,8 @@ public abstract partial class SharedGunSystem : EntitySystem
{ {
PopupSystem.PopupClient(attemptEv.Message, gunUid, user); PopupSystem.PopupClient(attemptEv.Message, gunUid, user);
} }
gun.BurstActivated = false;
gun.BurstShotsCount = 0;
gun.NextFire = TimeSpan.FromSeconds(Math.Max(lastFire.TotalSeconds + SafetyNextFire, gun.NextFire.TotalSeconds)); gun.NextFire = TimeSpan.FromSeconds(Math.Max(lastFire.TotalSeconds + SafetyNextFire, gun.NextFire.TotalSeconds));
return; return;
} }
@@ -328,6 +338,10 @@ public abstract partial class SharedGunSystem : EntitySystem
var emptyGunShotEvent = new OnEmptyGunShotEvent(); var emptyGunShotEvent = new OnEmptyGunShotEvent();
RaiseLocalEvent(gunUid, ref emptyGunShotEvent); RaiseLocalEvent(gunUid, ref emptyGunShotEvent);
gun.BurstActivated = false;
gun.BurstShotsCount = 0;
gun.NextFire += TimeSpan.FromSeconds(gun.BurstCooldown);
// Play empty gun sounds if relevant // Play empty gun sounds if relevant
// If they're firing an existing clip then don't play anything. // If they're firing an existing clip then don't play anything.
if (shots > 0) if (shots > 0)
@@ -347,6 +361,22 @@ public abstract partial class SharedGunSystem : EntitySystem
return; return;
} }
// Handle burstfire
if (gun.SelectedMode == SelectiveFire.Burst)
{
gun.BurstActivated = true;
}
if (gun.BurstActivated)
{
gun.BurstShotsCount += shots;
if (gun.BurstShotsCount >= gun.ShotsPerBurstModified)
{
gun.NextFire += TimeSpan.FromSeconds(gun.BurstCooldown);
gun.BurstActivated = false;
gun.BurstShotsCount = 0;
}
}
// Shoot confirmed - sounds also played here in case it's invalid (e.g. cartridge already spent). // Shoot confirmed - sounds also played here in case it's invalid (e.g. cartridge already spent).
Shoot(gunUid, gun, ev.Ammo, fromCoordinates, toCoordinates.Value, out var userImpulse, user, throwItems: attemptEv.ThrowItems); Shoot(gunUid, gun, ev.Ammo, fromCoordinates, toCoordinates.Value, out var userImpulse, user, throwItems: attemptEv.ThrowItems);
var shotEv = new GunShotEvent(user, ev.Ammo); var shotEv = new GunShotEvent(user, ev.Ammo);

View File

@@ -19,6 +19,7 @@
minAngle: 2 minAngle: 2
maxAngle: 16 maxAngle: 16
fireRate: 8 fireRate: 8
burstFireRate: 8
angleIncrease: 3 angleIncrease: 3
angleDecay: 16 angleDecay: 16
selectedMode: FullAuto selectedMode: FullAuto
@@ -27,6 +28,7 @@
- FullAuto - FullAuto
soundGunshot: soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/smg.ogg path: /Audio/Weapons/Guns/Gunshots/smg.ogg
defaultDirection: 1, 0
- type: ChamberMagazineAmmoProvider - type: ChamberMagazineAmmoProvider
soundRack: soundRack:
path: /Audio/Weapons/Guns/Cock/smg_cock.ogg path: /Audio/Weapons/Guns/Cock/smg_cock.ogg
@@ -140,12 +142,15 @@
- type: Gun - type: Gun
minAngle: 21 minAngle: 21
maxAngle: 32 maxAngle: 32
fireRate: 6 fireRate: 12
selectedMode: FullAuto burstFireRate: 12
selectedMode: Burst
soundGunshot: soundGunshot:
path: /Audio/Weapons/Guns/Gunshots/atreides.ogg path: /Audio/Weapons/Guns/Gunshots/atreides.ogg
availableModes: availableModes:
- FullAuto - Burst
shotsPerBurst: 3
burstCooldown: 0.25
- type: ItemSlots - type: ItemSlots
slots: slots:
gun_magazine: gun_magazine:
@@ -250,6 +255,8 @@
angleDecay: 6 angleDecay: 6
selectedMode: FullAuto selectedMode: FullAuto
shotsPerBurst: 5 shotsPerBurst: 5
burstCooldown: 0.2
burstFireRate: 7
availableModes: availableModes:
- SemiAuto - SemiAuto
- Burst - Burst