GunSystem.AutoFire.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Content.Shared.Damage;
  2. using Content.Shared.Weapons.Ranged.Components;
  3. using Robust.Shared.Map;
  4. namespace Content.Server.Weapons.Ranged.Systems;
  5. public sealed partial class GunSystem
  6. {
  7. [Dependency] private readonly SharedTransformSystem _transform = default!;
  8. public override void Update(float frameTime)
  9. {
  10. base.Update(frameTime);
  11. /*
  12. * On server because client doesn't want to predict other's guns.
  13. */
  14. // Automatic firing without stopping if the AutoShootGunComponent component is exist and enabled
  15. var query = EntityQueryEnumerator<GunComponent>();
  16. while (query.MoveNext(out var uid, out var gun))
  17. {
  18. if (gun.NextFire > Timing.CurTime)
  19. continue;
  20. if (TryComp(uid, out AutoShootGunComponent? autoShoot))
  21. {
  22. if (!autoShoot.Enabled)
  23. continue;
  24. AttemptShoot(uid, gun);
  25. }
  26. else if (gun.BurstActivated)
  27. {
  28. var parent = _transform.GetParentUid(uid);
  29. if (HasComp<DamageableComponent>(parent))
  30. AttemptShoot(parent, uid, gun, gun.ShootCoordinates ?? new EntityCoordinates(uid, gun.DefaultDirection));
  31. else
  32. AttemptShoot(uid, gun);
  33. }
  34. }
  35. }
  36. }