Constructor
new QuestGraph(definitionopt)
| Name | Type | Attributes | Description |
|---|---|---|---|
definition | Object | <optional> |
- Source
Classes
Members
currentStageId
Currently active stage ID.
- Source
history
History of quest state transitions.
- Source
state
Current quest state ('unstarted', 'active', 'completed', 'failed').
- Source
Methods
(static) validate(questDef) → {Object}
Validates a quest graph definition.
| Name | Type | Description |
|---|---|---|
questDef | Object |
- Source
- Type:
- Object
addStage(stage) → {this}
Adds a stage or objective to the quest graph.
| Name | Type | Description |
|---|---|---|
stage | Object |
- Source
- Type:
- this
bind(facts, busopt) → {function}
Binds WorldFacts and optional TypedEventBus to trigger fact/event-driven evaluation automatically.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
facts | WorldFacts | |||
bus | Object | <optional> | null |
- Source
Unbind callback
- Type:
- function
claimReward(reward, factsopt) → {Object}
Claims a one-time reward with deduplication guard. Prevents rewards from ever being awarded twice.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
reward | Object | | |||
facts | WorldFacts | <optional> | null |
- Source
Result object with awarded flag and rewardId
- Type:
- Object
complete() → {this}
Marks the quest as completed, awarding one-time quest rewards with deduplication.
- Source
- Type:
- this
completeStage(stageId) → {this}
Completes a specific stage, granting its deduplicated one-time rewards, and advances to the next stage or completes the quest.
| Name | Type | Description |
|---|---|---|
stageId | string |
- Source
- Type:
- this
diagnostics() → {Object}
Runs diagnostics on the quest graph: detects missing node references, absent speakers (if dialogue is attached), contradictory conditions, and unsupported cycles.
- Source
- Type:
- Object
evaluate(factsopt, eventopt) → {boolean}
Evaluates current active stage conditions against WorldFacts and optional event. If conditions are met, advances stage or completes quest.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
facts | WorldFacts | <optional> | null | |
event | Object | | <optional> | null |
- Source
True if stage transitioned
- Type:
- boolean
fail(reasonopt) → {this}
Marks the quest as failed.
| Name | Type | Attributes | Description |
|---|---|---|---|
reason | string | <optional> |
- Source
- Type:
- this
getActiveStage() → {Object|null}
Gets the currently active stage object.
- Source
- Type:
- Object |
null
getClaimedRewards() → {Array.<string>}
Returns an array of all claimed reward IDs.
- Source
- Type:
- Array.<string>
getStage(stageId) → {Object|null}
Gets a stage by ID.
| Name | Type | Description |
|---|---|---|
stageId | string |
- Source
- Type:
- Object |
null
hasClaimedReward(rewardId) → {boolean}
Checks if a reward ID has already been claimed.
| Name | Type | Description |
|---|---|---|
rewardId | string |
- Source
- Type:
- boolean
hasStage(stageId) → {boolean}
Checks if a stage exists.
| Name | Type | Description |
|---|---|---|
stageId | string |
- Source
- Type:
- boolean
isActive() → {boolean}
Checks if quest is currently active.
- Source
- Type:
- boolean
isCompleted() → {boolean}
Checks if quest has completed.
- Source
- Type:
- boolean
isFailed() → {boolean}
Checks if quest has failed.
- Source
- Type:
- boolean
reset()
Resets quest to unstarted state and clears active stage.
- Source
restore(snapshot) → {this}
Restores quest state, active stage, and claimed reward deduplication guards from snapshot.
| Name | Type | Description |
|---|---|---|
snapshot | Object |
- Source
- Type:
- this
setFacts(facts) → {this}
Sets or updates the authoritative WorldFacts instance.
| Name | Type | Description |
|---|---|---|
facts | WorldFacts |
- Source
- Type:
- this
snapshot() → {Object}
Serializes quest state, active stage, and claimed rewards for save games.
- Source
- Type:
- Object
start() → {this}
Starts the quest, activating the initial stage.
- Source
- Type:
- this