HijackShuttleConditionSystem.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using Content.Server.Objectives.Components;
  2. using Content.Server.Shuttles.Components;
  3. using Content.Server.Shuttles.Systems;
  4. using Content.Shared.Cuffs.Components;
  5. using Content.Shared.Humanoid;
  6. using Content.Shared.Mind;
  7. using Content.Shared.Mobs.Components;
  8. using Content.Shared.Mobs.Systems;
  9. using Content.Shared.Objectives.Components;
  10. using Content.Shared.Roles;
  11. using Robust.Shared.Player;
  12. namespace Content.Server.Objectives.Systems;
  13. public sealed class HijackShuttleConditionSystem : EntitySystem
  14. {
  15. [Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
  16. [Dependency] private readonly SharedMindSystem _mind = default!;
  17. [Dependency] private readonly SharedRoleSystem _role = default!;
  18. [Dependency] private readonly MobStateSystem _mobState = default!;
  19. public override void Initialize()
  20. {
  21. base.Initialize();
  22. SubscribeLocalEvent<HijackShuttleConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
  23. }
  24. private void OnGetProgress(EntityUid uid, HijackShuttleConditionComponent comp, ref ObjectiveGetProgressEvent args)
  25. {
  26. args.Progress = GetProgress(args.MindId, args.Mind);
  27. }
  28. private float GetProgress(EntityUid mindId, MindComponent mind)
  29. {
  30. // Not escaping alive if you're deleted/dead
  31. if (mind.OwnedEntity == null || _mind.IsCharacterDeadIc(mind))
  32. return 0f;
  33. // You're not escaping if you're restrained!
  34. if (TryComp<CuffableComponent>(mind.OwnedEntity, out var cuffed) && cuffed.CuffedHandCount > 0)
  35. return 0f;
  36. // There no emergency shuttles
  37. if (!_emergencyShuttle.EmergencyShuttleArrived)
  38. return 0f;
  39. // Check hijack for each emergency shuttle
  40. foreach (var stationData in EntityQuery<StationEmergencyShuttleComponent>())
  41. {
  42. if (stationData.EmergencyShuttle == null)
  43. continue;
  44. if (IsShuttleHijacked(stationData.EmergencyShuttle.Value, mindId))
  45. return 1f;
  46. }
  47. return 0f;
  48. }
  49. private bool IsShuttleHijacked(EntityUid shuttleGridId, EntityUid mindId)
  50. {
  51. var gridPlayers = Filter.BroadcastGrid(shuttleGridId).Recipients;
  52. var humanoids = GetEntityQuery<HumanoidAppearanceComponent>();
  53. var cuffable = GetEntityQuery<CuffableComponent>();
  54. EntityQuery<MobStateComponent>();
  55. var agentOnShuttle = false;
  56. foreach (var player in gridPlayers)
  57. {
  58. if (player.AttachedEntity == null ||
  59. !_mind.TryGetMind(player.AttachedEntity.Value, out var crewMindId, out _))
  60. continue;
  61. if (mindId == crewMindId)
  62. {
  63. agentOnShuttle = true;
  64. continue;
  65. }
  66. var isHumanoid = humanoids.HasComponent(player.AttachedEntity.Value);
  67. if (!isHumanoid) // Only humanoids count as enemies
  68. continue;
  69. var isAntagonist = _role.MindIsAntagonist(mindId);
  70. if (isAntagonist) // Allow antagonist
  71. continue;
  72. var isPersonIncapacitated = _mobState.IsIncapacitated(player.AttachedEntity.Value);
  73. if (isPersonIncapacitated) // Allow dead and crit
  74. continue;
  75. var isPersonCuffed =
  76. cuffable.TryGetComponent(player.AttachedEntity.Value, out var cuffed)
  77. && cuffed.CuffedHandCount > 0;
  78. if (isPersonCuffed) // Allow handcuffed
  79. continue;
  80. return false;
  81. }
  82. return agentOnShuttle;
  83. }
  84. }