StoreComponent.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Content.Shared.FixedPoint;
  2. using Robust.Shared.Audio;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Shared.Store.Components;
  6. /// <summary>
  7. /// This component manages a store which players can use to purchase different listings
  8. /// through the ui. The currency, listings, and categories are defined in yaml.
  9. /// </summary>
  10. [RegisterComponent, NetworkedComponent]
  11. public sealed partial class StoreComponent : Component
  12. {
  13. [DataField]
  14. public LocId Name = "store-ui-default-title";
  15. /// <summary>
  16. /// All the listing categories that are available on this store.
  17. /// The available listings are partially based on the categories.
  18. /// </summary>
  19. [DataField]
  20. public HashSet<ProtoId<StoreCategoryPrototype>> Categories = new();
  21. /// <summary>
  22. /// The total amount of currency that can be used in the store.
  23. /// The string represents the ID of te currency prototype, where the
  24. /// float is that amount.
  25. /// </summary>
  26. [DataField]
  27. public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> Balance = new();
  28. /// <summary>
  29. /// The list of currencies that can be inserted into this store.
  30. /// </summary>
  31. [DataField]
  32. public HashSet<ProtoId<CurrencyPrototype>> CurrencyWhitelist = new();
  33. /// <summary>
  34. /// The person/mind who "owns" the store/account. Used if you want the listings to be fixed
  35. /// regardless of who activated it. I.E. role specific items for uplinks.
  36. /// </summary>
  37. [DataField]
  38. public EntityUid? AccountOwner = null;
  39. /// <summary>
  40. /// Cached list of listings items with modifiers.
  41. /// </summary>
  42. [DataField]
  43. public HashSet<ListingDataWithCostModifiers> FullListingsCatalog = new();
  44. /// <summary>
  45. /// All available listings from the last time that it was checked.
  46. /// </summary>
  47. [ViewVariables]
  48. public HashSet<ListingDataWithCostModifiers> LastAvailableListings = new();
  49. /// <summary>
  50. /// All current entities bought from this shop. Useful for keeping track of refunds and upgrades.
  51. /// </summary>
  52. [ViewVariables, DataField]
  53. public List<EntityUid> BoughtEntities = new();
  54. /// <summary>
  55. /// The total balance spent in this store. Used for refunds.
  56. /// </summary>
  57. [ViewVariables, DataField]
  58. public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> BalanceSpent = new();
  59. /// <summary>
  60. /// Controls if the store allows refunds
  61. /// </summary>
  62. [ViewVariables, DataField]
  63. public bool RefundAllowed;
  64. /// <summary>
  65. /// Checks if store can be opened by the account owner only.
  66. /// Not meant to be used with uplinks.
  67. /// </summary>
  68. [ViewVariables(VVAccess.ReadWrite), DataField]
  69. public bool OwnerOnly;
  70. /// <summary>
  71. /// The map the store was originally from, used to block refunds if the map is changed
  72. /// </summary>
  73. [DataField]
  74. public EntityUid? StartingMap;
  75. #region audio
  76. /// <summary>
  77. /// The sound played to the buyer when a purchase is succesfully made.
  78. /// </summary>
  79. [DataField]
  80. public SoundSpecifier BuySuccessSound = new SoundPathSpecifier("/Audio/Effects/kaching.ogg");
  81. #endregion
  82. }
  83. /// <summary>
  84. /// Event that is broadcast when a store is added to an entity
  85. /// </summary>
  86. [ByRefEvent]
  87. public readonly record struct StoreAddedEvent;
  88. /// <summary>
  89. /// Event that is broadcast when a store is removed from an entity
  90. /// </summary>
  91. [ByRefEvent]
  92. public readonly record struct StoreRemovedEvent;
  93. /// <summary>
  94. /// Broadcast when an Entity with the <see cref="StoreRefundComponent"/> is deleted
  95. /// </summary>
  96. [ByRefEvent]
  97. public readonly struct RefundEntityDeletedEvent
  98. {
  99. public EntityUid Uid { get; }
  100. public RefundEntityDeletedEvent(EntityUid uid)
  101. {
  102. Uid = uid;
  103. }
  104. }