item_catalog.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. #include <span>
  5. #include "quest_initialization.h"
  6. namespace sunrise::state::build_data::items {
  7. /** Signed native definition indices give 32,768 item rows. */
  8. inline constexpr std::size_t kDefinitionCapacity = 32768;
  9. /** All bucket bits set mark a valid item row whose inventory bucket was not found. */
  10. inline constexpr std::uint8_t kUnresolvedBucketId = 0xFF;
  11. /** A plug with no authored insertion/enabled price carries all set-index bits. */
  12. inline constexpr std::uint16_t kUnavailableMaterialRequirementSetIndex = 0xFFFFU;
  13. /** An item-index field naming no row carries all bits set. */
  14. inline constexpr std::uint16_t kUnavailableLinkedPlugIndex = 0xFFFFU;
  15. /** One installed-build item identity, used to look up authored definition hashes. */
  16. struct Definition {
  17. std::uint32_t definitionHash{};
  18. std::uint16_t definitionIndex{};
  19. std::uint8_t bucketId{kUnresolvedBucketId};
  20. std::uint16_t insertionMaterialRequirementSetIndex{kUnavailableMaterialRequirementSetIndex};
  21. std::uint16_t enabledMaterialRequirementSetIndex{kUnavailableMaterialRequirementSetIndex};
  22. /** Native rarity ladder: 1 common through 5 exotic; 0 outside the ladder. */
  23. std::uint8_t tier{};
  24. /** Plug category the definition declares, or 0 when it declares none. */
  25. std::uint32_t plugCategoryHash{};
  26. /**
  27. * Ordinal of the server roll set that grants this plug in place of a socket's action plug;
  28. * kNoRollSet when the plug is socketed directly, kForeignRollSet when the service granted it
  29. * by other means.
  30. */
  31. std::uint16_t rollSetIndex{};
  32. /** Item index of the plug this one stands for, or kUnavailableLinkedPlugIndex when it stands
  33. * alone. */
  34. std::uint16_t linkedPlugIndex{kUnavailableLinkedPlugIndex};
  35. /** Empty unless this item is the first member of a supported quest set. */
  36. QuestInitialization questInitialization{};
  37. };
  38. /** Roll-set ordinals outside the rolled ladder. */
  39. inline constexpr std::uint16_t kNoRollSet = 0;
  40. inline constexpr std::uint16_t kForeignRollSet = 0xFFFFU;
  41. /** @return True when a definition is a plug the service rolled from a socket action. */
  42. [[nodiscard]] constexpr bool rolled_result(const Definition& definition) noexcept {
  43. return definition.rollSetIndex != kNoRollSet && definition.rollSetIndex != kForeignRollSet;
  44. }
  45. /** Native item tiers, as the definition's rarity byte encodes them. */
  46. enum class Tier : std::uint8_t {
  47. none = 0,
  48. common = 1,
  49. uncommon = 2,
  50. rare = 3,
  51. legendary = 4,
  52. exotic = 5,
  53. };
  54. /** Clears every generated item mapping. */
  55. void clear() noexcept;
  56. /**
  57. * Checks one complete dense item definition table.
  58. * @param definitions Candidate installed-build mappings.
  59. * @return True when every native index appears exactly once.
  60. */
  61. [[nodiscard]] bool valid(std::span<const Definition> definitions) noexcept;
  62. /**
  63. * Replaces the generated item definition table in one step.
  64. * @param definitions Complete dense installed-build mappings.
  65. * @return True when all rows pass the checks and fit fixed State storage.
  66. */
  67. [[nodiscard]] bool replace(std::span<const Definition> definitions) noexcept;
  68. /**
  69. * Finds one authored hash with its expected inventory bucket.
  70. * @param definitionHash Authored item definition hash.
  71. * @param bucketId Expected inventory bucket id.
  72. * @param definition Receives the one matching mapping.
  73. * @return True only when exactly one mapping with a known bucket matches both keys.
  74. */
  75. [[nodiscard]] bool
  76. find(std::uint32_t definitionHash, std::uint8_t bucketId, Definition& definition) noexcept;
  77. /**
  78. * Finds one authored hash without needing a known inventory bucket.
  79. * @param definitionHash Authored item or plug definition hash.
  80. * @param definition Receives the one matching installed-build mapping.
  81. * @return True only when exactly one native row carries the hash.
  82. */
  83. [[nodiscard]] bool find_hash(std::uint32_t definitionHash, Definition& definition) noexcept;
  84. /**
  85. * Finds one dense installed-build row by its native definition index.
  86. * @param definitionIndex Native item-definition row index.
  87. * @param definition Receives the matching installed-build mapping.
  88. * @return True when the table holds that row.
  89. */
  90. [[nodiscard]] bool find_index(std::uint16_t definitionIndex, Definition& definition) noexcept;
  91. /**
  92. * Copies every mapping in native definition-index order.
  93. * @param output Caller-owned fixed mapping storage.
  94. * @param count Receives the copied row count.
  95. * @return False only when the caller's storage cannot hold the whole table.
  96. */
  97. [[nodiscard]] bool snapshot(std::span<Definition> output, std::size_t& count) noexcept;
  98. /** @return Number of installed-build item mappings. */
  99. [[nodiscard]] std::size_t count() noexcept;
  100. } // namespace sunrise::state::build_data::items