Players Experience Per Level Generator
This generator creates a complete experience progression table for your game. Given a starting experience value and growth configuration, it calculates the experience required at every level up to a maximum, with support for dynamic growth factors that change as levels increase.
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 you use later as input for other tools.
- Create the input file, for example generate-data/players-experience-per-level.json, with the format described below.
- From the project root run:
npx reldens-generate players-experience-per-level ./generate-data/players-experience-per-level.json - The output is saved as generated/players-experience-per-level-[date-time].json inside the current folder. The optional jsonFileName and generateFolderPath input properties change the file name and the folder.
- Use the output as the second argument of the Enemies Experience Per Level generator, or import it as described in Using the Output.
Configuration reference
Input File Format
{
"startExp": 10,
"baseGrowthFactor": 2,
"maxLevel": 100,
"growthIncrease": 0.005,
"baseGrowthFactorPerLevel": {
"5": 1.5,
"10": 1.35,
"15": 1.271,
"20": 1.1,
"40": 1
}
}
Input Properties
- startExp (required) - Experience required to advance from level 1 to level 2
- baseGrowthFactor (required) - Starting multiplier applied to experience requirement each level
- maxLevel (required) - Maximum level to generate data for
- growthIncrease (optional) - Amount added to the growth factor each level (default: 0). Creates a curve that gets steeper as levels increase.
- baseGrowthFactorPerLevel (optional) - Override growth factor at specific levels. Useful for flattening out progression at higher levels.
- jsonFileName (optional) - Output file name (default: players-experience-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 a JSON object with level numbers as keys:
{
"1": {
"req": 10,
"total": 10,
"growthFactor": 2
},
"2": {
"diff": 10,
"req": 20,
"total": 30,
"growthFactor": 2.005
},
"3": {
"diff": 20,
"req": 40,
"total": 70,
"growthFactor": 2.01
}
}
Output fields per level:
- req - Experience required to advance from this level to the next
- total - Cumulative experience needed to have reached this level
- diff - Difference between this level's requirement and the previous one (omitted for level 1)
- growthFactor - The growth multiplier used when calculating this level
How Growth Works
Each level's experience requirement is calculated as:
req[n] = req[n-1] * growthFactor[n]
The growth factor for each level is:
growthFactor[n] = baseGrowthFactor + (growthIncrease * n)
If baseGrowthFactorPerLevel includes an override for level n, that value replaces the calculated factor from that level onward (until another override is encountered).
This lets you create progression curves like:
- Steep early levels that flatten at higher levels
- Milestone levels where the curve resets
- Gentle long-haul progression for end-game content
Using the Output
The generated JSON can be imported to assign the experience requirements (req) to the level records in the database:
npx reldens-import players-experience-per-level {theme} ./generated/players-experience-per-level-{timestamp}.json
It is also the required second input of the Enemies Experience Per Level generator, which calculates the experience rewards of the enemies so they scale with the player progression. That second output is the file the Objects Importer reads to set the enemies rewards.
Example Output
A complete example output file is available at:
https://cdn.reldens.com/assets/examples/generated/players-experience-per-level-2024-12-04-13-57-21.json
Code integration (advanced)
The command runs the PlayersExperiencePerLevel 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 { PlayersExperiencePerLevel } = require('@reldens/game-data-generator');
let generator = new PlayersExperiencePerLevel({startExp: 10, baseGrowthFactor: 2, maxLevel: 100});
generator.generate();
Related Documentation
- Enemies Experience Per Level Generator - Uses this output to calculate the enemies rewards
- Attributes Per Level Generator - Generate enemy stat progressions
- Objects Importer - Import enemies with generated stats and rewards
reldens