载入中...
搜索中...
未找到
SkillDefinitionRuntime.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4#include <cstdint>
5#include <limits>
6#include <set>
7#include <stdexcept>
8#include <unordered_map>
9#include <utility>
10#include "common/Value.h"
11#include "rpg/AttributeSystem.h"
12#include "rpg/RPGActor.h"
14#include "rpg/Skill.h"
15#include "rpg/SkillCondition.h"
17#include "rpg/SkillSystem.h"
18#include "rpg/StatusSystem.h"
19
20// SkillDefinitionRuntime.cpp
21namespace eve::rpg {
22namespace {
23
24eve::LogicalId skillSchema() {
25 static const eve::LogicalId value = [] {
26 const auto parsed = eve::LogicalId::parse("rpg.skill:runtime");
27 if (!parsed) throw std::logic_error("invalid built-in skill snapshot schema");
28 return *parsed;
29 }();
30 return value;
31}
32
35 const auto &logical = reference.id();
36 return registry.handle(std::string(logical.namespaceName()), std::string(logical.name()));
37}
38
39const eve::Value *field(const eve::Value::Object &object, std::string_view name) {
40 const auto it = object.find(std::string(name));
41 return it == object.end() ? nullptr : &it->second;
42}
43
44bool readNumber(const eve::Value::Object &object, std::string_view name, double &result) {
45 const auto *value = field(object, name);
46 if (const auto *number = value ? value->getIf<double>() : nullptr) {
47 result = *number;
48 return std::isfinite(result);
49 }
50 if (const auto *integer = value ? value->getIf<std::int64_t>() : nullptr) {
51 result = static_cast<double>(*integer);
52 return std::isfinite(result);
53 }
54 return false;
55}
56
57eve::Result<std::vector<std::string>> readStrings(const eve::Value::Object &object, std::string_view name) {
58 const auto *value = field(object, name);
59 if (value == nullptr) return eve::Result<std::vector<std::string>>::success({});
60 const auto *array = value->getIf<eve::Value::Array>();
61 if (array == nullptr)
64 std::string(name), {}, "rpg.skill.definition_runtime"));
65 std::vector<std::string> result;
66 result.reserve(array->size());
67 for (std::size_t index = 0; index < array->size(); ++index) {
68 const auto *text = (*array)[index].getIf<std::string>();
69 if (text == nullptr || text->empty())
70 return eve::Result<std::vector<std::string>>::failure(eve::Diagnostic::error(
71 eve::DiagnosticCode::InvalidArgument, "skill array item must be a non-empty string",
72 std::string(name) + "[" + std::to_string(index) + "]", {}, "rpg.skill.definition_runtime"));
73 result.push_back(*text);
74 }
75 return eve::Result<std::vector<std::string>>::success(std::move(result));
76}
77
81 const auto *payload = owned.value().getIf<eve::Value::Object>();
82 if (payload == nullptr)
84 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill definition payload must be an object",
85 "json", {}, "rpg.skill.definition_runtime"));
86
87 SkillDefinition result;
88 result.id = source.id;
89 const auto *target = field(*payload, "targetType");
90 if (target != nullptr) {
91 const auto *text = target->getIf<std::string>();
92 if (text == nullptr || text->empty())
94 eve::DiagnosticCode::InvalidArgument, "skill targetType must be a non-empty string", "targetType", {},
95 "rpg.skill.definition_runtime"));
96 result.targetType = *text;
97 }
98 double number = 0.0;
99 if (field(*payload, "cooldown") != nullptr) {
100 if (!readNumber(*payload, "cooldown", number) || number < 0.0 || number > std::numeric_limits<float>::max())
102 eve::DiagnosticCode::InvalidArgument, "skill cooldown must be finite and non-negative", "cooldown", {},
103 "rpg.skill.definition_runtime"));
104 result.cooldown = static_cast<float>(number);
105 }
106 if (field(*payload, "castTime") != nullptr) {
107 if (!readNumber(*payload, "castTime", number) || number < 0.0 || number > std::numeric_limits<float>::max())
109 eve::DiagnosticCode::InvalidArgument, "skill castTime must be finite and non-negative", "castTime", {},
110 "rpg.skill.definition_runtime"));
111 result.castTime = static_cast<float>(number);
112 }
113 auto effects = readStrings(*payload, "grantedEffects");
114 if (!effects) return eve::Result<SkillDefinition>::failure(effects.status());
115 result.grantedEffects = std::move(effects).takeValue();
116 auto tags = readStrings(*payload, "tags");
117 if (!tags) return eve::Result<SkillDefinition>::failure(tags.status());
118 result.tags = std::move(tags).takeValue();
119 if (const auto *condition = field(*payload, "castCondition")) {
120 auto decoded = decodeSkillCondition(*condition);
121 if (!decoded) return eve::Result<SkillDefinition>::failure(decoded.status());
122 result.castCondition = std::move(decoded).takeValue();
123 }
124 auto extras = field(*payload, "extra");
125 if (extras != nullptr) {
126 const auto *extraObject = extras->getIf<eve::Value::Object>();
127 if (extraObject == nullptr)
129 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill extra must be an object", "extra",
130 {}, "rpg.skill.definition_runtime"));
131 for (const auto &[key, value] : *extraObject) {
132 const auto *text = value.getIf<std::string>();
133 if (text == nullptr)
135 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill extra values must be strings",
136 "extra." + key, {}, "rpg.skill.definition_runtime"));
137 result.extra.emplace(key, *text);
138 }
139 }
140 const auto *costs = field(*payload, "costs");
141 if (costs != nullptr) {
142 const auto *array = costs->getIf<eve::Value::Array>();
143 if (array == nullptr)
145 "skill costs must be an array", "costs",
146 {}, "rpg.skill.definition_runtime"));
147 std::vector<eve::resource::ResourceCost> items;
148 for (std::size_t index = 0; index < array->size(); ++index) {
149 const auto *item = (*array)[index].getIf<eve::Value::Object>();
150 if (item == nullptr)
152 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill cost must be an object",
153 "costs[" + std::to_string(index) + "]", {}, "rpg.skill.definition_runtime"));
154 const auto *resource = field(*item, "attribute");
155 const auto *amount = field(*item, "amount");
156 const auto *name = resource ? resource->getIf<std::string>() : nullptr;
157 const auto *integer = amount ? amount->getIf<std::int64_t>() : nullptr;
158 if (name == nullptr || name->empty() || integer == nullptr || *integer <= 0)
160 eve::DiagnosticCode::InvalidArgument, "skill cost requires a positive attribute amount",
161 "costs[" + std::to_string(index) + "]", {}, "rpg.skill.definition_runtime"));
163 if (!cost) return eve::Result<SkillDefinition>::failure(cost.status());
164 items.push_back(std::move(cost).takeValue());
165 }
166 if (!items.empty()) {
167 auto cost = eve::resource::CostSpec::create(std::move(items));
168 if (!cost) return eve::Result<SkillDefinition>::failure(cost.status());
169 result.cost = std::move(cost).takeValue();
170 }
171 }
173}
174
175eve::Value encodeState(const SkillRuntimeState &state) {
177 {"cooldownRemaining", eve::Value(static_cast<double>(state.cooldownRemaining))},
178 {"learned", eve::Value(state.learned)},
179 });
180}
181
183 const auto *object = value.getIf<eve::Value::Object>();
184 if (object == nullptr)
186 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill runtime state must be an object",
187 "state", {}, "rpg.skill.definition_runtime"));
188 static const std::set<std::string> fields = {"cooldownRemaining", "learned"};
189 for (const auto &[name, unused] : *object) {
190 (void)unused;
191 if (!fields.contains(name))
193 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unknown skill runtime state field",
194 "state." + name, {}, "rpg.skill.definition_runtime"));
195 }
196 if (!object->contains("cooldownRemaining") || !object->contains("learned"))
198 eve::DiagnosticCode::InvalidArgument, "skill runtime state is missing a required field", "state", {},
199 "rpg.skill.definition_runtime"));
200 const auto *cooldown = object->at("cooldownRemaining").getIf<double>();
201 const auto *learned = object->at("learned").getIf<bool>();
202 if (cooldown == nullptr || learned == nullptr || !std::isfinite(*cooldown) || *cooldown < 0.0 ||
203 *cooldown > std::numeric_limits<float>::max())
205 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill cooldown state is invalid",
206 "state.cooldownRemaining", {}, "rpg.skill.definition_runtime"));
207 return eve::Result<SkillRuntimeState>::success(SkillRuntimeState{static_cast<float>(*cooldown), *learned});
208}
209
210} // namespace
211
213 eve::DefinitionRef definition,
216 if (!definition.id().isValid() || definition.id().namespaceName() != "rpg.skill")
218 eve::DiagnosticCode::InvalidArgument, "skill definition reference must use rpg.skill namespace",
219 "definition", {}, "rpg.skill.definition_runtime"));
220 auto handle = currentHandle(registry, definition);
222 auto resolved = registry.resolveHandle(handle.value());
224 auto typed = parseDefinition(resolved.value().get());
225 if (!typed) return eve::Result<SkillDefinitionRuntime>::failure(typed.status());
227 instanceId, std::move(definition), handle.value().generation, SkillRuntimeState{});
228 if (!runtime) return eve::Result<SkillDefinitionRuntime>::failure(runtime.status());
230 SkillDefinitionRuntime(registry, std::move(runtime).takeValue(), policy));
231}
232
234 std::string_view skillId,
236 auto logical = eve::LogicalId::fromParts("rpg.skill", skillId);
237 if (!logical)
239 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill id is not a valid logical name",
240 "skillId", {}, "rpg.skill.definition_runtime"));
241 auto reference = eve::DefinitionRef::fromId(*logical);
243 return create(eve::rpg::SkillRegistry::definitionRegistry(), std::move(reference).takeValue(), instanceId, policy);
244}
245
247 return runtime_.identity();
248}
249
250const SkillRuntimeState &SkillDefinitionRuntime::state() const noexcept { return runtime_.state(); }
251
252SkillRuntimeState &SkillDefinitionRuntime::state() noexcept { return runtime_.state(); }
253
255 return runtime_.identity().definitionHandle();
256}
257
259 if (registry_ == nullptr)
261 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill definition registry is not bound",
262 "registry", {}, "rpg.skill.definition_runtime"));
263 auto resolved = registry_->resolveHandle(definitionHandle());
265 return parseDefinition(resolved.value().get());
266}
267
268void SkillDefinitionRuntime::setActive(bool active) noexcept { runtime_.setActive(active); }
269
270bool SkillDefinitionRuntime::isActive() const noexcept { return runtime_.isActive(); }
271
273 if (actor == nullptr)
275 "skill runtime cannot project to a null RPGActor",
276 "actor", {}, "rpg.skill.definition_runtime"));
277 auto candidate = *actor->skills().operator->();
278 const std::string id(identity().definition.id().name());
279 if (state().learned)
280 candidate.known[id] = SkillRuntime{state().cooldownRemaining};
281 else
282 candidate.known.erase(id);
283 using std::swap;
284 swap(*actor->skills().operator->(), candidate);
286}
287
289 if (registry_ == nullptr)
291 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "skill definition registry is not bound",
292 "registry", {}, "rpg.skill.definition_runtime"));
293 auto next = currentHandle(*registry_, identity().definition);
294 if (!next) return eve::Result<eve::definition::ReloadOutcome>::failure(next.status());
295 auto resolved = registry_->resolveHandle(next.value());
297 auto typed = parseDefinition(resolved.value().get());
298 if (!typed) return eve::Result<eve::definition::ReloadOutcome>::failure(typed.status());
299 const float nextCooldown = typed.value().cooldown;
301 auto rebuild = [nextCooldown](const SkillRuntimeState &oldState, const eve::definition::InstanceIdentity &,
303 SkillRuntimeState rebuilt = oldState;
304 rebuilt.cooldownRemaining = std::clamp(oldState.cooldownRemaining, 0.f, nextCooldown);
306 };
307 auto result = runtime_.reload(next.value(), policy, defaults, std::move(rebuild));
308 if (result.ok()) policy_ = policy;
309 return result;
310}
311
320
328
330 const eve::SnapshotHashProvider &hashProvider) {
331 if (registry_ == nullptr)
333 "skill definition registry is not bound", "registry",
334 {}, "rpg.skill.definition_runtime"));
335 auto current = currentHandle(*registry_, identity().definition);
336 if (!current) return eve::Result<void>::failure(current.status());
337 if (current.value() != definitionHandle())
339 eve::DiagnosticCode::StaleHandle, "skill snapshot cannot restore against a replaced definition",
340 "definitionGeneration", {}, "rpg.skill.definition_runtime"));
342 return eve::definition::restoreRuntimeInstance(runtime_, snapshotValue, "rpg.skill.runtime", skillSchema(),
343 eve::SchemaVersion(1), hashProvider, decoder);
344}
345
346} // namespace eve::rpg
347
348// SkillSystem.cpp
349namespace eve::rpg {
350
351namespace {
352
353std::unordered_map<std::string, SkillSystem::CastCondition> &conditions() {
354 static std::unordered_map<std::string, SkillSystem::CastCondition> c;
355 return c;
356}
357
358std::vector<SkillCastEvent>& castQueue() { return detail::simulationEvents().casts; }
359
360bool checkCostsAffordable(RPGActor *actor, const SkillDefinition &def) {
361 if (!def.cost) return true;
362 for (const auto &cost : def.cost->items())
363 if (AttributeSystem::getFinal(actor, cost.resource.value()) < static_cast<double>(cost.amount.value()))
364 return false;
365 return true;
366}
367
368void deductCosts(RPGActor *actor, const SkillDefinition &def) {
369 if (!def.cost) return;
370 for (const auto &cost : def.cost->items())
371 AttributeSystem::modifyBase(actor, cost.resource.value(), -static_cast<double>(cost.amount.value()));
372}
373
374void resolveCast(RPGActor *actor, const SkillDefinition &def, RPGActor *target) {
375 RPGActor *effectTarget = target ? target : actor;
376 for (const std::string &effectId : def.grantedEffects)
377 StatusSystem::apply(effectTarget, effectId, "skill:" + def.id)
378 .ignore("skill effect application is reported through cast events");
379
380 SkillCastEvent evt;
381 evt.caster = actor;
382 evt.target = target;
383 evt.skillId = def.id;
384 castQueue().push_back(std::move(evt));
385}
386
387} // namespace
388
390 conditions()[name] = std::move(fn);
391}
392
393void SkillSystem::unregisterCastCondition(const std::string &name) { conditions().erase(name); }
394
395void SkillSystem::clearCastConditions() { conditions().clear(); }
396
397void SkillSystem::learn(RPGActor *actor, const std::string &skillId) {
398 if (!actor || skillId.empty()) return;
399 actor->skills()->known[skillId]; // default-constructs SkillRuntime if absent
400}
401
402bool SkillSystem::knows(RPGActor *actor, const std::string &skillId) {
403 if (!actor) return false;
404 auto &known = actor->skills()->known;
405 return known.find(skillId) != known.end();
406}
407
408bool SkillSystem::forget(RPGActor *actor, const std::string &skillId) {
409 if (!actor) return false;
410 return actor->skills()->known.erase(skillId) > 0;
411}
412
413std::string SkillSystem::getTargetType(RPGActor *actor, const std::string &skillId) {
414 if (!actor || !knows(actor, skillId)) return {};
415 const SkillDefinition *def = SkillRegistry::find(skillId);
416 return def ? def->targetType : std::string{};
417}
418
419float SkillSystem::getCooldownRemaining(RPGActor *actor, const std::string &skillId) {
420 if (!actor) return 0.f;
421 auto &known = actor->skills()->known;
422 auto it = known.find(skillId);
423 return it == known.end() ? 0.f : it->second.cooldownRemaining;
424}
425
426void SkillSystem::setCooldownRemaining(RPGActor *actor, const std::string &skillId, float seconds) {
427 if (!actor) return;
428 actor->skills()->known[skillId].cooldownRemaining = seconds;
429}
430
431bool SkillSystem::canCast(RPGActor *actor, const std::string &skillId, std::string *reason) {
432 auto fail = [&](const std::string &r) {
433 if (reason) *reason = r;
434 return false;
435 };
436 if (!actor) return fail("no_actor");
437 const SkillDefinition *def = SkillRegistry::find(skillId);
438 if (!def) return fail("unknown_skill");
439 if (!knows(actor, skillId)) return fail("not_learned");
440 if (isCasting(actor)) return fail("already_casting");
441 if (getCooldownRemaining(actor, skillId) > 0.f) return fail("on_cooldown");
442 if (!checkCostsAffordable(actor, *def)) return fail("insufficient_cost");
443
444 for (auto &kv : conditions()) {
445 std::string r;
446 if (!kv.second(actor, *def, r)) return fail(r.empty() ? kv.first : r);
447 }
448 const auto condition = SkillConditionAdapter::evaluate(actor, *def, def->castCondition);
449 if (!condition.passed()) return fail(condition::conditionReasonCodeName(condition.reasonCode()));
450 return true;
451}
452
453bool SkillSystem::beginCast(RPGActor *actor, const std::string &skillId, RPGActor *target, std::string *reason) {
454 if (!canCast(actor, skillId, reason)) return false;
455 const SkillDefinition *def = SkillRegistry::find(skillId);
456
457 deductCosts(actor, *def);
458 setCooldownRemaining(actor, skillId, def->cooldown);
459
460 if (def->castTime <= 0.f) {
461 resolveCast(actor, *def, target);
462 return true;
463 }
464
465 CastingState &cs = actor->skills()->casting;
466 cs.active = true;
467 cs.skillId = skillId;
468 cs.remaining = def->castTime;
469 cs.totalCastTime = def->castTime;
470 cs.target = target;
471 return true;
472}
473
475 if (!actor) return;
476 actor->skills()->casting = CastingState{};
477}
478
479bool SkillSystem::isCasting(RPGActor *actor) { return actor && actor->skills()->casting.active; }
480
482 return actor ? actor->skills()->casting.skillId : std::string{};
483}
484
486 if (!actor) return 0.f;
487 const CastingState &cs = actor->skills()->casting;
488 if (!cs.active || cs.totalCastTime <= 0.f) return 0.f;
489 float p = 1.f - (cs.remaining / cs.totalCastTime);
490 return p < 0.f ? 0.f : (p > 1.f ? 1.f : p);
491}
492
494 for (RPGActor *actor : RPGActor::liveActors()) {
495 for (auto &kv : actor->skills()->known)
496 if (kv.second.cooldownRemaining > 0.f) kv.second.cooldownRemaining -= dt;
497
498 CastingState &cs = actor->skills()->casting;
499 if (!cs.active) continue;
500 cs.remaining -= dt;
501 if (cs.remaining <= 0.f) {
503 RPGActor *target = cs.target;
504 cs.active = false; // clear before resolveCast in case it re-enters casting
505 if (def) resolveCast(actor, *def, target);
506 }
507 }
508}
509
510void SkillSystem::pollCastEvents(std::vector<SkillCastEvent> &out) {
511 auto &q = castQueue();
512 for (auto &e : q) out.push_back(std::move(e));
513 q.clear();
514}
515
516} // namespace eve::rpg
LogicalId target
Value::Object payload
bool & active
RPG's thin compatibility facade over the attributes module.
ActiveSource owned
std::uint64_t revision
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
glm::vec4 p[6]
eve::resource::CostSpec cost
eve::Value condition
std::vector< Value > defaults
Definition ECS.cpp:49
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
std::vector< std::string > fields
Definition ECS.cpp:42
int instanceId
std::array< double, 10 > q
double r
std::int32_t c
std::string id
Poco::JSON::Object::Ptr result
std::unordered_set< std::string > tags
double dt
PrimitiveHandle handle
const eve::script::BindingContractRegistry & registry
Object::Ptr value
RoadNetwork resolved
double number
std::string text
ScriptStructure out
std::string_view source
double current
std::string resource
RPG-owned Value codec for the shared decision condition tree.
RPG Skill adapter for the renderer-independent decision protocol.
Strongly typed runtime adapter for RPG skill definitions.
SimulationTick tick
Json object
uint32_t index
Owning, renderer-independent dynamic values.
Stable definition reference backed by LogicalId.
Definition ResourceRef.h:85
static Result< DefinitionRef > fromId(LogicalId id)
Build a definition reference from a valid LogicalId.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:414
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:49
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:37
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
std::map< std::string, Value > Object
Definition Value.h:34
std::vector< Value > Array
Definition Value.h:33
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.
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.
Id128 public API.
Definition Identity.h:111
static eve::Result< CostSpec > create(std::vector< ResourceCost > items)
Validate and canonicalize resource items.
属性 / 状态 / 技能三表合一的 ECS 实体。
Definition RPGActor.h:34
static const std::vector< RPGActor * > & liveActors()
返回当前 Table 中所有存活的 RPGActor(含派生类)。 StatusSystem::update / SkillSystem::update 用它遍历所有 actor 逐帧推进。
Definition RPGActor.cpp:27
static condition::ConditionResult evaluate(const RPGActor *actor, const SkillDefinition &definition, const condition::Condition &condition, SkillConditionQueries queries={})
Evaluate one skill condition against an actor and definition.
Definition Skill.cpp:360
Typed SkillDefinition-to-runtime adapter.
eve::Result< std::string > snapshotJson(eve::Revision revision, eve::SimulationTick tick, const eve::SnapshotHashProvider &hashProvider) const
Serialize snapshot() as canonical JSON.
void setActive(bool active) noexcept
Set the active-cast guard used by RejectWhileActive.
eve::definition::DefinitionHandle definitionHandle() const noexcept
Return the exact generation-qualified definition handle.
const eve::definition::InstanceIdentity & identity() const noexcept
Borrow the common identity, including exact definition generation.
eve::Result< SkillDefinition > definition() const
Resolve and parse the current typed definition projection.
bool isActive() const noexcept
Return whether this skill is currently active.
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.
eve::Result< void > applyTo(RPGActor *actor) const
Project this skill instance into an RPGActor's Skills component.
eve::Result< void > restore(const eve::SnapshotEnvelope &snapshot, const eve::SnapshotHashProvider &hashProvider)
Verify and restore a same-generation skill snapshot atomically.
const SkillRuntimeState & state() const noexcept
Borrow mutable per-instance skill state.
static eve::Result< SkillDefinitionRuntime > create(eve::definitions::DefinitionRegistry &registry, eve::DefinitionRef definition, eve::PersistentId instanceId, eve::definition::ReloadPolicy policy=eve::definition::ReloadPolicy::RebuildInstance)
Create a runtime from a generation-qualified common definition.
eve::Result< eve::definition::ReloadOutcome > reload(eve::definition::ReloadPolicy policy)
Reload the current registry generation using a typed policy.
static const SkillDefinition * find(const std::string &id)
Find a registered skill definition by id.
Definition Skill.cpp:98
static eve::definitions::DefinitionRegistry & definitionRegistry()
Return the common registry that owns canonical skill JSON.
Definition Skill.cpp:78
static bool forget(RPGActor *actor, const std::string &skillId)
Forget.
static void update(float dt)
遍历存活 RPGActor(liveActors / View):冷却倒计时 + 读条推进/结算。
static void cancelCast(RPGActor *actor)
打断当前读条(不退还已扣除的消耗/冷却)。
static std::string getCastingSkillId(RPGActor *actor)
Returns the casting skill id.
static float getCastProgress(RPGActor *actor)
Returns the cast progress.
static void setCooldownRemaining(RPGActor *actor, const std::string &skillId, float seconds)
Sets the cooldown remaining.
static std::string getTargetType(RPGActor *actor, const std::string &skillId)
技能的目标类型字符串("" 表示未学会/未知)。
static bool isCasting(RPGActor *actor)
True when casting.
static void clearCastConditions()
Clears cast conditions.
static void unregisterCastCondition(const std::string &name)
Unregisters cast condition.
static float getCooldownRemaining(RPGActor *actor, const std::string &skillId)
Returns the cooldown remaining.
static void learn(RPGActor *actor, const std::string &skillId)
Learn.
std::function< bool(RPGActor *actor, const SkillDefinition &def, std::string &outReason)> CastCondition
返回 false 表示禁止释放;通过 outReason 说明原因。
Definition SkillSystem.h:28
static bool knows(RPGActor *actor, const std::string &skillId)
Knows.
static void registerCastCondition(const std::string &name, CastCondition fn)
Registers cast condition.
static bool canCast(RPGActor *actor, const std::string &skillId, std::string *reason=nullptr)
检查冷却/消耗/学会状态/自定义条件,不产生任何副作用。
static bool beginCast(RPGActor *actor, const std::string &skillId, RPGActor *target=nullptr, std::string *reason=nullptr)
尝试释放技能:通过 canCast 检查后立即扣除消耗并进入冷却; castTime<=0 时立即结算(授予效果 + 产生 SkillCastEvent), 否则进入读条状态,由 update() 在读...
static void pollCastEvents(std::vector< SkillCastEvent > &out)
Polls cast events.
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
const char * conditionReasonCodeName(ConditionReasonCode code) noexcept
Return the stable lowercase spelling of a condition reason code. @ownership Borrowed process-static t...
Definition Condition.cpp:84
ReloadPolicy
Policy used when a live definition is replaced.
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.
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.
std::function< eve::Result< State >(const eve::Value &)> RuntimeStateDecoder
Decodes one domain-owned runtime state from an owning Value.
std::function< eve::Result< eve::Value >(const State &)> RuntimeStateEncoder
Converts one domain-owned runtime state into an owning Value.
eve::Result< double > readNumber(const eve::Value::Object &object, std::string_view name)
Reads a required finite number.
SimulationEvents & simulationEvents()
Borrow the current thread's event owner for the immediate synchronous operation.
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
eve::Result< eve::condition::Condition > decodeSkillCondition(const eve::Value &value)
Decode one Skill condition tree from an owning Value.
Definition Skill.cpp:376
int64_t integer(const RuntimeTensor &v, size_t i=0)
Integer.
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
SettlementPipeline::Stage fn
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
A generation-qualified reference to one definition incarnation.
Canonical identity carried by every typed runtime instance.
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.
施法状态:同一时间每个 actor 只有一个进行中的引导/读条(可按需扩展为多槽)。
Definition SkillTypes.h:16
class RPGActor * target
Definition SkillTypes.h:21
SkillDefinition public API.
Definition Skill.h:29
float castTime
0 = 瞬发
Definition Skill.h:32
std::string targetType
Definition Skill.h:33
eve::condition::Condition castCondition
Side-effect-free condition tree required before this skill can cast.
Definition Skill.h:39
Mutable state belonging to one learned skill instance.
单个已学会技能的运行时状态(冷却)。
Definition SkillTypes.h:11
std::vector< SkillCastEvent > casts