载入中...
搜索中...
未找到
SkillDefinitionRuntime.cpp
浏览该文件的文档.
27eve::Result<eve::definition::DefinitionHandle> currentHandle(eve::definitions::DefinitionRegistry& registry,
51eve::Result<std::vector<std::string>> readStrings(const eve::Value::Object& object, std::string_view name) {
78 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill definition payload must be an object",
88 eve::DiagnosticCode::InvalidArgument, "skill targetType must be a non-empty string", "targetType", {},
94 if (!readNumber(*payload, "cooldown", number) || number < 0.0 || number > std::numeric_limits<float>::max())
96 eve::DiagnosticCode::InvalidArgument, "skill cooldown must be finite and non-negative", "cooldown", {},
101 if (!readNumber(*payload, "castTime", number) || number < 0.0 || number > std::numeric_limits<float>::max())
103 eve::DiagnosticCode::InvalidArgument, "skill castTime must be finite and non-negative", "castTime", {},
123 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill extra must be an object", "extra",
129 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill extra values must be strings",
138 return eve::Result<SkillDefinition>::failure(eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument,
180 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill runtime state must be an object",
187 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unknown skill runtime state field",
192 eve::DiagnosticCode::InvalidArgument, "skill runtime state is missing a required field", "state", {},
196 if (cooldown == nullptr || learned == nullptr || !std::isfinite(*cooldown) || *cooldown < 0.0 ||
201 return eve::Result<SkillRuntimeState>::success(SkillRuntimeState{static_cast<float>(*cooldown), *learned});
206eve::Result<SkillDefinitionRuntime> SkillDefinitionRuntime::create(eve::definitions::DefinitionRegistry& registry,
212 eve::DiagnosticCode::InvalidArgument, "skill definition reference must use rpg.skill namespace",
233 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill id is not a valid logical name",
237 return create(eve::rpg::SkillRegistry::definitionRegistry(), std::move(reference).takeValue(), instanceId, policy);
244const SkillRuntimeState& SkillDefinitionRuntime::state() const noexcept { return runtime_.state(); }
255 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill definition registry is not bound",
282eve::Result<eve::definition::ReloadOutcome> SkillDefinitionRuntime::reload(eve::definition::ReloadPolicy policy) {
285 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill definition registry is not bound",
295 auto rebuild = [nextCooldown](const SkillRuntimeState& oldState, const eve::definition::InstanceIdentity&,
307 eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider& hashProvider) const {
308 const eve::definition::RuntimeStateEncoder<SkillRuntimeState> encoder = [](const SkillRuntimeState& value) {
311 return eve::definition::snapshotRuntimeInstance(runtime_, "rpg.skill.runtime", skillSchema(), eve::SchemaVersion(1),
333 eve::DiagnosticCode::StaleHandle, "skill snapshot cannot restore against a replaced definition",
336 return eve::definition::restoreRuntimeInstance(runtime_, snapshotValue, "rpg.skill.runtime", skillSchema(),
RPG-owned Value codec for the shared decision condition tree.
Strongly typed runtime adapter for RPG skill definitions.
Owning, renderer-independent dynamic values.
static Result< DefinitionRef > fromId(LogicalId id)
Build a definition reference from a valid LogicalId.
Definition ResourceRef.cpp:50
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:411
static std::optional< LogicalId > fromParts(std::string_view namespaceName, std::string_view name)
Builds a logical ID from separate namespace and name components.
Definition Identity.cpp:48
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
static eve::Result< RuntimeInstance > create(eve::PersistentId instanceId, eve::DefinitionRef definition, eve::Generation definitionGeneration, State state, bool active=true)
Construct a runtime instance after validating its identity.
Definition DefinitionRuntime.h:321
Deterministic registry of topic-neutral, versioned JSON definitions.
Definition Definitions.h:58
eve::ResultRef< const Definition > resolveHandle(const DefinitionHandle &handle) const
Resolves a generation-qualified handle and reports stale identities.
Definition Definitions.cpp:319
eve::Result< DefinitionHandle > handle(const std::string &type, const std::string &id) const
Returns the current generation-qualified handle through Result.
Definition Definitions.cpp:325
static eve::Result< CostSpec > create(std::vector< ResourceCost > items)
Validate and canonicalize resource items.
Definition ResourceAccount.cpp:74
Typed SkillDefinition-to-runtime adapter.
Definition SkillDefinitionRuntime.h:42
eve::Result< std::string > snapshotJson(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Serialize snapshot() as canonical JSON.
Definition SkillDefinitionRuntime.cpp:315
void setActive(bool active) noexcept
Set the active-cast guard used by RejectWhileActive.
Definition SkillDefinitionRuntime.cpp:262
eve::definition::DefinitionHandle definitionHandle() const noexcept
Return the exact generation-qualified definition handle.
Definition SkillDefinitionRuntime.cpp:248
const eve::definition::InstanceIdentity & identity() const noexcept
Borrow the common identity, including exact definition generation.
Definition SkillDefinitionRuntime.cpp:240
eve::Result< SkillDefinition > definition() const
Resolve and parse the current typed definition projection.
Definition SkillDefinitionRuntime.cpp:252
bool isActive() const noexcept
Return whether this skill is currently active.
Definition SkillDefinitionRuntime.cpp:264
eve::Result< eve::SnapshotEnvelope > snapshot(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Capture this skill's instance state in a common SnapshotEnvelope.
Definition SkillDefinitionRuntime.cpp:306
eve::Result< void > applyTo(RPGActor *actor) const
Project this skill instance into an RPGActor's Skills component.
Definition SkillDefinitionRuntime.cpp:266
eve::Result< void > restore(const eve::SnapshotEnvelope &snapshot, const eve::SnapshotHashProvider &hashProvider)
Verify and restore a same-generation skill snapshot atomically.
Definition SkillDefinitionRuntime.cpp:323
const SkillRuntimeState & state() const noexcept
Borrow mutable per-instance skill state.
Definition SkillDefinitionRuntime.cpp:244
static eve::Result< SkillDefinitionRuntime > create(eve::definitions::DefinitionRegistry ®istry, eve::DefinitionRef definition, eve::PersistentId instanceId, eve::definition::ReloadPolicy policy=eve::definition::ReloadPolicy::RebuildInstance)
Create a runtime from a generation-qualified common definition.
Definition SkillDefinitionRuntime.cpp:206
eve::Result< eve::definition::ReloadOutcome > reload(eve::definition::ReloadPolicy policy)
Reload the current registry generation using a typed policy.
Definition SkillDefinitionRuntime.cpp:282
static eve::definitions::DefinitionRegistry & definitionRegistry()
Return the common registry that owns canonical skill JSON.
Definition Skill.cpp:70
eve::Result< eve::SnapshotEnvelope > snapshotRuntimeInstance(const RuntimeInstance< State > &runtime, std::string type, eve::LogicalId schema, eve::SchemaVersion schemaVersion, eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateEncoder< State > &encode)
Capture a typed runtime instance in the common snapshot envelope.
Definition RuntimeSnapshot.h:96
eve::Result< void > restoreRuntimeInstance(RuntimeInstance< State > &runtime, const eve::SnapshotEnvelope &snapshot, std::string_view expectedType, const eve::LogicalId &expectedSchema, eve::SchemaVersion expectedVersion, const eve::SnapshotHashProvider &hashProvider, const RuntimeStateDecoder< State > &decode)
Verify and atomically restore a typed runtime instance.
Definition RuntimeSnapshot.h:135
std::function< eve::Result< State >(const eve::Value &)> RuntimeStateDecoder
Decodes one domain-owned runtime state from an owning Value.
Definition RuntimeSnapshot.h:31
std::function< eve::Result< eve::Value >(const State &)> RuntimeStateEncoder
Converts one domain-owned runtime state into an owning Value.
Definition RuntimeSnapshot.h:27
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
bool readNumber(const EditorValue &value, const char *name, float &output)
Definition RoadNetworkEditTarget.cpp:30
eve::Result< eve::decision::Condition > decodeSkillCondition(const eve::Value &value)
Decode one Skill condition tree from an owning Value.
Definition SkillConditionCodec.cpp:299
@ InvalidArgument
@ StaleHandle
Result< std::string > serializeSnapshotEnvelope(const SnapshotEnvelope &snapshot)
Serialize an envelope as deterministic compact JSON.
Definition Snapshot.cpp:184
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
A generation-qualified reference to one definition incarnation.
Definition DefinitionRuntime.h:69
Canonical identity carried by every typed runtime instance.
Definition DefinitionRuntime.h:87
One immutable view of a registered versioned JSON definition.
Definition Definitions.h:31
static eve::Result< ResourceCost > create(std::string_view resourceId, std::int64_t amountValue)
Construct and validate one cost item.
Definition ResourceAccount.cpp:63
Mutable state belonging to one learned skill instance.
Definition SkillDefinitionRuntime.h:28
float cooldownRemaining
Definition SkillDefinitionRuntime.h:29