inventory_state.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 every named slot currently represented by State. */
  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. artifact,
  27. count,
  28. };
  29. /** One fixed entry exists for every semantic equipment slot. */
  30. inline constexpr std::size_t kEquipmentSlotCount = static_cast<std::size_t>(EquipmentSlot::count);
  31. /** An authored item can pick at most 12 ordinary socket lanes. */
  32. inline constexpr std::size_t kPlugCapacity = 12;
  33. /** The engine no-definition hash cannot identify an authored item or plug. */
  34. inline constexpr std::uint32_t kNoDefinitionHash = 0x811C9DC5U;
  35. /** Says whether Middleware uses native socket defaults or authored lanes. */
  36. enum class SocketPolicy : std::uint8_t {
  37. nativeDefaults,
  38. authored,
  39. };
  40. /** Fixed authored socket choices. An empty optional is an explicit empty lane. */
  41. struct Sockets {
  42. SocketPolicy policy{SocketPolicy::nativeDefaults};
  43. std::array<std::optional<std::uint32_t>, kPlugCapacity> plugs{};
  44. std::size_t plugCount{};
  45. };
  46. /** Account-wide stacks can occupy every row of the native 701-row profile inventory. */
  47. inline constexpr std::size_t kProfileItemCapacity = 701;
  48. /** The supported mod and shader profile bucket runs reserve 50 action-source rows each. */
  49. inline constexpr std::size_t kProfileActionSourceCapacity = 100;
  50. /** Runtime-owned SOIDs for profile stacks use a namespace separate from created item instances. */
  51. inline constexpr std::uint64_t kFirstProfileItemInstanceSoid = 0x5000000000000001ULL;
  52. /**
  53. * Native item-state bit the Client sets to lock one item against destruction.
  54. * Confirmed against the installed build by three observed lock and unlock transitions.
  55. */
  56. inline constexpr std::uint32_t kLockedItemFlag = 0x1;
  57. /** 151 native rows minus the 16 equipped rows leaves 135 unequipped item rows. */
  58. inline constexpr std::size_t kCharacterItemCapacity = 135;
  59. /** Runtime-owned non-instanced character stacks. */
  60. inline constexpr std::size_t kCharacterStackCapacity = 32;
  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. /**
  77. * Rising per-character generation assigned whenever this item changes inventory rows. The
  78. * Client also orders a bucket's grid by it, so an equip swap hands the displaced item the
  79. * clicked item's prior serial to keep it in the clicked cell.
  80. */
  81. std::int32_t mutationSerial{};
  82. /** Native accumulated item-state bits such as the finisher favorite marker. */
  83. std::uint32_t flags{};
  84. Sockets sockets;
  85. /**
  86. * Selected ability-node socket entries. Only meaningful on a subclass. Kept on the item, not
  87. * the character, so each owned subclass remembers its own picks. Defaults match
  88. * state::kDefault*AbilityEntry, literal here to avoid a circular include.
  89. */
  90. std::uint8_t movementAbilityEntry{4};
  91. std::uint8_t grenadeAbilityEntry{7};
  92. std::uint8_t superAbilityEntry{10};
  93. std::uint8_t meleeAbilityEntry{11};
  94. std::uint8_t classAbilityEntry{2};
  95. };
  96. /** Ordered unequipped items placed into their native character-inventory bucket ranges. */
  97. struct CharacterItems {
  98. std::array<Item, kCharacterItemCapacity> values{};
  99. std::size_t count{};
  100. };
  101. struct CharacterStack {
  102. std::uint32_t definitionHash{};
  103. std::int32_t quantity{};
  104. std::int32_t mutationSerial{};
  105. };
  106. struct CharacterStacks {
  107. std::array<CharacterStack, kCharacterStackCapacity> values{};
  108. std::size_t count{};
  109. };
  110. /** One optional authored item for every semantic equipment slot. */
  111. struct Equipment {
  112. std::array<std::optional<Item>, kEquipmentSlotCount> slots{};
  113. };
  114. /**
  115. * Finds the semantic State slot for one exact JSON equipment name.
  116. * @param name Borrowed case-sensitive equipment name.
  117. * @return Matching slot, or no value for an unknown name.
  118. */
  119. [[nodiscard]] std::optional<EquipmentSlot> slot_from_name(std::string_view name) noexcept;
  120. /**
  121. * Checks the canonical socket policy and every authored plug hash.
  122. * @return True when the policy, count and fixed tail agree.
  123. */
  124. [[nodiscard]] bool valid(const Sockets& sockets) noexcept;
  125. /**
  126. * Checks one whole authored item without reading installed build data.
  127. * @return True when the id, scalar and socket fields are valid.
  128. */
  129. [[nodiscard]] bool valid(const Item& item) noexcept;
  130. /**
  131. * Checks every item present in the fixed semantic equipment array.
  132. * @return True when every used slot holds a whole item.
  133. */
  134. [[nodiscard]] bool valid(const Equipment& equipment) noexcept;
  135. /** Checks the used prefix and empty tail of one character's unequipped item array. */
  136. [[nodiscard]] bool valid(const CharacterItems& items) noexcept;
  137. [[nodiscard]] bool valid(const CharacterStacks& items) noexcept;
  138. } // namespace sunrise::state::account::inventory