GunSystem.AutoFire.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. public override void Update(float frameTime)
  8. {
  9. base.Update(frameTime);
  10. /*
  11. * On server because client doesn't want to predict other's guns.
  12. */
  13. // Automatic firing without stopping if the AutoShootGunComponent component is exist and enabled
  14. var query = EntityQueryEnumerator<GunComponent>();
  15. while (query.MoveNext(out var uid, out var gun))
  16. {
  17. if (gun.NextFire > Timing.CurTime)
  18. continue;
  19. if (TryComp(uid, out AutoShootGunComponent? autoShoot))
  20. {
  21. if (!autoShoot.Enabled)
  22. continue;
  23. AttemptShoot(uid, gun);
  24. }
  25. else if (gun.BurstActivated)
  26. {
  27. var parent = _transform.GetParentUid(uid);
  28. if (HasComp<DamageableComponent>(parent))
  29. AttemptShoot(parent, uid, gun, gun.ShootCoordinates ?? new EntityCoordinates(uid, gun.DefaultDirection));
  30. else
  31. AttemptShoot(uid, gun);
  32. }
  33. }
  34. }
  35. }