SharedPneumaticCannonSystem.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Content.Shared.Popups;
  2. using Content.Shared.Weapons.Ranged.Systems;
  3. using Robust.Shared.Containers;
  4. using Robust.Shared.Serialization;
  5. namespace Content.Shared.PneumaticCannon;
  6. public abstract class SharedPneumaticCannonSystem : EntitySystem
  7. {
  8. [Dependency] protected readonly SharedContainerSystem Container = default!;
  9. [Dependency] protected readonly SharedPopupSystem Popup = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<PneumaticCannonComponent, AttemptShootEvent>(OnAttemptShoot);
  14. }
  15. private void OnAttemptShoot(EntityUid uid, PneumaticCannonComponent component, ref AttemptShootEvent args)
  16. {
  17. // if the cannon doesn't need gas then it will always predict firing
  18. if (component.GasUsage == 0f)
  19. return;
  20. // pneumatic cannon usually doesn't shoot bullets
  21. args.ThrowItems = component.ThrowItems;
  22. // we don't have atmos on shared, so just predict by the existence of a slot item
  23. // server will handle auto ejecting/not adding the slot item if it doesnt have enough gas,
  24. // so this won't mispredict
  25. if (!Container.TryGetContainer(uid, PneumaticCannonComponent.TankSlotId, out var container) ||
  26. container is not ContainerSlot slot || slot.ContainedEntity is null)
  27. {
  28. args.Cancelled = true;
  29. }
  30. }
  31. }