GunSystem.Ballistic.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Content.Shared.Weapons.Ranged.Components;
  2. using Content.Shared.Weapons.Ranged.Events;
  3. using Robust.Shared.Map;
  4. namespace Content.Server.Weapons.Ranged.Systems;
  5. public sealed partial class GunSystem
  6. {
  7. protected override void Cycle(EntityUid uid, BallisticAmmoProviderComponent component, MapCoordinates coordinates)
  8. {
  9. EntityUid? ent = null;
  10. // TODO: Combine with TakeAmmo
  11. if (component.Entities.Count > 0)
  12. {
  13. var existing = component.Entities[^1];
  14. component.Entities.RemoveAt(component.Entities.Count - 1);
  15. DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.Entities));
  16. Containers.Remove(existing, component.Container);
  17. EnsureShootable(existing);
  18. }
  19. else if (component.UnspawnedCount > 0)
  20. {
  21. component.UnspawnedCount--;
  22. DirtyField(uid, component, nameof(BallisticAmmoProviderComponent.UnspawnedCount));
  23. ent = Spawn(component.Proto, coordinates);
  24. EnsureShootable(ent.Value);
  25. }
  26. if (ent != null)
  27. EjectCartridge(ent.Value);
  28. var cycledEvent = new GunCycledEvent();
  29. RaiseLocalEvent(uid, ref cycledEvent);
  30. }
  31. }