36 lines
1.5 KiB
C++
36 lines
1.5 KiB
C++
#pragma once
|
|
#include "gateway/gameplay.hpp"
|
|
#include <array>
|
|
#include <deque>
|
|
#include <optional>
|
|
|
|
namespace gateway::npc_text {
|
|
inline constexpr uint32_t Query = 0x3e0145, Response = 0x4b0008;
|
|
using Signature = std::array<uint8_t, 32>;
|
|
using Lookup = uint32_t (*)(const Signature&);
|
|
uint32_t broadcast_text_id(const Signature&);
|
|
Bytes native_reply(std::span<const uint8_t> source, Lookup lookup = broadcast_text_id);
|
|
// Select the menu's BroadcastTextID from a validated QueryNPCTextResponse.
|
|
// unit_roll must be in [0, 1). Zero means there is no selectable greeting.
|
|
uint32_t choose_greeting(std::span<const uint8_t> native_reply, double unit_roll);
|
|
|
|
// Source only echoes TextID. Preserve the send order for each ID, including
|
|
// retired menu generations, until the corresponding server reply is consumed.
|
|
class Queries {
|
|
struct Pending { uint32_t id; uint64_t menu; };
|
|
std::deque<Pending> pending_;
|
|
uint64_t menu_ = 0;
|
|
public:
|
|
void new_menu() { ++menu_; }
|
|
std::optional<Bytes> greeting_request(const GossipMenu&);
|
|
// The first correlated reply chooses the title once. Later native queries
|
|
// for this menu still receive the complete weighted NPC-text response.
|
|
void resolve(GossipMenu&, std::span<const uint8_t> native_reply) const;
|
|
Bytes request(std::span<const uint8_t>, const GossipMenu*,
|
|
const std::map<uint64_t, Guid128>&) const;
|
|
bool awaiting(uint32_t id) const;
|
|
void sent(uint32_t id);
|
|
std::optional<Bytes> response(std::span<const uint8_t>, const GossipMenu*);
|
|
};
|
|
}
|