9#include <unordered_set>
30 return it ==
extra.end() ? fallback : it->second;
33std::unordered_map<std::string, QuestDefinition> &
questTable() {
34 static std::unordered_map<std::string, QuestDefinition>
t;
40std::string normalizeStart(
const std::string &policy) {
return policy ==
"auto" ?
"auto" :
"manual"; }
42std::string normalizeComplete(
const std::string &policy) {
return policy ==
"claim" ?
"claim" :
"auto"; }
44std::string normalizeObjectivePolicy(
const std::string &policy) {
45 if (policy ==
"any" || policy ==
"ordered")
return policy;
50bool idOnCycle(
const std::unordered_map<std::string, QuestDefinition> &
table,
const std::string &
start) {
51 std::unordered_set<std::string>
visiting;
52 std::unordered_set<std::string> visited;
53 std::function<bool(
const std::string &)> dfs = [&](
const std::string &
id) ->
bool {
55 if (visited.count(
id))
return false;
56 auto it =
table.find(
id);
57 if (it ==
table.end())
return false;
59 for (
const auto &req : it->
second.requiresIds) {
60 if (dfs(req))
return true;
71 if (!o.isObject())
return obj;
72 obj.id = o.getString(
"id");
73 obj.topic = o.getString(
"topic");
74 obj.target = o.getString(
"target");
75 obj.count = o.getInt(
"count", 1);
76 obj.optional = o.getBool(
"optional",
false);
77 if (obj.count <= 0) obj.count = 1;
81RewardSpec parseReward(Value o) {
83 if (!o.isObject())
return reward;
84 reward.type = o.getString(
"type");
85 reward.id = o.getString(
"id");
86 reward.amount = o.getDouble(
"amount", 0.0);
91QuestDefinition parseQuestObject(Value o) {
93 if (!o.isObject())
return def;
94 def.id = o.getString(
"id");
95 def.startPolicy = normalizeStart(o.getString(
"startPolicy",
"manual"));
96 def.completePolicy = normalizeComplete(o.getString(
"completePolicy",
"auto"));
97 def.objectivePolicy = normalizeObjectivePolicy(o.getString(
"objectivePolicy",
"all"));
98 def.requiresIds = o.getStringArray(
"requires");
99 def.tags = o.getStringArray(
"tags");
100 def.extra = o.getStringMap(
"extra");
101 def.timeLimitSeconds = o.getDouble(
"timeLimitSeconds", 0.0);
102 if (!(def.timeLimitSeconds > 0.0) || !std::isfinite(def.timeLimitSeconds)) def.timeLimitSeconds = 0.0;
103 def.refreshKey = o.getString(
"refreshKey");
106 std::unordered_set<std::string> seen;
108 for (
size_t i = 0; i <
objectives.size(); ++i) {
110 if (obj.id.empty() || !seen.insert(obj.id).second) {
114 def.objectives.push_back(std::move(obj));
121 const Value rewards = o.get(
"rewards");
122 for (
size_t i = 0; i < rewards.size(); ++i) {
123 RewardSpec reward = parseReward(rewards.at(i));
124 def.rewards.push_back(std::move(reward));
131 std::move(
path), {},
"rpg.quest-content"));
134bool validContentId(
const std::string &
id) {
135 if (
id.empty() ||
id.
size() > 256)
return false;
136 return std::none_of(
id.
begin(),
id.
end(), [](
unsigned char c) {
return c < 0x20 ||
c == 0x7f; });
139bool stringArrayIsStrict(Value
value) {
140 if (!
value.isArray())
return false;
141 for (
size_t i = 0; i <
value.size(); ++i)
142 if (!
value.at(i).isString())
return false;
146bool stringMapIsStrict(Value
value) {
147 if (!
value.isObject())
return false;
149 if (!
value.get(
key.c_str()).isString()) return false;
156 if (def.
id.empty())
return;
158 auto old =
t.find(def.
id);
160 bool hadOld = old !=
t.end();
168 t[def.
id] = normalized;
169 if (idOnCycle(
t, def.
id)) {
180 auto it =
t.find(
id);
181 return it ==
t.end() ? nullptr : &it->second;
191 std::vector<std::string>
out;
192 for (
const auto &[
id, unused] :
questTable()) {
205 if (
error) *
error = err.empty() ?
"invalid json" : err;
211 if (
root.isArray()) {
212 for (
size_t i = 0; i <
root.size(); ++i)
objects.push_back(
root.at(i));
213 }
else if (
root.isObject()) {
218 std::vector<QuestDefinition> parsed;
219 std::vector<std::string> candidateIds;
220 for (
const auto &o :
objects) {
222 if (def.
id.empty())
continue;
223 parsed.push_back(def);
224 candidateIds.push_back(def.
id);
229 for (
const auto &def : parsed) proposed[def.id] = def;
230 std::unordered_set<std::string> rejected;
231 for (
const auto &
id : candidateIds) {
232 if (idOnCycle(proposed,
id)) rejected.insert(
id);
236 for (
const auto &def : parsed) {
237 if (rejected.count(def.id))
continue;
245 std::string parseError;
247 if (!doc.
valid())
return strictFailure(parseError.empty() ?
"invalid JSON" : parseError,
"$");
250 if (!
root.isArray() && !
root.isObject())
return strictFailure(
"quest catalogue must be an object or array",
"$");
253 if (
root.isArray()) {
254 if (
root.size() == 0)
return strictFailure(
"quest catalogue must not be empty",
"$");
255 for (
size_t i = 0; i <
root.size(); ++i)
objects.push_back(
root.at(i));
260 std::unordered_map<std::string, QuestDefinition> proposed;
261 for (
size_t questIndex = 0; questIndex <
objects.size(); ++questIndex) {
263 const std::string base =
"$[" + std::to_string(questIndex) +
"]";
264 if (!
object.isObject())
return strictFailure(
"quest entry must be an object", base);
266 const Value idValue =
object.
get(
"id");
268 return strictFailure(
"quest id must be a non-empty stable id of at most 256 bytes", base +
".id");
272 if (proposed.count(definition.id) != 0)
return strictFailure(
"duplicate quest id", base +
".id");
274 const Value startPolicy =
object.
get(
"startPolicy");
277 return strictFailure(
"startPolicy must be 'manual' or 'auto'", base +
".startPolicy");
278 definition.startPolicy = startPolicy ? startPolicy.
asString() :
"manual";
280 const Value completePolicy =
object.
get(
"completePolicy");
281 if (completePolicy && (!completePolicy.
isString() ||
282 (completePolicy.
asString() !=
"auto" && completePolicy.
asString() !=
"claim")))
283 return strictFailure(
"completePolicy must be 'auto' or 'claim'", base +
".completePolicy");
284 definition.completePolicy = completePolicy ? completePolicy.
asString() :
"auto";
286 const Value objectivePolicy =
object.
get(
"objectivePolicy");
287 if (objectivePolicy && (!objectivePolicy.
isString() ||
288 (objectivePolicy.
asString() !=
"all" && objectivePolicy.
asString() !=
"any" &&
289 objectivePolicy.
asString() !=
"ordered")))
290 return strictFailure(
"objectivePolicy must be 'all', 'any', or 'ordered'", base +
".objectivePolicy");
291 definition.objectivePolicy = objectivePolicy ? objectivePolicy.
asString() :
"all";
293 const Value timeLimitSeconds =
object.
get(
"timeLimitSeconds");
294 if (timeLimitSeconds) {
295 if (!timeLimitSeconds.
isNumber() || !std::isfinite(timeLimitSeconds.
asDouble()) ||
297 return strictFailure(
"timeLimitSeconds must be a finite non-negative number",
298 base +
".timeLimitSeconds");
299 definition.timeLimitSeconds = timeLimitSeconds.
asDouble();
302 const Value refreshKey =
object.
get(
"refreshKey");
305 return strictFailure(
"refreshKey must be empty or a stable id", base +
".refreshKey");
306 definition.refreshKey = refreshKey.
asString();
309 const Value prerequisites =
object.
get(
"requires");
310 if (prerequisites && !stringArrayIsStrict(prerequisites))
311 return strictFailure(
"requires must be an array of quest ids", base +
".requires");
312 std::unordered_set<std::string> seenRequirements;
313 definition.requiresIds = prerequisites ? prerequisites.
toStringArray() : std::vector<std::string>{};
314 for (
size_t i = 0; i < definition.requiresIds.size(); ++i) {
315 const auto &
required = definition.requiresIds[i];
317 return strictFailure(
"requires contains an invalid or duplicate quest id",
318 base +
".requires[" + std::to_string(i) +
"]");
323 return strictFailure(
"objectives must be an array", base +
".objectives");
324 std::unordered_set<std::string> seenObjectives;
325 for (
size_t i = 0; i <
objectives.size(); ++i) {
327 const auto path = base +
".objectives[" + std::to_string(i) +
"]";
328 if (!item.
isObject())
return strictFailure(
"objective must be an object",
path);
329 const Value objectiveId = item.
get(
"id");
330 const Value topic = item.
get(
"topic");
332 !seenObjectives.insert(objectiveId.
asString()).second)
333 return strictFailure(
"objective id must be unique and stable",
path +
".id");
335 return strictFailure(
"objective topic must be a stable id",
path +
".topic");
338 return strictFailure(
"objective target must be empty or a stable id",
path +
".target");
341 return strictFailure(
"objective count must be a positive integer",
path +
".count");
342 const Value optional = item.
get(
"optional");
343 if (optional && !optional.
isBool())
344 return strictFailure(
"objective optional must be a boolean",
path +
".optional");
350 const Value rewards =
object.
get(
"rewards");
351 if (rewards && !rewards.
isArray())
return strictFailure(
"rewards must be an array", base +
".rewards");
352 for (
size_t i = 0; i < rewards.
size(); ++i) {
353 const Value item = rewards.
at(i);
354 const auto path = base +
".rewards[" + std::to_string(i) +
"]";
355 if (!item.
isObject())
return strictFailure(
"reward must be an object",
path);
358 const Value amount = item.
get(
"amount");
359 if (!
type.isString() || !validContentId(
type.asString()))
360 return strictFailure(
"reward type must be a stable id",
path +
".type");
361 if (!
id.isString() || !validContentId(
id.asString()))
362 return strictFailure(
"reward id must be a stable id",
path +
".id");
364 return strictFailure(
"reward amount must be finite and positive",
path +
".amount");
365 definition.rewards.push_back({
type.asString(),
id.asString(), amount.
asDouble()});
369 if (
tags && !stringArrayIsStrict(
tags))
370 return strictFailure(
"tags must be an array of strings", base +
".tags");
371 definition.tags =
tags ?
tags.toStringArray() : std::vector<std::string>{};
372 for (
size_t i = 0; i < definition.tags.size(); ++i)
373 if (!validContentId(definition.tags[i]))
374 return strictFailure(
"tag must be a stable id", base +
".tags[" + std::to_string(i) +
"]");
376 const Value extra =
object.
get(
"extra");
377 if (extra && !stringMapIsStrict(extra))
378 return strictFailure(
"extra must be an object containing only string values", base +
".extra");
380 for (
const auto &
key : extra.
keys()) definition.extra[
key] = extra.
get(
key.c_str()).asString();
382 proposed.emplace(definition.id, std::move(definition));
385 for (
const auto &[
id, definition] : proposed) {
386 for (
const auto &
required : definition.requiresIds)
388 return strictFailure(
"required quest is missing from replacement catalogue",
id +
".requires");
389 if (idOnCycle(proposed,
id))
return strictFailure(
"quest prerequisite cycle detected",
id +
".requires");
410 const std::string &questId) {
415 if (tracker.
getState(questId) !=
"ready")
417 "quest must be ready before rewards can be claimed",
"quest.state", questId);
419 std::vector<inventory::InventoryItemGrant> itemGrants;
420 itemGrants.reserve(definition->rewards.size());
421 for (std::size_t
index = 0;
index < definition->rewards.size(); ++
index) {
423 const std::string
path =
"quest.rewards[" + std::to_string(
index) +
"]";
424 if (reward.
id.empty() || !std::isfinite(reward.
amount) || reward.
amount <= 0.0)
426 "quest reward requires an id and finite positive amount",
path, questId);
427 if (reward.
type ==
"item") {
428 if (reward.
amount >
static_cast<double>(INT_MAX) || std::floor(reward.
amount) != reward.
amount)
430 "item reward amount must be a positive integer",
path +
".amount", questId);
431 itemGrants.push_back({reward.
id,
static_cast<int>(reward.
amount)});
432 }
else if (reward.
type ==
"attribute") {
436 "attribute reward would produce a non-finite value",
path +
".amount", questId);
439 "quest reward type is not supported by the canonical claim transaction",
440 path +
".type", questId);
444 std::optional<inventory::PreparedInventoryAdd> preparedInventory;
445 if (!itemGrants.empty()) {
448 preparedInventory.emplace(std::move(prepared).takeValue());
453 std::string gameStateSnapshot = std::move(gameStateBefore).takeValue();
454 auto entriesBefore = tracker.
entries;
455 auto orderBefore = tracker.
order;
456 auto pendingBefore = tracker.
pending;
457 auto polledBefore = tracker.
polled;
459 for (
const RewardSpec &reward : definition->rewards)
460 if (reward.type ==
"attribute") gameState.
addVariable(reward.id, reward.amount);
462 std::string claimReason;
465 const bool restoredOk = restored.
ok();
466 tracker.
entries = std::move(entriesBefore);
467 tracker.
order = std::move(orderBefore);
468 tracker.
pending = std::move(pendingBefore);
469 tracker.
polled = std::move(polledBefore);
472 "quest reward rollback could not restore GameState",
"rollback", questId);
474 "quest.state", questId);
477 if (preparedInventory) {
481 const bool restoredOk = restored.
ok();
482 tracker.
entries = std::move(entriesBefore);
483 tracker.
order = std::move(orderBefore);
484 tracker.
pending = std::move(pendingBefore);
485 tracker.
polled = std::move(polledBefore);
488 "quest reward rollback could not restore GameState",
"rollback", questId);
504bool objectivesSatisfiedFor(
const QuestDefinition *def,
const QuestRuntime &rt) {
507 if (!o.done)
return false;
511 const size_t n = std::min(def->objectives.size(), rt.objectives.size());
512 if (def->objectivePolicy ==
"any") {
513 bool hasRequired =
false;
514 for (
size_t i = 0; i <
n; ++i) {
515 if (def->objectives[i].optional)
continue;
517 if (rt.objectives[i].done)
return true;
520 if (
n == 0)
return true;
521 for (
size_t i = 0; i <
n; ++i) {
522 if (rt.objectives[i].done)
return true;
528 for (
size_t i = 0; i <
n; ++i) {
529 if (def->objectives[i].optional)
continue;
530 if (!rt.objectives[i].done)
return false;
535bool objectiveAcceptsNotify(
const QuestDefinition &def,
const QuestRuntime &rt,
size_t index) {
536 if (
index >= def.objectives.size() ||
index >= rt.objectives.size())
return false;
537 if (rt.objectives[
index].done)
return false;
538 if (def.objectivePolicy !=
"ordered")
return true;
539 if (def.objectives[
index].optional)
return true;
540 for (
size_t i = 0; i <
index; ++i) {
541 if (def.objectives[i].optional)
continue;
542 if (!rt.objectives[i].done)
return false;
547void pushEvent(Tracker *
t, QuestEvent ev) {
t->pending.push_back(std::move(ev)); }
549void pushReject(Tracker *
t,
const std::string &entryId,
const std::string &reason) {
551 ev.entryId = entryId;
552 ev.action =
"reject";
554 t->pending.push_back(std::move(ev));
557void onObjectivesFull(Tracker *
t, QuestRuntime &rt) {
559 const std::string policy = def ? def->completePolicy :
"auto";
560 if (policy ==
"claim") {
561 if (rt.state ==
"ready" || rt.state ==
"completed")
return;
563 pushEvent(
t, {rt.id,
"",
"ready",
"",
"", 0,
""});
565 if (rt.state ==
"completed")
return;
566 rt.state =
"completed";
567 pushEvent(
t, {rt.id,
"",
"complete",
"",
"", 0,
""});
572void clearDeadline(QuestRuntime &rt) { rt.deadlineAt = 0.0; }
578 auto it =
t.entries.find(
id);
579 if (it ==
t.entries.end())
return false;
580 if (it->second.state !=
"completed")
return false;
586 return def.
startPolicy ==
"auto" ?
"active" :
"inactive";
593 if (
t->entries.count(
id))
continue;
603 orun.
count = obj.count > 0 ? obj.count : 1;
607 t->entries[
id] = std::move(rt);
608 t->order.push_back(
id);
611 for (
size_t pass = 0; pass <=
t->entries.size(); ++pass) {
613 for (
auto &[
id, rt] :
t->entries) {
614 if (rt.state !=
"locked")
continue;
620 if (newState ==
"active") {
622 pushEvent(
t, {
id,
"",
"activate",
"",
"", 0,
""});
624 if (newState ==
"active" && objectivesSatisfiedFor(def, rt)) onObjectivesFull(
t, rt);
632 if (!
t)
return "unknown";
633 auto it =
t->entries.find(
id);
634 if (it ==
t->entries.end())
return "unknown";
636 if (!def)
return "unknown";
637 const std::string &
state = it->second.state;
638 if (
state ==
"locked")
return "locked";
639 if (
state ==
"active")
return "alreadyActive";
640 if (
state ==
"completed")
return "alreadyCompleted";
641 if (
state ==
"failed")
return "failed";
642 if (
state ==
"ready")
return "ready";
649 if (reason) *reason =
r;
655 if (reason) *reason =
"unknown";
658 auto it =
t->entries.find(
id);
659 if (it ==
t->entries.end()) {
660 if (reason) *reason =
"unknown";
661 pushReject(
t,
id,
"unknown");
666 if (reason) *reason = why;
667 pushReject(
t,
id, why);
670 it->second.state =
"active";
671 clearDeadline(it->second);
672 pushEvent(
t, {
id,
"",
"activate",
"",
"", 0,
""});
674 if (objectivesSatisfiedFor(def, it->second)) onObjectivesFull(
t, it->second);
679 if (!
t || amount <= 0)
return;
680 std::vector<std::string> fullIds;
681 for (
auto &[
id, rt] :
t->entries) {
682 if (rt.state !=
"active")
continue;
685 const size_t n = std::min(def->
objectives.size(), rt.objectives.size());
686 for (
size_t i = 0; i <
n; ++i) {
688 auto &rtObj = rt.objectives[i];
689 if (!objectiveAcceptsNotify(*def, rt, i))
continue;
690 if (rtObj.count <= 0) rtObj.count = 1;
691 const bool match = objDef.topic == topic && (objDef.target.empty() || objDef.target ==
target);
692 if (!match)
continue;
693 const int added = std::min(amount, rtObj.count - rtObj.current);
694 rtObj.current += added;
695 if (rtObj.current >= rtObj.count) rtObj.done =
true;
696 pushEvent(
t, {
id, rtObj.id,
"progress", topic,
target, added,
""});
698 if (objectivesSatisfiedFor(def, rt)) fullIds.push_back(
id);
700 for (
const auto &fid : fullIds) {
701 auto it =
t->entries.find(fid);
702 if (it !=
t->entries.end()) onObjectivesFull(
t, it->second);
708 if (reason) *reason =
"unknown";
711 auto it =
t->entries.find(
id);
712 if (it ==
t->entries.end()) {
713 if (reason) *reason =
"unknown";
714 pushReject(
t,
id,
"unknown");
717 if (it->second.state !=
"ready") {
718 if (reason) *reason = it->second.state;
719 pushReject(
t,
id, it->second.state);
722 it->second.state =
"completed";
723 pushEvent(
t, {
id,
"",
"complete",
"",
"", 0,
""});
729 if (!
t)
return false;
730 auto it =
t->entries.find(
id);
731 if (it ==
t->entries.end())
return false;
741 orun.
count = obj.count > 0 ? obj.count : 1;
747 pushEvent(
t, {
id,
"",
"reset",
"",
"", 0,
""});
748 if (rt.
state ==
"active" && objectivesSatisfiedFor(def, rt)) onObjectivesFull(
t, rt);
753bool failImpl(
Tracker *
t,
const std::string &
id,
const std::string &reason) {
754 if (!
t)
return false;
755 auto it =
t->entries.find(
id);
756 if (it ==
t->entries.end()) {
757 pushReject(
t,
id,
"unknown");
760 const std::string &st = it->second.state;
761 if (st !=
"inactive" && st !=
"active" && st !=
"ready") {
762 pushReject(
t,
id, st);
765 it->second.state =
"failed";
766 clearDeadline(it->second);
767 pushEvent(
t, {
id,
"",
"fail",
"",
"", 0, reason});
777 auto it =
t.entries.find(
id);
778 if (it ==
t.entries.end())
return false;
783 const std::string
state = [&]() -> std::string {
784 auto it =
t.entries.find(questId);
785 return it ==
t.entries.end() ? std::string{} : it->second.state;
787 if (
state.empty())
return {};
788 if (
state ==
"locked" ||
state ==
"inactive")
return "offer";
789 if (
state ==
"active")
return "active";
790 if (
state ==
"ready")
return "turnin";
791 if (
state ==
"completed")
return "completed";
792 if (
state ==
"failed")
return "failed";
797 const std::string &dialogueBase) {
798 if (dialogueBase.empty())
return {};
800 if (
phase.empty())
return {};
801 return dialogueBase +
"." +
phase;
805 if (!
t || !std::isfinite(nowSeconds))
return 0;
807 for (
auto &
id :
t->order) {
808 auto it =
t->entries.find(
id);
809 if (it ==
t->entries.end())
continue;
811 if (rt.
state !=
"active" && rt.
state !=
"ready")
continue;
816 if (failImpl(
t,
id,
"expired")) ++failed;
823 if (!
t || refreshKey.empty())
return 0;
826 const std::vector<std::string>
ids =
t->order;
827 for (
const auto &
id :
ids) {
829 if (!def || def->
refreshKey != refreshKey)
continue;
830 auto it =
t->entries.find(
id);
831 if (it ==
t->entries.end())
continue;
832 if (it->second.refreshStamp ==
stamp)
continue;
834 it =
t->entries.find(
id);
835 if (it ==
t->entries.end())
continue;
836 it->second.refreshStamp =
stamp;
全局游戏状态:开关(bool)、变量(数字)、独立变量(按作用域)。
Atomic orchestration for claiming data-driven quest rewards.
任务 / 成就 / 教程的通用定义模板与进程级注册表。
Battle::Objectives objectives
目标追踪器运行时实例(玩家日志 / 成就 / 教程可各建一份)。
std::set< std::string > visiting
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
static eve::Result< int > commitAddBatch(PreparedInventoryAdd prepared)
Commit one prepared addition and then publish its change events.
static eve::Result< PreparedInventoryAdd > prepareAddBatch(Bag *bag, const std::vector< InventoryItemGrant > &grants)
Validate a multi-item addition against a private candidate Bag.
EVENGINE_API_FOUNDATION public API.
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
EVENGINE_API_FOUNDATION public API.
bool isObject() const
True when object.
double asDouble(double fallback=0.0) const
As double.
Value get(const char *key) const
Returns the value.
size_t size() const
Returns the size of .
bool isArray() const
True when array.
Value at(size_t index) const
At.
bool isString() const
True when string.
bool isNumber() const
True when number.
bool asBool(bool fallback=false) const
As bool.
bool isBool() const
True when bool.
std::vector< std::string > keys() const
Keys.
std::string asString(const std::string &fallback={}) const
As string.
std::vector< std::string > toStringArray() const
To string array.
double getVariable(const std::string &name) const
Returns the variable.
void addVariable(const std::string &name, double delta)
Adds variable.
eve::Result< void > restoreSnapshotJson(std::string_view json)
Validate and atomically restore a canonical RPG game-state JSON document.
eve::Result< std::string > snapshotJson() const
Serialize this state as the canonical versioned RPG game-state JSON document.
static int loadFromJson(const std::string &json, std::string *error=nullptr)
从 JSON 数组/对象批量注册;缺 id、重复 objective id、环形 requires 的定义被拒绝。
static void registerQuest(const QuestDefinition &def)
Registers quest.
static std::vector< std::string > ids()
Ids.
static int count()
Returns the number of .
static void clear()
Clears .
static eve::Result< int > replaceFromJsonStrict(const std::string &json)
Strictly validate and atomically replace every registered quest definition.
static bool remove(const std::string &id)
Remove a quest by id (compatibility facade returning whether it was present).
static bool contains(const std::string &id)
Return whether one exact stable quest id is registered.
static const QuestDefinition * find(const std::string &id)
Find a registered quest definition by id.
static eve::Result< int > claim(Tracker &tracker, GameState &gameState, inventory::Bag &bag, const std::string &questId)
Validate and atomically claim every reward declared by one ready quest.
static std::string dialogueConversationId(const Tracker &t, const std::string &questId, const std::string &dialogueBase)
拼接 dialogueBase + "." + dialoguePhase;相位或 base 为空时返回空串。
static bool canActivate(Tracker *t, const std::string &id, std::string *reason=nullptr)
是否可激活(谓词查询,可返回 reason)。
static bool isObjectivesSatisfied(const Tracker &t, const std::string &id)
按定义的 objectivePolicy / optional 判定条目目标是否已满足完成条件。
static bool reset(Tracker *t, const std::string &id)
进度清零并按当前 requires 回落 locked/inactive/active;不级联(compatibility facade (脚本兼容门面))。
static bool claim(Tracker *t, const std::string &id, std::string *reason=nullptr)
仅 state==ready 时成功 → completed 并触发解锁;否则 reject(compatibility facade (脚本兼容门面))。
static void syncAuto(Tracker *t)
补建 Registry 里尚不在 Tracker 上的条目,并解开前置已齐的 locked 条目。
static int refreshByKey(Tracker *t, const std::string &refreshKey, const std::string &stamp)
对 refreshKey 匹配的条目,若 stamp 与 refreshStamp 不同则 reset 并写入新 stamp。
static std::string canActivateReason(Tracker *t, const std::string &id)
不可激活的原因("" 可激活,否则 unknown/locked/alreadyActive/alreadyCompleted/failed/ready)。
static std::string stateForUnlocked(const QuestDefinition &def)
解锁后的落点:startPolicy==auto → "active",否则 "inactive"。
static bool hasMetRequirements(const Tracker &t, const QuestDefinition &def)
def 的全部 requires 在本 Tracker 上均已 completed(谓词查询)。
static bool fail(Tracker *t, const std::string &id, const std::string &reason)
Fail.
static bool activate(Tracker *t, const std::string &id, std::string *reason=nullptr)
激活:仅 inactive 且前置已齐时成功;否则 push reject 并返回 false(compatibility facade (脚本兼容门面))。
static void pollEvents(Tracker *t, std::vector< QuestEvent > &out)
把 Tracker 的 pending 移动并清空到 out。
static void notify(Tracker *t, const std::string &topic, const std::string &target, int amount)
报告事实 (topic, target, amount);只推进 state==active 的条目。
static int applyClock(Tracker *t, double nowSeconds)
武装未设 deadline 的限时条目,并 fail 已过期的 active/ready(reason=expired)。
static std::string dialoguePhase(const Tracker &t, const std::string &questId)
将 Tracker 状态映射为对话相位后缀:offer|active|turnin|completed|failed。
static bool abandon(Tracker *t, const std::string &id)
abandon/fail → failed;对 completed/failed/locked/未知 id 为 reject(compatibility facade (脚本兼容门面))。
std::unordered_map< std::string, QuestRuntime > entries
运行时条目(QuestSystem 读写;公开以便测试与脚本查询)。
std::vector< std::string > order
std::vector< QuestEvent > pending
std::string getState(const std::string &id) const
Returns the state.
std::vector< QuestEvent > polled
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
void keys(const Value &value, std::initializer_list< const char * > names)
Status invalid(const char *message)
RPG 模块的基础实体:把属性 / 状态 / 技能三张表挂到一个 ECS 实体上。
std::unordered_map< std::string, QuestDefinition > & questTable()
std::unordered_map< std::string, SkillDefinition > & table()
DiagnosticCode
Stable machine-readable diagnostic codes.
bool hasTag(const std::string &tag) const
True when tag.
double timeLimitSeconds
限时秒数;<=0 表示无限时。进入 active 后由 Tracker::applyClock(now) 武装 deadlineAt。
std::string refreshKey
刷新族键(如 "daily");空表示不参与 refreshByKey。
std::vector< std::string > tags
std::unordered_map< std::string, std::string > extra
std::string startPolicy
"manual" | "auto",缺省 "manual"。
std::vector< std::string > requiresIds
本 Tracker 上须已 completed 的条目 id,全部 AND。
std::string objectivePolicy
目标完成关系:"all"(缺省,非 optional 全部 AND)| "any"(非 optional 任一)| "ordered"(非 optional 按数组顺序解锁听 notify,完成判定同 ...
std::string completePolicy
"auto" | "claim",缺省 "auto"。
std::vector< QuestObjective > objectives
std::string getExtra(const std::string &key, const std::string &fallback={}) const
Returns the extra.
double deadlineAt
绝对截止时刻(与 Tracker::applyClock 使用同一时间轴);0 表示未武装或无限时。
std::vector< ObjectiveRuntime > objectives
std::string state
locked | inactive | active | ready | completed | failed