+using Content.Shared.Damage;
using Content.Shared.Weapons.Ranged.Components;
+using Robust.Shared.Map;
namespace Content.Server.Weapons.Ranged.Systems;
*/
// 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)
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);
+ }
}
}
}
+using System.Numerics;
using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Audio;
[AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
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>
/// Used for tracking semi-auto / burst
/// </summary>
/// </summary>
[DataField]
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]
/// </summary>
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;
AttemptShoot(gunUid, gunUid, gun);
gun.ShotCounter = 0;
var fireRate = TimeSpan.FromSeconds(1f / gun.FireRateModified);
+ if (gun.SelectedMode == SelectiveFire.Burst || gun.BurstActivated)
+ fireRate = TimeSpan.FromSeconds(1f / gun.BurstFireRate);
+
// First shot
// 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.
// 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.
- switch (gun.SelectedMode)
+ if (!gun.BurstActivated)
+ {
+ switch (gun.SelectedMode)
+ {
+ case SelectiveFire.SemiAuto:
+ shots = Math.Min(shots, 1 - gun.ShotCounter);
+ break;
+ case SelectiveFire.Burst:
+ shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter);
+ break;
+ case SelectiveFire.FullAuto:
+ break;
+ default:
+ throw new ArgumentOutOfRangeException($"No implemented shooting behavior for {gun.SelectedMode}!");
+ }
+ } else
{
- case SelectiveFire.SemiAuto:
- shots = Math.Min(shots, 1 - gun.ShotCounter);
- break;
- case SelectiveFire.Burst:
- shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter);
- break;
- case SelectiveFire.FullAuto:
- break;
- default:
- throw new ArgumentOutOfRangeException($"No implemented shooting behavior for {gun.SelectedMode}!");
+ shots = Math.Min(shots, gun.ShotsPerBurstModified - gun.ShotCounter);
}
var attemptEv = new AttemptShootEvent(user, null);
{
PopupSystem.PopupClient(attemptEv.Message, gunUid, user);
}
-
+ gun.BurstActivated = false;
+ gun.BurstShotsCount = 0;
gun.NextFire = TimeSpan.FromSeconds(Math.Max(lastFire.TotalSeconds + SafetyNextFire, gun.NextFire.TotalSeconds));
return;
}
var emptyGunShotEvent = new OnEmptyGunShotEvent();
RaiseLocalEvent(gunUid, ref emptyGunShotEvent);
+ gun.BurstActivated = false;
+ gun.BurstShotsCount = 0;
+ gun.NextFire += TimeSpan.FromSeconds(gun.BurstCooldown);
+
// Play empty gun sounds if relevant
// If they're firing an existing clip then don't play anything.
if (shots > 0)
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(gunUid, gun, ev.Ammo, fromCoordinates, toCoordinates.Value, out var userImpulse, user, throwItems: attemptEv.ThrowItems);
var shotEv = new GunShotEvent(user, ev.Ammo);