@reldens/game-data-generator 0.1.0 → 0.2.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/examples/attributes-per-level.json +9802 -0
- package/examples/{generate-monsters-attributes-per-level.js → generate-attributes-per-level.js} +11 -12
- package/lib/generator/{monsters-attributes-per-level.js → attributes-per-level.js} +23 -23
- package/lib/validator/attributes-per-level-validator.js +29 -0
- package/package.json +4 -2
- package/examples/monsters-attributes-per-level.json +0 -9802
- package/lib/validator/monsters-attributes-per-level-validator.js +0 -33
package/examples/{generate-monsters-attributes-per-level.js → generate-attributes-per-level.js}
RENAMED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { AttributesPerLevel } = require('../lib/generator/attributes-per-level');
|
|
8
8
|
|
|
9
|
-
let
|
|
10
|
-
|
|
9
|
+
let attributesPerLevel = new AttributesPerLevel({
|
|
10
|
+
templateBase: {
|
|
11
11
|
hp: 10,
|
|
12
12
|
atk: 10,
|
|
13
13
|
def: 10,
|
|
@@ -19,9 +19,9 @@ let monstersExperiencePerLevel = new MonsterAttributesPerLevel({
|
|
|
19
19
|
},
|
|
20
20
|
typeTemplates: {
|
|
21
21
|
melee: {
|
|
22
|
-
hp: {min:
|
|
23
|
-
atk: {min:
|
|
24
|
-
def: {min:
|
|
22
|
+
hp: {min: 10, max: 20},
|
|
23
|
+
atk: {min: 10, max: 20},
|
|
24
|
+
def: {min: 10, max: 20},
|
|
25
25
|
speed: {min: 1, max: 2},
|
|
26
26
|
mAtk: {min: 1, max: 2},
|
|
27
27
|
mDef: {min: 1, max: 2},
|
|
@@ -33,8 +33,8 @@ let monstersExperiencePerLevel = new MonsterAttributesPerLevel({
|
|
|
33
33
|
atk: {min: 1, max: 2},
|
|
34
34
|
def: {min: 1, max: 2},
|
|
35
35
|
speed: {min: 1, max: 4},
|
|
36
|
-
mAtk: {min:
|
|
37
|
-
mDef: {min:
|
|
36
|
+
mAtk: {min: 10, max: 20},
|
|
37
|
+
mDef: {min: 10, max: 20},
|
|
38
38
|
dodge: {min: 1, max: 2},
|
|
39
39
|
aim: {min: 5, max: 10}
|
|
40
40
|
},
|
|
@@ -49,12 +49,11 @@ let monstersExperiencePerLevel = new MonsterAttributesPerLevel({
|
|
|
49
49
|
aim: {min: 7, max: 20}
|
|
50
50
|
}
|
|
51
51
|
},
|
|
52
|
-
|
|
52
|
+
typesVariations: {
|
|
53
53
|
monsterA: {min: 1, max: 1.5},
|
|
54
54
|
monsterB: {min: 1.5, max: 1.8},
|
|
55
55
|
boss: {min: 2.5, max: 3.5}
|
|
56
|
-
}
|
|
57
|
-
monsterTypesVariations: ['monsterA', 'monsterB', 'boss']
|
|
56
|
+
}
|
|
58
57
|
});
|
|
59
58
|
|
|
60
|
-
|
|
59
|
+
attributesPerLevel.generate();
|
|
@@ -4,31 +4,31 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const { AttributesPerLevelValidator } = require('../validator/attributes-per-level-validator');
|
|
8
8
|
const { GameDataGenerator } = require('./game-data-generator');
|
|
9
|
-
const {
|
|
9
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class AttributesPerLevel extends GameDataGenerator
|
|
12
12
|
{
|
|
13
13
|
|
|
14
14
|
constructor(props)
|
|
15
15
|
{
|
|
16
16
|
super();
|
|
17
|
-
this.optionsValidator = new
|
|
17
|
+
this.optionsValidator = new AttributesPerLevelValidator();
|
|
18
18
|
this.typeScaleFactors = {};
|
|
19
|
-
this.
|
|
19
|
+
this.variations = {};
|
|
20
20
|
this.setReady(props);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
setOptions(options)
|
|
24
24
|
{
|
|
25
25
|
// required:
|
|
26
|
-
this.
|
|
26
|
+
this.templateBase = sc.get(options, 'templateBase', false);
|
|
27
27
|
this.typeTemplates = sc.get(options, 'typeTemplates', false);
|
|
28
|
-
this.
|
|
29
|
-
this.variationsScaleFactorsMinMax = sc.get(options, 'variationsScaleFactorsMinMax', false);
|
|
28
|
+
this.typesVariations = sc.get(options, 'typesVariations', false);
|
|
30
29
|
// optional:
|
|
31
|
-
this.
|
|
30
|
+
this.maxLevel = sc.get(options, 'maxLevel', 100);
|
|
31
|
+
this.jsonFileName = sc.get(options, 'jsonFileName', 'attributes-per-level-'+this.currentDate+'.json');
|
|
32
32
|
this.generateFolderPath = sc.get(options, 'generateFolderPath', 'generated');
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -39,9 +39,9 @@ class MonsterAttributesPerLevel extends GameDataGenerator
|
|
|
39
39
|
return false;
|
|
40
40
|
}
|
|
41
41
|
// define scale factors for each monster type:
|
|
42
|
-
for (let
|
|
43
|
-
let factor = this.
|
|
44
|
-
this.typeScaleFactors[
|
|
42
|
+
for (let variationType of Object.keys(this.typesVariations)) {
|
|
43
|
+
let factor = this.typesVariations[variationType];
|
|
44
|
+
this.typeScaleFactors[variationType] = Math.random() * (factor.max - factor.min) + factor.min;
|
|
45
45
|
}
|
|
46
46
|
await this.fileHandler.createFolder(this.generateFolderPath);
|
|
47
47
|
await this.fileHandler.writeFile(
|
|
@@ -53,38 +53,38 @@ class MonsterAttributesPerLevel extends GameDataGenerator
|
|
|
53
53
|
|
|
54
54
|
generateMonstersData()
|
|
55
55
|
{
|
|
56
|
-
for (let level = 1; level <=
|
|
57
|
-
this.
|
|
56
|
+
for (let level = 1; level <= this.maxLevel; level ++) {
|
|
57
|
+
this.variations[level] = {};
|
|
58
58
|
this.generateMonster(level);
|
|
59
59
|
}
|
|
60
|
-
return this.
|
|
60
|
+
return this.variations;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
generateMonster(level)
|
|
64
64
|
{
|
|
65
65
|
let typesKeys = Object.keys(this.typeTemplates);
|
|
66
|
-
for (let
|
|
67
|
-
this.
|
|
66
|
+
for (let variationType of Object.keys(this.typesVariations)) {
|
|
67
|
+
this.variations[level][variationType] = {};
|
|
68
68
|
for (let typeKey of typesKeys) {
|
|
69
|
-
this.
|
|
69
|
+
this.variations[level][variationType][typeKey] = this.applyTemplate(typeKey, level, variationType);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
applyTemplate(typeKey, level,
|
|
74
|
+
applyTemplate(typeKey, level, variationType)
|
|
75
75
|
{
|
|
76
|
-
let base = this.
|
|
76
|
+
let base = this.templateBase;
|
|
77
77
|
let result = {...base};
|
|
78
|
-
let scaleTypeFactor = this.typeScaleFactors[
|
|
78
|
+
let scaleTypeFactor = this.typeScaleFactors[variationType];
|
|
79
79
|
let templatesProperties = Object.keys(this.typeTemplates[typeKey]);
|
|
80
80
|
for (let key of templatesProperties) {
|
|
81
81
|
let range = this.typeTemplates[typeKey][key];
|
|
82
82
|
let scale = Math.random() * (range.max - range.min) + range.min;
|
|
83
|
-
result[key] = Math.round(base[key] * (1 + scale / 100) * (1 + level /
|
|
83
|
+
result[key] = Math.round(base[key] * (1 + scale / 100) * (1 + level / scale) * scaleTypeFactor);
|
|
84
84
|
}
|
|
85
85
|
return result;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
module.exports.
|
|
90
|
+
module.exports.AttributesPerLevel = AttributesPerLevel;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Game Data Generator - AttributesPerLevelValidator
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
8
|
+
|
|
9
|
+
class AttributesPerLevelValidator
|
|
10
|
+
{
|
|
11
|
+
validate(options)
|
|
12
|
+
{
|
|
13
|
+
if(!sc.get(options, 'templateBase')){
|
|
14
|
+
Logger.error('Missing required option: "templateBase".');
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if(!sc.get(options, 'typeTemplates')){
|
|
18
|
+
Logger.error('Missing required option: "typeTemplates".');
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if(!sc.get(options, 'typesVariations')){
|
|
22
|
+
Logger.error('Missing required option: "typesVariations".');
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports.AttributesPerLevelValidator = AttributesPerLevelValidator;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reldens/game-data-generator",
|
|
3
3
|
"scope": "@reldens",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "Reldens - Game Data Generator",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
"enemy",
|
|
30
30
|
"enemies",
|
|
31
31
|
"level",
|
|
32
|
-
"experience"
|
|
32
|
+
"experience",
|
|
33
|
+
"stats",
|
|
34
|
+
"attribute"
|
|
33
35
|
],
|
|
34
36
|
"bugs": {
|
|
35
37
|
"url": "https://github.com/damian-pastorini/game-data-generator/issues"
|