ContainmentFieldGeneratorComponent.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Content.Shared.Physics;
  2. using Content.Shared.Tag;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Serialization;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  7. namespace Content.Shared.Singularity.Components;
  8. [RegisterComponent, NetworkedComponent]
  9. public sealed partial class ContainmentFieldGeneratorComponent : Component
  10. {
  11. private int _powerBuffer;
  12. /// <summary>
  13. /// Store power with a cap. Decrease over time if not being powered from source.
  14. /// </summary>
  15. [DataField("powerBuffer")]
  16. public int PowerBuffer
  17. {
  18. get => _powerBuffer;
  19. set => _powerBuffer = Math.Clamp(value, 0, 25); //have this decrease over time if not hit by a bolt
  20. }
  21. /// <summary>
  22. /// The minimum the field generator needs to start generating a connection
  23. /// </summary>
  24. [ViewVariables(VVAccess.ReadWrite)]
  25. [DataField("powerMinimum")]
  26. public int PowerMinimum = 6;
  27. /// <summary>
  28. /// How much power should this field generator receive from a collision
  29. /// </summary>
  30. [ViewVariables(VVAccess.ReadWrite)]
  31. [DataField("power")]
  32. public int PowerReceived = 3;
  33. /// <summary>
  34. /// How much power should this field generator lose if not powered?
  35. /// </summary>
  36. [ViewVariables(VVAccess.ReadWrite)]
  37. [DataField("powerLoss")]
  38. public int PowerLoss = 2;
  39. /// <summary>
  40. /// Used to check if it's received power recently.
  41. /// </summary>
  42. [DataField("accumulator")]
  43. public float Accumulator;
  44. /// <summary>
  45. /// How many seconds should the generators wait before losing power?
  46. /// </summary>
  47. [DataField("threshold")]
  48. public float Threshold = 20f;
  49. /// <summary>
  50. /// How many tiles should this field check before giving up?
  51. /// </summary>
  52. [DataField("maxLength")]
  53. public float MaxLength = 8F;
  54. /// <summary>
  55. /// What collision should power this generator?
  56. /// It really shouldn't be anything but an emitter bolt but it's here for fun.
  57. /// </summary>
  58. [ViewVariables(VVAccess.ReadWrite)]
  59. [DataField("idTag", customTypeSerializer: typeof(PrototypeIdSerializer<TagPrototype>))]
  60. public string IDTag = "EmitterBolt";
  61. /// <summary>
  62. /// Which fixture ID should test collision with from the entity that powers the generator?
  63. /// Prevents the generator from being powered by fly-by fixtures.
  64. /// </summary>
  65. [DataField]
  66. public string SourceFixtureId = "projectile";
  67. /// <summary>
  68. /// Is the generator toggled on?
  69. /// </summary>
  70. [DataField]
  71. public bool Enabled;
  72. /// <summary>
  73. /// Is this generator connected to fields?
  74. /// </summary>
  75. [ViewVariables(VVAccess.ReadWrite)]
  76. public bool IsConnected;
  77. /// <summary>
  78. /// The masks the raycast should not go through
  79. /// </summary>
  80. [DataField("collisionMask")]
  81. public int CollisionMask = (int) (CollisionGroup.MobMask | CollisionGroup.Impassable | CollisionGroup.MachineMask | CollisionGroup.Opaque);
  82. /// <summary>
  83. /// A collection of connections that the generator has based on direction.
  84. /// Stores a list of fields connected between generators in this direction.
  85. /// </summary>
  86. [ViewVariables]
  87. public Dictionary<Direction, (Entity<ContainmentFieldGeneratorComponent>, List<EntityUid>)> Connections = new();
  88. /// <summary>
  89. /// What fields should this spawn?
  90. /// </summary>
  91. [ViewVariables(VVAccess.ReadWrite)]
  92. [DataField("createdField", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
  93. public string CreatedField = "ContainmentField";
  94. }
  95. [Serializable, NetSerializable]
  96. public enum ContainmentFieldGeneratorVisuals : byte
  97. {
  98. PowerLight,
  99. FieldLight,
  100. OnLight,
  101. }
  102. [Serializable, NetSerializable]
  103. public enum PowerLevelVisuals : byte
  104. {
  105. NoPower,
  106. LowPower,
  107. MediumPower,
  108. HighPower,
  109. }
  110. [Serializable, NetSerializable]
  111. public enum FieldLevelVisuals : byte
  112. {
  113. NoLevel,
  114. On,
  115. OneField,
  116. MultipleFields,
  117. }