载入中...
搜索中...
未找到
DialogueState.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
10#include "common/StateAccess.h"
11#include "common/StateValue.h"
12#include "decision/Condition.h"
14
15#include <cstdint>
16#include <functional>
17#include <optional>
18#include <span>
19#include <string>
20#include <string_view>
21
22namespace eve::dialogue {
23
25enum class CommandRequestKind : std::uint8_t {
28};
29
51
55 enum class Status : std::uint8_t { Completed, Blocked, Failed };
56
59 std::string error;
60};
61
64
71
78
87public:
89 explicit StateEvaluationContext(std::string subject = {}, eve::IStateQuery* provider = nullptr);
90
92 void setSubject(std::string subject);
94 void setProvider(eve::IStateQuery* provider) noexcept { provider_ = provider; }
97 std::function<std::optional<eve::decision::ConditionResult>(std::string_view, const eve::Value&)> evaluator) {
98 policyEvaluator_ = std::move(evaluator);
99 }
100
103 [[nodiscard]] std::optional<eve::Value> value(std::string_view key) const override;
106 [[nodiscard]] std::optional<bool> hasTag(std::string_view tag) const override;
109 [[nodiscard]] std::optional<eve::Value> attribute(std::string_view key) const override;
112 [[nodiscard]] std::optional<eve::Value> resource(std::string_view key) const override;
115 [[nodiscard]] std::optional<eve::Value> state(std::string_view key) const override;
118 [[nodiscard]] std::optional<bool> authority(std::string_view scope) const override;
121 [[nodiscard]] std::optional<eve::decision::ConditionResult> policy(std::string_view name,
122 const eve::Value& arguments) const override;
123
124private:
125 std::string subject_;
126 eve::IStateQuery* provider_ = nullptr;
127 std::function<std::optional<eve::decision::ConditionResult>(std::string_view, const eve::Value&)> policyEvaluator_;
128};
129
140public:
142 explicit DialogueStateContext(std::string subject = {});
143
145 void setSubject(std::string subject);
147 const std::string& subject() const noexcept { return subject_; }
149 void setQueryProvider(eve::IStateQuery* provider) noexcept { queryProvider_ = provider; }
151 void setMutationProvider(eve::IStateMutation* provider) noexcept { mutationProvider_ = provider; }
154 std::function<std::optional<eve::decision::ConditionResult>(std::string_view, const eve::Value&)> evaluator) {
155 policyEvaluator_ = std::move(evaluator);
156 }
157
159 [[nodiscard]] std::optional<eve::Value> value(std::string_view key) const;
161 [[nodiscard]] std::optional<bool> hasTag(std::string_view tag) const;
163 [[nodiscard]] std::optional<eve::Value> attribute(std::string_view key) const;
165 [[nodiscard]] std::optional<eve::Value> resource(std::string_view key) const;
167 [[nodiscard]] std::optional<eve::Value> state(std::string_view key) const;
168
170 [[nodiscard]] eve::Result<eve::decision::Condition> compileCondition(const eve::Value& specification) const;
172 [[nodiscard]] eve::decision::ConditionResult evaluate(const eve::decision::Condition& condition) const;
174 [[nodiscard]] eve::decision::ConditionResult evaluate(const eve::Value& specification) const;
175
177 [[nodiscard]] eve::Result<eve::MutationReceipt> apply(std::span<const eve::StateMutation> mutations,
178 const eve::MutationContext& context) const;
179
180private:
181 StateEvaluationContext evaluationContext() const;
182
183 std::string subject_;
184 eve::IStateQuery* queryProvider_ = nullptr;
185 eve::IStateMutation* mutationProvider_ = nullptr;
186 std::function<std::optional<eve::decision::ConditionResult>(std::string_view, const eve::Value&)> policyEvaluator_;
187};
188
189} // namespace eve::dialogue
double value
int subject
Definition AnimSmr.cpp:163
Pure, explainable condition trees shared by gameplay domains.
Dialogue payment specifications and transaction composition.
eve::Value condition
#define EVENGINE_API_ORCHESTRATION
Definition Export.h:111
std::uint32_t key
JobScope scope
std::string name
const std::string * tag
std::string resource
Consumer-owned query and mutation contracts for authoritative world state.
const VegetationPresetContext & context
Move-only operation result carrying either a value or Status.
Definition Result.h:155
JSON-compatible state value tree used by state hot reload.
Definition StateValue.h:20
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
Explain one condition evaluation in a UI- and log-friendly form.
Definition Condition.h:129
Immutable condition AST node.
Definition Condition.h:195
Read-only state boundary used by every condition evaluation.
Definition Condition.h:166
Dialogue-owned facade for world reads, unified conditions, and mutations.
void setMutationProvider(eve::IStateMutation *provider) noexcept
Bind a borrowed mutation provider for this context's lifetime.
void setPolicyEvaluator(std::function< std::optional< eve::decision::ConditionResult >(std::string_view, const eve::Value &)> evaluator)
Install a read-only policy evaluator used by PolicyCall conditions.
void setQueryProvider(eve::IStateQuery *provider) noexcept
Bind a borrowed query provider for this context's lifetime.
const std::string & subject() const noexcept
Return the currently selected subject id.
Decision EvaluationContext backed by one dialogue subject.
std::optional< eve::decision::ConditionResult > policy(std::string_view name, const eve::Value &arguments) const override
Evaluate a named read-only policy with owned arguments.
void setProvider(eve::IStateQuery *provider) noexcept
Set a borrowed query provider valid for this context's lifetime.
std::optional< eve::Value > attribute(std::string_view key) const override
Query an attribute value; nullopt means the attribute is absent.
void setSubject(std::string subject)
Change the subject used by subsequent synchronous queries.
void setPolicyEvaluator(std::function< std::optional< eve::decision::ConditionResult >(std::string_view, const eve::Value &)> evaluator)
Install a read-only policy callback without retaining its arguments.
std::optional< bool > hasTag(std::string_view tag) const override
Query tag membership; nullopt means the tag source is unavailable.
All-or-nothing mutation boundary owned by the consumer.
Read-only world-state boundary owned by consumers such as Dialogue.
Definition StateAccess.h:79
CommandRequestKind
Destination protocol requested by a dialogue command node.
eve::Value toCanonicalValue(const eve::StateValue &value)
Convert the legacy reload value into the canonical common value.
eve::StateValue toDialogueStateValue(const eve::Value &value)
Convert a canonical value to the legacy reload representation.
std::function< CommandResponse(const CommandRequest &)> CommandRequestHandler
Handler implemented by the owning operation or gameplay domain.
Immutable request emitted by a command node.
PaymentSpec payment
Optional atomic money/reputation payment for this command.
std::vector< eve::StateMutation > stateMutations
Optional StatePatch mutations committed in the same transaction.
std::string requestId
Stable identifier for this exact suspended command execution.
Structured response to a request emitted by a command node.
Canonical money/reputation cost attached to a dialogue choice or command.
Correlation metadata shared by a mutation transaction.
Definition StateAccess.h:57