@reldens/game-data-generator 0.4.0 → 0.6.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
*
|
|
3
|
-
* Reldens - Game Data Generator -
|
|
3
|
+
* Reldens - Game Data Generator - AttributesPerLevel
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -27,7 +27,11 @@ class AttributesPerLevel extends GameDataGenerator
|
|
|
27
27
|
this.typeTemplates = sc.get(options, 'typeTemplates', false);
|
|
28
28
|
this.typesVariations = sc.get(options, 'typesVariations', false);
|
|
29
29
|
// optional:
|
|
30
|
+
this.setBaseAsInitialLevel = sc.get(options, 'setBaseAsInitialLevel', false);
|
|
30
31
|
this.maxLevel = sc.get(options, 'maxLevel', 100);
|
|
32
|
+
this.typeScaleFactorRandom = sc.get(options, 'typeScaleFactorRandom', Math.random());
|
|
33
|
+
this.scaleDivisor = sc.get(options, 'scaleDivisor', 10);
|
|
34
|
+
this.levelDivisor = sc.get(options, 'levelDivisor', 10);
|
|
31
35
|
this.jsonFileName = sc.get(options, 'jsonFileName', 'attributes-per-level-'+this.currentDate+'.json');
|
|
32
36
|
this.generateFolderPath = sc.get(options, 'generateFolderPath', 'generated');
|
|
33
37
|
}
|
|
@@ -38,29 +42,32 @@ class AttributesPerLevel extends GameDataGenerator
|
|
|
38
42
|
if(!this.isReady){
|
|
39
43
|
return false;
|
|
40
44
|
}
|
|
41
|
-
// define scale factors for each
|
|
42
|
-
for
|
|
45
|
+
// define scale factors for each type:
|
|
46
|
+
for(let variationType of Object.keys(this.typesVariations)){
|
|
43
47
|
let factor = this.typesVariations[variationType];
|
|
44
|
-
this.typeScaleFactors[variationType] =
|
|
48
|
+
this.typeScaleFactors[variationType] = this.typeScaleFactorRandom * (factor.max - factor.min) + factor.min;
|
|
45
49
|
}
|
|
46
50
|
await this.fileHandler.createFolder(this.generateFolderPath);
|
|
47
51
|
await this.fileHandler.writeFile(
|
|
48
52
|
this.fileHandler.joinPaths(this.generateFolderPath, this.jsonFileName),
|
|
49
|
-
JSON.stringify(
|
|
53
|
+
JSON.stringify({
|
|
54
|
+
attributesByLevelAndVariation: this.generateAttributesData(),
|
|
55
|
+
typeScaleFactorRandom: this.typeScaleFactorRandom
|
|
56
|
+
})
|
|
50
57
|
);
|
|
51
58
|
Logger.info('Data saved! Check the "generated" folder.');
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
generateAttributesData()
|
|
55
62
|
{
|
|
56
63
|
for (let level = 1; level <= this.maxLevel; level ++) {
|
|
57
64
|
this.variations[level] = {};
|
|
58
|
-
this.
|
|
65
|
+
this.generateVariation(level);
|
|
59
66
|
}
|
|
60
67
|
return this.variations;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
generateVariation(level)
|
|
64
71
|
{
|
|
65
72
|
let typesKeys = Object.keys(this.typeTemplates);
|
|
66
73
|
for (let variationType of Object.keys(this.typesVariations)) {
|
|
@@ -77,12 +84,18 @@ class AttributesPerLevel extends GameDataGenerator
|
|
|
77
84
|
let result = {...base};
|
|
78
85
|
let scaleTypeFactor = this.typeScaleFactors[variationType];
|
|
79
86
|
let templatesProperties = Object.keys(this.typeTemplates[typeKey]);
|
|
80
|
-
for
|
|
87
|
+
for(let key of templatesProperties){
|
|
88
|
+
if(1 === level && this.setBaseAsInitialLevel){
|
|
89
|
+
result[key] = base[key];
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
81
92
|
let templateData = this.typeTemplates[typeKey][key];
|
|
82
93
|
let scale = sc.isObject(templateData)
|
|
83
94
|
? sc.randomInteger(templateData.min, templateData.max) + templateData.min
|
|
84
95
|
: templateData;
|
|
85
|
-
result[key] = Math.round(
|
|
96
|
+
result[key] = Math.round(
|
|
97
|
+
base[key] * (1 + scale / this.scaleDivisor) * (1 + level / this.levelDivisor) * scaleTypeFactor
|
|
98
|
+
);
|
|
86
99
|
}
|
|
87
100
|
return result;
|
|
88
101
|
}
|