Tier 2 features that wrap core generation. With default options and no template library loaded, you always get Tier 1 core output.
const generator = new RPGEventGenerator({
enableTemplates: true,
templateLibrary: 'fantasy' // built-in genre key, if available
});
If no template matches the player context, generation falls through to GeneratorCore.
generator.registerEventTemplate('merchant_gold', {
title: 'Wealthy Merchant',
narrative: 'A prosperous trader blocks your path.',
choices: [
{ text: 'Browse wares', effect: { gold: -50 } },
{ text: 'Pass by', effect: {} }
],
conditional_choices: [{
choice_index: 0,
conditions: [{ type: 'stat_requirement', operator: 'gte', field: 'gold', value: 1000 }],
show_when: true
}]
});
const event = generator.generateFromTemplate('merchant_gold', { gold: 1500, level: 10 });
const event = generator.generateFromTemplate('my_template', playerContext);
// null if template not found or conditions fail
generateFromGenre('fantasy') returns null in v4. Use generateEvent(context) or load templates explicitly.
const generator = new RPGEventGenerator({
enableRuleEngine: true,
customRules: {
low_health: {
conditions: [{ type: 'stat_requirement', field: 'health', operator: 'lt', value: 20 }],
effects: { difficulty: 'easy' }
}
}
});
Rules run after environmental modifiers, before optional AI.
Enabled by default (enableModifiers: true). Uses player context:
generator.generateEvent({
weather: 'rainy', // maps to rain modifier
timeOfDay: 'night',
season: 'winter'
});
Modifiers can adjust description atmosphere and attach environmentalEffects to the event.
Weather aliases: rainy→rain, stormy→storm, midnight→night.
generator.registerChain('rescue_quest', {
stages: [/* ... */]
});
const chain = generator.startChain('rescue_quest', playerContext);
See ChainSystem in the API reference.