CuffableSystem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Shared.ActionBlocker;
  2. using Content.Shared.Cuffs;
  3. using Content.Shared.Cuffs.Components;
  4. using Content.Shared.Humanoid;
  5. using Robust.Client.GameObjects;
  6. using Robust.Shared.GameStates;
  7. namespace Content.Client.Cuffs;
  8. public sealed class CuffableSystem : SharedCuffableSystem
  9. {
  10. [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<CuffableComponent, ComponentShutdown>(OnCuffableShutdown);
  15. SubscribeLocalEvent<CuffableComponent, ComponentHandleState>(OnCuffableHandleState);
  16. }
  17. private void OnCuffableShutdown(EntityUid uid, CuffableComponent component, ComponentShutdown args)
  18. {
  19. if (TryComp<SpriteComponent>(uid, out var sprite))
  20. sprite.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
  21. }
  22. private void OnCuffableHandleState(EntityUid uid, CuffableComponent component, ref ComponentHandleState args)
  23. {
  24. if (args.Current is not CuffableComponentState cuffState)
  25. return;
  26. component.CanStillInteract = cuffState.CanStillInteract;
  27. _actionBlocker.UpdateCanMove(uid);
  28. var ev = new CuffedStateChangeEvent();
  29. RaiseLocalEvent(uid, ref ev);
  30. if (!TryComp<SpriteComponent>(uid, out var sprite))
  31. return;
  32. var cuffed = cuffState.NumHandsCuffed > 0;
  33. sprite.LayerSetVisible(HumanoidVisualLayers.Handcuffs, cuffed);
  34. // if they are not cuffed, that means that we didn't get a valid color,
  35. // iconstate, or RSI. that also means we don't need to update the sprites.
  36. if (!cuffed)
  37. return;
  38. sprite.LayerSetColor(HumanoidVisualLayers.Handcuffs, cuffState.Color!.Value);
  39. if (!Equals(component.CurrentRSI, cuffState.RSI) && cuffState.RSI != null) // we don't want to keep loading the same RSI
  40. {
  41. component.CurrentRSI = cuffState.RSI;
  42. sprite.LayerSetState(HumanoidVisualLayers.Handcuffs, cuffState.IconState, component.CurrentRSI);
  43. }
  44. else
  45. {
  46. sprite.LayerSetState(HumanoidVisualLayers.Handcuffs, cuffState.IconState);
  47. }
  48. }
  49. }