@sharpee/character 0.9.106 → 0.9.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apply.d.ts +29 -7
- package/apply.d.ts.map +1 -1
- package/apply.js +15 -7
- package/apply.js.map +1 -1
- package/character-builder.d.ts +67 -4
- package/character-builder.d.ts.map +1 -1
- package/character-builder.js +116 -7
- package/character-builder.js.map +1 -1
- package/conversation/acl.d.ts +62 -0
- package/conversation/acl.d.ts.map +1 -0
- package/conversation/acl.js +117 -0
- package/conversation/acl.js.map +1 -0
- package/conversation/builder.d.ts +247 -0
- package/conversation/builder.d.ts.map +1 -0
- package/conversation/builder.js +324 -0
- package/conversation/builder.js.map +1 -0
- package/conversation/constraint-evaluator.d.ts +147 -0
- package/conversation/constraint-evaluator.d.ts.map +1 -0
- package/conversation/constraint-evaluator.js +247 -0
- package/conversation/constraint-evaluator.js.map +1 -0
- package/conversation/conversation-messages.d.ts +56 -0
- package/conversation/conversation-messages.d.ts.map +1 -0
- package/conversation/conversation-messages.js +69 -0
- package/conversation/conversation-messages.js.map +1 -0
- package/conversation/dialogue-extension.d.ts +87 -0
- package/conversation/dialogue-extension.d.ts.map +1 -0
- package/conversation/dialogue-extension.js +302 -0
- package/conversation/dialogue-extension.js.map +1 -0
- package/conversation/dialogue-types.d.ts +71 -0
- package/conversation/dialogue-types.d.ts.map +1 -0
- package/conversation/dialogue-types.js +13 -0
- package/conversation/dialogue-types.js.map +1 -0
- package/conversation/index.d.ts +19 -0
- package/conversation/index.d.ts.map +1 -0
- package/conversation/index.js +37 -0
- package/conversation/index.js.map +1 -0
- package/conversation/lifecycle.d.ts +212 -0
- package/conversation/lifecycle.d.ts.map +1 -0
- package/conversation/lifecycle.js +348 -0
- package/conversation/lifecycle.js.map +1 -0
- package/conversation/response-types.d.ts +98 -0
- package/conversation/response-types.d.ts.map +1 -0
- package/conversation/response-types.js +30 -0
- package/conversation/response-types.js.map +1 -0
- package/conversation/topic-registry.d.ts +130 -0
- package/conversation/topic-registry.d.ts.map +1 -0
- package/conversation/topic-registry.js +187 -0
- package/conversation/topic-registry.js.map +1 -0
- package/goals/builder.d.ts +135 -0
- package/goals/builder.d.ts.map +1 -0
- package/goals/builder.js +193 -0
- package/goals/builder.js.map +1 -0
- package/goals/goal-activation.d.ts +99 -0
- package/goals/goal-activation.d.ts.map +1 -0
- package/goals/goal-activation.js +212 -0
- package/goals/goal-activation.js.map +1 -0
- package/goals/goal-types.d.ts +138 -0
- package/goals/goal-types.d.ts.map +1 -0
- package/goals/goal-types.js +20 -0
- package/goals/goal-types.js.map +1 -0
- package/goals/index.d.ts +15 -0
- package/goals/index.d.ts.map +1 -0
- package/goals/index.js +24 -0
- package/goals/index.js.map +1 -0
- package/goals/pathfinding.d.ts +67 -0
- package/goals/pathfinding.d.ts.map +1 -0
- package/goals/pathfinding.js +134 -0
- package/goals/pathfinding.js.map +1 -0
- package/goals/step-evaluator.d.ts +52 -0
- package/goals/step-evaluator.d.ts.map +1 -0
- package/goals/step-evaluator.js +153 -0
- package/goals/step-evaluator.js.map +1 -0
- package/index.d.ts +6 -1
- package/index.d.ts.map +1 -1
- package/index.js +60 -1
- package/index.js.map +1 -1
- package/influence/builder.d.ts +136 -0
- package/influence/builder.d.ts.map +1 -0
- package/influence/builder.js +198 -0
- package/influence/builder.js.map +1 -0
- package/influence/index.d.ts +16 -0
- package/influence/index.d.ts.map +1 -0
- package/influence/index.js +25 -0
- package/influence/index.js.map +1 -0
- package/influence/influence-duration.d.ts +82 -0
- package/influence/influence-duration.d.ts.map +1 -0
- package/influence/influence-duration.js +148 -0
- package/influence/influence-duration.js.map +1 -0
- package/influence/influence-evaluator.d.ts +55 -0
- package/influence/influence-evaluator.d.ts.map +1 -0
- package/influence/influence-evaluator.js +183 -0
- package/influence/influence-evaluator.js.map +1 -0
- package/influence/influence-messages.d.ts +30 -0
- package/influence/influence-messages.d.ts.map +1 -0
- package/influence/influence-messages.js +40 -0
- package/influence/influence-messages.js.map +1 -0
- package/influence/influence-types.d.ts +123 -0
- package/influence/influence-types.d.ts.map +1 -0
- package/influence/influence-types.js +12 -0
- package/influence/influence-types.js.map +1 -0
- package/influence/pc-influence.d.ts +38 -0
- package/influence/pc-influence.d.ts.map +1 -0
- package/influence/pc-influence.js +56 -0
- package/influence/pc-influence.js.map +1 -0
- package/package.json +4 -3
- package/propagation/builder.d.ts +47 -0
- package/propagation/builder.d.ts.map +1 -0
- package/propagation/builder.js +46 -0
- package/propagation/builder.js.map +1 -0
- package/propagation/fact-transfer.d.ts +47 -0
- package/propagation/fact-transfer.d.ts.map +1 -0
- package/propagation/fact-transfer.js +76 -0
- package/propagation/fact-transfer.js.map +1 -0
- package/propagation/index.d.ts +16 -0
- package/propagation/index.d.ts.map +1 -0
- package/propagation/index.js +28 -0
- package/propagation/index.js.map +1 -0
- package/propagation/propagation-evaluator.d.ts +53 -0
- package/propagation/propagation-evaluator.d.ts.map +1 -0
- package/propagation/propagation-evaluator.js +231 -0
- package/propagation/propagation-evaluator.js.map +1 -0
- package/propagation/propagation-messages.d.ts +30 -0
- package/propagation/propagation-messages.d.ts.map +1 -0
- package/propagation/propagation-messages.js +37 -0
- package/propagation/propagation-messages.js.map +1 -0
- package/propagation/propagation-types.d.ts +100 -0
- package/propagation/propagation-types.d.ts.map +1 -0
- package/propagation/propagation-types.js +68 -0
- package/propagation/propagation-types.js.map +1 -0
- package/propagation/visibility.d.ts +46 -0
- package/propagation/visibility.d.ts.map +1 -0
- package/propagation/visibility.js +79 -0
- package/propagation/visibility.js.map +1 -0
- package/tick-phases.d.ts +93 -0
- package/tick-phases.d.ts.map +1 -0
- package/tick-phases.js +433 -0
- package/tick-phases.js.map +1 -0
package/goals/builder.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Goal builder API (ADR-145 layer 5)
|
|
4
|
+
*
|
|
5
|
+
* Fluent builder for defining NPC goals with activation conditions,
|
|
6
|
+
* pursuit modes, behavior sequences, and interruption rules.
|
|
7
|
+
* Returns from CharacterBuilder.goal(id) and compiles to GoalDef
|
|
8
|
+
* stored in CompiledCharacter.goalDefs.
|
|
9
|
+
*
|
|
10
|
+
* Public interface: GoalBuilder.
|
|
11
|
+
* Owner context: @sharpee/character / goals
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.GoalBuilder = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Fluent builder for a single goal definition.
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* ```
|
|
20
|
+
* builder.goal('eliminate-player')
|
|
21
|
+
* .activatesWhen('knows murder discovered', 'has weapon')
|
|
22
|
+
* .priority('critical')
|
|
23
|
+
* .mode('prepared')
|
|
24
|
+
* .pursues([
|
|
25
|
+
* { type: 'moveTo', target: 'study' },
|
|
26
|
+
* { type: 'acquire', target: 'knife' },
|
|
27
|
+
* ])
|
|
28
|
+
* .actsWhen('alone with player')
|
|
29
|
+
* .act('colonel-attacks-player')
|
|
30
|
+
* .onInterrupt('colonel-retreats')
|
|
31
|
+
* .resumeOnClear(true)
|
|
32
|
+
* .done()
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
class GoalBuilder {
|
|
36
|
+
_id;
|
|
37
|
+
_parent;
|
|
38
|
+
_finalize;
|
|
39
|
+
_activatesWhen = [];
|
|
40
|
+
_interruptedBy = [];
|
|
41
|
+
_priority = 'medium';
|
|
42
|
+
_mode = 'sequential';
|
|
43
|
+
_steps = [];
|
|
44
|
+
_actsWhen = [];
|
|
45
|
+
_actMessageId;
|
|
46
|
+
_onInterrupt;
|
|
47
|
+
_resumeOnClear = false;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new goal builder.
|
|
50
|
+
*
|
|
51
|
+
* @param id - Unique goal identifier
|
|
52
|
+
* @param parent - Parent builder to return to on .done()
|
|
53
|
+
* @param finalize - Callback to register the compiled GoalDef
|
|
54
|
+
*/
|
|
55
|
+
constructor(id, parent, finalize) {
|
|
56
|
+
this._id = id;
|
|
57
|
+
this._parent = parent;
|
|
58
|
+
this._finalize = finalize;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Set predicate conditions that activate this goal.
|
|
62
|
+
*
|
|
63
|
+
* @param predicates - Predicate names (all must be true)
|
|
64
|
+
* @returns this for chaining
|
|
65
|
+
*/
|
|
66
|
+
activatesWhen(...predicates) {
|
|
67
|
+
this._activatesWhen.push(...predicates);
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Set goal priority.
|
|
72
|
+
*
|
|
73
|
+
* @param priority - Priority word
|
|
74
|
+
* @returns this for chaining
|
|
75
|
+
*/
|
|
76
|
+
priority(priority) {
|
|
77
|
+
this._priority = priority;
|
|
78
|
+
return this;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Set pursuit mode.
|
|
82
|
+
*
|
|
83
|
+
* @param mode - How the NPC pursues the goal
|
|
84
|
+
* @returns this for chaining
|
|
85
|
+
*/
|
|
86
|
+
mode(mode) {
|
|
87
|
+
this._mode = mode;
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Set the behavior sequence (for sequential and prepared modes).
|
|
92
|
+
*
|
|
93
|
+
* @param steps - Array of goal steps
|
|
94
|
+
* @returns this for chaining
|
|
95
|
+
*/
|
|
96
|
+
pursues(steps) {
|
|
97
|
+
this._steps = [...steps];
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Set conditions for the final act (opportunistic/prepared modes).
|
|
102
|
+
*
|
|
103
|
+
* @param predicates - Predicate names (all must be true)
|
|
104
|
+
* @returns this for chaining
|
|
105
|
+
*/
|
|
106
|
+
actsWhen(...predicates) {
|
|
107
|
+
this._actsWhen.push(...predicates);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set the message ID for the final act.
|
|
112
|
+
*
|
|
113
|
+
* @param messageId - Message ID
|
|
114
|
+
* @returns this for chaining
|
|
115
|
+
*/
|
|
116
|
+
act(messageId) {
|
|
117
|
+
this._actMessageId = messageId;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Set predicate conditions that interrupt (suspend) this goal.
|
|
122
|
+
*
|
|
123
|
+
* @param predicates - Predicate names
|
|
124
|
+
* @returns this for chaining
|
|
125
|
+
*/
|
|
126
|
+
interruptedBy(...predicates) {
|
|
127
|
+
this._interruptedBy.push(...predicates);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Set the message ID when the goal is interrupted.
|
|
132
|
+
*
|
|
133
|
+
* @param messageId - Message ID
|
|
134
|
+
* @returns this for chaining
|
|
135
|
+
*/
|
|
136
|
+
onInterrupt(messageId) {
|
|
137
|
+
this._onInterrupt = messageId;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Set whether the goal resumes from where it left off after interruption.
|
|
142
|
+
*
|
|
143
|
+
* @param resume - Whether to resume
|
|
144
|
+
* @returns this for chaining
|
|
145
|
+
*/
|
|
146
|
+
resumeOnClear(resume) {
|
|
147
|
+
this._resumeOnClear = resume;
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Finalize this goal definition and return the parent builder.
|
|
152
|
+
*
|
|
153
|
+
* @returns The parent builder
|
|
154
|
+
*/
|
|
155
|
+
done() {
|
|
156
|
+
this._finalize(this._buildDef());
|
|
157
|
+
return this._parent;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Compile the parent builder, auto-finalizing this goal.
|
|
161
|
+
* Allows calling .compile() directly from a goal chain without .done().
|
|
162
|
+
*
|
|
163
|
+
* @returns Compiled character data (delegates to parent's compile())
|
|
164
|
+
*/
|
|
165
|
+
compile() {
|
|
166
|
+
const parent = this.done();
|
|
167
|
+
return parent.compile();
|
|
168
|
+
}
|
|
169
|
+
/** @internal Build the GoalDef without finalizing. */
|
|
170
|
+
_buildDef() {
|
|
171
|
+
const def = {
|
|
172
|
+
id: this._id,
|
|
173
|
+
activatesWhen: [...this._activatesWhen],
|
|
174
|
+
priority: this._priority,
|
|
175
|
+
mode: this._mode,
|
|
176
|
+
};
|
|
177
|
+
if (this._steps.length > 0)
|
|
178
|
+
def.steps = [...this._steps];
|
|
179
|
+
if (this._interruptedBy.length > 0)
|
|
180
|
+
def.interruptedBy = [...this._interruptedBy];
|
|
181
|
+
if (this._actsWhen.length > 0)
|
|
182
|
+
def.actsWhen = [...this._actsWhen];
|
|
183
|
+
if (this._actMessageId !== undefined)
|
|
184
|
+
def.actMessageId = this._actMessageId;
|
|
185
|
+
if (this._onInterrupt !== undefined)
|
|
186
|
+
def.onInterrupt = this._onInterrupt;
|
|
187
|
+
if (this._resumeOnClear)
|
|
188
|
+
def.resumeOnClear = true;
|
|
189
|
+
return def;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.GoalBuilder = GoalBuilder;
|
|
193
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/character/src/goals/builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AASH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,WAAW;IACL,GAAG,CAAS;IACZ,OAAO,CAAU;IACjB,SAAS,CAAyB;IAClC,cAAc,GAAa,EAAE,CAAC;IAC9B,cAAc,GAAa,EAAE,CAAC;IACvC,SAAS,GAAiB,QAAQ,CAAC;IACnC,KAAK,GAAgB,YAAY,CAAC;IAClC,MAAM,GAAe,EAAE,CAAC;IACf,SAAS,GAAa,EAAE,CAAC;IAClC,aAAa,CAAU;IACvB,YAAY,CAAU;IACtB,cAAc,GAAG,KAAK,CAAC;I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C,cAAc;YAAE,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC;QAElD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AArKD,kCAqKC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal activation and lifecycle (ADR-145)
|
|
3
|
+
*
|
|
4
|
+
* Evaluates goal activation conditions against character state,
|
|
5
|
+
* manages the active goal queue (priority-sorted), and handles
|
|
6
|
+
* interruption/resumption.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: GoalManager.
|
|
9
|
+
* Owner context: @sharpee/character / goals
|
|
10
|
+
*/
|
|
11
|
+
import { CharacterModelTrait } from "../../world-model/index";
|
|
12
|
+
import { GoalDef, ActiveGoal } from './goal-types';
|
|
13
|
+
/**
|
|
14
|
+
* Manages goal activation, deactivation, interruption, and the
|
|
15
|
+
* active goal queue for a single NPC.
|
|
16
|
+
*/
|
|
17
|
+
export declare class GoalManager {
|
|
18
|
+
/** All authored goal definitions for this NPC. */
|
|
19
|
+
private readonly defs;
|
|
20
|
+
/** Currently active goals, sorted by priority (highest first). */
|
|
21
|
+
private activeGoals;
|
|
22
|
+
/**
|
|
23
|
+
* Register a goal definition.
|
|
24
|
+
*
|
|
25
|
+
* @param def - The goal definition
|
|
26
|
+
*/
|
|
27
|
+
registerGoal(def: GoalDef): void;
|
|
28
|
+
/**
|
|
29
|
+
* Register multiple goal definitions.
|
|
30
|
+
*
|
|
31
|
+
* @param defs - The goal definitions
|
|
32
|
+
*/
|
|
33
|
+
registerGoals(defs: GoalDef[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Evaluate all goal activation and interruption conditions.
|
|
36
|
+
* Activates new goals, interrupts active ones, resumes cleared ones.
|
|
37
|
+
*
|
|
38
|
+
* @param trait - The NPC's CharacterModelTrait
|
|
39
|
+
* @returns The current active goal queue (priority-sorted)
|
|
40
|
+
*/
|
|
41
|
+
evaluate(trait: CharacterModelTrait): ActiveGoal[];
|
|
42
|
+
/**
|
|
43
|
+
* Get the highest-priority non-interrupted active goal.
|
|
44
|
+
*
|
|
45
|
+
* @returns The top goal, or undefined
|
|
46
|
+
*/
|
|
47
|
+
getTopGoal(): ActiveGoal | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a goal is currently active.
|
|
50
|
+
*
|
|
51
|
+
* @param goalId - The goal ID
|
|
52
|
+
* @returns True if the goal is in the active queue
|
|
53
|
+
*/
|
|
54
|
+
isActive(goalId: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Get all active goals.
|
|
57
|
+
*
|
|
58
|
+
* @returns The active goal queue
|
|
59
|
+
*/
|
|
60
|
+
getActiveGoals(): readonly ActiveGoal[];
|
|
61
|
+
/**
|
|
62
|
+
* Advance the current step of a goal (after step completion).
|
|
63
|
+
*
|
|
64
|
+
* @param goalId - The goal ID
|
|
65
|
+
*/
|
|
66
|
+
advanceStep(goalId: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* Complete a goal and remove it from the active queue.
|
|
69
|
+
*
|
|
70
|
+
* @param goalId - The goal ID
|
|
71
|
+
*/
|
|
72
|
+
complete(goalId: string): void;
|
|
73
|
+
/** Export active goals for save/restore. */
|
|
74
|
+
toJSON(): ActiveGoalState[];
|
|
75
|
+
/** Restore active goals from serialized state. */
|
|
76
|
+
restoreState(states: ActiveGoalState[]): void;
|
|
77
|
+
/**
|
|
78
|
+
* Evaluate interruption and resumption conditions for all active goals.
|
|
79
|
+
*
|
|
80
|
+
* For interrupted goals with resumeOnClear, checks if interruption
|
|
81
|
+
* conditions have cleared and resumes them. For non-interrupted goals,
|
|
82
|
+
* checks if any interruption conditions are now met and interrupts them.
|
|
83
|
+
*
|
|
84
|
+
* @param activeGoals - The active goal queue
|
|
85
|
+
* @param trait - The NPC's CharacterModelTrait
|
|
86
|
+
*/
|
|
87
|
+
private evaluateInterruptions;
|
|
88
|
+
private activate;
|
|
89
|
+
private deactivate;
|
|
90
|
+
}
|
|
91
|
+
/** Serialized active goal state. */
|
|
92
|
+
export interface ActiveGoalState {
|
|
93
|
+
defId: string;
|
|
94
|
+
currentStep: number;
|
|
95
|
+
paused: boolean;
|
|
96
|
+
interrupted: boolean;
|
|
97
|
+
prepared: boolean;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=goal-activation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-activation.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/goals/goal-activation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EACL,OAAO,EACP,UAAU,EAEX,MAAM,cAAc,CAAC;AAMtB;;;GAGG;AACH,qBAAa,WAAW;IACtB,kDAAkD;IAClD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IAEtC,kEAAkE;IAClE,OAAO,CAAC,WAAW,CAAoB;IAMvC;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI;IAIhC;;;;OAIG;IACH,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAQpC;;;;;;OAMG;IACH,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,UAAU,EAAE;IAgClD;;;;OAIG;IACH,UAAU,IAAI,UAAU,GAAG,SAAS;IAIpC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAIjC;;;;OAIG;IACH,cAAc,IAAI,SAAS,UAAU,EAAE;IAIvC;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAkBjC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAQ9B,4CAA4C;IAC5C,MAAM,IAAI,eAAe,EAAE;IAU3B,kDAAkD;IAClD,YAAY,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,IAAI;IAoB7C;;;;;;;;;OASG;IACH,OAAO,CAAC,qBAAqB;IA8B7B,OAAO,CAAC,QAAQ;IAUhB,OAAO,CAAC,UAAU;CAGnB;AAMD,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Goal activation and lifecycle (ADR-145)
|
|
4
|
+
*
|
|
5
|
+
* Evaluates goal activation conditions against character state,
|
|
6
|
+
* manages the active goal queue (priority-sorted), and handles
|
|
7
|
+
* interruption/resumption.
|
|
8
|
+
*
|
|
9
|
+
* Public interface: GoalManager.
|
|
10
|
+
* Owner context: @sharpee/character / goals
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.GoalManager = void 0;
|
|
14
|
+
const goal_types_1 = require("./goal-types");
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Goal manager
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
/**
|
|
19
|
+
* Manages goal activation, deactivation, interruption, and the
|
|
20
|
+
* active goal queue for a single NPC.
|
|
21
|
+
*/
|
|
22
|
+
class GoalManager {
|
|
23
|
+
/** All authored goal definitions for this NPC. */
|
|
24
|
+
defs = [];
|
|
25
|
+
/** Currently active goals, sorted by priority (highest first). */
|
|
26
|
+
activeGoals = [];
|
|
27
|
+
// =========================================================================
|
|
28
|
+
// Registration
|
|
29
|
+
// =========================================================================
|
|
30
|
+
/**
|
|
31
|
+
* Register a goal definition.
|
|
32
|
+
*
|
|
33
|
+
* @param def - The goal definition
|
|
34
|
+
*/
|
|
35
|
+
registerGoal(def) {
|
|
36
|
+
this.defs.push(def);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Register multiple goal definitions.
|
|
40
|
+
*
|
|
41
|
+
* @param defs - The goal definitions
|
|
42
|
+
*/
|
|
43
|
+
registerGoals(defs) {
|
|
44
|
+
this.defs.push(...defs);
|
|
45
|
+
}
|
|
46
|
+
// =========================================================================
|
|
47
|
+
// Evaluation (called each NPC turn)
|
|
48
|
+
// =========================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Evaluate all goal activation and interruption conditions.
|
|
51
|
+
* Activates new goals, interrupts active ones, resumes cleared ones.
|
|
52
|
+
*
|
|
53
|
+
* @param trait - The NPC's CharacterModelTrait
|
|
54
|
+
* @returns The current active goal queue (priority-sorted)
|
|
55
|
+
*/
|
|
56
|
+
evaluate(trait) {
|
|
57
|
+
// Check for new activations
|
|
58
|
+
for (const def of this.defs) {
|
|
59
|
+
if (this.isActive(def.id))
|
|
60
|
+
continue;
|
|
61
|
+
const shouldActivate = def.activatesWhen.every(pred => trait.evaluate(pred));
|
|
62
|
+
if (shouldActivate) {
|
|
63
|
+
this.activate(def);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Check for interruptions on active goals
|
|
67
|
+
this.evaluateInterruptions(this.activeGoals, trait);
|
|
68
|
+
// Sort by priority (highest first), interrupted goals at the end
|
|
69
|
+
this.activeGoals.sort((a, b) => {
|
|
70
|
+
if (a.interrupted !== b.interrupted) {
|
|
71
|
+
return a.interrupted ? 1 : -1;
|
|
72
|
+
}
|
|
73
|
+
return goal_types_1.GOAL_PRIORITY_VALUES[b.def.priority] - goal_types_1.GOAL_PRIORITY_VALUES[a.def.priority];
|
|
74
|
+
});
|
|
75
|
+
return this.activeGoals;
|
|
76
|
+
}
|
|
77
|
+
// =========================================================================
|
|
78
|
+
// State queries
|
|
79
|
+
// =========================================================================
|
|
80
|
+
/**
|
|
81
|
+
* Get the highest-priority non-interrupted active goal.
|
|
82
|
+
*
|
|
83
|
+
* @returns The top goal, or undefined
|
|
84
|
+
*/
|
|
85
|
+
getTopGoal() {
|
|
86
|
+
return this.activeGoals.find(g => !g.interrupted && !g.paused);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if a goal is currently active.
|
|
90
|
+
*
|
|
91
|
+
* @param goalId - The goal ID
|
|
92
|
+
* @returns True if the goal is in the active queue
|
|
93
|
+
*/
|
|
94
|
+
isActive(goalId) {
|
|
95
|
+
return this.activeGoals.some(g => g.def.id === goalId);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get all active goals.
|
|
99
|
+
*
|
|
100
|
+
* @returns The active goal queue
|
|
101
|
+
*/
|
|
102
|
+
getActiveGoals() {
|
|
103
|
+
return this.activeGoals;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Advance the current step of a goal (after step completion).
|
|
107
|
+
*
|
|
108
|
+
* @param goalId - The goal ID
|
|
109
|
+
*/
|
|
110
|
+
advanceStep(goalId) {
|
|
111
|
+
const goal = this.activeGoals.find(g => g.def.id === goalId);
|
|
112
|
+
if (!goal)
|
|
113
|
+
return;
|
|
114
|
+
goal.currentStep++;
|
|
115
|
+
// Check if all sequential steps are done
|
|
116
|
+
if (goal.def.steps && goal.currentStep >= goal.def.steps.length) {
|
|
117
|
+
if (goal.def.mode === 'prepared') {
|
|
118
|
+
// Switch to opportunistic for the final act
|
|
119
|
+
goal.prepared = true;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Sequential goal complete — remove from active
|
|
123
|
+
this.deactivate(goalId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Complete a goal and remove it from the active queue.
|
|
129
|
+
*
|
|
130
|
+
* @param goalId - The goal ID
|
|
131
|
+
*/
|
|
132
|
+
complete(goalId) {
|
|
133
|
+
this.deactivate(goalId);
|
|
134
|
+
}
|
|
135
|
+
// =========================================================================
|
|
136
|
+
// Serialization
|
|
137
|
+
// =========================================================================
|
|
138
|
+
/** Export active goals for save/restore. */
|
|
139
|
+
toJSON() {
|
|
140
|
+
return this.activeGoals.map(g => ({
|
|
141
|
+
defId: g.def.id,
|
|
142
|
+
currentStep: g.currentStep,
|
|
143
|
+
paused: g.paused,
|
|
144
|
+
interrupted: g.interrupted,
|
|
145
|
+
prepared: g.prepared,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
/** Restore active goals from serialized state. */
|
|
149
|
+
restoreState(states) {
|
|
150
|
+
this.activeGoals = [];
|
|
151
|
+
for (const state of states) {
|
|
152
|
+
const def = this.defs.find(d => d.id === state.defId);
|
|
153
|
+
if (!def)
|
|
154
|
+
continue;
|
|
155
|
+
this.activeGoals.push({
|
|
156
|
+
def,
|
|
157
|
+
currentStep: state.currentStep,
|
|
158
|
+
paused: state.paused,
|
|
159
|
+
interrupted: state.interrupted,
|
|
160
|
+
prepared: state.prepared,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// =========================================================================
|
|
165
|
+
// Private helpers
|
|
166
|
+
// =========================================================================
|
|
167
|
+
/**
|
|
168
|
+
* Evaluate interruption and resumption conditions for all active goals.
|
|
169
|
+
*
|
|
170
|
+
* For interrupted goals with resumeOnClear, checks if interruption
|
|
171
|
+
* conditions have cleared and resumes them. For non-interrupted goals,
|
|
172
|
+
* checks if any interruption conditions are now met and interrupts them.
|
|
173
|
+
*
|
|
174
|
+
* @param activeGoals - The active goal queue
|
|
175
|
+
* @param trait - The NPC's CharacterModelTrait
|
|
176
|
+
*/
|
|
177
|
+
evaluateInterruptions(activeGoals, trait) {
|
|
178
|
+
for (const goal of activeGoals) {
|
|
179
|
+
if (goal.interrupted) {
|
|
180
|
+
// Check if interruption conditions cleared and goal should resume
|
|
181
|
+
if (goal.def.resumeOnClear && goal.def.interruptedBy) {
|
|
182
|
+
const stillInterrupted = goal.def.interruptedBy.some(pred => trait.evaluate(pred));
|
|
183
|
+
if (!stillInterrupted) {
|
|
184
|
+
goal.interrupted = false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
// Check if this goal should be interrupted
|
|
190
|
+
if (goal.def.interruptedBy) {
|
|
191
|
+
const shouldInterrupt = goal.def.interruptedBy.some(pred => trait.evaluate(pred));
|
|
192
|
+
if (shouldInterrupt) {
|
|
193
|
+
goal.interrupted = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
activate(def) {
|
|
199
|
+
this.activeGoals.push({
|
|
200
|
+
def,
|
|
201
|
+
currentStep: 0,
|
|
202
|
+
paused: false,
|
|
203
|
+
interrupted: false,
|
|
204
|
+
prepared: false,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
deactivate(goalId) {
|
|
208
|
+
this.activeGoals = this.activeGoals.filter(g => g.def.id !== goalId);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.GoalManager = GoalManager;
|
|
212
|
+
//# sourceMappingURL=goal-activation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-activation.js","sourceRoot":"","sources":["../../../../../../../repos/sharpee/packages/character/src/goals/goal-activation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAGH,6CAIsB;AAEtB,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E;;;GAGG;AACH,MAAa,WAAW;IACtB,kDAAkD;IACjC,IAAI,GAAc,EAAE,CAAC;IAEtC,kEAAkE;IAC1D,WAAW,GAAiB,EAAE,CAAC;IAEvC,4EAA4E;IAC5E,eAAe;IACf,4EAA4E;IAE5E;;;;OAIG;IACH,YAAY,CAAC,GAAY;QACvB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,aAAa,CAAC,IAAe;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,4E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AAG,KAAK,CAAC;oBAC3B,CAAC;gBACH,CAAC;gBACD,SAAS;YACX,CAAC;YAED,2CAA2C;YAC3C,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;gBAC3B,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACzD,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CACrB,CAAC;gBACF,IAAI,eAAe,EAAE,CAAC;oBACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;gBAC1B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAEO,QAAQ,CAAC,GAAY;QAC3B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;YACpB,GAAG;YACH,WAAW,EAAE,CAAC;YACd,MAAM,EAAE,KAAK;YACb,WAAW,EAAE,KAAK;YAClB,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;IACL,CAAC;IAEO,UAAU,CAAC,MAAc;QAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;IACvE,CAAC;CACF;AA7ND,kCA6NC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NPC goal pursuit types (ADR-145)
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for authored behavior sequences: goal definitions,
|
|
5
|
+
* step types, pursuit modes, and active goal state.
|
|
6
|
+
*
|
|
7
|
+
* Public interface: All exported types.
|
|
8
|
+
* Owner context: @sharpee/character / goals
|
|
9
|
+
*/
|
|
10
|
+
/** Goal priority levels. */
|
|
11
|
+
export type GoalPriority = 'critical' | 'high' | 'medium' | 'low';
|
|
12
|
+
/** Maps priority words to numeric values for sorting. */
|
|
13
|
+
export declare const GOAL_PRIORITY_VALUES: Record<GoalPriority, number>;
|
|
14
|
+
/**
|
|
15
|
+
* How the NPC pursues the goal.
|
|
16
|
+
* - sequential: execute steps in order, one per turn
|
|
17
|
+
* - opportunistic: no steps — wait for act conditions
|
|
18
|
+
* - prepared: sequential prep steps, then switch to opportunistic
|
|
19
|
+
*/
|
|
20
|
+
export type PursuitMode = 'sequential' | 'opportunistic' | 'prepared';
|
|
21
|
+
/** Base for all step types. */
|
|
22
|
+
interface StepBase {
|
|
23
|
+
/** Message ID when player witnesses this step. */
|
|
24
|
+
witnessed?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Move toward a location or entity. */
|
|
27
|
+
export interface SeekStep extends StepBase {
|
|
28
|
+
type: 'seek';
|
|
29
|
+
target: string;
|
|
30
|
+
from?: string;
|
|
31
|
+
}
|
|
32
|
+
/** Pick up or obtain an item. */
|
|
33
|
+
export interface AcquireStep extends StepBase {
|
|
34
|
+
type: 'acquire';
|
|
35
|
+
target: string;
|
|
36
|
+
}
|
|
37
|
+
/** Pause until a condition is met. */
|
|
38
|
+
export interface WaitForStep extends StepBase {
|
|
39
|
+
type: 'waitFor';
|
|
40
|
+
conditions: string[];
|
|
41
|
+
}
|
|
42
|
+
/** Go to a specific location. */
|
|
43
|
+
export interface MoveToStep extends StepBase {
|
|
44
|
+
type: 'moveTo';
|
|
45
|
+
target: string;
|
|
46
|
+
}
|
|
47
|
+
/** Perform an authored action. */
|
|
48
|
+
export interface ActStep extends StepBase {
|
|
49
|
+
type: 'act';
|
|
50
|
+
messageId: string;
|
|
51
|
+
}
|
|
52
|
+
/** Initiate conversation. */
|
|
53
|
+
export interface SayStep extends StepBase {
|
|
54
|
+
type: 'say';
|
|
55
|
+
messageId: string;
|
|
56
|
+
target?: string;
|
|
57
|
+
}
|
|
58
|
+
/** Hand an item to another entity. */
|
|
59
|
+
export interface GiveStep extends StepBase {
|
|
60
|
+
type: 'give';
|
|
61
|
+
item: string;
|
|
62
|
+
target: string;
|
|
63
|
+
}
|
|
64
|
+
/** Leave an item somewhere. */
|
|
65
|
+
export interface DropStep extends StepBase {
|
|
66
|
+
type: 'drop';
|
|
67
|
+
item: string;
|
|
68
|
+
location?: string;
|
|
69
|
+
}
|
|
70
|
+
/** Union of all goal step types. */
|
|
71
|
+
export type GoalStep = SeekStep | AcquireStep | WaitForStep | MoveToStep | ActStep | SayStep | GiveStep | DropStep;
|
|
72
|
+
/** Author-defined goal with activation conditions and behavior sequence. */
|
|
73
|
+
export interface GoalDef {
|
|
74
|
+
/** Unique goal identifier. */
|
|
75
|
+
id: string;
|
|
76
|
+
/** Predicate conditions that activate this goal. */
|
|
77
|
+
activatesWhen: string[];
|
|
78
|
+
/** Predicate conditions that interrupt (suspend) this goal. */
|
|
79
|
+
interruptedBy?: string[];
|
|
80
|
+
/** Goal priority. */
|
|
81
|
+
priority: GoalPriority;
|
|
82
|
+
/** Pursuit mode. */
|
|
83
|
+
mode: PursuitMode;
|
|
84
|
+
/** Behavior sequence (for sequential and prepared modes). */
|
|
85
|
+
steps?: GoalStep[];
|
|
86
|
+
/**
|
|
87
|
+
* Act conditions (for opportunistic and prepared modes).
|
|
88
|
+
* When all conditions are met, the final act fires.
|
|
89
|
+
*/
|
|
90
|
+
actsWhen?: string[];
|
|
91
|
+
/** Message ID for the final act (opportunistic/prepared). */
|
|
92
|
+
actMessageId?: string;
|
|
93
|
+
/** Message ID when the goal is interrupted. */
|
|
94
|
+
onInterrupt?: string;
|
|
95
|
+
/** Whether the goal resumes from where it left off after interruption clears. */
|
|
96
|
+
resumeOnClear?: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** Runtime state of an active goal. */
|
|
99
|
+
export interface ActiveGoal {
|
|
100
|
+
/** The goal definition. */
|
|
101
|
+
def: GoalDef;
|
|
102
|
+
/** Current step index (for sequential/prepared modes). */
|
|
103
|
+
currentStep: number;
|
|
104
|
+
/** Whether the goal is paused (preempted by higher priority). */
|
|
105
|
+
paused: boolean;
|
|
106
|
+
/** Whether the goal is interrupted (conditions met). */
|
|
107
|
+
interrupted: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Whether the preparatory steps are complete (for prepared mode).
|
|
110
|
+
* When true, the goal switches to opportunistic behavior.
|
|
111
|
+
*/
|
|
112
|
+
prepared: boolean;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* NPC movement profile — defines map knowledge and access.
|
|
116
|
+
* NPCs can only pathfind through known rooms and accessible passages.
|
|
117
|
+
*/
|
|
118
|
+
export interface MovementProfile {
|
|
119
|
+
/** Room IDs the NPC knows about, or 'all'. */
|
|
120
|
+
knows: string[] | 'all';
|
|
121
|
+
/** Passage/connection IDs the NPC can traverse, or 'all'. */
|
|
122
|
+
access: string[] | 'all';
|
|
123
|
+
}
|
|
124
|
+
/** Result of evaluating a single goal step. */
|
|
125
|
+
export type StepResult = {
|
|
126
|
+
status: 'completed';
|
|
127
|
+
witnessed?: string;
|
|
128
|
+
} | {
|
|
129
|
+
status: 'in-progress';
|
|
130
|
+
witnessed?: string;
|
|
131
|
+
} | {
|
|
132
|
+
status: 'waiting';
|
|
133
|
+
} | {
|
|
134
|
+
status: 'blocked';
|
|
135
|
+
reason: string;
|
|
136
|
+
};
|
|
137
|
+
export {};
|
|
138
|
+
//# sourceMappingURL=goal-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-types.d.ts","sourceRoot":"","sources":["../../../../../../repos/sharpee/packages/character/src/goals/goal-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,4BAA4B;AAC5B,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;AAElE,yDAAyD;AACzD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAK7D,CAAC;AAMF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,UAAU,CAAC;AAMtE,+BAA+B;AAC/B,UAAU,QAAQ;IAChB,kDAAkD;IA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A;CAAE,GAC7C;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NPC goal pursuit types (ADR-145)
|
|
4
|
+
*
|
|
5
|
+
* Type definitions for authored behavior sequences: goal definitions,
|
|
6
|
+
* step types, pursuit modes, and active goal state.
|
|
7
|
+
*
|
|
8
|
+
* Public interface: All exported types.
|
|
9
|
+
* Owner context: @sharpee/character / goals
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GOAL_PRIORITY_VALUES = void 0;
|
|
13
|
+
/** Maps priority words to numeric values for sorting. */
|
|
14
|
+
exports.GOAL_PRIORITY_VALUES = {
|
|
15
|
+
critical: 100,
|
|
16
|
+
high: 75,
|
|
17
|
+
medium: 50,
|
|
18
|
+
low: 25,
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=goal-types.js.map
|