MaterialStorageComponent.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Content.Shared.Whitelist;
  2. using Robust.Shared.Audio;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Prototypes;
  5. using Robust.Shared.Serialization;
  6. namespace Content.Shared.Materials;
  7. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
  8. [Access(typeof(SharedMaterialStorageSystem))]
  9. public sealed partial class MaterialStorageComponent : Component
  10. {
  11. [DataField, AutoNetworkedField]
  12. public Dictionary<ProtoId<MaterialPrototype>, int> Storage { get; set; } = new();
  13. /// <summary>
  14. /// Whether or not interacting with the materialstorage inserts the material in hand.
  15. /// </summary>
  16. [DataField]
  17. public bool InsertOnInteract = true;
  18. /// <summary>
  19. /// How much material the storage can store in total.
  20. /// </summary>
  21. [ViewVariables(VVAccess.ReadWrite), DataField]
  22. public int? StorageLimit;
  23. /// <summary>
  24. /// Whitelist for specifying the kind of items that can be insert into this entity.
  25. /// </summary>
  26. [DataField]
  27. public EntityWhitelist? Whitelist;
  28. /// <summary>
  29. /// Whether or not to drop contained materials when deconstructed.
  30. /// </summary>
  31. [DataField]
  32. public bool DropOnDeconstruct = true;
  33. /// <summary>
  34. /// Whitelist generated on runtime for what specific materials can be inserted into this entity.
  35. /// </summary>
  36. [DataField, AutoNetworkedField]
  37. public List<ProtoId<MaterialPrototype>>? MaterialWhiteList;
  38. /// <summary>
  39. /// Whether or not the visualization for the insertion animation
  40. /// should ignore the color of the material being inserted.
  41. /// </summary>
  42. [DataField]
  43. public bool IgnoreColor;
  44. /// <summary>
  45. /// The sound that plays when inserting an item into the storage
  46. /// </summary>
  47. [DataField]
  48. public SoundSpecifier? InsertingSound;
  49. /// <summary>
  50. /// How long the inserting animation will play
  51. /// </summary>
  52. [DataField]
  53. public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing
  54. /// <summary>
  55. /// Whether the storage can eject the materials stored within it
  56. /// </summary>
  57. [DataField]
  58. public bool CanEjectStoredMaterials = true;
  59. }
  60. [Serializable, NetSerializable]
  61. public enum MaterialStorageVisuals : byte
  62. {
  63. Inserting
  64. }
  65. /// <summary>
  66. /// event raised on the materialStorage when a material entity is inserted into it.
  67. /// </summary>
  68. [ByRefEvent]
  69. public readonly record struct MaterialEntityInsertedEvent(MaterialComponent MaterialComp)
  70. {
  71. public readonly MaterialComponent MaterialComp = MaterialComp;
  72. }
  73. /// <summary>
  74. /// Event raised when a material amount is changed
  75. /// </summary>
  76. [ByRefEvent]
  77. public readonly record struct MaterialAmountChangedEvent;
  78. /// <summary>
  79. /// Event raised to get all the materials that the
  80. /// </summary>
  81. [ByRefEvent]
  82. public record struct GetMaterialWhitelistEvent(EntityUid Storage)
  83. {
  84. public readonly EntityUid Storage = Storage;
  85. public List<ProtoId<MaterialPrototype>> Whitelist = new();
  86. }
  87. /// <summary>
  88. /// Message sent to try and eject a material from a storage
  89. /// </summary>
  90. [Serializable, NetSerializable]
  91. public sealed class EjectMaterialMessage : EntityEventArgs
  92. {
  93. public NetEntity Entity;
  94. public string Material;
  95. public int SheetsToExtract;
  96. public EjectMaterialMessage(NetEntity entity, string material, int sheetsToExtract)
  97. {
  98. Entity = entity;
  99. Material = material;
  100. SheetsToExtract = sheetsToExtract;
  101. }
  102. }