account_state.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 stays small but leaves room for build variants. */
  11. inline constexpr std::size_t kDismantleRewardPolicyCapacity = 8;
  12. /** One profile material credited when ordinary character gear is dismantled. */
  13. struct DismantleRewardPolicy {
  14. std::uint32_t definitionHash{};
  15. std::int32_t quantity{};
  16. };
  17. /** Stable character race values authored independently of package definition mappings. */
  18. enum class CharacterRace : std::uint8_t {
  19. /** Wire value 0 is a Human character. */
  20. human = 0,
  21. /** Wire value 1 is an Awoken character. */
  22. awoken = 1,
  23. /** Wire value 2 is an Exo character. */
  24. exo = 2,
  25. };
  26. /** Stable character gender values authored independently of package definition mappings. */
  27. enum class CharacterGender : std::uint8_t {
  28. /** Wire value 0 is a male character. */
  29. male = 0,
  30. /** Wire value 1 is a female character. */
  31. female = 1,
  32. };
  33. /** Stable character class values authored independently of package definition mappings. */
  34. enum class CharacterClass : std::uint8_t {
  35. /** Wire value 0 is a Titan character. */
  36. titan = 0,
  37. /** Wire value 1 is a Hunter character. */
  38. hunter = 1,
  39. /** Wire value 2 is a Warlock character. */
  40. warlock = 2,
  41. };
  42. /** Default movement entry. Each subclass offers 3, as entries 4, 5 and 6 of its group. */
  43. inline constexpr std::uint8_t kDefaultMovementAbilityEntry = 4;
  44. /** No socket entry list declares more entries than this, so a larger value is not an entry. */
  45. inline constexpr std::uint8_t kMaximumMovementAbilityEntry = 63;
  46. /**
  47. * Socket entries of the other abilities a subclass lets the player choose. Each names one entry
  48. * of that ability's group. The subclass offers several and the character picks one. These
  49. * defaults are the first option of each group, where every shipped subclass starts.
  50. */
  51. inline constexpr std::uint8_t kDefaultGrenadeAbilityEntry = 7;
  52. /** Default super entry. It is the lane that carries no plug source and kind 34. */
  53. inline constexpr std::uint8_t kDefaultSuperAbilityEntry = 10;
  54. /** Default melee entry. */
  55. inline constexpr std::uint8_t kDefaultMeleeAbilityEntry = 11;
  56. /** Default class-ability entry. Which bucket it publishes into follows the character class. */
  57. inline constexpr std::uint8_t kDefaultClassAbilityEntry = 2;
  58. /**
  59. * Semantic ability-bucket destinations shared by the wire encoder and the selection logic that
  60. * routes a clicked socket entry to a character field. A subclass entry's authored selector chain,
  61. * not its table position, decides which of these it reaches; a bundled pick (an Attunement, for
  62. * example) can freely mix members across them.
  63. */
  64. inline constexpr std::uint8_t kGrenadeAbilityBucket = 0;
  65. inline constexpr std::uint8_t kSuperAbilityBucket = 1;
  66. inline constexpr std::uint8_t kMeleeAbilityBucket = 2;
  67. inline constexpr std::uint8_t kMovementAbilityBucket = 3;
  68. inline constexpr std::uint8_t kSprintAbilityBucket = 4;
  69. /**
  70. * Widest node bundle one summary pick can publish together.
  71. * Some groups (an Attunement pick, for example) hold several consecutive entries that all
  72. * activate, and contribute their hashes, as one unit rather than a single alternative per group.
  73. */
  74. inline constexpr std::size_t kMaxAttunementBundleSize = 4;
  75. /** @param characterClass Authored class. @return The bucket its class ability publishes into. */
  76. [[nodiscard]] inline constexpr std::uint8_t
  77. class_ability_bucket(CharacterClass characterClass) noexcept {
  78. switch (characterClass) {
  79. case CharacterClass::hunter:
  80. return 9;
  81. case CharacterClass::warlock:
  82. return 11;
  83. case CharacterClass::titan:
  84. default:
  85. return 6;
  86. }
  87. }
  88. /** Authored state for one playable character slot. */
  89. struct CharacterState {
  90. std::uint64_t soid{};
  91. /** Runtime selection, moved only by the character pick. No character is selected at boot. */
  92. bool selected{};
  93. CharacterRace race{CharacterRace::human};
  94. CharacterGender gender{CharacterGender::male};
  95. CharacterClass characterClass{CharacterClass::titan};
  96. std::uint8_t level{};
  97. bool accepted{};
  98. bool previewAvailable{};
  99. /** Authored scalar kept for the family-specific character presentation encoders. */
  100. float appearanceValue{};
  101. /** Compact default destination hash used until a later runtime selection replaces it. */
  102. std::uint32_t lastOrbitedDestination{};
  103. /** Server policy that arms content checks only with the matching family-5 flag. */
  104. bool contentBypass{};
  105. /**
  106. * Runtime-only socket entries the player has selected at least once. Selected entries still
  107. * publish active; this mask keeps a later inactive entry acquired instead of new/unclaimed.
  108. * EXPERIMENT: defaulted to all-set so every ready entry reads as acquired instead of new, to
  109. * test whether the client only allows clicking an already-acquired node.
  110. */
  111. std::uint64_t acquiredSubclassAbilityMask{~std::uint64_t{0}};
  112. /** Authored loadout keyed only by stable semantic equipment slots. */
  113. account::inventory::Equipment equipment;
  114. /** Unequipped items routed into their installed character-inventory bucket ranges. */
  115. account::inventory::CharacterItems inventory;
  116. /** Next row generation; equip transactions consume two values for the two moved items. */
  117. std::uint32_t nextInventorySerial{};
  118. };
  119. /** Account identity shared by backend object families. */
  120. struct AccountState {
  121. std::uint64_t primarySoid{};
  122. /** Economy policy comes from configuration, never from item-specific runtime constants. */
  123. std::array<DismantleRewardPolicy, kDismantleRewardPolicyCapacity> dismantleRewards{};
  124. std::size_t dismantleRewardCount{};
  125. /** Account-wide currencies and materials, placed by bucket rather than by authored slot. */
  126. std::array<account::inventory::ProfileItem, account::inventory::kProfileItemCapacity>
  127. profileItems{};
  128. std::size_t profileItemCount{};
  129. std::array<CharacterState, kCharacterCapacity> characters{};
  130. std::size_t characterCount{};
  131. account::settings::AccountSettings settings;
  132. };
  133. namespace account {
  134. [[nodiscard]] bool valid(const AccountState& state) noexcept;
  135. /** Checks settings-authored State before runtime-only profile stack SOIDs are assigned. */
  136. [[nodiscard]] bool valid_authored(const AccountState& state) noexcept;
  137. [[nodiscard]] std::uint64_t selected_character_soid(const AccountState& state) noexcept;
  138. /**
  139. * Reports the character the family-zero banner pair names.
  140. * The pair is published before any pick. A refusal spends the family's only acceptance window,
  141. * so it falls back to the first character.
  142. * @param state Account snapshot read under the lock.
  143. * @return The character's SOID, or zero when the account owns none.
  144. */
  145. [[nodiscard]] std::uint64_t banner_character_soid(const AccountState& state) noexcept;
  146. } // namespace account
  147. } // namespace sunrise::state