package_reward_build.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <span>
  6. #include <vector>
  7. #include "../../../../middleware/content/packages/reader/reader.h"
  8. #include "../../../../middleware/content/packages/tables/definition_index_table.h"
  9. #include "../../../../state/account/account_state.h"
  10. #include "../../../../state/build_data/rewards/definition.h"
  11. namespace sunrise::client::content::items::packages {
  12. struct SlotMaps;
  13. /** Resolves expression references and unlock slots once for a package pass. */
  14. class RewardConditions {
  15. public:
  16. /** Reads the root's flag, value, expression and class tables; false when one is missing. */
  17. [[nodiscard]] bool load(const middleware::content::packages::reader::Source& source,
  18. middleware::content::packages::reader::Scratch& scratch,
  19. std::span<const std::byte> root,
  20. const SlotMaps& maps) noexcept;
  21. /** @return True when the last load() succeeded. */
  22. [[nodiscard]] bool loaded() const noexcept;
  23. /** Binds one native instruction; flag and value slots resolve to their saved bank. */
  24. [[nodiscard]] bool bind(std::uint32_t native,
  25. std::uint32_t operand,
  26. state::build_data::rewards::Instruction& instruction) const noexcept;
  27. /** Appends one expanded expression; the bank is unchanged on failure. */
  28. [[nodiscard]] bool read(std::span<const std::byte> blob,
  29. std::size_t at,
  30. std::vector<state::build_data::rewards::Instruction>& bank,
  31. state::build_data::rewards::Range& range,
  32. bool& bankFull) const noexcept;
  33. /** Expands a list of expressions into one program where every expression must hold. */
  34. [[nodiscard]] bool read_list(std::span<const std::byte> blob,
  35. std::size_t at,
  36. std::span<state::build_data::rewards::Instruction> output,
  37. std::size_t& count) const noexcept;
  38. private:
  39. [[nodiscard]] bool append_expression(std::span<const std::byte> blob,
  40. std::size_t at,
  41. std::vector<state::build_data::rewards::Instruction>& bank,
  42. std::size_t depth) const noexcept;
  43. void load_class_flags(const middleware::content::packages::reader::Source& source,
  44. middleware::content::packages::reader::Scratch& scratch,
  45. std::span<const std::byte> root) noexcept;
  46. std::array<std::uint16_t, state::kCharacterClassCount> classFlags_{};
  47. const SlotMaps* maps_{};
  48. bool loaded_{};
  49. std::vector<std::byte> flags_;
  50. std::vector<std::byte> values_;
  51. std::vector<std::byte> expressions_;
  52. middleware::content::packages::tables::Array flagRows_{};
  53. middleware::content::packages::tables::Array valueRows_{};
  54. middleware::content::packages::tables::Array expressionRows_{};
  55. };
  56. /** Reward metadata collected alongside the existing item-definition walk. */
  57. class RewardBuild {
  58. public:
  59. RewardConditions conditions;
  60. /** Reads every reward pool; unreadable entries are skipped, a full bank refuses the load. */
  61. [[nodiscard]] bool load(const middleware::content::packages::reader::Source& source,
  62. middleware::content::packages::reader::Scratch& scratch,
  63. std::span<const std::byte> root,
  64. const SlotMaps& maps) noexcept;
  65. /** Sizes the dense item rows before the item walk. */
  66. [[nodiscard]] bool begin_items(std::size_t count) noexcept;
  67. /** Records one item's wrapper and acquisition flag; an unreadable item stays unavailable. */
  68. void item(std::uint16_t index, std::uint32_t hash, std::span<const std::byte> blob) noexcept;
  69. /** Drops rows naming items or pools that were not read, then publishes the banks. */
  70. [[nodiscard]] bool publish() noexcept;
  71. private:
  72. /** Appends one entry; fullBank names the bank that refused it, if any. */
  73. [[nodiscard]] bool
  74. entry(std::span<const std::byte> blob, std::size_t at, const char*& fullBank) noexcept;
  75. [[nodiscard]] bool read_item(std::uint32_t hash,
  76. std::span<const std::byte> blob,
  77. state::build_data::rewards::Item& item) noexcept;
  78. bool loaded_{};
  79. bool supplementalMissing_{};
  80. std::size_t unboundAcquiredFlags_{};
  81. std::vector<state::build_data::rewards::Pool> pools_;
  82. std::vector<state::build_data::rewards::Entry> entries_;
  83. std::vector<state::build_data::rewards::Item> items_;
  84. std::vector<state::build_data::rewards::Instruction> instructions_;
  85. std::vector<state::build_data::rewards::Modifier> modifiers_;
  86. std::vector<state::build_data::rewards::SocketOverride> sockets_;
  87. };
  88. /** Progression rewards and pool entries use the same socket-override layout. */
  89. [[nodiscard]] bool read_reward_sockets(std::span<const std::byte> blob,
  90. std::size_t at,
  91. std::span<state::build_data::rewards::SocketOverride> output,
  92. std::size_t& count) noexcept;
  93. } // namespace sunrise::client::content::items::packages