GrapplingGunSystem.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Net;
  2. using Content.Client.Hands.Systems;
  3. using Content.Shared.CombatMode;
  4. using Content.Shared.Weapons.Misc;
  5. using Content.Shared.Weapons.Ranged.Components;
  6. using Robust.Client.GameObjects;
  7. using Robust.Client.Player;
  8. using Robust.Shared.Input;
  9. using Robust.Shared.Physics;
  10. using Robust.Shared.Physics.Dynamics.Joints;
  11. namespace Content.Client.Weapons.Misc;
  12. public sealed class GrapplingGunSystem : SharedGrapplingGunSystem
  13. {
  14. [Dependency] private readonly HandsSystem _hands = default!;
  15. [Dependency] private readonly InputSystem _input = default!;
  16. [Dependency] private readonly IPlayerManager _player = default!;
  17. public override void Update(float frameTime)
  18. {
  19. base.Update(frameTime);
  20. // Oh boy another input handler.
  21. // If someone thinks of a better way to unify this please tell me.
  22. if (!Timing.IsFirstTimePredicted)
  23. return;
  24. var local = _player.LocalEntity;
  25. var handUid = _hands.GetActiveHandEntity();
  26. if (!TryComp<GrapplingGunComponent>(handUid, out var grappling))
  27. return;
  28. if (!TryComp<JointComponent>(handUid, out var jointComp) ||
  29. !jointComp.GetJoints.TryGetValue(GrapplingJoint, out var joint) ||
  30. joint is not DistanceJoint distance)
  31. {
  32. return;
  33. }
  34. if (distance.MaxLength <= distance.MinLength)
  35. return;
  36. var reelKey = _input.CmdStates.GetState(EngineKeyFunctions.UseSecondary) == BoundKeyState.Down;
  37. if (!TryComp<CombatModeComponent>(local, out var combatMode) ||
  38. !combatMode.IsInCombatMode)
  39. {
  40. reelKey = false;
  41. }
  42. if (grappling.Reeling == reelKey)
  43. return;
  44. RaisePredictiveEvent(new RequestGrapplingReelMessage(reelKey));
  45. }
  46. }