1
0

EscapeShuttleConditionSystem.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Content.Server.Objectives.Components;
  2. using Content.Server.Shuttles.Systems;
  3. using Content.Shared.Cuffs.Components;
  4. using Content.Shared.Mind;
  5. using Content.Shared.Objectives.Components;
  6. namespace Content.Server.Objectives.Systems;
  7. public sealed class EscapeShuttleConditionSystem : EntitySystem
  8. {
  9. [Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
  10. [Dependency] private readonly SharedMindSystem _mind = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<EscapeShuttleConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
  15. }
  16. private void OnGetProgress(EntityUid uid, EscapeShuttleConditionComponent comp, ref ObjectiveGetProgressEvent args)
  17. {
  18. args.Progress = GetProgress(args.MindId, args.Mind);
  19. }
  20. private float GetProgress(EntityUid mindId, MindComponent mind)
  21. {
  22. // not escaping alive if you're deleted/dead
  23. if (mind.OwnedEntity == null || _mind.IsCharacterDeadIc(mind))
  24. return 0f;
  25. // You're not escaping if you're restrained!
  26. if (TryComp<CuffableComponent>(mind.OwnedEntity, out var cuffed) && cuffed.CuffedHandCount > 0)
  27. return 0f;
  28. // Any emergency shuttle counts for this objective, but not pods.
  29. return _emergencyShuttle.IsTargetEscaping(mind.OwnedEntity.Value) ? 1f : 0f;
  30. }
  31. }