Attributes Per Level Generator
This generator creates stat progressions for every level for each entity type and variation in your game. It is primarily used to generate balanced stat tables for enemies and NPCs, though the same approach can apply to player classes. The output feeds directly into the Objects Importer.
Running the generator
This generator has no page in the administration panel, it is a command line tool. It runs from a terminal in your project folder and writes a JSON file that the Objects Importer (available in the administration panel) uses to set the stats of each enemy.
- Create the input file, for example generate-data/attributes-per-level.json, with the format described below.
- From the project root run:
npx reldens-generate attributes-per-level ./generate-data/attributes-per-level.json - The output is saved as generated/attributes-per-level-[date-time].json inside the current folder (change it with the optional jsonFileName and generateFolderPath input properties). Keep the typeScaleFactorRandom value of the output if you want to reproduce the same stats later.
- Reference the output file as attributesPerLevelFile in the objects import data and set level, attributesKey and attributesSubTypeKey on each enemy, as shown in Using the Output.
Configuration reference
Input File Format
{
"templateBase": {
"hp": 10, "mp": 10, "atk": 10, "def": 10,
"speed": 10, "mAtk": 10, "mDef": 10,
"dodge": 10, "aim": 10
},
"typeTemplates": {
"melee": {
"hp": {"min": 10, "max": 20},
"atk": {"min": 10, "max": 20},
"def": {"min": 10, "max": 20},
"mp": {"min": 1, "max": 5},
"speed": {"min": 1, "max": 2},
"mAtk": {"min": 1, "max": 2},
"mDef": {"min": 1, "max": 2},
"dodge": {"min": 1, "max": 4},
"aim": {"min": 1, "max": 2}
},
"mage": {
"hp": {"min": 5, "max": 10},
"mp": {"min": 10, "max": 20},
"mAtk": {"min": 10, "max": 20},
"mDef": {"min": 10, "max": 20},
"atk": {"min": 1, "max": 3},
"def": {"min": 1, "max": 3},
"speed": {"min": 1, "max": 2},
"dodge": {"min": 1, "max": 2},
"aim": {"min": 1, "max": 4}
}
},
"typesVariations": {
"normal": {"min": 1, "max": 1.5},
"strong": {"min": 1.5, "max": 1.8},
"boss": {"min": 2.5, "max": 3.5}
},
"maxLevel": 100
}
Input Properties
- templateBase (required) - Base stat values shared by all entity types. Each key is a stat name and the value is the starting base.
- typeTemplates (required) - Per-type scaling templates. Each type (e.g. melee, mage) defines min/max growth ranges per stat. The generator picks a random value within those ranges to determine how fast each stat grows for that type.
- typesVariations (required) - Variation multiplier ranges. Each variation (e.g. normal, boss) applies an additional scale factor to all stats, creating weaker and stronger versions of the same type.
- maxLevel (optional) - Maximum level to generate (default: 100)
- setBaseAsInitialLevel (optional) - If true, level 1 uses the templateBase values directly (default: false)
- typeScaleFactorRandom (optional) - Fixed random seed value between 0 and 1. If not provided, a new random value is used each run, so results vary between executions.
- scaleDivisor and levelDivisor (optional) - Divisors of the scaling formula below (default: 10).
- jsonFileName (optional) - Output file name (default: attributes-per-level-[date-time].json).
- generateFolderPath (optional) - Output folder, relative to the folder where the command runs (default: generated).
Output File Format
The output is nested: statsByVariation[variation][level][type][stat]
{
"statsByVariation": {
"normal": {
"1": {
"melee": {"hp": 14, "atk": 14, "def": 14, "mp": 2, ...},
"mage": {"hp": 7, "mp": 14, "mAtk": 14, ...}
},
"2": {
"melee": {"hp": 15, "atk": 15, ...},
"mage": {...}
}
},
"strong": {
"1": {...},
"2": {...}
},
"boss": {
"1": {...}
}
},
"typeScaleFactorRandom": 0.5327
}
How Stat Scaling Works
For each stat at each level, the formula is:
stat = base * (1 + scale / scaleDivisor) * (1 + level / levelDivisor) * variationFactor
Where:
- base - value from templateBase
- scale - random integer between the min and max of the stat in typeTemplates, plus the min value
- scaleDivisor - controls how strongly template scaling applies (default: 10)
- levelDivisor - controls how quickly stats grow per level (default: 10)
- variationFactor - value within the min/max range from typesVariations, placed by typeScaleFactorRandom
The typeScaleFactorRandom value in the output lets you reproduce the same variation factors in a future run by setting it as input.
Using the Output
Pass the generated file to the Objects Importer via attributesPerLevelFile (the path is relative to the project generate-data folder). Each object in the import JSON then gets the stats of its level, where attributesKey is the variation and attributesSubTypeKey is the type:
{
"attributesPerLevelFile": "generated/attributes-per-level-{timestamp}.json",
"objects": [
{
"clientKey": "forest_wolf",
"level": "5",
"attributesKey": "normal",
"attributesSubTypeKey": "melee"
}
]
}
Difference From Player Attributes
This generator is designed for enemies and NPCs where many variations of the same entity type exist at different strength levels. For player class stat progressions, you typically define level modifiers directly in the admin panel under Classes & Levels > Levels Modifiers, giving you precise control over each stat at each level milestone.
Example Output
A complete example output file is available at:
https://cdn.reldens.com/assets/examples/generated/attributes-per-level-2024-12-06-19-03-48.json
Code integration (advanced)
The command runs the AttributesPerLevel class of the @reldens/game-data-generator package (bin/generate.js). The same class can be used from your own scripts with the input properties above:
const { AttributesPerLevel } = require('@reldens/game-data-generator');
let generator = new AttributesPerLevel(inputData);
generator.generate();
The Objects Importer reads statsByVariation[attributesKey][level][attributesSubTypeKey] from the file and replaces the object stats with that result.
Related Documentation
- Objects Importer - Import enemies with the generated stats
- Enemies Experience Per Level Generator - Generate the enemies experience rewards
- Level Modifiers Entity - Player stats per level
reldens