ThiefBeaconSystem.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Content.Server.Mind;
  2. using Content.Server.Objectives.Components;
  3. using Content.Server.Roles;
  4. using Content.Server.Thief.Components;
  5. using Content.Shared.Examine;
  6. using Content.Shared.Foldable;
  7. using Content.Shared.Popups;
  8. using Content.Shared.Verbs;
  9. using Content.Shared.Roles;
  10. using Robust.Shared.Audio.Systems;
  11. namespace Content.Server.Thief.Systems;
  12. /// <summary>
  13. /// <see cref="ThiefBeaconComponent"/>
  14. /// </summary>
  15. public sealed class ThiefBeaconSystem : EntitySystem
  16. {
  17. [Dependency] private readonly SharedAudioSystem _audio = default!;
  18. [Dependency] private readonly SharedPopupSystem _popup = default!;
  19. [Dependency] private readonly MindSystem _mind = default!;
  20. [Dependency] private readonly SharedRoleSystem _roles = default!;
  21. public override void Initialize()
  22. {
  23. base.Initialize();
  24. SubscribeLocalEvent<ThiefBeaconComponent, GetVerbsEvent<InteractionVerb>>(OnGetInteractionVerbs);
  25. SubscribeLocalEvent<ThiefBeaconComponent, FoldedEvent>(OnFolded);
  26. SubscribeLocalEvent<ThiefBeaconComponent, ExaminedEvent>(OnExamined);
  27. }
  28. private void OnGetInteractionVerbs(Entity<ThiefBeaconComponent> beacon, ref GetVerbsEvent<InteractionVerb> args)
  29. {
  30. if (!args.CanAccess || !args.CanInteract || args.Hands is null)
  31. return;
  32. if (TryComp<FoldableComponent>(beacon, out var foldable) && foldable.IsFolded)
  33. return;
  34. var mind = _mind.GetMind(args.User);
  35. if (mind == null || !_roles.MindHasRole<ThiefRoleComponent>(mind.Value))
  36. return;
  37. var user = args.User;
  38. args.Verbs.Add(new()
  39. {
  40. Act = () =>
  41. {
  42. SetCoordinate(beacon, mind.Value);
  43. },
  44. Message = Loc.GetString("thief-fulton-verb-message"),
  45. Text = Loc.GetString("thief-fulton-verb-text"),
  46. });
  47. }
  48. private void OnFolded(Entity<ThiefBeaconComponent> beacon, ref FoldedEvent args)
  49. {
  50. if (args.IsFolded)
  51. ClearCoordinate(beacon);
  52. }
  53. private void OnExamined(Entity<ThiefBeaconComponent> beacon, ref ExaminedEvent args)
  54. {
  55. if (!TryComp<StealAreaComponent>(beacon, out var area))
  56. return;
  57. args.PushText(Loc.GetString(area.Owners.Count == 0
  58. ? "thief-fulton-examined-unset"
  59. : "thief-fulton-examined-set"));
  60. }
  61. private void SetCoordinate(Entity<ThiefBeaconComponent> beacon, EntityUid mind)
  62. {
  63. if (!TryComp<StealAreaComponent>(beacon, out var area))
  64. return;
  65. _audio.PlayPvs(beacon.Comp.LinkSound, beacon);
  66. _popup.PopupEntity(Loc.GetString("thief-fulton-set"), beacon);
  67. area.Owners.Clear(); //We only reconfigure the beacon for ourselves, we don't need multiple thieves to steal from the same beacon.
  68. area.Owners.Add(mind);
  69. }
  70. private void ClearCoordinate(Entity<ThiefBeaconComponent> beacon)
  71. {
  72. if (!TryComp<StealAreaComponent>(beacon, out var area))
  73. return;
  74. if (area.Owners.Count == 0)
  75. return;
  76. _audio.PlayPvs(beacon.Comp.UnlinkSound, beacon);
  77. _popup.PopupEntity(Loc.GetString("thief-fulton-clear"), beacon);
  78. area.Owners.Clear();
  79. }
  80. }