Locked.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Content.Shared.Construction;
  2. using Content.Shared.Examine;
  3. using Content.Shared.Lock;
  4. using JetBrains.Annotations;
  5. namespace Content.Server.Construction.Conditions
  6. {
  7. [UsedImplicitly]
  8. [DataDefinition]
  9. public sealed partial class Locked : IGraphCondition
  10. {
  11. [DataField("locked")]
  12. public bool IsLocked { get; private set; } = true;
  13. public bool Condition(EntityUid uid, IEntityManager entityManager)
  14. {
  15. if (!entityManager.TryGetComponent(uid, out LockComponent? lockcomp))
  16. return true;
  17. return lockcomp.Locked == IsLocked;
  18. }
  19. public bool DoExamine(ExaminedEvent args)
  20. {
  21. var entMan = IoCManager.Resolve<IEntityManager>();
  22. var entity = args.Examined;
  23. if (!entMan.TryGetComponent(entity, out LockComponent? lockcomp))
  24. return true;
  25. switch (IsLocked)
  26. {
  27. case true when !lockcomp.Locked:
  28. args.PushMarkup(Loc.GetString("construction-examine-condition-lock"));
  29. return true;
  30. case false when lockcomp.Locked:
  31. args.PushMarkup(Loc.GetString("construction-examine-condition-unlock"));
  32. return true;
  33. }
  34. return false;
  35. }
  36. public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
  37. {
  38. yield return new ConstructionGuideEntry()
  39. {
  40. Localization = IsLocked
  41. ? "construction-step-condition-wire-panel-lock"
  42. : "construction-step-condition-wire-panel-unlock"
  43. };
  44. }
  45. }
  46. }