rpg-event-generator 3.0.2 → 3.1.0
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/README.md +1 -1
- package/dist/RPGEventGenerator.d.ts +12 -0
- package/dist/RPGEventGenerator.d.ts.map +1 -1
- package/dist/RPGEventGenerator.js +199 -70
- package/dist/RPGEventGenerator.js.map +1 -1
- package/dist/core/ContextAnalyzer.d.ts +14 -0
- package/dist/core/ContextAnalyzer.d.ts.map +1 -1
- package/dist/core/ContextAnalyzer.js +131 -11
- package/dist/core/ContextAnalyzer.js.map +1 -1
- package/dist/core/DifficultyScaler.d.ts.map +1 -1
- package/dist/core/DifficultyScaler.js +10 -24
- package/dist/core/DifficultyScaler.js.map +1 -1
- package/dist/core/GeneratorCore.d.ts +12 -2
- package/dist/core/GeneratorCore.d.ts.map +1 -1
- package/dist/core/GeneratorCore.js +304 -35
- package/dist/core/GeneratorCore.js.map +1 -1
- package/dist/core/MarkovEngine.d.ts.map +1 -1
- package/dist/core/MarkovEngine.js +34 -0
- package/dist/core/MarkovEngine.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/scripts/event-economy.js +6 -6
- package/dist/scripts/event-economy.js.map +1 -1
- package/dist/src/types/config.d.ts +1 -0
- package/dist/src/types/config.d.ts.map +1 -1
- package/dist/src/types/events.d.ts +5 -4
- package/dist/src/types/events.d.ts.map +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/events.d.ts +5 -4
- package/dist/types/events.d.ts.map +1 -1
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +4 -4
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/text.js +2 -2
- package/dist/utils/text.js.map +1 -1
- package/package.json +3 -1
- package/scripts/event-economy.ts +22 -22
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ export declare class RPGEventGenerator {
|
|
|
23
23
|
private pureMarkovMode;
|
|
24
24
|
private _enableRuleEngine;
|
|
25
25
|
constructor(options?: GeneratorOptions);
|
|
26
|
+
/**
|
|
27
|
+
* Validate configuration options
|
|
28
|
+
*/
|
|
29
|
+
private validateConfig;
|
|
26
30
|
/**
|
|
27
31
|
* Initialize all systems with provided options
|
|
28
32
|
*/
|
|
@@ -31,6 +35,14 @@ export declare class RPGEventGenerator {
|
|
|
31
35
|
* Generate a single event
|
|
32
36
|
*/
|
|
33
37
|
generateEvent(playerContext?: PlayerContext): Event;
|
|
38
|
+
/**
|
|
39
|
+
* Try to generate an event from a matching template
|
|
40
|
+
*/
|
|
41
|
+
private tryGenerateFromTemplate;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a template matches the player context
|
|
44
|
+
*/
|
|
45
|
+
private templateMatchesContext;
|
|
34
46
|
/**
|
|
35
47
|
* Generate multiple events
|
|
36
48
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RPGEventGenerator.d.ts","sourceRoot":"","sources":["../src/RPGEventGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,SAAS,
|
|
1
|
+
{"version":3,"file":"RPGEventGenerator.d.ts","sourceRoot":"","sources":["../src/RPGEventGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,EACL,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,SAAS,EAEV,MAAM,SAAS,CAAC;AA2CjB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,gBAAgB,CAAmB;IAE3C,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,UAAU,CAAa;I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AAC,GAAG,CAAC;IAQtC;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;OAEG;IACH,qBAAqB,IAAI,MAAM;CAMhC"}
|
|
@@ -18,11 +18,9 @@ const ai_1 = require("./ai");
|
|
|
18
18
|
const world_1 = require("./world");
|
|
19
19
|
const database_1 = require("./database");
|
|
20
20
|
const MemoryDatabaseAdapter_1 = require("./database/MemoryDatabaseAdapter");
|
|
21
|
-
// Conditional imports for Node.js environment (not available in React Native)
|
|
22
21
|
let Worker, isMainThread, parentPort, workerData;
|
|
23
22
|
let pathModule, osModule;
|
|
24
23
|
try {
|
|
25
|
-
// Only available in Node.js environments
|
|
26
24
|
const workerThreads = require('worker_threads');
|
|
27
25
|
Worker = workerThreads.Worker;
|
|
28
26
|
isMainThread = workerThreads.isMainThread;
|
|
@@ -32,7 +30,6 @@ try {
|
|
|
32
30
|
osModule = require('os');
|
|
33
31
|
}
|
|
34
32
|
catch (e) {
|
|
35
|
-
// In React Native or other environments, these will be undefined
|
|
36
33
|
Worker = null;
|
|
37
34
|
isMainThread = true;
|
|
38
35
|
parentPort = null;
|
|
@@ -45,14 +42,17 @@ class RPGEventGenerator {
|
|
|
45
42
|
this.templateDatabase = null;
|
|
46
43
|
this.options = options;
|
|
47
44
|
this.chance = options.chance || new chance_1.Chance();
|
|
48
|
-
//
|
|
45
|
+
// Validate configuration
|
|
46
|
+
const validationResult = this.validateConfig(options);
|
|
47
|
+
if (!validationResult.isValid && validationResult.warnings.length > 0) {
|
|
48
|
+
console.warn('Configuration warnings:', validationResult.warnings);
|
|
49
|
+
}
|
|
49
50
|
this.enableTemplates = options.enableTemplates !== false;
|
|
50
51
|
this.enableDependencies = options.enableDependencies !== false;
|
|
51
52
|
this._enableModifiers = options.enableModifiers !== false;
|
|
52
53
|
this._enableRelationships = options.enableRelationships !== false;
|
|
53
54
|
this._enableRuleEngine = options.enableRuleEngine !== false;
|
|
54
55
|
this.pureMarkovMode = options.pureMarkovMode || false;
|
|
55
|
-
// Initialize core systems
|
|
56
56
|
this.markovEngine = new core_1.MarkovEngine({ stateSize: options.stateSize });
|
|
57
57
|
this.contextAnalyzer = new core_1.ContextAnalyzer();
|
|
58
58
|
this.difficultyScaler = new core_1.DifficultyScaler();
|
|
@@ -60,7 +60,6 @@ class RPGEventGenerator {
|
|
|
60
60
|
...options,
|
|
61
61
|
chance: this.chance
|
|
62
62
|
});
|
|
63
|
-
// Initialize feature systems
|
|
64
63
|
this.templateSystem = new templates_1.TemplateSystem(options.templateLibrary);
|
|
65
64
|
this.chainSystem = new chains_1.ChainSystem(this.chance);
|
|
66
65
|
this.ruleEngine = new rules_1.RuleEngine();
|
|
@@ -70,9 +69,7 @@ class RPGEventGenerator {
|
|
|
70
69
|
this.localizationSystem = new localization_1.LocalizationSystem(options.language);
|
|
71
70
|
this.aiEnhancer = new ai_1.AIEnhancer(options.aiEnhancement);
|
|
72
71
|
this.worldBuildingSystem = new world_1.WorldBuildingSystem();
|
|
73
|
-
// Initialize template database if enabled
|
|
74
72
|
if (options.enableDatabase !== false) {
|
|
75
|
-
// Use synchronous initialization for memory adapter to avoid async constructor issues
|
|
76
73
|
if (!options.databaseAdapter || options.databaseAdapter instanceof MemoryDatabaseAdapter_1.MemoryDatabaseAdapter) {
|
|
77
74
|
this.initializeDatabaseSync(options.databaseAdapter);
|
|
78
75
|
}
|
|
@@ -80,22 +77,49 @@ class RPGEventGenerator {
|
|
|
80
77
|
this.initializeDatabase(options.databaseAdapter);
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
// Initialize systems
|
|
84
80
|
this.initializeSystems(options);
|
|
85
|
-
// Load training data if provided
|
|
86
81
|
if (options.trainingData) {
|
|
87
82
|
this.markovEngine.addData(options.trainingData);
|
|
83
|
+
if (options.debug) {
|
|
84
|
+
console.log(`[RPGEventGenerator] Loaded ${options.trainingData.length} training data entries`);
|
|
85
|
+
}
|
|
88
86
|
}
|
|
89
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Validate configuration options
|
|
90
|
+
*/
|
|
91
|
+
validateConfig(options) {
|
|
92
|
+
const warnings = [];
|
|
93
|
+
// Check for conflicting options
|
|
94
|
+
if (options.pureMarkovMode && options.enableTemplates) {
|
|
95
|
+
warnings.push('pureMarkovMode is enabled but enableTemplates is also true. Templates will be ignored.');
|
|
96
|
+
}
|
|
97
|
+
if (options.pureMarkovMode && options.enableRelationships) {
|
|
98
|
+
warnings.push('pureMarkovMode is enabled but enableRelationships is also true. Relationships will be ignored.');
|
|
99
|
+
}
|
|
100
|
+
// Check for missing dependencies
|
|
101
|
+
if (options.enableTemplates && !options.templateLibrary && !options.trainingData) {
|
|
102
|
+
warnings.push('enableTemplates is true but no templateLibrary or trainingData provided. Template generation may be limited.');
|
|
103
|
+
}
|
|
104
|
+
if (options.enableRelationships && !options.enableModifiers) {
|
|
105
|
+
warnings.push('enableRelationships is true but enableModifiers is false. Some relationship features may not work properly.');
|
|
106
|
+
}
|
|
107
|
+
// Validate state size
|
|
108
|
+
if (options.stateSize !== undefined && (options.stateSize < 1 || options.stateSize > 5)) {
|
|
109
|
+
warnings.push(`stateSize should be between 1 and 5, got ${options.stateSize}. Using default value.`);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
isValid: warnings.length === 0,
|
|
113
|
+
warnings
|
|
114
|
+
};
|
|
115
|
+
}
|
|
90
116
|
/**
|
|
91
117
|
* Initialize all systems with provided options
|
|
92
118
|
*/
|
|
93
119
|
initializeSystems(options) {
|
|
94
|
-
// Load template library if enabled
|
|
95
120
|
if (this.enableTemplates && options.templateLibrary && !this.pureMarkovMode) {
|
|
96
121
|
this.templateSystem.loadTemplateLibrary(options.templateLibrary);
|
|
97
122
|
}
|
|
98
|
-
// Load default English localization
|
|
99
123
|
this.localizationSystem.loadLanguagePack('en', {
|
|
100
124
|
ui: {
|
|
101
125
|
'event.title.default': 'Unexpected Event',
|
|
@@ -115,50 +139,161 @@ class RPGEventGenerator {
|
|
|
115
139
|
* Generate a single event
|
|
116
140
|
*/
|
|
117
141
|
generateEvent(playerContext = {}) {
|
|
118
|
-
// Analyze player context
|
|
119
142
|
const analyzedContext = this.contextAnalyzer.analyzeContext(playerContext);
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
// Debug logging if enabled
|
|
144
|
+
if (this.options.debug) {
|
|
145
|
+
console.log('[RPGEventGenerator] Generating event with context:', {
|
|
146
|
+
level: analyzedContext.level,
|
|
147
|
+
powerLevel: analyzedContext.powerLevel,
|
|
148
|
+
wealthTier: analyzedContext.wealthTier,
|
|
149
|
+
lifeStage: analyzedContext.lifeStage,
|
|
150
|
+
careerPath: analyzedContext.careerPath
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// If templates are enabled, try to use a matching template first
|
|
154
|
+
let event;
|
|
155
|
+
let usedTemplate = false;
|
|
156
|
+
if (this.enableTemplates && !this.pureMarkovMode) {
|
|
157
|
+
const templateEvent = this.tryGenerateFromTemplate(playerContext, analyzedContext);
|
|
158
|
+
if (templateEvent) {
|
|
159
|
+
event = templateEvent;
|
|
160
|
+
usedTemplate = true;
|
|
161
|
+
if (this.options.debug) {
|
|
162
|
+
console.log('[RPGEventGenerator] Generated event from template');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Fall back to core generation if no template matched
|
|
167
|
+
event = this.generatorCore.generateEvent(playerContext);
|
|
168
|
+
if (this.options.debug) {
|
|
169
|
+
console.log('[RPGEventGenerator] Generated event using core generator (Markov chain)');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
// Use core generation directly
|
|
175
|
+
event = this.generatorCore.generateEvent(playerContext);
|
|
176
|
+
if (this.options.debug) {
|
|
177
|
+
console.log('[RPGEventGenerator] Generated event using core generator (Markov chain)');
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// Ensure context is properly set
|
|
181
|
+
event.context = playerContext;
|
|
182
|
+
// Debug logging for generated event
|
|
183
|
+
if (this.options.debug) {
|
|
184
|
+
console.log('[RPGEventGenerator] Generated event:', {
|
|
185
|
+
id: event.id,
|
|
186
|
+
title: event.title,
|
|
187
|
+
type: event.type,
|
|
188
|
+
difficulty: event.difficulty,
|
|
189
|
+
usedTemplate,
|
|
190
|
+
descriptionLength: event.description.length,
|
|
191
|
+
choicesCount: event.choices.length
|
|
192
|
+
});
|
|
193
|
+
}
|
|
123
194
|
if (this.enableModifiers) {
|
|
124
|
-
// Get current time information from time system
|
|
125
195
|
const currentTime = this.timeSystem.getCurrentTime();
|
|
126
196
|
const environmentalContext = {
|
|
127
|
-
weather: 'clear',
|
|
197
|
+
weather: 'clear',
|
|
128
198
|
season: currentTime.season,
|
|
129
|
-
timeOfDay: 'day'
|
|
199
|
+
timeOfDay: 'day'
|
|
130
200
|
};
|
|
131
201
|
this.environmentalSystem.setEnvironmentalContext(environmentalContext);
|
|
132
|
-
|
|
202
|
+
const modifiedEvent = this.environmentalSystem.applyModifiers(event);
|
|
203
|
+
if (modifiedEvent) {
|
|
204
|
+
event = modifiedEvent;
|
|
205
|
+
}
|
|
133
206
|
}
|
|
134
|
-
// Apply rule engine modifications if enabled
|
|
135
207
|
if (this.enableRuleEngine) {
|
|
136
|
-
|
|
208
|
+
const processedEvent = this.ruleEngine.processEvent(event, analyzedContext);
|
|
209
|
+
if (processedEvent) {
|
|
210
|
+
event = processedEvent;
|
|
211
|
+
}
|
|
137
212
|
}
|
|
138
|
-
// Apply AI enhancement if enabled
|
|
139
213
|
if (this.aiEnhancer.isEnabled() && this.aiEnhancer.isAvailable()) {
|
|
140
214
|
try {
|
|
141
215
|
const aiContext = {
|
|
142
216
|
playerLevel: analyzedContext.level,
|
|
143
217
|
playerClass: analyzedContext.career,
|
|
144
218
|
currentLocation: analyzedContext.location,
|
|
145
|
-
recentEvents: [],
|
|
219
|
+
recentEvents: [],
|
|
146
220
|
storyTone: 'neutral',
|
|
147
221
|
genre: 'fantasy'
|
|
148
222
|
};
|
|
149
|
-
|
|
223
|
+
const enhancedEvent = this.aiEnhancer.enhanceEvent(event, aiContext);
|
|
224
|
+
if (enhancedEvent) {
|
|
225
|
+
event = enhancedEvent;
|
|
226
|
+
}
|
|
150
227
|
}
|
|
151
228
|
catch {
|
|
152
|
-
// Keep original event if AI enhancement fails
|
|
153
229
|
}
|
|
154
230
|
}
|
|
155
|
-
// Localize event text if language is set
|
|
156
231
|
if (this.localizationSystem.getCurrentLanguage() !== 'en') {
|
|
157
232
|
event.title = this.localizationSystem.translate(event.title);
|
|
158
233
|
event.description = this.localizationSystem.translate(event.description);
|
|
159
234
|
}
|
|
160
235
|
return event;
|
|
161
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Try to generate an event from a matching template
|
|
239
|
+
*/
|
|
240
|
+
tryGenerateFromTemplate(playerContext, analyzedContext) {
|
|
241
|
+
if (!this.templateSystem)
|
|
242
|
+
return null;
|
|
243
|
+
const loadedTemplates = this.templateSystem.getLoadedTemplates();
|
|
244
|
+
if (loadedTemplates.size === 0)
|
|
245
|
+
return null;
|
|
246
|
+
// Find templates that match the context
|
|
247
|
+
const matchingTemplates = [];
|
|
248
|
+
for (const [templateId, template] of loadedTemplates.entries()) {
|
|
249
|
+
// Check if template matches context requirements
|
|
250
|
+
if (this.templateMatchesContext(template, analyzedContext)) {
|
|
251
|
+
matchingTemplates.push(templateId);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (matchingTemplates.length > 0) {
|
|
255
|
+
// Select a random matching template
|
|
256
|
+
const selectedTemplateId = this.chance.pickone(matchingTemplates);
|
|
257
|
+
const templateContext = {
|
|
258
|
+
...playerContext,
|
|
259
|
+
level: analyzedContext.level,
|
|
260
|
+
powerLevel: analyzedContext.powerLevel,
|
|
261
|
+
wealthTier: analyzedContext.wealthTier,
|
|
262
|
+
lifeStage: analyzedContext.lifeStage
|
|
263
|
+
};
|
|
264
|
+
return this.templateSystem.generateFromTemplate(selectedTemplateId, templateContext);
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Check if a template matches the player context
|
|
270
|
+
*/
|
|
271
|
+
templateMatchesContext(template, context) {
|
|
272
|
+
// If template has no context requirements, it matches
|
|
273
|
+
if (!template.context_requirements || !template.context_requirements.length) {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
// Check each requirement
|
|
277
|
+
for (const requirement of template.context_requirements) {
|
|
278
|
+
if (requirement.type === 'level' && context.level !== undefined) {
|
|
279
|
+
if (requirement.min && context.level < requirement.min)
|
|
280
|
+
return false;
|
|
281
|
+
if (requirement.max && context.level > requirement.max)
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
if (requirement.type === 'power_level' && context.powerLevel !== undefined) {
|
|
285
|
+
if (requirement.min && context.powerLevel < requirement.min)
|
|
286
|
+
return false;
|
|
287
|
+
if (requirement.max && context.powerLevel > requirement.max)
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
if (requirement.type === 'wealth_tier' && context.wealthTier) {
|
|
291
|
+
if (requirement.value && context.wealthTier !== requirement.value)
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
162
297
|
/**
|
|
163
298
|
* Generate multiple events
|
|
164
299
|
*/
|
|
@@ -179,7 +314,7 @@ class RPGEventGenerator {
|
|
|
179
314
|
* Generate random event from genre (backward compatibility - removed)
|
|
180
315
|
*/
|
|
181
316
|
generateFromGenre(genre, context = {}) {
|
|
182
|
-
return null;
|
|
317
|
+
return null;
|
|
183
318
|
}
|
|
184
319
|
// ===== TEMPLATE SYSTEM METHODS =====
|
|
185
320
|
/**
|
|
@@ -204,7 +339,7 @@ class RPGEventGenerator {
|
|
|
204
339
|
* Get available templates by genre (pre-built library removed)
|
|
205
340
|
*/
|
|
206
341
|
getAvailableTemplates() {
|
|
207
|
-
return {};
|
|
342
|
+
return {};
|
|
208
343
|
}
|
|
209
344
|
// ===== EVENT CHAIN METHODS =====
|
|
210
345
|
/**
|
|
@@ -379,7 +514,6 @@ class RPGEventGenerator {
|
|
|
379
514
|
* Export custom content
|
|
380
515
|
*/
|
|
381
516
|
exportCustomContent() {
|
|
382
|
-
// Convert NPC array to object keyed by ID
|
|
383
517
|
const npcs = {};
|
|
384
518
|
if (this.enableRelationships) {
|
|
385
519
|
const npcArray = this.relationshipSystem.getAllNPCs();
|
|
@@ -387,10 +521,8 @@ class RPGEventGenerator {
|
|
|
387
521
|
npcs[npc.id] = npc;
|
|
388
522
|
});
|
|
389
523
|
}
|
|
390
|
-
// Convert loaded templates map to export format
|
|
391
524
|
const templates = {};
|
|
392
525
|
if (this.enableTemplates) {
|
|
393
|
-
// Template IDs include genre prefix (e.g., "fantasy:event_1")
|
|
394
526
|
this.templateSystem.getLoadedTemplates().forEach((template, id) => {
|
|
395
527
|
templates[id] = template;
|
|
396
528
|
});
|
|
@@ -414,12 +546,9 @@ class RPGEventGenerator {
|
|
|
414
546
|
rules: { success: 0, failed: [] },
|
|
415
547
|
npcs: { success: 0, failed: [] }
|
|
416
548
|
};
|
|
417
|
-
// Import templates
|
|
418
549
|
if (data.templates && this.enableTemplates) {
|
|
419
|
-
// Implementation would go here
|
|
420
550
|
results.templates.success = 1;
|
|
421
551
|
}
|
|
422
|
-
// Import chains
|
|
423
552
|
if (data.chains) {
|
|
424
553
|
Object.entries(data.chains).forEach(([id, chain]) => {
|
|
425
554
|
try {
|
|
@@ -431,7 +560,6 @@ class RPGEventGenerator {
|
|
|
431
560
|
}
|
|
432
561
|
});
|
|
433
562
|
}
|
|
434
|
-
// Import rules
|
|
435
563
|
if (data.rules && this.enableRuleEngine) {
|
|
436
564
|
if (!results.rules) {
|
|
437
565
|
results.rules = { success: 0, failed: [] };
|
|
@@ -446,7 +574,6 @@ class RPGEventGenerator {
|
|
|
446
574
|
}
|
|
447
575
|
});
|
|
448
576
|
}
|
|
449
|
-
// Import NPCs
|
|
450
577
|
if (data.npcs && this.enableRelationships) {
|
|
451
578
|
if (!results.npcs) {
|
|
452
579
|
results.npcs = { success: 0, failed: [] };
|
|
@@ -463,7 +590,6 @@ class RPGEventGenerator {
|
|
|
463
590
|
}
|
|
464
591
|
return results;
|
|
465
592
|
}
|
|
466
|
-
// Public getters for feature flags (for testing compatibility)
|
|
467
593
|
get enableRuleEngine() { return this._enableRuleEngine; }
|
|
468
594
|
get enableModifiers() { return this._enableModifiers; }
|
|
469
595
|
get enableRelationships() { return this._enableRelationships; }
|
|
@@ -502,9 +628,9 @@ class RPGEventGenerator {
|
|
|
502
628
|
return {
|
|
503
629
|
timeSystem: this.timeSystem.getState(),
|
|
504
630
|
activeChains,
|
|
505
|
-
completedEvents: new Set(),
|
|
506
|
-
player: {},
|
|
507
|
-
gameState: {}
|
|
631
|
+
completedEvents: new Set(),
|
|
632
|
+
player: {},
|
|
633
|
+
gameState: {}
|
|
508
634
|
};
|
|
509
635
|
}
|
|
510
636
|
/**
|
|
@@ -515,9 +641,7 @@ class RPGEventGenerator {
|
|
|
515
641
|
if (gameState.timeSystem) {
|
|
516
642
|
this.timeSystem.loadState(gameState.timeSystem);
|
|
517
643
|
}
|
|
518
|
-
// Restore active chains if any
|
|
519
644
|
if (gameState.activeChains) {
|
|
520
|
-
// Implementation would restore chain states
|
|
521
645
|
}
|
|
522
646
|
return true;
|
|
523
647
|
}
|
|
@@ -529,9 +653,15 @@ class RPGEventGenerator {
|
|
|
529
653
|
// ===== BACKWARD COMPATIBILITY METHODS =====
|
|
530
654
|
addTrainingData(texts) {
|
|
531
655
|
this.generatorCore.addTrainingData(texts);
|
|
656
|
+
if (this.options.debug) {
|
|
657
|
+
console.log(`[RPGEventGenerator] Added ${texts.length} training data entries`);
|
|
658
|
+
}
|
|
532
659
|
}
|
|
533
660
|
addCustomTrainingData(texts, theme) {
|
|
534
661
|
this.generatorCore.addTrainingData(texts, theme);
|
|
662
|
+
if (this.options.debug) {
|
|
663
|
+
console.log(`[RPGEventGenerator] Added ${texts.length} custom training data entries${theme ? ` with theme '${theme}'` : ''}`);
|
|
664
|
+
}
|
|
535
665
|
}
|
|
536
666
|
generateTimeAwareEvent(context = {}) {
|
|
537
667
|
return this.generateEvent({
|
|
@@ -554,9 +684,6 @@ class RPGEventGenerator {
|
|
|
554
684
|
registerEventDependency(eventId, dependency) {
|
|
555
685
|
if (!this.enableRuleEngine)
|
|
556
686
|
return;
|
|
557
|
-
// Handle dependency structure correctly
|
|
558
|
-
// If dependency has operator and conditions, use the conditions directly
|
|
559
|
-
// Otherwise, treat the dependency as a single condition
|
|
560
687
|
const conditions = dependency.operator && dependency.conditions
|
|
561
688
|
? dependency.conditions
|
|
562
689
|
: [dependency];
|
|
@@ -591,13 +718,13 @@ class RPGEventGenerator {
|
|
|
591
718
|
* Scale effects for difficulty (backward compatibility - stub)
|
|
592
719
|
*/
|
|
593
720
|
scaleEffectsForDifficulty(effects, difficulty) {
|
|
594
|
-
return effects;
|
|
721
|
+
return effects;
|
|
595
722
|
}
|
|
596
723
|
/**
|
|
597
724
|
* Calculate difficulty tier (backward compatibility - stub)
|
|
598
725
|
*/
|
|
599
726
|
calculateDifficultyTier(powerLevel) {
|
|
600
|
-
return 'normal';
|
|
727
|
+
return 'normal';
|
|
601
728
|
}
|
|
602
729
|
/**
|
|
603
730
|
* Register event chain (backward compatibility)
|
|
@@ -684,9 +811,7 @@ class RPGEventGenerator {
|
|
|
684
811
|
}
|
|
685
812
|
// ===== PARALLEL GENERATION METHODS =====
|
|
686
813
|
async generateEventsParallel(count, context = {}, options = {}) {
|
|
687
|
-
// Check if we're in a Node.js environment that supports workers
|
|
688
814
|
if (!Worker || !osModule) {
|
|
689
|
-
// Fallback to sequential generation for React Native and other environments
|
|
690
815
|
console.warn('Parallel generation not supported in this environment. Falling back to sequential generation.');
|
|
691
816
|
const events = [];
|
|
692
817
|
for (let i = 0; i < count; i++) {
|
|
@@ -695,21 +820,31 @@ class RPGEventGenerator {
|
|
|
695
820
|
}
|
|
696
821
|
return events;
|
|
697
822
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
823
|
+
try {
|
|
824
|
+
const maxWorkers = options.maxWorkers || Math.min(osModule.cpus().length, 4);
|
|
825
|
+
const eventsPerWorker = Math.ceil(count / maxWorkers);
|
|
826
|
+
const workerPromises = [];
|
|
827
|
+
for (let i = 0; i < maxWorkers; i++) {
|
|
828
|
+
const startIndex = i * eventsPerWorker;
|
|
829
|
+
const endIndex = Math.min((i + 1) * eventsPerWorker, count);
|
|
830
|
+
const workerCount = endIndex - startIndex;
|
|
831
|
+
if (workerCount > 0) {
|
|
832
|
+
workerPromises.push(this.spawnEventGenerationWorker(workerCount, context));
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
const workerResults = await Promise.all(workerPromises);
|
|
836
|
+
const allEvents = workerResults.flat();
|
|
837
|
+
return allEvents.slice(0, count);
|
|
838
|
+
}
|
|
839
|
+
catch (error) {
|
|
840
|
+
console.warn('Worker loading failed, falling back to sequential generation:', error instanceof Error ? error.message : String(error));
|
|
841
|
+
const events = [];
|
|
842
|
+
for (let i = 0; i < count; i++) {
|
|
843
|
+
const event = await this.generateEvent(context);
|
|
844
|
+
events.push(event);
|
|
707
845
|
}
|
|
846
|
+
return events;
|
|
708
847
|
}
|
|
709
|
-
const workerResults = await Promise.all(workerPromises);
|
|
710
|
-
const allEvents = workerResults.flat();
|
|
711
|
-
// Return only the requested number of events
|
|
712
|
-
return allEvents.slice(0, count);
|
|
713
848
|
}
|
|
714
849
|
async spawnEventGenerationWorker(count, context) {
|
|
715
850
|
return new Promise((resolve, reject) => {
|
|
@@ -748,10 +883,7 @@ class RPGEventGenerator {
|
|
|
748
883
|
const event = this.generateEvent(context);
|
|
749
884
|
events.push(event);
|
|
750
885
|
}
|
|
751
|
-
// Optional: Add small delay between batches to prevent blocking
|
|
752
886
|
if (batch < batches - 1) {
|
|
753
|
-
// In a real implementation, you might want to use setImmediate or similar
|
|
754
|
-
// For now, we'll just continue synchronously
|
|
755
887
|
}
|
|
756
888
|
}
|
|
757
889
|
return events;
|
|
@@ -763,7 +895,6 @@ class RPGEventGenerator {
|
|
|
763
895
|
this.templateDatabase = new database_1.TemplateDatabase();
|
|
764
896
|
await this.templateDatabase.initialize(databaseAdapter);
|
|
765
897
|
this.templateSystem.setDatabase(this.templateDatabase);
|
|
766
|
-
// Load existing templates from database
|
|
767
898
|
await this.templateSystem.loadTemplatesFromDatabase();
|
|
768
899
|
}
|
|
769
900
|
catch (error) {
|
|
@@ -774,10 +905,8 @@ class RPGEventGenerator {
|
|
|
774
905
|
try {
|
|
775
906
|
const databaseAdapter = adapter || new MemoryDatabaseAdapter_1.MemoryDatabaseAdapter();
|
|
776
907
|
this.templateDatabase = new database_1.TemplateDatabase();
|
|
777
|
-
// For memory adapter, we can do synchronous initialization
|
|
778
908
|
if (databaseAdapter instanceof MemoryDatabaseAdapter_1.MemoryDatabaseAdapter) {
|
|
779
909
|
databaseAdapter.connect();
|
|
780
|
-
// Note: This is still async, but for memory adapter it should work synchronously
|
|
781
910
|
this.templateDatabase.initialize(databaseAdapter).then(() => {
|
|
782
911
|
this.templateSystem.setDatabase(this.templateDatabase);
|
|
783
912
|
this.templateSystem.loadTemplatesFromDatabase();
|
|
@@ -837,7 +966,7 @@ class RPGEventGenerator {
|
|
|
837
966
|
*/
|
|
838
967
|
getOptimalWorkerCount() {
|
|
839
968
|
if (!Worker || !osModule) {
|
|
840
|
-
return 1;
|
|
969
|
+
return 1;
|
|
841
970
|
}
|
|
842
971
|
return Math.min(osModule.cpus().length, 4);
|
|
843
972
|
}
|