AllWiresCut.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Content.Server.Wires;
  2. using Content.Shared.Construction;
  3. using Content.Shared.Examine;
  4. using JetBrains.Annotations;
  5. namespace Content.Server.Construction.Conditions
  6. {
  7. /// <summary>
  8. /// A condition that requires all wires to be cut (or intact)
  9. /// Returns true if the entity doesn't have a wires component.
  10. /// </summary>
  11. [UsedImplicitly]
  12. [DataDefinition]
  13. public sealed partial class AllWiresCut : IGraphCondition
  14. {
  15. [DataField("value")] public bool Value { get; private set; } = true;
  16. public bool Condition(EntityUid uid, IEntityManager entityManager)
  17. {
  18. if (!entityManager.TryGetComponent(uid, out WiresComponent? wires))
  19. return true;
  20. foreach (var wire in wires.WiresList)
  21. {
  22. switch (Value)
  23. {
  24. case true when !wire.IsCut:
  25. case false when wire.IsCut:
  26. return false;
  27. }
  28. }
  29. return true;
  30. }
  31. public bool DoExamine(ExaminedEvent args)
  32. {
  33. if (Condition(args.Examined, IoCManager.Resolve<IEntityManager>()))
  34. return false;
  35. args.PushMarkup(Loc.GetString(Value
  36. ? "construction-examine-condition-all-wires-cut"
  37. : "construction-examine-condition-all-wires-intact"));
  38. return true;
  39. }
  40. public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
  41. {
  42. yield return new ConstructionGuideEntry()
  43. {
  44. Localization = Value ? "construction-guide-condition-all-wires-cut"
  45. : "construction-guide-condition-all-wires-intact"
  46. };
  47. }
  48. }
  49. }