KillPersonConditionSystem.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Content.Server.Objectives.Components;
  2. using Content.Server.Shuttles.Systems;
  3. using Content.Shared.CCVar;
  4. using Content.Shared.Mind;
  5. using Content.Shared.Objectives.Components;
  6. using Robust.Shared.Configuration;
  7. namespace Content.Server.Objectives.Systems;
  8. /// <summary>
  9. /// Handles kill person condition logic and picking random kill targets.
  10. /// </summary>
  11. public sealed class KillPersonConditionSystem : EntitySystem
  12. {
  13. [Dependency] private readonly EmergencyShuttleSystem _emergencyShuttle = default!;
  14. [Dependency] private readonly IConfigurationManager _config = default!;
  15. [Dependency] private readonly SharedMindSystem _mind = default!;
  16. [Dependency] private readonly TargetObjectiveSystem _target = default!;
  17. public override void Initialize()
  18. {
  19. base.Initialize();
  20. SubscribeLocalEvent<KillPersonConditionComponent, ObjectiveGetProgressEvent>(OnGetProgress);
  21. }
  22. private void OnGetProgress(EntityUid uid, KillPersonConditionComponent comp, ref ObjectiveGetProgressEvent args)
  23. {
  24. if (!_target.GetTarget(uid, out var target))
  25. return;
  26. args.Progress = GetProgress(target.Value, comp.RequireDead);
  27. }
  28. private float GetProgress(EntityUid target, bool requireDead)
  29. {
  30. // deleted or gibbed or something, counts as dead
  31. if (!TryComp<MindComponent>(target, out var mind) || mind.OwnedEntity == null)
  32. return 1f;
  33. // dead is success
  34. if (_mind.IsCharacterDeadIc(mind))
  35. return 1f;
  36. // if the target has to be dead dead then don't check evac stuff
  37. if (requireDead)
  38. return 0f;
  39. // if evac is disabled then they really do have to be dead
  40. if (!_config.GetCVar(CCVars.EmergencyShuttleEnabled))
  41. return 0f;
  42. // target is escaping so you fail
  43. if (_emergencyShuttle.IsTargetEscaping(mind.OwnedEntity.Value))
  44. return 0f;
  45. // evac has left without the target, greentext since the target is afk in space with a full oxygen tank and coordinates off.
  46. if (_emergencyShuttle.ShuttlesLeft)
  47. return 1f;
  48. // if evac is still here and target hasn't boarded, show 50% to give you an indicator that you are doing good
  49. return _emergencyShuttle.EmergencyShuttleArrived ? 0.5f : 0f;
  50. }
  51. }