account_state.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include "inventory/inventory_state.h"
  6. #include "settings/settings_state.h"
  7. namespace sunrise::state {
  8. /** One account can own at most the 3 playable character slots. */
  9. inline constexpr std::size_t kCharacterCapacity = 3;
  10. /** A server-authored dismantle policy: a few rows per rarity and gear class. */
  11. inline constexpr std::size_t kDismantleRewardPolicyCapacity = 32;
  12. /** Gear classes a dismantle payout row can be limited to. */
  13. enum class DismantleGearClass : std::uint8_t {
  14. weapon = 1U << 0U,
  15. armor = 1U << 1U,
  16. };
  17. /** Whether a payout row wants the dismantled item masterworked. */
  18. enum class DismantleMasterworkFilter : std::uint8_t {
  19. any = 0,
  20. masterworked = 1,
  21. notMasterworked = 2,
  22. };
  23. /**
  24. * One profile material credited when ordinary character gear is dismantled. Every filter left at
  25. * its "any" value matches every item; the payout is the sum of the matching rows.
  26. */
  27. struct DismantleRewardPolicy {
  28. std::uint32_t definitionHash{};
  29. std::int32_t quantity{};
  30. /** Bit (1 << tier) per native tier 1-5 the row pays for; 0 pays for every tier. */
  31. std::uint8_t tierMask{};
  32. /** DismantleGearClass bits the row pays for; 0 pays for both. */
  33. std::uint8_t classMask{};
  34. DismantleMasterworkFilter masterwork{DismantleMasterworkFilter::any};
  35. };
  36. /** @return True when both rows are the same row: same material under the same filters. */
  37. [[nodiscard]] constexpr bool
  38. same_dismantle_policy_key(const DismantleRewardPolicy& left,
  39. const DismantleRewardPolicy& right) noexcept {
  40. return left.definitionHash == right.definitionHash && left.tierMask == right.tierMask
  41. && left.classMask == right.classMask && left.masterwork == right.masterwork;
  42. }
  43. /** Stable character race values authored independently of package definition mappings. */
  44. enum class CharacterRace : std::uint8_t {
  45. /** Wire value 0 is a Human character. */
  46. human = 0,
  47. /** Wire value 1 is an Awoken character. */
  48. awoken = 1,
  49. /** Wire value 2 is an Exo character. */
  50. exo = 2,
  51. };
  52. /** Stable character gender values authored independently of package definition mappings. */
  53. enum class CharacterGender : std::uint8_t {
  54. /** Wire value 0 is a male character. */
  55. male = 0,
  56. /** Wire value 1 is a female character. */
  57. female = 1,
  58. };
  59. /** Stable character class values authored independently of package definition mappings. */
  60. enum class CharacterClass : std::uint8_t {
  61. /** Wire value 0 is a Titan character. */
  62. titan = 0,
  63. /** Wire value 1 is a Hunter character. */
  64. hunter = 1,
  65. /** Wire value 2 is a Warlock character. */
  66. warlock = 2,
  67. };
  68. /** Default movement entry. Each subclass offers 3, as entries 4, 5 and 6 of its group. */
  69. inline constexpr std::uint8_t kDefaultMovementAbilityEntry = 4;
  70. /** No socket entry list declares more entries than this, so a larger value is not an entry. */
  71. inline constexpr std::uint8_t kMaximumMovementAbilityEntry = 63;
  72. /**
  73. * Socket entries of the other abilities a subclass lets the player choose. Each names one entry
  74. * of that ability's group. The subclass offers several and the character picks one. These
  75. * defaults are the first option of each group, where every shipped subclass starts.
  76. */
  77. inline constexpr std::uint8_t kDefaultGrenadeAbilityEntry = 7;
  78. /** Default super entry. It is the lane that carries no plug source and kind 34. */
  79. inline constexpr std::uint8_t kDefaultSuperAbilityEntry = 10;
  80. /** Default melee entry. */
  81. inline constexpr std::uint8_t kDefaultMeleeAbilityEntry = 11;
  82. /** Default class-ability entry. Which bucket it publishes into follows the character class. */
  83. inline constexpr std::uint8_t kDefaultClassAbilityEntry = 2;
  84. /**
  85. * Semantic ability-bucket destinations shared by the wire encoder and the selection logic that
  86. * routes a clicked socket entry to a character field. A subclass entry's authored selector chain,
  87. * not its table position, decides which it reaches; a bundled pick can mix members across them.
  88. */
  89. inline constexpr std::uint8_t kGrenadeAbilityBucket = 0;
  90. inline constexpr std::uint8_t kSuperAbilityBucket = 1;
  91. inline constexpr std::uint8_t kMeleeAbilityBucket = 2;
  92. inline constexpr std::uint8_t kMovementAbilityBucket = 3;
  93. inline constexpr std::uint8_t kSprintAbilityBucket = 4;
  94. /**
  95. * Widest node bundle one summary pick can publish together.
  96. * Some groups (an Attunement pick, for example) hold several consecutive entries that all
  97. * activate, and contribute their hashes, as one unit rather than a single alternative per group.
  98. */
  99. inline constexpr std::size_t kMaxAttunementBundleSize = 4;
  100. /** @param characterClass Authored class. @return The bucket its class ability publishes into. */
  101. [[nodiscard]] inline constexpr std::uint8_t
  102. class_ability_bucket(CharacterClass characterClass) noexcept {
  103. switch (characterClass) {
  104. case CharacterClass::hunter:
  105. return 9;
  106. case CharacterClass::warlock:
  107. return 11;
  108. case CharacterClass::titan:
  109. default:
  110. return 6;
  111. }
  112. }
  113. /** Authored state for one playable character slot. */
  114. struct CharacterState {
  115. std::uint64_t soid{};
  116. /** Runtime selection, moved only by the character pick. No character is selected at boot. */
  117. bool selected{};
  118. CharacterRace race{CharacterRace::human};
  119. CharacterGender gender{CharacterGender::male};
  120. CharacterClass characterClass{CharacterClass::titan};
  121. std::uint8_t level{};
  122. bool accepted{};
  123. bool previewAvailable{};
  124. /** Authored scalar kept for the family-specific character presentation encoders. */
  125. float appearanceValue{};
  126. /** Compact default destination hash used until a later runtime selection replaces it. */
  127. std::uint32_t lastOrbitedDestination{};
  128. /**
  129. * Activity whose orbit bubble the character is in, family-4 `+45896`. Authored at sign-in.
  130. * A launch moves it to the target before the client's launch commit, which latches it.
  131. */
  132. std::uint16_t currentActivityIndex{};
  133. /** Server policy that arms content checks only with the matching family-5 flag. */
  134. bool contentBypass{};
  135. /**
  136. * Unix seconds the account signed in, from one clock read shared by every character.
  137. * The character records publish it as their last applied daily and weekly reset; zero
  138. * makes both rollovers due the moment the client accepts the record.
  139. */
  140. std::uint64_t signInSeconds{};
  141. /**
  142. * Runtime-only socket entries the player has selected at least once. Selected entries still
  143. * publish active; this mask keeps a later inactive entry acquired instead of new. Unverified:
  144. * defaulted all-set, assuming the Client only allows clicking an already-acquired node.
  145. */
  146. std::uint64_t acquiredSubclassAbilityMask{~std::uint64_t{0}};
  147. /** Authored loadout keyed only by stable semantic equipment slots. */
  148. account::inventory::Equipment equipment;
  149. /** Unequipped items routed into their installed character-inventory bucket ranges. */
  150. account::inventory::CharacterItems inventory;
  151. /** Next row generation; equip transactions consume two values for the two moved items. */
  152. std::uint32_t nextInventorySerial{};
  153. };
  154. /** Account identity shared by backend object families. */
  155. struct AccountState {
  156. std::uint64_t primarySoid{};
  157. /** Economy policy comes from configuration, never from item-specific runtime constants. */
  158. std::array<DismantleRewardPolicy, kDismantleRewardPolicyCapacity> dismantleRewards{};
  159. std::size_t dismantleRewardCount{};
  160. /** Account-wide currencies and materials, placed by bucket rather than by authored slot. */
  161. std::array<account::inventory::ProfileItem, account::inventory::kProfileItemCapacity>
  162. profileItems{};
  163. std::size_t profileItemCount{};
  164. std::array<CharacterState, kCharacterCapacity> characters{};
  165. std::size_t characterCount{};
  166. /** True after this account has completed the client's one-time profile setup flow. */
  167. bool profileSetupCompleted{};
  168. account::settings::AccountSettings settings;
  169. };
  170. namespace account {
  171. [[nodiscard]] bool valid(const AccountState& state) noexcept;
  172. /** Checks settings-authored State before runtime-only profile stack SOIDs are assigned. */
  173. [[nodiscard]] bool valid_authored(const AccountState& state) noexcept;
  174. [[nodiscard]] std::uint64_t selected_character_soid(const AccountState& state) noexcept;
  175. /**
  176. * Reports the character the family-zero banner pair names.
  177. * The pair is published before any pick. A refusal spends the family's only acceptance window,
  178. * so it falls back to the first character.
  179. * @param state Account snapshot read under the lock.
  180. * @return The character's SOID, or zero when the account owns none.
  181. */
  182. [[nodiscard]] std::uint64_t banner_character_soid(const AccountState& state) noexcept;
  183. } // namespace account
  184. } // namespace sunrise::state