inventory_state.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <optional>
  6. #include <string_view>
  7. namespace sunrise::state::account::inventory {
  8. /** Authored equipment exposes the 16 named slots the first State supports. */
  9. enum class EquipmentSlot : std::uint8_t {
  10. kinetic,
  11. energy,
  12. heavy,
  13. helmet,
  14. gauntlets,
  15. chest,
  16. legs,
  17. classItem,
  18. ghost,
  19. vehicle,
  20. ship,
  21. subclass,
  22. clanBanner,
  23. emblem,
  24. emote,
  25. finisher,
  26. count,
  27. };
  28. /** One fixed entry exists for every semantic equipment slot. */
  29. inline constexpr std::size_t kEquipmentSlotCount = static_cast<std::size_t>(EquipmentSlot::count);
  30. /** An authored item can pick at most 12 ordinary socket lanes. */
  31. inline constexpr std::size_t kPlugCapacity = 12;
  32. /** The engine no-definition hash cannot identify an authored item or plug. */
  33. inline constexpr std::uint32_t kNoDefinitionHash = 0x811C9DC5U;
  34. /** Says whether Middleware uses native socket defaults or authored lanes. */
  35. enum class SocketPolicy : std::uint8_t {
  36. nativeDefaults,
  37. authored,
  38. };
  39. /** Fixed authored socket choices. An empty optional is an explicit empty lane. */
  40. struct Sockets {
  41. SocketPolicy policy{SocketPolicy::nativeDefaults};
  42. std::array<std::optional<std::uint32_t>, kPlugCapacity> plugs{};
  43. std::size_t plugCount{};
  44. };
  45. /** Account-wide stacks can occupy every row of the native 701-row profile inventory. */
  46. inline constexpr std::size_t kProfileItemCapacity = 701;
  47. /** The supported mod and shader profile bucket runs reserve 50 action-source rows each. */
  48. inline constexpr std::size_t kProfileActionSourceCapacity = 100;
  49. /** Runtime-owned SOIDs for profile stacks use a namespace separate from created item instances. */
  50. inline constexpr std::uint64_t kFirstProfileItemInstanceSoid = 0x5000000000000001ULL;
  51. /**
  52. * Native item-state bit the Client sets to lock one item against destruction.
  53. * Confirmed against the installed build by three observed lock and unlock transitions.
  54. */
  55. inline constexpr std::uint32_t kLockedItemFlag = 0x1;
  56. /**
  57. * The 16 supported character equipment buckets reserve 151 native rows in this build. One row
  58. * * per semantic slot can be equipped, leaving at most 135 simultaneously unequipped instances.
  59. */
  60. inline constexpr std::size_t kCharacterItemCapacity = 135;
  61. /** One authored account-wide item, placed by the inventory bucket its definition names. */
  62. struct ProfileItem {
  63. /** Stable runtime identity required to materialize this row as an inventory action source. */
  64. std::uint64_t instanceSoid{};
  65. std::uint32_t definitionHash{};
  66. std::int32_t quantity{};
  67. /** Rising generation copied into the native row and matched by acquisition feedback. */
  68. std::int32_t mutationSerial{};
  69. };
  70. /** One authored equipment item without native table or wire-layout fields. */
  71. struct Item {
  72. std::uint64_t instanceSoid{};
  73. std::uint32_t definitionHash{};
  74. std::int32_t level{};
  75. std::int32_t quantity{};
  76. /** Rising per-character generation assigned whenever this item changes inventory rows. */
  77. std::int32_t mutationSerial{};
  78. /** Native accumulated item-state bits such as the finisher favorite marker. */
  79. std::uint32_t flags{};
  80. Sockets sockets;
  81. };
  82. /** Ordered unequipped items placed into their native character-inventory bucket ranges. */
  83. struct CharacterItems {
  84. std::array<Item, kCharacterItemCapacity> values{};
  85. std::size_t count{};
  86. };
  87. /** One optional authored item for every semantic equipment slot. */
  88. struct Equipment {
  89. std::array<std::optional<Item>, kEquipmentSlotCount> slots{};
  90. };
  91. /**
  92. * Finds the semantic State slot for one exact JSON equipment name.
  93. * @param name Borrowed case-sensitive equipment name.
  94. * @return Matching slot, or no value for an unknown name.
  95. */
  96. [[nodiscard]] std::optional<EquipmentSlot> slot_from_name(std::string_view name) noexcept;
  97. /**
  98. * Checks the canonical socket policy and every authored plug hash.
  99. * @return True when the policy, count and fixed tail agree.
  100. */
  101. [[nodiscard]] bool valid(const Sockets& sockets) noexcept;
  102. /**
  103. * Checks one whole authored item without reading installed build data.
  104. * @return True when the id, scalar and socket fields are valid.
  105. */
  106. [[nodiscard]] bool valid(const Item& item) noexcept;
  107. /**
  108. * Checks every item present in the fixed semantic equipment array.
  109. * @return True when every used slot holds a whole item.
  110. */
  111. [[nodiscard]] bool valid(const Equipment& equipment) noexcept;
  112. /** Checks the used prefix and empty tail of one character's unequipped item array. */
  113. [[nodiscard]] bool valid(const CharacterItems& items) noexcept;
  114. } // namespace sunrise::state::account::inventory