1
0

EmagProviderSystem.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Content.Shared.Administration.Logs;
  2. using Content.Shared.Database;
  3. using Content.Shared.Emag.Systems;
  4. using Content.Shared.Interaction;
  5. using Content.Shared.Ninja.Components;
  6. using Content.Shared.Tag;
  7. using Content.Shared.Whitelist;
  8. using Robust.Shared.Audio.Systems;
  9. namespace Content.Shared.Ninja.Systems;
  10. /// <summary>
  11. /// Handles emagging whitelisted objects when clicked.
  12. /// </summary>
  13. public sealed class EmagProviderSystem : EntitySystem
  14. {
  15. [Dependency] private readonly SharedAudioSystem _audio = default!;
  16. [Dependency] private readonly EmagSystem _emag = default!;
  17. [Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
  18. [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
  19. [Dependency] private readonly SharedNinjaGlovesSystem _gloves = default!;
  20. [Dependency] private readonly TagSystem _tag = default!;
  21. public override void Initialize()
  22. {
  23. base.Initialize();
  24. SubscribeLocalEvent<EmagProviderComponent, BeforeInteractHandEvent>(OnBeforeInteractHand);
  25. }
  26. /// <summary>
  27. /// Emag clicked entities that are on the whitelist.
  28. /// </summary>
  29. private void OnBeforeInteractHand(Entity<EmagProviderComponent> ent, ref BeforeInteractHandEvent args)
  30. {
  31. // TODO: change this into a generic check event thing
  32. if (args.Handled || !_gloves.AbilityCheck(ent, args, out var target))
  33. return;
  34. var (uid, comp) = ent;
  35. // only allowed to emag entities on the whitelist
  36. if (_whitelist.IsWhitelistFail(comp.Whitelist, target))
  37. return;
  38. // only allowed to emag non-immune entities
  39. if (_tag.HasTag(target, comp.AccessBreakerImmuneTag))
  40. return;
  41. var emagEv = new GotEmaggedEvent(uid, EmagType.Access);
  42. RaiseLocalEvent(args.Target, ref emagEv);
  43. if (!emagEv.Handled)
  44. return;
  45. _audio.PlayPredicted(comp.EmagSound, uid, uid);
  46. _adminLogger.Add(LogType.Emag, LogImpact.High, $"{ToPrettyString(uid):player} emagged {ToPrettyString(target):target} with flag(s): {ent.Comp.EmagType}");
  47. var ev = new EmaggedSomethingEvent(target);
  48. RaiseLocalEvent(uid, ref ev);
  49. args.Handled = true;
  50. }
  51. }
  52. /// <summary>
  53. /// Raised on the player when access breaking something.
  54. /// </summary>
  55. [ByRefEvent]
  56. public record struct EmaggedSomethingEvent(EntityUid Target);