rpg-event-generator 1.0.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/LICENSE +21 -0
- package/README.md +430 -0
- package/dist/index.js +1144 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Decept1kon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
# RPG Event Generator
|
|
2
|
+
|
|
3
|
+
A powerful procedural event generation system for RPG games, capable of creating virtually infinite contextual events based on player state and game world.
|
|
4
|
+
|
|
5
|
+
## โจ Features
|
|
6
|
+
|
|
7
|
+
- **Infinite Event Generation**: Creates unique, contextual events using custom Markov chains and procedural techniques
|
|
8
|
+
- **Player-Aware**: Events adapt to player stats, career, relationships, life stage, reputation, and social standing
|
|
9
|
+
- **14+ Dramatic Event Types**: From court scandals and noble duels to ancient curses and bandit kings
|
|
10
|
+
- **Immersive Storytelling**: Each event features rich narratives with atmospheric descriptions and meaningful consequences
|
|
11
|
+
- **Dynamic Effects**: Context-aware rewards and consequences that scale with character development and power level
|
|
12
|
+
- **Career Integration**: Events specifically tailored to noble, merchant, warrior, and criminal careers
|
|
13
|
+
- **Relationship Impact**: Events that affect and are affected by your social connections and personal history
|
|
14
|
+
- **Seasonal & Location Themes**: Events adapt to time of year and geographical setting for added immersion
|
|
15
|
+
- **Consequence Tracking**: Events can have long-term effects on character development and reputation
|
|
16
|
+
- **Personality-Driven Choices**: Multiple meaningful choices that define your character's personality and path
|
|
17
|
+
- **Quality Filtering**: Built-in filters ensure only interesting, non-generic events are generated
|
|
18
|
+
- **Modular Design**: Easy to integrate into existing game systems
|
|
19
|
+
- **Highly Configurable**: Customize training data, templates, and generation parameters
|
|
20
|
+
|
|
21
|
+
## ๐ Quick Start
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install rpg-event-generator
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import { RPGEventGenerator, generateRPGEvent } from 'rpg-event-generator';
|
|
29
|
+
|
|
30
|
+
// Quick single event
|
|
31
|
+
const event = generateRPGEvent({
|
|
32
|
+
age: 25,
|
|
33
|
+
gold: 500,
|
|
34
|
+
influence: 15,
|
|
35
|
+
career: 'merchant'
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.log(event.title); // "Golden Opportunity"
|
|
39
|
+
console.log(event.description); // Procedurally generated description
|
|
40
|
+
console.log(event.choices); // Array of choices with effects
|
|
41
|
+
|
|
42
|
+
// Advanced usage with custom generator
|
|
43
|
+
const generator = new RPGEventGenerator({
|
|
44
|
+
stateSize: 2,
|
|
45
|
+
trainingData: ['Your custom story fragments...']
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Generate multiple events
|
|
49
|
+
const events = generator.generateEvents({
|
|
50
|
+
age: 30,
|
|
51
|
+
gold: 1000,
|
|
52
|
+
influence: 25,
|
|
53
|
+
career: 'knight',
|
|
54
|
+
skills: { combat: 60, diplomacy: 40 }
|
|
55
|
+
}, 3);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## ๐ Usage Examples
|
|
59
|
+
|
|
60
|
+
### Basic Event Generation
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const generator = new RPGEventGenerator();
|
|
64
|
+
|
|
65
|
+
// Generate a random event
|
|
66
|
+
const event = generator.generateEvent();
|
|
67
|
+
|
|
68
|
+
console.log(event);
|
|
69
|
+
// {
|
|
70
|
+
// id: "event_1704567890123_xyz789",
|
|
71
|
+
// title: "Perilous Bandit King's Challenge",
|
|
72
|
+
// description: "The infamous bandit king blocks your path, offering you a choice: join his band or face certain death. Your business interests are directly affected by this development. Choose wisely, for the wrong path leads to ruin.",
|
|
73
|
+
// narrative: "The infamous bandit king blocks your path, offering you a choice: join his band or face certain death.",
|
|
74
|
+
// choices: [
|
|
75
|
+
// {
|
|
76
|
+
// text: "Join the bandits",
|
|
77
|
+
// effect: { gold: 375, reputation: -23, combat_skill: 12 },
|
|
78
|
+
// consequence: "bandit"
|
|
79
|
+
// },
|
|
80
|
+
// {
|
|
81
|
+
// text: "Challenge him to single combat",
|
|
82
|
+
// effect: { reputation: 32, health: -18 },
|
|
83
|
+
// requirements: { combat_skill: 60 },
|
|
84
|
+
// consequence: "hero"
|
|
85
|
+
// },
|
|
86
|
+
// {
|
|
87
|
+
// text: "Bribe your way past",
|
|
88
|
+
// effect: { gold: -320, safe_passage: true },
|
|
89
|
+
// consequence: "diplomat"
|
|
90
|
+
// }
|
|
91
|
+
// ],
|
|
92
|
+
// type: "BANDIT_KING",
|
|
93
|
+
// consequence: null,
|
|
94
|
+
// urgency: "normal",
|
|
95
|
+
// theme: "adventure",
|
|
96
|
+
// context: { /* player context used */ }
|
|
97
|
+
// }
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Context-Aware Events
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
const playerContext = {
|
|
104
|
+
age: 35,
|
|
105
|
+
gold: 2500,
|
|
106
|
+
influence: 40,
|
|
107
|
+
reputation: 25,
|
|
108
|
+
career: 'noble',
|
|
109
|
+
skills: {
|
|
110
|
+
diplomacy: 70,
|
|
111
|
+
combat: 45,
|
|
112
|
+
intrigue: 30
|
|
113
|
+
},
|
|
114
|
+
relationships: [
|
|
115
|
+
{ name: 'Lord Harrington', type: 'ally', relationship: 60 },
|
|
116
|
+
{ name: 'Lady Beaumont', type: 'lover', relationship: 45 }
|
|
117
|
+
],
|
|
118
|
+
location: 'capital',
|
|
119
|
+
season: 'winter'
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const event = generator.generateEvent(playerContext);
|
|
123
|
+
// Generates events like:
|
|
124
|
+
// - Diplomatic missions (high diplomacy skill)
|
|
125
|
+
// - Court intrigue opportunities (high influence)
|
|
126
|
+
// - Social events involving relationships
|
|
127
|
+
// - Winter-themed challenges
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Custom Training Data
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
const customTrainingData = [
|
|
134
|
+
'In the shadowed alleys of the ancient city',
|
|
135
|
+
'The dragon\'s roar echoes through the mountains',
|
|
136
|
+
'Elven merchants display their enchanted wares',
|
|
137
|
+
'A dwarven smith forges weapons of legend',
|
|
138
|
+
'The tavern is filled with adventurers and mercenaries',
|
|
139
|
+
'Ancient runes glow with mystical power',
|
|
140
|
+
'The forest whispers secrets to those who listen'
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
const generator = new RPGEventGenerator({
|
|
144
|
+
trainingData: customTrainingData
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## ๐ง API Reference
|
|
149
|
+
|
|
150
|
+
### RPGEventGenerator Class
|
|
151
|
+
|
|
152
|
+
#### Constructor Options
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
const generator = new RPGEventGenerator({
|
|
156
|
+
stateSize: 2, // Markov chain state size (default: 2)
|
|
157
|
+
trainingData: [...] // Custom training data array (optional)
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Methods
|
|
162
|
+
|
|
163
|
+
- `generateEvent(playerContext)` - Generate a single event
|
|
164
|
+
- `generateEvents(playerContext, count)` - Generate multiple events
|
|
165
|
+
- `addTrainingData(data)` - Add more training data
|
|
166
|
+
- `resetTrainingData(data)` - Reset with new training data
|
|
167
|
+
|
|
168
|
+
### Player Context Object
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
{
|
|
172
|
+
age: number, // Player age
|
|
173
|
+
gold: number, // Player wealth
|
|
174
|
+
influence: number, // Political/social influence
|
|
175
|
+
reputation: number, // Social reputation
|
|
176
|
+
career: string, // Player's career/job
|
|
177
|
+
skills: { // Skill levels object
|
|
178
|
+
combat: number,
|
|
179
|
+
diplomacy: number,
|
|
180
|
+
// ... other skills
|
|
181
|
+
},
|
|
182
|
+
relationships: [{ // Array of relationships
|
|
183
|
+
name: string,
|
|
184
|
+
type: string, // 'friend', 'lover', 'ally', etc.
|
|
185
|
+
relationship: number // Relationship strength (0-100)
|
|
186
|
+
}],
|
|
187
|
+
location: string, // Current location
|
|
188
|
+
season: string // Current season
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Event Object Structure
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
{
|
|
196
|
+
id: string, // Unique event identifier
|
|
197
|
+
title: string, // Dynamic, context-aware title
|
|
198
|
+
description: string, // Rich procedural description
|
|
199
|
+
narrative: string, // Core story premise
|
|
200
|
+
choices: [{ // Array of meaningful choices
|
|
201
|
+
text: string, // Choice text with contextual flavor
|
|
202
|
+
effect: { // Effects scaled by context
|
|
203
|
+
gold?: number, // Wealth changes
|
|
204
|
+
influence?: number, // Social/political power
|
|
205
|
+
reputation?: number, // Social standing
|
|
206
|
+
health?: number, // Physical well-being
|
|
207
|
+
stress?: number, // Mental strain
|
|
208
|
+
karma?: number, // Moral standing
|
|
209
|
+
// ... many more effects
|
|
210
|
+
},
|
|
211
|
+
consequence: string // Long-term character effect
|
|
212
|
+
}],
|
|
213
|
+
type: string, // Rich event category (COURT_SCANDAL, etc.)
|
|
214
|
+
consequence: string|null, // Applied consequence after choice
|
|
215
|
+
urgency: string, // 'normal', 'high', 'critical'
|
|
216
|
+
theme: string, // 'political', 'criminal', 'supernatural', etc.
|
|
217
|
+
context: object // Full context used for generation
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## ๐ฎ Integration Guide
|
|
222
|
+
|
|
223
|
+
### React Native Game Integration
|
|
224
|
+
|
|
225
|
+
```javascript
|
|
226
|
+
import React, { useState, useEffect } from 'react';
|
|
227
|
+
import { RPGEventGenerator } from 'rpg-event-generator';
|
|
228
|
+
|
|
229
|
+
function GameEventSystem({ playerStats }) {
|
|
230
|
+
const [currentEvent, setCurrentEvent] = useState(null);
|
|
231
|
+
const [generator] = useState(() => new RPGEventGenerator());
|
|
232
|
+
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
// Generate event when time advances
|
|
235
|
+
const event = generator.generateEvent(playerStats);
|
|
236
|
+
setCurrentEvent(event);
|
|
237
|
+
}, [playerStats, generator]);
|
|
238
|
+
|
|
239
|
+
const handleChoice = (choiceIndex) => {
|
|
240
|
+
const choice = currentEvent.choices[choiceIndex];
|
|
241
|
+
// Apply effects to player stats
|
|
242
|
+
applyEffects(choice.effect);
|
|
243
|
+
setCurrentEvent(null); // Clear event
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
if (!currentEvent) return null;
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<EventDialog
|
|
250
|
+
event={currentEvent}
|
|
251
|
+
onChoice={handleChoice}
|
|
252
|
+
/>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Redux Integration
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
// Action creators
|
|
261
|
+
export const generateEvent = (playerContext) => {
|
|
262
|
+
const generator = new RPGEventGenerator();
|
|
263
|
+
const event = generator.generateEvent(playerContext);
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
type: 'GENERATE_EVENT',
|
|
267
|
+
payload: event
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export const resolveEvent = (eventId, choiceIndex) => ({
|
|
272
|
+
type: 'RESOLVE_EVENT',
|
|
273
|
+
payload: { eventId, choiceIndex }
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Reducer
|
|
277
|
+
const eventReducer = (state = {}, action) => {
|
|
278
|
+
switch (action.type) {
|
|
279
|
+
case 'GENERATE_EVENT':
|
|
280
|
+
return { ...state, currentEvent: action.payload };
|
|
281
|
+
case 'RESOLVE_EVENT':
|
|
282
|
+
return { ...state, currentEvent: null };
|
|
283
|
+
default:
|
|
284
|
+
return state;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## ๐งช Testing
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
npm test
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
The package includes comprehensive tests covering:
|
|
296
|
+
- Event generation with various contexts
|
|
297
|
+
- Effect resolution
|
|
298
|
+
- Markov chain text generation
|
|
299
|
+
- Template selection algorithms
|
|
300
|
+
|
|
301
|
+
## ๐ฏ Event Types
|
|
302
|
+
|
|
303
|
+
### Court & Political (Variable probability)
|
|
304
|
+
- **Court Scandal**: Royal court intrigue with betrayal and scandal
|
|
305
|
+
- **Noble Duel**: Honor challenges and duels of reputation
|
|
306
|
+
- **Market Crash**: Economic disasters affecting trade and wealth
|
|
307
|
+
- **Trade War**: Merchant rivalries and economic warfare
|
|
308
|
+
|
|
309
|
+
### Criminal Underworld (Variable probability)
|
|
310
|
+
- **Thieves' Guild**: Criminal organization recruitment and underworld dealings
|
|
311
|
+
- **Blackmail Opportunity**: Leverage compromising information for gain
|
|
312
|
+
- **Bandit King Challenge**: Highway robbery and outlaw confrontations
|
|
313
|
+
|
|
314
|
+
### Supernatural & Mysterious (Variable probability)
|
|
315
|
+
- **Ancient Curse**: Cursed artifacts and supernatural afflictions
|
|
316
|
+
- **Ghostly Visitation**: Spirits seeking justice or redemption
|
|
317
|
+
- **Lost Civilization**: Archaeological discoveries and ancient treasures
|
|
318
|
+
|
|
319
|
+
### Personal & Dramatic (Variable probability)
|
|
320
|
+
- **Forbidden Love**: Romance across social boundaries with scandal
|
|
321
|
+
- **Family Secret**: Hidden lineage and ancestral revelations
|
|
322
|
+
- **Desertion Temptation**: Military crises testing loyalty and courage
|
|
323
|
+
- **Mercenary Contract**: Dangerous employment with high rewards
|
|
324
|
+
|
|
325
|
+
### Adventure & Exploration (Variable probability)
|
|
326
|
+
- **Bandit King**: Confrontations with notorious outlaws
|
|
327
|
+
- **Lost Civilization**: Exploration of ancient ruins and artifacts
|
|
328
|
+
|
|
329
|
+
Probabilities dynamically adjust based on player career, skills, reputation, wealth, and current life circumstances.
|
|
330
|
+
|
|
331
|
+
## ๐ How It Works
|
|
332
|
+
|
|
333
|
+
### 1. Context Analysis
|
|
334
|
+
The generator analyzes player stats to understand their current situation and capabilities.
|
|
335
|
+
|
|
336
|
+
### 2. Template Selection
|
|
337
|
+
Based on context, it selects an appropriate event template from 14+ rich narrative types (Court Scandal, Forbidden Love, Ancient Curse, etc.).
|
|
338
|
+
|
|
339
|
+
### 3. Procedural Description
|
|
340
|
+
Uses custom Markov chains trained on immersive RPG-themed text to generate unique, atmospheric descriptions.
|
|
341
|
+
|
|
342
|
+
### 4. Dynamic Choices
|
|
343
|
+
Creates contextually appropriate choices with effects that scale based on player stats, career, and relationships.
|
|
344
|
+
|
|
345
|
+
### 5. Effect Resolution
|
|
346
|
+
Converts effect ranges into specific numbers and applies sophisticated context multipliers based on character background.
|
|
347
|
+
|
|
348
|
+
## ๐จ Customization
|
|
349
|
+
|
|
350
|
+
### Custom Event Templates
|
|
351
|
+
|
|
352
|
+
```javascript
|
|
353
|
+
const customTemplates = {
|
|
354
|
+
QUEST: {
|
|
355
|
+
title: 'Epic Quest',
|
|
356
|
+
choices: [
|
|
357
|
+
{ text: 'Accept the quest', effect: { influence: [20, 40] } },
|
|
358
|
+
{ text: 'Decline politely', effect: {} }
|
|
359
|
+
]
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// Extend the generator
|
|
364
|
+
class CustomRPGEventGenerator extends RPGEventGenerator {
|
|
365
|
+
constructor(options) {
|
|
366
|
+
super(options);
|
|
367
|
+
this.templates = { ...this.templates, ...customTemplates };
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Custom Effect Types
|
|
373
|
+
|
|
374
|
+
```javascript
|
|
375
|
+
// Add custom effects
|
|
376
|
+
const event = generator.generateEvent(playerContext);
|
|
377
|
+
|
|
378
|
+
// Custom effect resolution
|
|
379
|
+
function resolveCustomEffects(choice, playerContext) {
|
|
380
|
+
const effects = resolveEffect(choice.effect, playerContext);
|
|
381
|
+
|
|
382
|
+
// Add custom logic
|
|
383
|
+
if (effects.experience) {
|
|
384
|
+
// Handle experience gain
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (effects.relationshipChange) {
|
|
388
|
+
// Update relationship values
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return effects;
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
## ๐ Performance
|
|
396
|
+
|
|
397
|
+
- **Generation Speed**: ~10-50ms per event
|
|
398
|
+
- **Memory Usage**: ~2-5MB for trained Markov generator
|
|
399
|
+
- **Infinite Variety**: Can generate millions of unique events
|
|
400
|
+
- **Scalable**: Works with any number of players/contexts
|
|
401
|
+
|
|
402
|
+
## ๐ค Contributing
|
|
403
|
+
|
|
404
|
+
1. Fork the repository
|
|
405
|
+
2. Create a feature branch
|
|
406
|
+
3. Add tests for new functionality
|
|
407
|
+
4. Ensure all tests pass
|
|
408
|
+
5. Submit a pull request
|
|
409
|
+
|
|
410
|
+
## ๐ License
|
|
411
|
+
|
|
412
|
+
MIT License - see LICENSE file for details.
|
|
413
|
+
|
|
414
|
+
## ๐ Acknowledgments
|
|
415
|
+
|
|
416
|
+
- Uses [Chance.js](https://chancejs.com/) for random number generation
|
|
417
|
+
- Custom Markov chain implementation for procedural text generation
|
|
418
|
+
|
|
419
|
+
## ๐ฎ Future Enhancements
|
|
420
|
+
|
|
421
|
+
- **Thematic Training Sets**: Fantasy, Sci-fi, Historical themes
|
|
422
|
+
- **Multi-language Support**: Generate events in different languages
|
|
423
|
+
- **Event Chains**: Multi-part event sequences
|
|
424
|
+
- **Dynamic Difficulty**: Events scale with player power level
|
|
425
|
+
- **Cultural Context**: Region-specific event generation
|
|
426
|
+
- **Time-based Events**: Events that change over time
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
**Generate infinite adventures with RPG Event Generator!** โ๏ธ๐โจ
|