TetherGunSystem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Content.Server.PowerCell;
  2. using Content.Shared.Item.ItemToggle;
  3. using Content.Shared.PowerCell;
  4. using Content.Shared.Weapons.Misc;
  5. using Robust.Shared.Physics.Components;
  6. namespace Content.Server.Weapons.Misc;
  7. public sealed class TetherGunSystem : SharedTetherGunSystem
  8. {
  9. [Dependency] private readonly PowerCellSystem _cell = default!;
  10. [Dependency] private readonly ItemToggleSystem _toggle = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<TetherGunComponent, PowerCellSlotEmptyEvent>(OnGunEmpty);
  15. SubscribeLocalEvent<ForceGunComponent, PowerCellSlotEmptyEvent>(OnGunEmpty);
  16. }
  17. private void OnGunEmpty(EntityUid uid, BaseForceGunComponent component, ref PowerCellSlotEmptyEvent args)
  18. {
  19. StopTether(uid, component);
  20. }
  21. protected override bool CanTether(EntityUid uid, BaseForceGunComponent component, EntityUid target, EntityUid? user)
  22. {
  23. if (!base.CanTether(uid, component, target, user))
  24. return false;
  25. if (!_cell.HasDrawCharge(uid, user: user))
  26. return false;
  27. return true;
  28. }
  29. protected override void StartTether(EntityUid gunUid, BaseForceGunComponent component, EntityUid target, EntityUid? user,
  30. PhysicsComponent? targetPhysics = null, TransformComponent? targetXform = null)
  31. {
  32. base.StartTether(gunUid, component, target, user, targetPhysics, targetXform);
  33. _toggle.TryActivate(gunUid);
  34. }
  35. protected override void StopTether(EntityUid gunUid, BaseForceGunComponent component, bool land = true, bool transfer = false)
  36. {
  37. base.StopTether(gunUid, component, land, transfer);
  38. _toggle.TryDeactivate(gunUid);
  39. }
  40. }