CriminalRecordsHackerSystem.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using Content.Server.Chat.Systems;
  2. using Content.Server.Station.Systems;
  3. using Content.Server.StationRecords.Systems;
  4. using Content.Shared.CriminalRecords;
  5. using Content.Shared.CriminalRecords.Components;
  6. using Content.Shared.CriminalRecords.Systems;
  7. using Content.Shared.Dataset;
  8. using Content.Shared.Security;
  9. using Content.Shared.StationRecords;
  10. using Robust.Shared.Prototypes;
  11. using Robust.Shared.Random;
  12. namespace Content.Server.CriminalRecords.Systems;
  13. public sealed class CriminalRecordsHackerSystem : SharedCriminalRecordsHackerSystem
  14. {
  15. [Dependency] private readonly ChatSystem _chat = default!;
  16. [Dependency] private readonly CriminalRecordsSystem _criminalRecords = default!;
  17. [Dependency] private readonly IPrototypeManager _proto = default!;
  18. [Dependency] private readonly IRobustRandom _random = default!;
  19. [Dependency] private readonly StationSystem _station = default!;
  20. [Dependency] private readonly StationRecordsSystem _records = default!;
  21. public override void Initialize()
  22. {
  23. base.Initialize();
  24. SubscribeLocalEvent<CriminalRecordsHackerComponent, CriminalRecordsHackDoAfterEvent>(OnDoAfter);
  25. }
  26. private void OnDoAfter(Entity<CriminalRecordsHackerComponent> ent, ref CriminalRecordsHackDoAfterEvent args)
  27. {
  28. if (args.Cancelled || args.Handled || args.Target == null)
  29. return;
  30. if (_station.GetOwningStation(ent) is not {} station)
  31. return;
  32. var reasons = _proto.Index<DatasetPrototype>(ent.Comp.Reasons);
  33. foreach (var (key, record) in _records.GetRecordsOfType<CriminalRecord>(station))
  34. {
  35. var reason = _random.Pick(reasons.Values);
  36. _criminalRecords.OverwriteStatus(new StationRecordKey(key, station), record, SecurityStatus.Wanted, reason);
  37. // no radio message since spam
  38. // no history since lazy and its easy to remove anyway
  39. // main damage with this is existing arrest warrants are lost and to anger beepsky
  40. }
  41. _chat.DispatchGlobalAnnouncement(Loc.GetString(ent.Comp.Announcement), playSound: true, colorOverride: Color.Red);
  42. // once is enough
  43. RemComp<CriminalRecordsHackerComponent>(ent);
  44. var ev = new CriminalRecordsHackedEvent(ent, args.Target.Value);
  45. RaiseLocalEvent(args.User, ref ev);
  46. }
  47. }
  48. /// <summary>
  49. /// Raised on the user after hacking a criminal records console.
  50. /// </summary>
  51. [ByRefEvent]
  52. public record struct CriminalRecordsHackedEvent(EntityUid User, EntityUid Target);