state_rolled_socket_plugs.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. #include <cstddef>
  3. #include <cstdint>
  4. #include "../build_data/items/details/definition.h"
  5. #include "../build_data/items/item_catalog.h"
  6. namespace sunrise::state::runtime::detail {
  7. /**
  8. * Some sockets offer only action plugs, which carry no effect of their own. The service answered
  9. * them with a result plug from a roll set: result plugs sit outside the socket's own pool but each
  10. * names its set and shares the action plugs' category. All of it is derived from the item table.
  11. */
  12. /** How one requested plug should be socketed. */
  13. enum class RolledPlugAction : std::uint8_t {
  14. /** An ordinary plug; socket it as asked. */
  15. none,
  16. /** An action plug of a rolled socket; roll a result plug and socket that instead. */
  17. roll,
  18. };
  19. /**
  20. * Classifies one requested plug for one target lane.
  21. * @param requested Installed definition of the plug the Client asked to socket.
  22. * @param target Installed definition of the item being socketed.
  23. * @param lane Ordinary socket lane the request names.
  24. * @return roll when the plug is stat-less, pooled for that lane, and its category has result
  25. * plugs the pool does not offer.
  26. */
  27. [[nodiscard]] RolledPlugAction classify_rolled_plug(const build_data::items::Definition& requested,
  28. const build_data::items::Definition& target,
  29. std::uint8_t lane) noexcept;
  30. /**
  31. * @return True when a plug already in a lane is a rolled result of any set, which is what a
  32. * re-roll replaces and what marks the item as masterworked.
  33. */
  34. [[nodiscard]] bool is_rolled_result(std::uint32_t plugHash) noexcept;
  35. /** One roll outcome: the result plug and, for a delegating result, the perk it stands for. */
  36. struct RolledPlug {
  37. std::uint32_t plugHash{};
  38. /** Lane whose pool offers the linked perk; only meaningful when linkedPerkHash is nonzero. */
  39. std::uint8_t linkedLane{};
  40. /** Stat perk the result stands for, which the service swapped into linkedLane; 0 for none. */
  41. std::uint32_t linkedPerkHash{};
  42. };
  43. /**
  44. * Rolls one result plug for a target item. A stat-carrying result needs every stat it contributes
  45. * declared by the target; a delegating result needs the target's pools to offer a perk of its
  46. * group, else the delegate-less result for the class. The current plug is never rolled again.
  47. * @param requested The action plug, which names the roll set through its category.
  48. * @param target Installed detail of the item being socketed.
  49. * @param characterClass Wire class of the owning character.
  50. * @param currentPlugHash Plug already in the lane, or 0.
  51. * @param seed Any per-request entropy.
  52. * @param rolled Receives the outcome.
  53. * @return True when at least one eligible result existed.
  54. */
  55. [[nodiscard]] bool roll_socket_plug(const build_data::items::Definition& requested,
  56. const build_data::items::details::Definition& target,
  57. std::uint8_t characterClass,
  58. std::uint32_t currentPlugHash,
  59. std::uint64_t seed,
  60. RolledPlug& rolled) noexcept;
  61. /**
  62. * Re-derives the linked perk for a result an earlier staging rolled, so a re-staging lands on
  63. * the same after-image.
  64. * @param plugHash Result plug the earlier staging chose.
  65. * @param target Installed detail of the item being socketed.
  66. * @param rolled Receives the plug and its linked perk, if it has one.
  67. * @return True when the plug is a rolled result the target could have rolled.
  68. */
  69. [[nodiscard]] bool pin_rolled_plug(std::uint32_t plugHash,
  70. const build_data::items::details::Definition& target,
  71. RolledPlug& rolled) noexcept;
  72. } // namespace sunrise::state::runtime::detail