@reldens/skills 0.11.0 → 0.13.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/lib/class-path.js +9 -11
- package/lib/client/receiver.js +2 -2
- package/lib/constants.js +1 -1
- package/lib/levels-set.js +51 -52
- package/lib/server/sender.js +4 -6
- package/lib/server/storage/class-path-generator.js +47 -0
- package/lib/server/storage/conditions-generator.js +29 -0
- package/lib/server/storage/levels-generator.js +41 -0
- package/lib/server/storage/models-manager.js +30 -156
- package/lib/server/storage/modifiers-generator.js +28 -0
- package/lib/server/storage/skills-generator.js +101 -0
- package/lib/skill.js +19 -17
- package/lib/types/attack.js +61 -58
- package/lib/types/physical-skill-runner.js +6 -6
- package/package.json +1 -1
package/lib/class-path.js
CHANGED
|
@@ -30,16 +30,9 @@ class ClassPath extends LevelsSet
|
|
|
30
30
|
this.skillsByLevel = sc.hasOwn(props, 'skillsByLevel') ? props.skillsByLevel : false;
|
|
31
31
|
this.skillsByLevelKeys = this.getSkillsByLevelKeys();
|
|
32
32
|
// the set of skills for the current object instance:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.currentSkills = {};
|
|
37
|
-
await this.setOwnerSkills();
|
|
38
|
-
}
|
|
39
|
-
if(sc.hasOwn(props, 'affectedProperty')){
|
|
40
|
-
// the affected property is the one to which the damage calculation will have effect:
|
|
41
|
-
this.affectedProperty = props.affectedProperty;
|
|
42
|
-
}
|
|
33
|
+
await this.setOwnerSkills(sc.get(props, 'currentSkills', false));
|
|
34
|
+
// the affected property is the one to which the damage calculation will have effect:
|
|
35
|
+
this.affectedProperty = sc.get(props, 'affectedProperty', false);
|
|
43
36
|
await this.fireEvent(SkillsEvents.INIT_CLASS_PATH_END, this);
|
|
44
37
|
}
|
|
45
38
|
|
|
@@ -105,8 +98,13 @@ class ClassPath extends LevelsSet
|
|
|
105
98
|
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_AFTER, this, skills);
|
|
106
99
|
}
|
|
107
100
|
|
|
108
|
-
async setOwnerSkills()
|
|
101
|
+
async setOwnerSkills(skills)
|
|
109
102
|
{
|
|
103
|
+
if(skills) {
|
|
104
|
+
this.currentSkills = skills;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.currentSkills = {};
|
|
110
108
|
for(let i of Object.keys(this.levels)){
|
|
111
109
|
let level = this.levels[i];
|
|
112
110
|
if(this.skillsByLevel && sc.hasOwn(this.skillsByLevel, level.key) && level.key <= this.currentLevel){
|
package/lib/client/receiver.js
CHANGED
|
@@ -68,7 +68,7 @@ class Receiver
|
|
|
68
68
|
Logger.error('Skills action not found', message.act);
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
|
-
if(typeof this[this.actions[message.act]]
|
|
71
|
+
if('function' !== typeof this[this.actions[message.act]]){
|
|
72
72
|
// for now I'm leaving this a silent return (will probably end up making the error log configurable):
|
|
73
73
|
Logger.error('Skills action is not a function', message.act);
|
|
74
74
|
return false;
|
|
@@ -78,7 +78,7 @@ class Receiver
|
|
|
78
78
|
|
|
79
79
|
isValidMessage(message)
|
|
80
80
|
{
|
|
81
|
-
return
|
|
81
|
+
return 0 === message.act.indexOf(SkillConst.ACTIONS_PREF);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
}
|
package/lib/constants.js
CHANGED
package/lib/levels-set.js
CHANGED
|
@@ -11,9 +11,10 @@ const { EventsManagerSingleton, ErrorManager, Logger, sc } = require('@reldens/u
|
|
|
11
11
|
class LevelsSet
|
|
12
12
|
{
|
|
13
13
|
|
|
14
|
-
constructor(props)
|
|
14
|
+
constructor(props = {})
|
|
15
15
|
{
|
|
16
16
|
this.events = sc.get(props, 'events', EventsManagerSingleton);
|
|
17
|
+
this.owner = sc.get(props, 'owner', false);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
setOwner(props)
|
|
@@ -34,7 +35,7 @@ class LevelsSet
|
|
|
34
35
|
if(!sc.hasOwn(this, 'owner')){
|
|
35
36
|
ErrorManager.error('Undefined owner for levels.');
|
|
36
37
|
}
|
|
37
|
-
if(typeof
|
|
38
|
+
if(typeof this.owner.getPosition !== 'function'){
|
|
38
39
|
ErrorManager.error('Undefined owner position method.');
|
|
39
40
|
}
|
|
40
41
|
if(!sc.hasOwn(props, 'levels') || !Object.keys(props.levels).length){
|
|
@@ -49,12 +50,13 @@ class LevelsSet
|
|
|
49
50
|
this.autoFillExperienceMultiplier = sc.get(props, 'autoFillExperienceMultiplier', 1.5);
|
|
50
51
|
this.currentLevel = sc.get(props, 'currentLevel', 0);
|
|
51
52
|
this.currentExp = sc.get(props, 'currentExp', 0);
|
|
53
|
+
this.setRequiredExperienceLimit = sc.get(props, 'setRequiredExperienceLimit', false);
|
|
52
54
|
// set levels is almost the last thing to happen here, first we need to validate all the other parameters:
|
|
53
55
|
this.levels = await this.setLevels(props.levels);
|
|
54
|
-
// @NOTE: if you
|
|
55
|
-
// skipped because the experience on those will be
|
|
56
|
+
// @NOTE: if you set up levelsByExperience and autoFillRanges at the same time the levels autogenerated will be
|
|
57
|
+
// skipped because the experience on those will be lowed one. For example, level 1 required experience = 10p,
|
|
56
58
|
// level 5 required experience = 20p, level 2, 3 and 4 are auto-generated with required exp. = 20p, so when the
|
|
57
|
-
// player reach 20p of experience it will jump to level 5. In summary you shouldn't mix these options unless
|
|
59
|
+
// player reach 20p of experience it will jump to level 5. In summary, you shouldn't mix these options unless
|
|
58
60
|
// you expect the described behavior.
|
|
59
61
|
this.increaseLevelsWithExperience = sc.get(props, 'increaseLevelsWithExperience', true);
|
|
60
62
|
// unless specified, levels by experience must just be sorted by their key attribute (without auto-fill):
|
|
@@ -64,30 +66,31 @@ class LevelsSet
|
|
|
64
66
|
|
|
65
67
|
async setLevels(levels)
|
|
66
68
|
{
|
|
67
|
-
|
|
68
|
-
this.levels = levels;
|
|
69
|
-
} else {
|
|
70
|
-
this.levels = {};
|
|
71
|
-
let levelsKeys = Object.keys(levels);
|
|
72
|
-
for(let i of levelsKeys){
|
|
73
|
-
let level = levels[i];
|
|
74
|
-
this.levels[i] = level;
|
|
75
|
-
let levelsKeysNextIndex = levelsKeys.indexOf(i) + 1;
|
|
76
|
-
let nextLevelKey = levelsKeys.length > levelsKeysNextIndex ? levelsKeys[levelsKeysNextIndex] : false;
|
|
77
|
-
let nextLevel = false;
|
|
78
|
-
if(sc.hasOwn(levels, (nextLevelKey))){
|
|
79
|
-
nextLevel = levels[nextLevelKey];
|
|
80
|
-
}
|
|
81
|
-
if(sc.hasOwn(nextLevel, 'key') && (nextLevel.key - level.key) > 0){
|
|
82
|
-
await this.generateLevels(level, nextLevel);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
69
|
+
!this.autoFillRanges ? (this.levels = levels) : await this.createLevels(levels);
|
|
86
70
|
await this.fireEvent(SkillsEvents.SET_LEVELS, this, levels);
|
|
87
71
|
return this.levels;
|
|
88
72
|
}
|
|
89
73
|
|
|
90
|
-
async
|
|
74
|
+
async createLevels(levels)
|
|
75
|
+
{
|
|
76
|
+
this.levels = {};
|
|
77
|
+
let levelsKeys = Object.keys(levels);
|
|
78
|
+
for(let i of levelsKeys){
|
|
79
|
+
let level = levels[i];
|
|
80
|
+
this.levels[i] = level;
|
|
81
|
+
let levelsKeysNextIndex = levelsKeys.indexOf(i) + 1;
|
|
82
|
+
let nextLevelKey = levelsKeys.length > levelsKeysNextIndex ? levelsKeys[levelsKeysNextIndex] : false;
|
|
83
|
+
let nextLevel = false;
|
|
84
|
+
if(sc.hasOwn(levels, (nextLevelKey))){
|
|
85
|
+
nextLevel = levels[nextLevelKey];
|
|
86
|
+
}
|
|
87
|
+
if(sc.hasOwn(nextLevel, 'key') && (nextLevel.key - level.key) > 0){
|
|
88
|
+
await this.createAndAutofillLevelsInstances(level, nextLevel);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async createAndAutofillLevelsInstances(level, nextLevel)
|
|
91
94
|
{
|
|
92
95
|
for(let n = level.key + 1; n < nextLevel.key; n++){
|
|
93
96
|
let requiredExp = Math.round(this.levels[n-1].requiredExperience * this.autoFillExperienceMultiplier);
|
|
@@ -101,11 +104,8 @@ class LevelsSet
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
sortLevelsBy(levels, sortField)
|
|
107
|
+
sortLevelsBy(levels, sortField = 'key')
|
|
105
108
|
{
|
|
106
|
-
if(!sortField){
|
|
107
|
-
sortField = 'key';
|
|
108
|
-
}
|
|
109
109
|
return Object.keys(levels).sort((a,b) => {
|
|
110
110
|
return (levels[a][sortField] > levels[b][sortField]) ? 1 : -1;
|
|
111
111
|
});
|
|
@@ -127,7 +127,7 @@ class LevelsSet
|
|
|
127
127
|
|
|
128
128
|
async levelDown()
|
|
129
129
|
{
|
|
130
|
-
if(this.currentLevel
|
|
130
|
+
if(1 >= this.currentLevel){
|
|
131
131
|
// reached first level:
|
|
132
132
|
return false;
|
|
133
133
|
}
|
|
@@ -147,23 +147,18 @@ class LevelsSet
|
|
|
147
147
|
return false;
|
|
148
148
|
}
|
|
149
149
|
await this.fireEvent(SkillsEvents.LEVEL_APPLY_MODIFIERS, this, currentLevelInstance);
|
|
150
|
+
if(!currentLevelInstance.modifiers){
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
150
153
|
for(let modifier of currentLevelInstance.modifiers){
|
|
151
|
-
|
|
152
|
-
modifier.revert(this.owner);
|
|
153
|
-
} else {
|
|
154
|
-
modifier.apply(this.owner);
|
|
155
|
-
}
|
|
154
|
+
revert ? modifier.revert(this.owner) : modifier.apply(this.owner);
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
|
|
159
158
|
getLevelInstance(level)
|
|
160
159
|
{
|
|
161
160
|
// @NOTE: if you only specify 1 level the same calculation will be used for all the levels.
|
|
162
|
-
|
|
163
|
-
if(sc.hasOwn(this.levels, level)){
|
|
164
|
-
currentLevelInstance = this.levels[level];
|
|
165
|
-
}
|
|
166
|
-
return currentLevelInstance;
|
|
161
|
+
return sc.get(this.levels, level, false);
|
|
167
162
|
}
|
|
168
163
|
|
|
169
164
|
async addExperience(number)
|
|
@@ -174,9 +169,11 @@ class LevelsSet
|
|
|
174
169
|
let nextLevelKey = this.levelsByExperience[nextLevelIndex];
|
|
175
170
|
let nextLevel = this.levels[nextLevelKey];
|
|
176
171
|
let nextLevelExp = 0;
|
|
172
|
+
let isLevelUp = false;
|
|
177
173
|
if(sc.hasOwn(this.levels, this.currentLevel) && nextLevel && newTotalExp >= nextLevel.requiredExperience){
|
|
178
174
|
for(let levelByExp of this.levelsByExperience.slice(nextLevelIndex)){
|
|
179
175
|
if(newTotalExp >= this.levels[levelByExp].requiredExperience){
|
|
176
|
+
isLevelUp = true;
|
|
180
177
|
await this.levelUp();
|
|
181
178
|
}
|
|
182
179
|
if(newTotalExp < this.levels[levelByExp].requiredExperience){
|
|
@@ -185,6 +182,10 @@ class LevelsSet
|
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
184
|
}
|
|
185
|
+
let expNextLevelIndex = !isLevelUp ? nextLevelIndex : (nextLevelIndex + 1)
|
|
186
|
+
if((!nextLevel || expNextLevelIndex === this.levelsByExperience.length) && this.setRequiredExperienceLimit){
|
|
187
|
+
newTotalExp = this.getLevelInstance(this.currentLevel).requiredExperience;
|
|
188
|
+
}
|
|
188
189
|
this.currentExp = newTotalExp;
|
|
189
190
|
await this.fireEvent(SkillsEvents.LEVEL_EXPERIENCE_ADDED,
|
|
190
191
|
this,
|
|
@@ -205,23 +206,21 @@ class LevelsSet
|
|
|
205
206
|
let nextLevelIndex = currentLevelIndex + 1;
|
|
206
207
|
let nextLevelKey = this.levelsByExperience[nextLevelIndex];
|
|
207
208
|
let nextLevel = this.getLevelInstance(nextLevelKey);
|
|
208
|
-
let nextLevelExp = currentLevel.requiredExperience;
|
|
209
209
|
if(!nextLevel){
|
|
210
|
-
return
|
|
210
|
+
return currentLevel.requiredExperience;
|
|
211
211
|
}
|
|
212
212
|
if(nextLevel && this.currentExp < nextLevel.requiredExperience){
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
213
|
+
return nextLevel.requiredExperience;
|
|
214
|
+
}
|
|
215
|
+
if(!sc.hasOwn(this.levels, this.currentLevel) || !nextLevel){
|
|
216
|
+
return nextLevel.requiredExperience;
|
|
217
|
+
}
|
|
218
|
+
for(let levelByExp of this.levelsByExperience.slice(nextLevelIndex)){
|
|
219
|
+
if(this.currentExp < this.levels[levelByExp].requiredExperience){
|
|
220
|
+
return this.levels[levelByExp].requiredExperience;
|
|
222
221
|
}
|
|
223
222
|
}
|
|
224
|
-
return
|
|
223
|
+
return nextLevel.requiredExperience;
|
|
225
224
|
}
|
|
226
225
|
|
|
227
226
|
getOwnerId()
|
package/lib/server/sender.js
CHANGED
|
@@ -52,8 +52,8 @@ class Sender
|
|
|
52
52
|
if(nextLevelExp > 0){
|
|
53
53
|
messageData.ne = nextLevelExp;
|
|
54
54
|
}
|
|
55
|
-
// @NOTE: we could send just this.currentLabel but better check if there's
|
|
56
|
-
//
|
|
55
|
+
// @NOTE: we could send just this.currentLabel but better check if there's a specific one for this level and
|
|
56
|
+
// don't send extra information we already have on the client.
|
|
57
57
|
if(classPath.labelsByLevel[classPath.currentLevel]){
|
|
58
58
|
messageData.nl = classPath.labelsByLevel[classPath.currentLevel];
|
|
59
59
|
}
|
|
@@ -121,9 +121,7 @@ class Sender
|
|
|
121
121
|
|
|
122
122
|
async onSkillAttachApplyDamage(skill, target, damage, newValue)
|
|
123
123
|
{
|
|
124
|
-
let messageData = {
|
|
125
|
-
d: damage
|
|
126
|
-
};
|
|
124
|
+
let messageData = {d: damage};
|
|
127
125
|
if(typeof skill.owner.getSkillExtraData === 'function'){
|
|
128
126
|
Object.assign(messageData, {extraData: skill.owner.getSkillExtraData({skill, target})});
|
|
129
127
|
}
|
|
@@ -137,7 +135,7 @@ class Sender
|
|
|
137
135
|
|
|
138
136
|
async runBehaviors(messageData, actionName, behavior, ownerId)
|
|
139
137
|
{
|
|
140
|
-
// @NOTE: since the sender is a new instance for each SkillsServer but it's listening on a single EventsManager
|
|
138
|
+
// @NOTE: since the sender is a new instance for each SkillsServer, but it's listening on a single EventsManager
|
|
141
139
|
// which fires the event for every player then we need to check if the current event fired was related to the
|
|
142
140
|
// current player.
|
|
143
141
|
if(this.classPath.getOwnerId() !== ownerId){
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - ClassPathGenerator
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ClassPath = require('../../class-path');
|
|
8
|
+
const { LevelsGenerator } = require('./levels-generator');
|
|
9
|
+
const { sc } = require('@reldens/utils');
|
|
10
|
+
|
|
11
|
+
class ClassPathGenerator
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
static fromClassPathModels(classPathModels, classPathClasses)
|
|
15
|
+
{
|
|
16
|
+
if(!sc.isArray(classPathModels) || 0 === classPathModels.length) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
let classPathsById = {};
|
|
20
|
+
let classPathsByKey = {};
|
|
21
|
+
for(let classPathModel of classPathModels){
|
|
22
|
+
let classPathData = {class: sc.get(classPathClasses, classPathModel.key, ClassPath), data: classPathModel};
|
|
23
|
+
classPathModel.classPathLevels = LevelsGenerator.fromLevelsModels(
|
|
24
|
+
classPathModel.skills_levels_set.skills_levels_set_levels
|
|
25
|
+
);
|
|
26
|
+
classPathModel.labelsByLevel = this.extractLabelsByLevels(classPathModel.skills_class_path_level_labels);
|
|
27
|
+
classPathsById[classPathModel.id] = classPathData;
|
|
28
|
+
classPathsByKey[classPathModel.key] = classPathData;
|
|
29
|
+
}
|
|
30
|
+
return {classPathModels: classPathModels, classPathsById, classPathsByKey};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static extractLabelsByLevels(levelLabelsModel)
|
|
34
|
+
{
|
|
35
|
+
if(!sc.isArray(levelLabelsModel) || 0 === levelLabelsModel.length){
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
let labelsByLevel = {};
|
|
39
|
+
for(let labelData of levelLabelsModel){
|
|
40
|
+
labelsByLevel[labelData['label_level'].key] = labelData.label;
|
|
41
|
+
}
|
|
42
|
+
return labelsByLevel;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports.ClassPathGenerator = ClassPathGenerator;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - ConditionsGenerator
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Condition } = require('@reldens/modifiers');
|
|
8
|
+
const { sc } = require('@reldens/utils');
|
|
9
|
+
|
|
10
|
+
class ConditionsGenerator
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
static fromConditionsModels(conditionsModels)
|
|
14
|
+
{
|
|
15
|
+
if(!sc.isArray(conditionsModels) || 0 === conditionsModels.length){
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
let conditions = [];
|
|
19
|
+
for (let conditionModel of conditionsModels) {
|
|
20
|
+
conditionModel['propertyKey'] = conditionModel['property_key'];
|
|
21
|
+
let condition = new Condition(conditionModel);
|
|
22
|
+
conditions.push(condition);
|
|
23
|
+
}
|
|
24
|
+
return conditions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports.ConditionsGenerator = ConditionsGenerator;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - LevelsGenerator
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const Level = require('../../level');
|
|
8
|
+
const { Modifier } = require('@reldens/modifiers');
|
|
9
|
+
const { sc } = require('@reldens/utils');
|
|
10
|
+
|
|
11
|
+
class LevelsGenerator
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
static fromLevelsModels(levelsModels)
|
|
15
|
+
{
|
|
16
|
+
let levels = {};
|
|
17
|
+
for(let levelData of levelsModels){
|
|
18
|
+
levelData.modifiers = this.extractModifiers(levelData['level_modifiers']);
|
|
19
|
+
let levelKey = parseInt(levelData['key']);
|
|
20
|
+
levelData.key = levelKey;
|
|
21
|
+
levels[levelKey] = new Level(levelData);
|
|
22
|
+
}
|
|
23
|
+
return levels;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static extractModifiers(modifiersModels)
|
|
27
|
+
{
|
|
28
|
+
if(!sc.isArray(modifiersModels) || 0 === modifiersModels.length){
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
let levelModifiers = [];
|
|
32
|
+
for(let modifierData of modifiersModels){
|
|
33
|
+
let modifier = new Modifier(modifierData);
|
|
34
|
+
levelModifiers.push(modifier);
|
|
35
|
+
}
|
|
36
|
+
return levelModifiers;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports.LevelsGenerator = LevelsGenerator;
|
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const Level = require('../../level');
|
|
7
|
+
const { ClassPathGenerator } = require('./class-path-generator');
|
|
9
8
|
const { DataServerValidator } = require('../data-server-validator');
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
9
|
+
const { SkillsGenerator } = require('./skills-generator');
|
|
10
|
+
const { Logger, EventsManagerSingleton, sc } = require('@reldens/utils');
|
|
12
11
|
|
|
13
12
|
class ModelsManager
|
|
14
13
|
{
|
|
@@ -26,101 +25,51 @@ class ModelsManager
|
|
|
26
25
|
|
|
27
26
|
async loadOwnerClassPath(ownerId)
|
|
28
27
|
{
|
|
29
|
-
return await this.getEntity('ownersClassPath').loadOneByWithRelations(
|
|
28
|
+
return await this.getEntity('ownersClassPath').loadOneByWithRelations(
|
|
29
|
+
'owner_id',
|
|
30
|
+
ownerId,
|
|
31
|
+
'[owner_full_class_path]'
|
|
32
|
+
);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
async updateLevel(levelsSet)
|
|
33
36
|
{
|
|
34
|
-
return await this.getEntity('ownersClassPath')
|
|
35
|
-
|
|
37
|
+
return await this.getEntity('ownersClassPath').updateBy(
|
|
38
|
+
'owner_id',
|
|
39
|
+
levelsSet.getOwnerId(),
|
|
40
|
+
{currentLevel: levelsSet.currentLevel}
|
|
41
|
+
);
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
async updateExperience(levelsSet)
|
|
39
45
|
{
|
|
40
|
-
return await this.getEntity('ownersClassPath')
|
|
41
|
-
|
|
46
|
+
return await this.getEntity('ownersClassPath').updateBy(
|
|
47
|
+
'owner_id',
|
|
48
|
+
levelsSet.getOwnerId(),
|
|
49
|
+
{currentExp: levelsSet.currentExp}
|
|
50
|
+
);
|
|
42
51
|
}
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
async prepareSkillsInstancesList(skillsClasses)
|
|
53
|
+
async generateSkillsDataFromModels(skillsClasses)
|
|
46
54
|
{
|
|
47
55
|
// @TODO - BETA - Replace relations by constants on the registered-entities definition.
|
|
48
|
-
//
|
|
49
|
-
//
|
|
56
|
+
// This way we will be able to use the get method, save the entity in a variable and call the relations list
|
|
57
|
+
// from it.
|
|
50
58
|
let skillsModels = await this.getEntity('skill').loadAllWithRelations([
|
|
51
59
|
'skill_owner_conditions',
|
|
52
60
|
'skill_owner_effects',
|
|
53
61
|
'skill_target_effects'
|
|
54
62
|
]);
|
|
55
|
-
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
|
-
let skillsList = {};
|
|
59
|
-
for(let skillModel of skillsModels){
|
|
60
|
-
let skillClass = sc.hasOwn(skillsClasses, skillModel.type) ? skillsClasses[skillModel.type] : false;
|
|
61
|
-
if(!skillClass){
|
|
62
|
-
ErrorManager.error('Undefined skill type in skillsList:' + skillModel.type);
|
|
63
|
-
}
|
|
64
|
-
// force to use the same events manager instance used on the main package:
|
|
65
|
-
skillModel.events = this.events;
|
|
66
|
-
skillsList[skillModel.key] = {class: skillClass, data: skillModel};
|
|
67
|
-
}
|
|
68
|
-
return {skillsModels, skillsList};
|
|
63
|
+
return SkillsGenerator.dataFromSkillsModelsWithClasses(skillsModels, skillsClasses, this.events);
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
|
|
72
|
-
async prepareClassPathInstancesList(classPathClasses)
|
|
66
|
+
async generateClassPathInstances(classPathClasses)
|
|
73
67
|
{
|
|
74
|
-
let result = {};
|
|
75
68
|
// @TODO - BETA - Remove the executeCustomQuery.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
for(let classPathModel of classPathModels){
|
|
81
|
-
let classPathClass = ClassPath;
|
|
82
|
-
if(sc.hasOwn(classPathClasses, classPathModel.key)){
|
|
83
|
-
classPathClass = classPathClasses[classPathModel.key];
|
|
84
|
-
}
|
|
85
|
-
let classPathData = {class: classPathClass, data: classPathModel};
|
|
86
|
-
classPathModel.classPathLevels = this.getClassPathLevels(
|
|
87
|
-
classPathModel.skills_levels_set.skills_levels_set_levels
|
|
88
|
-
);
|
|
89
|
-
classPathModel.labelsByLevel = this.parseLabelsByLevels(classPathModel.skills_class_path_level_labels);
|
|
90
|
-
classPathsById[classPathModel.id] = classPathData;
|
|
91
|
-
classPathsByKey[classPathModel.key] = classPathData;
|
|
92
|
-
}
|
|
93
|
-
result = {classPathModels: classPathModels, classPathsById, classPathsByKey};
|
|
94
|
-
}
|
|
95
|
-
return result;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
parseLabelsByLevels(levelLabelsModel)
|
|
99
|
-
{
|
|
100
|
-
let labelsByLevel = {};
|
|
101
|
-
for(let labelData of levelLabelsModel){
|
|
102
|
-
labelsByLevel[labelData['label_level'].key] = labelData.label;
|
|
103
|
-
}
|
|
104
|
-
return labelsByLevel;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
getClassPathLevels(levelsModels)
|
|
108
|
-
{
|
|
109
|
-
let levels = {};
|
|
110
|
-
for(let levelData of levelsModels){
|
|
111
|
-
let levelModifiers = [];
|
|
112
|
-
if(levelData['level_modifiers'].length){
|
|
113
|
-
for(let modifierData of levelData['level_modifiers']){
|
|
114
|
-
let modifier = new Modifier(modifierData);
|
|
115
|
-
levelModifiers.push(modifier);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
levelData.modifiers = levelModifiers;
|
|
119
|
-
let levelKey = parseInt(levelData['key']);
|
|
120
|
-
levelData.key = levelKey;
|
|
121
|
-
levels[levelKey] = new Level(levelData);
|
|
122
|
-
}
|
|
123
|
-
return levels;
|
|
69
|
+
return ClassPathGenerator.fromClassPathModels(
|
|
70
|
+
await this.getEntity('classPath').executeCustomQuery('fullPathData'),
|
|
71
|
+
classPathClasses
|
|
72
|
+
);
|
|
124
73
|
}
|
|
125
74
|
|
|
126
75
|
async prepareClassPathData(owner, ownerIdProperty, classPathsListById, skillsClassesList)
|
|
@@ -132,11 +81,12 @@ class ModelsManager
|
|
|
132
81
|
return false;
|
|
133
82
|
}
|
|
134
83
|
let currentClassPath = classPathsListById[currentPlayerClassPath.class_path_id];
|
|
135
|
-
let skillsByLevel =
|
|
84
|
+
let skillsByLevel = SkillsGenerator.skillsByLevelsFromSkillsModels(
|
|
136
85
|
currentClassPath.data.skills_class_path_level_skills,
|
|
137
86
|
owner,
|
|
138
87
|
ownerIdProperty,
|
|
139
|
-
skillsClassesList
|
|
88
|
+
skillsClassesList,
|
|
89
|
+
this.events
|
|
140
90
|
);
|
|
141
91
|
return {
|
|
142
92
|
key: currentClassPath.data.key,
|
|
@@ -153,82 +103,6 @@ class ModelsManager
|
|
|
153
103
|
};
|
|
154
104
|
}
|
|
155
105
|
|
|
156
|
-
// @TODO - BETA - Create a skills generator class to replace this function.
|
|
157
|
-
parseSkillsByLevels(levelSkillsModel, owner, ownerIdProperty, skillsClassesList)
|
|
158
|
-
{
|
|
159
|
-
let skillsByLevel = {};
|
|
160
|
-
for(let skillData of levelSkillsModel){
|
|
161
|
-
let levelKey = parseInt(skillData['class_path_level'].key);
|
|
162
|
-
if(!sc.hasOwn(skillsByLevel, levelKey)){
|
|
163
|
-
skillsByLevel[levelKey] = {};
|
|
164
|
-
}
|
|
165
|
-
let skillModel = skillData.class_path_level_skill;
|
|
166
|
-
skillModel.owner = owner;
|
|
167
|
-
skillModel.ownerIdProperty = ownerIdProperty;
|
|
168
|
-
skillModel.events = this.events;
|
|
169
|
-
// @TODO - BETA - Make attack properties configurable.
|
|
170
|
-
if(sc.isTrue(skillModel, 'skill_attack')){
|
|
171
|
-
skillModel['attackProperties'] = skillModel['skill_attack'].attackProperties.split(',');
|
|
172
|
-
skillModel['defenseProperties'] = skillModel['skill_attack'].defenseProperties.split(',');
|
|
173
|
-
skillModel['aimProperties'] = skillModel['skill_attack'].aimProperties.split(',');
|
|
174
|
-
skillModel['dodgeProperties'] = skillModel['skill_attack'].dodgeProperties.split(',');
|
|
175
|
-
let attackProps = [
|
|
176
|
-
'affectedProperty',
|
|
177
|
-
'allowEffectBelowZero',
|
|
178
|
-
'hitDamage',
|
|
179
|
-
'applyDirectDamage',
|
|
180
|
-
'dodgeFullEnabled',
|
|
181
|
-
'dodgeOverAimSuccess',
|
|
182
|
-
'damageAffected',
|
|
183
|
-
'criticalAffected'
|
|
184
|
-
];
|
|
185
|
-
for(let i of attackProps){
|
|
186
|
-
skillModel[i] = skillModel['skill_attack'][i];
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
// @TODO - BETA - Make physical properties configurable.
|
|
190
|
-
if(sc.isTrue(skillModel, 'skill_physical_data')){
|
|
191
|
-
let physicalProps = [
|
|
192
|
-
'magnitude',
|
|
193
|
-
'objectWidth',
|
|
194
|
-
'objectHeight',
|
|
195
|
-
'validateTargetOnHit'
|
|
196
|
-
];
|
|
197
|
-
for(let i of physicalProps){
|
|
198
|
-
skillModel[i] = skillModel['skill_physical_data'][i];
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if(sc.isTrue(skillModel, 'skill_owner_conditions')){
|
|
202
|
-
skillModel.ownerConditions = [];
|
|
203
|
-
for(let conditionData of skillModel['skill_owner_conditions']){
|
|
204
|
-
conditionData['propertyKey'] = conditionData['property_key'];
|
|
205
|
-
let skillCondition = new Condition(conditionData);
|
|
206
|
-
skillModel.ownerConditions.push(skillCondition);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
if(sc.isTrue(skillModel, 'skill_owner_effects')){
|
|
210
|
-
// @NOTE: skill effects are just modifiers that will affect the skill owner.
|
|
211
|
-
let skillEffects = [];
|
|
212
|
-
for(let effectData of skillModel['skill_owner_effects']){
|
|
213
|
-
let effectModifier = new Modifier(effectData);
|
|
214
|
-
skillEffects.push(effectModifier);
|
|
215
|
-
}
|
|
216
|
-
skillModel.ownerEffects = skillEffects;
|
|
217
|
-
}
|
|
218
|
-
if(sc.isTrue(skillModel, 'skill_target_effects')){
|
|
219
|
-
// @NOTE: skill effects are just modifiers that will affect the skill owner.
|
|
220
|
-
let skillEffects = [];
|
|
221
|
-
for(let effectData of skillModel['skill_target_effects']){
|
|
222
|
-
let effectModifier = new Modifier(effectData);
|
|
223
|
-
skillEffects.push(effectModifier);
|
|
224
|
-
}
|
|
225
|
-
skillModel.targetEffects = skillEffects;
|
|
226
|
-
}
|
|
227
|
-
skillsByLevel[levelKey][skillModel.key] = new skillsClassesList[skillModel.key]['class'](skillModel);
|
|
228
|
-
}
|
|
229
|
-
return skillsByLevel;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
106
|
}
|
|
233
107
|
|
|
234
108
|
module.exports.ModelsManager = ModelsManager;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - ModifiersGenerator
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { Modifier } = require('@reldens/modifiers');
|
|
8
|
+
const { sc } = require('@reldens/utils');
|
|
9
|
+
|
|
10
|
+
class ModifiersGenerator
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
static fromModifiersModels(modifiersModels)
|
|
14
|
+
{
|
|
15
|
+
if(!sc.isArray(modifiersModels) || 0 === modifiersModels.length){
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
let modifiers = [];
|
|
19
|
+
for (let modifierModel of modifiersModels) {
|
|
20
|
+
let modifier = new Modifier(modifierModel);
|
|
21
|
+
modifiers.push(modifier);
|
|
22
|
+
}
|
|
23
|
+
return modifiers;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports.ModifiersGenerator = ModifiersGenerator;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - SkillsGenerator
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { ModifiersGenerator } = require('./modifiers-generator');
|
|
8
|
+
const { ConditionsGenerator } = require('./conditions-generator');
|
|
9
|
+
const { sc, ErrorManager} = require('@reldens/utils');
|
|
10
|
+
|
|
11
|
+
class SkillsGenerator
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
static dataFromSkillsModelsWithClasses(skillsModels, skillsClasses, events)
|
|
15
|
+
{
|
|
16
|
+
if(0 === skillsModels.length){
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
let skillsList = {};
|
|
20
|
+
for(let skillModel of skillsModels){
|
|
21
|
+
let skillClass = sc.hasOwn(skillsClasses, skillModel.type) ? skillsClasses[skillModel.type] : false;
|
|
22
|
+
if(!skillClass){
|
|
23
|
+
ErrorManager.error('Undefined skill type in skillsList:' + skillModel.type);
|
|
24
|
+
}
|
|
25
|
+
// force to use the same events manager instance used on the main package:
|
|
26
|
+
skillModel.events = events;
|
|
27
|
+
skillsList[skillModel.key] = {class: skillClass, data: skillModel};
|
|
28
|
+
}
|
|
29
|
+
return {skillsModels, skillsList};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static skillsByLevelsFromSkillsModels(levelSkillsModels, owner, ownerIdProperty, skillsClassesList, events)
|
|
33
|
+
{
|
|
34
|
+
if(!sc.isArray(levelSkillsModels) || 0 === levelSkillsModels.length){
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
let skillsByLevel = {};
|
|
38
|
+
for(let skillData of levelSkillsModels){
|
|
39
|
+
let levelKey = parseInt(skillData['class_path_level'].key);
|
|
40
|
+
if(!sc.hasOwn(skillsByLevel, levelKey)){
|
|
41
|
+
skillsByLevel[levelKey] = {};
|
|
42
|
+
}
|
|
43
|
+
let skillModel = skillData.class_path_level_skill;
|
|
44
|
+
skillModel.owner = owner;
|
|
45
|
+
skillModel.ownerIdProperty = ownerIdProperty;
|
|
46
|
+
skillModel.events = events;
|
|
47
|
+
this.enrichWithAttackData(skillModel);
|
|
48
|
+
this.enrichWithPhysicalData(skillModel);
|
|
49
|
+
skillModel.ownerConditions = ConditionsGenerator.fromConditionsModels(skillModel['skill_owner_conditions']);
|
|
50
|
+
// @NOTE: skill effects are modifiers that will affect the skill owner or target.
|
|
51
|
+
skillModel.ownerEffects = ModifiersGenerator.fromModifiersModels(skillModel['skill_owner_effects']);
|
|
52
|
+
skillModel.targetEffects = ModifiersGenerator.fromModifiersModels(skillModel['skill_target_effects']);
|
|
53
|
+
skillsByLevel[levelKey][skillModel.key] = new skillsClassesList[skillModel.key]['class'](skillModel);
|
|
54
|
+
}
|
|
55
|
+
return skillsByLevel;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static enrichWithPhysicalData(skillModel)
|
|
59
|
+
{
|
|
60
|
+
if(!sc.isTrue(skillModel, 'skill_physical_data')){
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// @TODO - BETA - Make physical properties configurable.
|
|
64
|
+
let physicalProps = [
|
|
65
|
+
'magnitude',
|
|
66
|
+
'objectWidth',
|
|
67
|
+
'objectHeight',
|
|
68
|
+
'validateTargetOnHit'
|
|
69
|
+
];
|
|
70
|
+
for(let i of physicalProps){
|
|
71
|
+
skillModel[i] = skillModel['skill_physical_data'][i];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static enrichWithAttackData(skillModel)
|
|
76
|
+
{
|
|
77
|
+
if(!sc.isTrue(skillModel, 'skill_attack')){
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
// @TODO - BETA - Make attack properties configurable.
|
|
81
|
+
skillModel['attackProperties'] = skillModel['skill_attack'].attackProperties.split(',');
|
|
82
|
+
skillModel['defenseProperties'] = skillModel['skill_attack'].defenseProperties.split(',');
|
|
83
|
+
skillModel['aimProperties'] = skillModel['skill_attack'].aimProperties.split(',');
|
|
84
|
+
skillModel['dodgeProperties'] = skillModel['skill_attack'].dodgeProperties.split(',');
|
|
85
|
+
let attackProps = [
|
|
86
|
+
'affectedProperty',
|
|
87
|
+
'allowEffectBelowZero',
|
|
88
|
+
'hitDamage',
|
|
89
|
+
'applyDirectDamage',
|
|
90
|
+
'dodgeFullEnabled',
|
|
91
|
+
'dodgeOverAimSuccess',
|
|
92
|
+
'damageAffected',
|
|
93
|
+
'criticalAffected'
|
|
94
|
+
];
|
|
95
|
+
for(let i of attackProps){
|
|
96
|
+
skillModel[i] = skillModel['skill_attack'][i];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports.SkillsGenerator = SkillsGenerator;
|
package/lib/skill.js
CHANGED
|
@@ -178,12 +178,7 @@ class Skill
|
|
|
178
178
|
// custom conditions:
|
|
179
179
|
!this.onExecuteConditions()
|
|
180
180
|
// range:
|
|
181
|
-
|| (
|
|
182
|
-
this.rangeAutomaticValidation
|
|
183
|
-
&& this.rangePropertyX
|
|
184
|
-
&& this.rangePropertyY
|
|
185
|
-
&& !(await this.validateRange(target))
|
|
186
|
-
)
|
|
181
|
+
|| await this.isValidRange(target)
|
|
187
182
|
// cast validation:
|
|
188
183
|
|| (this.autoValidation && !this.validate())
|
|
189
184
|
// @TODO - BETA - Auto validation doesn't work, check ActionsMessageActions.parseMessageAndRunActions.
|
|
@@ -211,6 +206,14 @@ class Skill
|
|
|
211
206
|
return skillLogicResult;
|
|
212
207
|
}
|
|
213
208
|
|
|
209
|
+
async isValidRange(target)
|
|
210
|
+
{
|
|
211
|
+
return this.rangeAutomaticValidation
|
|
212
|
+
&& this.rangePropertyX
|
|
213
|
+
&& this.rangePropertyY
|
|
214
|
+
&& !(await this.validateRange(target));
|
|
215
|
+
}
|
|
216
|
+
|
|
214
217
|
async finishExecution(target)
|
|
215
218
|
{
|
|
216
219
|
await this.fireEvent(SkillsEvents.SKILL_BEFORE_RUN_LOGIC, this, target);
|
|
@@ -238,21 +241,21 @@ class Skill
|
|
|
238
241
|
|
|
239
242
|
applyCriticalValue(normalValue)
|
|
240
243
|
{
|
|
241
|
-
if(this.isCritical()){
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
if(!this.isCritical()){
|
|
245
|
+
return normalValue;
|
|
246
|
+
}
|
|
247
|
+
if(this.criticalMultiplier){
|
|
248
|
+
normalValue = normalValue * this.criticalMultiplier;
|
|
249
|
+
}
|
|
250
|
+
if(this.criticalFixedValue){
|
|
251
|
+
normalValue = normalValue + this.criticalFixedValue;
|
|
248
252
|
}
|
|
249
253
|
return normalValue;
|
|
250
254
|
}
|
|
251
255
|
|
|
252
256
|
getCriticalDiff(normalValue)
|
|
253
257
|
{
|
|
254
|
-
|
|
255
|
-
return criticalValue - normalValue;
|
|
258
|
+
return this.applyCriticalValue(normalValue) - normalValue;
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
isCritical()
|
|
@@ -260,8 +263,7 @@ class Skill
|
|
|
260
263
|
if(this.criticalChance <= 0){
|
|
261
264
|
return false;
|
|
262
265
|
}
|
|
263
|
-
|
|
264
|
-
return rand > this.criticalChance;
|
|
266
|
+
return this.criticalChance < this.randomInteger(1, 100);
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
randomInteger(min, max)
|
package/lib/types/attack.js
CHANGED
|
@@ -18,7 +18,7 @@ class Attack extends Skill
|
|
|
18
18
|
{
|
|
19
19
|
super(props);
|
|
20
20
|
this.type = SkillsConst.SKILL_TYPE_ATTACK;
|
|
21
|
-
if(!sc.
|
|
21
|
+
if(!sc.get(props, 'affectedProperty', false)){
|
|
22
22
|
ErrorManager.error('Missing skill affectedProperty to which the result damage will be applied.');
|
|
23
23
|
}
|
|
24
24
|
// the affected property is the one to which the damage calculation will have effect:
|
|
@@ -39,7 +39,7 @@ class Attack extends Skill
|
|
|
39
39
|
// specify if the damage or the critical will be affected by the aim and dodge properties:
|
|
40
40
|
this.damageAffected = sc.hasOwn(props, 'damageAffected') ? props.damageAffected : false;
|
|
41
41
|
this.criticalAffected = sc.hasOwn(props, 'criticalAffected') ? props.criticalAffected : false;
|
|
42
|
-
// properties
|
|
42
|
+
// properties total calculator operators:
|
|
43
43
|
// example: {
|
|
44
44
|
// {key: 'propName1', op: ModifierConst.OPS.INC},
|
|
45
45
|
// {key: 'propName2', op: ModifierConst.OPS.DEC}
|
|
@@ -67,68 +67,71 @@ class Attack extends Skill
|
|
|
67
67
|
return false;
|
|
68
68
|
}
|
|
69
69
|
let affectedPropertyValue = this.getAffectedPropertyValue(target);
|
|
70
|
-
if(this.allowEffectBelowZero
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
await this.fireEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, this, target, damage, modifiedValue);
|
|
111
|
-
this.setAffectedPropertyValue(target, modifiedValue);
|
|
70
|
+
if(!this.allowEffectBelowZero && 0 >= affectedPropertyValue){
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
// dodge proportion:
|
|
74
|
+
let dodgeAimDiff = this.getDiffProportion(ownerAim, targetDodge);
|
|
75
|
+
let damage = this.applyDirectDamage
|
|
76
|
+
? this.hitDamage // 100%
|
|
77
|
+
: this.calculateProportionDamage(target, this.hitDamage, targetDodge, ownerAim, dodgeAimDiff);
|
|
78
|
+
// critical calculation:
|
|
79
|
+
damage = damage + this.calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff);
|
|
80
|
+
// avoid getting below 0:
|
|
81
|
+
let modifiedValue = (!this.allowEffectBelowZero && affectedPropertyValue < damage)
|
|
82
|
+
? 0
|
|
83
|
+
: affectedPropertyValue - damage;
|
|
84
|
+
this.setAffectedPropertyValue(target, modifiedValue);
|
|
85
|
+
await this.fireEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, this, target, damage, modifiedValue);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff)
|
|
89
|
+
{
|
|
90
|
+
let criticalValue = this.getCriticalDiff(damage);
|
|
91
|
+
if(!this.criticalAffected || targetDodge > ownerAim){
|
|
92
|
+
return criticalValue;
|
|
93
|
+
}
|
|
94
|
+
// calculate dodge proportion over critical damage and remove it from the critical total:
|
|
95
|
+
return criticalValue - (Math.floor((criticalValue * dodgeAimDiff / 100)));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
calculateProportionDamage(target, damage, targetDodge, ownerAim, dodgeAimDiff)
|
|
99
|
+
{
|
|
100
|
+
let ownerAtk = this.getPropertiesTotal(this.owner, this.attackProperties);
|
|
101
|
+
let targetDef = this.getPropertiesTotal(target, this.defenseProperties);
|
|
102
|
+
// atk and def calculation to affect the hit damage:
|
|
103
|
+
let diff = ownerAtk - targetDef;
|
|
104
|
+
if(diff > 0){
|
|
105
|
+
let p = diff < targetDef ? (diff * 100 / targetDef) : 99;
|
|
106
|
+
p = p > 99 ? 99 : p; // maximum modifier percentage to add.
|
|
107
|
+
let additionalDamage = Math.ceil((p * damage / 100));
|
|
108
|
+
damage = damage + additionalDamage;
|
|
112
109
|
}
|
|
110
|
+
if(diff < 0){
|
|
111
|
+
let p = -diff < ownerAtk ? (-diff * 100 / ownerAtk) : 99;
|
|
112
|
+
p = p > 99 ? 99 : p; // maximum modifier percentage to remove.
|
|
113
|
+
let reduceDamage = Math.floor((p * damage / 100));
|
|
114
|
+
damage = damage - reduceDamage;
|
|
115
|
+
}
|
|
116
|
+
if(this.damageAffected && targetDodge > ownerAim){
|
|
117
|
+
// calculate dodge proportion over damage and remove it from the total:
|
|
118
|
+
let damageProportion = Math.floor((damage * dodgeAimDiff / 100));
|
|
119
|
+
damage = damage - damageProportion;
|
|
120
|
+
}
|
|
121
|
+
return damage;
|
|
113
122
|
}
|
|
114
123
|
|
|
115
124
|
getPropertiesTotal(object, propertiesArray)
|
|
116
125
|
{
|
|
126
|
+
if(0 === propertiesArray.length){
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
117
129
|
let totalValue = 0;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
totalValue,
|
|
124
|
-
this.propertiesTotalOperators[prop],
|
|
125
|
-
propValue
|
|
126
|
-
);
|
|
127
|
-
} else {
|
|
128
|
-
// default operation:
|
|
129
|
-
totalValue = totalValue + propValue;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
130
|
+
for(let prop of propertiesArray){
|
|
131
|
+
let propValue = this.propertyManager.getPropertyValue(object, prop);
|
|
132
|
+
totalValue = sc.hasOwn(this.propertiesTotalOperators, prop)
|
|
133
|
+
? this.calculator.calculateNewValue(totalValue, this.propertiesTotalOperators[prop], propValue)
|
|
134
|
+
: totalValue + propValue;
|
|
132
135
|
}
|
|
133
136
|
return totalValue;
|
|
134
137
|
}
|
|
@@ -20,13 +20,13 @@ class PhysicalSkillRunner
|
|
|
20
20
|
static async executeOnHit(target, skill, skillType, runSkillLogicCallback)
|
|
21
21
|
{
|
|
22
22
|
await skill.fireEvent(skillType, skill, target);
|
|
23
|
-
if(
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
return await runSkillLogicCallback(target);
|
|
23
|
+
if(skill.validateTargetOnHit && target !== skill.target){
|
|
24
|
+
return false;
|
|
28
25
|
}
|
|
29
|
-
|
|
26
|
+
if('function' !== typeof runSkillLogicCallback){
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return await runSkillLogicCallback(target);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
}
|