@reldens/skills 0.56.0 → 0.58.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/.github/workflows/npm-publish.yml +135 -0
- package/CLAUDE.md +619 -619
- package/README.md +353 -353
- package/index.js +19 -19
- package/lib/class-path.js +143 -143
- package/lib/client/receiver.js +86 -86
- package/lib/constants.js +67 -67
- package/lib/level.js +31 -31
- package/lib/levels-set.js +276 -276
- package/lib/server/sender.js +180 -180
- package/lib/server.js +53 -53
- package/lib/skill.js +345 -345
- package/lib/skills-events.js +45 -45
- package/lib/types/attack.js +202 -202
- package/lib/types/effect.js +52 -52
- package/lib/types/physical-attack.js +46 -46
- package/lib/types/physical-effect.js +46 -46
- package/lib/types/physical-properties-validator.js +35 -35
- package/lib/types/physical-skill-runner.js +41 -41
- package/package.json +52 -52
- package/tests/unit/test-class-path.js +4 -3
- package/tests/unit/test-levels-set.js +4 -3
- package/tests/unit/test-skill.js +4 -3
- package/tests/unit/types/test-attack.js +4 -3
- package/tests/unit/types/test-effect.js +4 -3
package/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
SkillsEvents: require('./lib/skills-events'),
|
|
9
|
-
Receiver: require('./lib/client/receiver'),
|
|
10
|
-
ClassPath: require('./lib/class-path'),
|
|
11
|
-
LevelsSet: require('./lib/levels-set'),
|
|
12
|
-
Level: require('./lib/level'),
|
|
13
|
-
Skill: require('./lib/skill'),
|
|
14
|
-
SkillConst: require('./lib/constants'),
|
|
15
|
-
Attack: require('./lib/types/attack'),
|
|
16
|
-
Effect: require('./lib/types/effect'),
|
|
17
|
-
PhysicalAttack: require('./lib/types/physical-attack'),
|
|
18
|
-
PhysicalEffect: require('./lib/types/physical-effect')
|
|
19
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
SkillsEvents: require('./lib/skills-events'),
|
|
9
|
+
Receiver: require('./lib/client/receiver'),
|
|
10
|
+
ClassPath: require('./lib/class-path'),
|
|
11
|
+
LevelsSet: require('./lib/levels-set'),
|
|
12
|
+
Level: require('./lib/level'),
|
|
13
|
+
Skill: require('./lib/skill'),
|
|
14
|
+
SkillConst: require('./lib/constants'),
|
|
15
|
+
Attack: require('./lib/types/attack'),
|
|
16
|
+
Effect: require('./lib/types/effect'),
|
|
17
|
+
PhysicalAttack: require('./lib/types/physical-attack'),
|
|
18
|
+
PhysicalEffect: require('./lib/types/physical-effect')
|
|
19
|
+
};
|
package/lib/class-path.js
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - Class Path
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const LevelsSet = require('./levels-set');
|
|
8
|
-
const SkillsEvents = require('./skills-events');
|
|
9
|
-
const { Logger, sc } = require('@reldens/utils');
|
|
10
|
-
|
|
11
|
-
class ClassPath extends LevelsSet
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
async init(props)
|
|
15
|
-
{
|
|
16
|
-
await super.init(props);
|
|
17
|
-
let key = sc.get(props, 'key');
|
|
18
|
-
if(!key){
|
|
19
|
-
Logger.critical('Undefined key for class path.');
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
// key is the code for class-path itself and label y the name that can be used for display:
|
|
23
|
-
this.key = key;
|
|
24
|
-
// the label will be the default display name for the class path:
|
|
25
|
-
this.label = sc.get(props, 'label', key);
|
|
26
|
-
// labelsByLevel can be an object of {levelKey: 'path level label'}, the current path level display name.
|
|
27
|
-
// for example: the path "Warrior" (this.label), at level 10 could become "Experienced Warrior".
|
|
28
|
-
this.labelsByLevel = sc.get(props, 'labelsByLevel', false);
|
|
29
|
-
// the current label is used for the current object instance:
|
|
30
|
-
this.currentLabel = sc.get(props, 'currentLabel', this.getCurrentLabel());
|
|
31
|
-
// skillsByLevel can be an object of {levelKey: [skillInstances]}, these will be all the skills available.
|
|
32
|
-
this.skillsByLevel = sc.get(props, 'skillsByLevel', false);
|
|
33
|
-
this.skillsByLevelKeys = this.getSkillsByLevelKeys();
|
|
34
|
-
// the set of skills for the current object instance:
|
|
35
|
-
await this.setOwnerSkills(sc.get(props, 'currentSkills', false));
|
|
36
|
-
// the affected property is the one to which the damage calculation will have effect:
|
|
37
|
-
this.affectedProperty = sc.get(props, 'affectedProperty', false);
|
|
38
|
-
await this.fireEvent(SkillsEvents.INIT_CLASS_PATH_END, this);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getCurrentLabel()
|
|
42
|
-
{
|
|
43
|
-
return sc.hasOwn(this.labelsByLevel, this.currentLevel)
|
|
44
|
-
? this.labelsByLevel[this.currentLevel]
|
|
45
|
-
: this.loopLevelsForLabel();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
loopLevelsForLabel()
|
|
49
|
-
{
|
|
50
|
-
let label = this.label;
|
|
51
|
-
for(let i of Object.keys(this.labelsByLevel)){
|
|
52
|
-
if(i <= this.currentLevel){
|
|
53
|
-
label = this.labelsByLevel[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return label;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async levelUp()
|
|
60
|
-
{
|
|
61
|
-
// @NOTE: the level will be increased in the parent LevelSet call.
|
|
62
|
-
let nextLevel = this.currentLevel + 1;
|
|
63
|
-
if(sc.hasOwn(this.skillsByLevel, nextLevel)){
|
|
64
|
-
await this.addSkills(this.skillsByLevel[nextLevel]);
|
|
65
|
-
}
|
|
66
|
-
if(sc.hasOwn(this.labelsByLevel, nextLevel)){
|
|
67
|
-
this.currentLabel = this.labelsByLevel[nextLevel];
|
|
68
|
-
}
|
|
69
|
-
await super.levelUp();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async levelDown()
|
|
73
|
-
{
|
|
74
|
-
// @NOTE: the level will be decreased in the parent LevelSet call.
|
|
75
|
-
if(sc.hasOwn(this.skillsByLevel, this.currentLevel)){
|
|
76
|
-
await this.removeSkills(this.skillsByLevel[this.currentLevel]);
|
|
77
|
-
}
|
|
78
|
-
let previousLevel = this.currentLevel - 1;
|
|
79
|
-
if(sc.hasOwn(this.labelsByLevel, previousLevel)){
|
|
80
|
-
this.currentLabel = this.labelsByLevel[previousLevel];
|
|
81
|
-
}
|
|
82
|
-
await super.levelDown();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async addSkills(skills)
|
|
86
|
-
{
|
|
87
|
-
await this.fireEvent(SkillsEvents.ADD_SKILLS_BEFORE, this, skills);
|
|
88
|
-
for(let i of Object.keys(skills)){
|
|
89
|
-
let skill = skills[i];
|
|
90
|
-
this.currentSkills[skill.key] = skill;
|
|
91
|
-
}
|
|
92
|
-
await this.fireEvent(SkillsEvents.ADD_SKILLS_AFTER, this, skills);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async removeSkills(skills)
|
|
96
|
-
{
|
|
97
|
-
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_BEFORE, this, skills);
|
|
98
|
-
for(let i of Object.keys(skills)){
|
|
99
|
-
let skillOrKey = skills[i];
|
|
100
|
-
let skillKey = 'string' === typeof skillOrKey ? skillOrKey : skillOrKey.key;
|
|
101
|
-
delete this.currentSkills[skillKey];
|
|
102
|
-
}
|
|
103
|
-
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_AFTER, this, skills);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async setOwnerSkills(skills)
|
|
107
|
-
{
|
|
108
|
-
if(skills){
|
|
109
|
-
this.currentSkills = skills;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
this.currentSkills = {};
|
|
113
|
-
for(let i of Object.keys(this.levels)){
|
|
114
|
-
let level = this.levels[i];
|
|
115
|
-
if(this.skillsByLevel && sc.hasOwn(this.skillsByLevel, level.key) && level.key <= this.currentLevel){
|
|
116
|
-
await this.addSkills(this.skillsByLevel[level.key]);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
await this.fireEvent(SkillsEvents.SET_SKILLS, this);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
getSkillsByLevelKeys()
|
|
123
|
-
{
|
|
124
|
-
if(!this.skillsByLevel){
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
let skillsByLevelKeys = {};
|
|
128
|
-
for(let i of Object.keys(this.skillsByLevel)){
|
|
129
|
-
let level = this.skillsByLevel[i];
|
|
130
|
-
if(!sc.hasOwn(skillsByLevelKeys, level)){
|
|
131
|
-
skillsByLevelKeys[i] = [];
|
|
132
|
-
}
|
|
133
|
-
for(let a of Object.keys(level)){
|
|
134
|
-
let skill = level[a];
|
|
135
|
-
skillsByLevelKeys[i].push(skill.key);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return skillsByLevelKeys;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
module.exports = ClassPath;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - Class Path
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const LevelsSet = require('./levels-set');
|
|
8
|
+
const SkillsEvents = require('./skills-events');
|
|
9
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
10
|
+
|
|
11
|
+
class ClassPath extends LevelsSet
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
async init(props)
|
|
15
|
+
{
|
|
16
|
+
await super.init(props);
|
|
17
|
+
let key = sc.get(props, 'key');
|
|
18
|
+
if(!key){
|
|
19
|
+
Logger.critical('Undefined key for class path.');
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
// key is the code for class-path itself and label y the name that can be used for display:
|
|
23
|
+
this.key = key;
|
|
24
|
+
// the label will be the default display name for the class path:
|
|
25
|
+
this.label = sc.get(props, 'label', key);
|
|
26
|
+
// labelsByLevel can be an object of {levelKey: 'path level label'}, the current path level display name.
|
|
27
|
+
// for example: the path "Warrior" (this.label), at level 10 could become "Experienced Warrior".
|
|
28
|
+
this.labelsByLevel = sc.get(props, 'labelsByLevel', false);
|
|
29
|
+
// the current label is used for the current object instance:
|
|
30
|
+
this.currentLabel = sc.get(props, 'currentLabel', this.getCurrentLabel());
|
|
31
|
+
// skillsByLevel can be an object of {levelKey: [skillInstances]}, these will be all the skills available.
|
|
32
|
+
this.skillsByLevel = sc.get(props, 'skillsByLevel', false);
|
|
33
|
+
this.skillsByLevelKeys = this.getSkillsByLevelKeys();
|
|
34
|
+
// the set of skills for the current object instance:
|
|
35
|
+
await this.setOwnerSkills(sc.get(props, 'currentSkills', false));
|
|
36
|
+
// the affected property is the one to which the damage calculation will have effect:
|
|
37
|
+
this.affectedProperty = sc.get(props, 'affectedProperty', false);
|
|
38
|
+
await this.fireEvent(SkillsEvents.INIT_CLASS_PATH_END, this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getCurrentLabel()
|
|
42
|
+
{
|
|
43
|
+
return sc.hasOwn(this.labelsByLevel, this.currentLevel)
|
|
44
|
+
? this.labelsByLevel[this.currentLevel]
|
|
45
|
+
: this.loopLevelsForLabel();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
loopLevelsForLabel()
|
|
49
|
+
{
|
|
50
|
+
let label = this.label;
|
|
51
|
+
for(let i of Object.keys(this.labelsByLevel)){
|
|
52
|
+
if(i <= this.currentLevel){
|
|
53
|
+
label = this.labelsByLevel[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return label;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async levelUp()
|
|
60
|
+
{
|
|
61
|
+
// @NOTE: the level will be increased in the parent LevelSet call.
|
|
62
|
+
let nextLevel = this.currentLevel + 1;
|
|
63
|
+
if(sc.hasOwn(this.skillsByLevel, nextLevel)){
|
|
64
|
+
await this.addSkills(this.skillsByLevel[nextLevel]);
|
|
65
|
+
}
|
|
66
|
+
if(sc.hasOwn(this.labelsByLevel, nextLevel)){
|
|
67
|
+
this.currentLabel = this.labelsByLevel[nextLevel];
|
|
68
|
+
}
|
|
69
|
+
await super.levelUp();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async levelDown()
|
|
73
|
+
{
|
|
74
|
+
// @NOTE: the level will be decreased in the parent LevelSet call.
|
|
75
|
+
if(sc.hasOwn(this.skillsByLevel, this.currentLevel)){
|
|
76
|
+
await this.removeSkills(this.skillsByLevel[this.currentLevel]);
|
|
77
|
+
}
|
|
78
|
+
let previousLevel = this.currentLevel - 1;
|
|
79
|
+
if(sc.hasOwn(this.labelsByLevel, previousLevel)){
|
|
80
|
+
this.currentLabel = this.labelsByLevel[previousLevel];
|
|
81
|
+
}
|
|
82
|
+
await super.levelDown();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async addSkills(skills)
|
|
86
|
+
{
|
|
87
|
+
await this.fireEvent(SkillsEvents.ADD_SKILLS_BEFORE, this, skills);
|
|
88
|
+
for(let i of Object.keys(skills)){
|
|
89
|
+
let skill = skills[i];
|
|
90
|
+
this.currentSkills[skill.key] = skill;
|
|
91
|
+
}
|
|
92
|
+
await this.fireEvent(SkillsEvents.ADD_SKILLS_AFTER, this, skills);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async removeSkills(skills)
|
|
96
|
+
{
|
|
97
|
+
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_BEFORE, this, skills);
|
|
98
|
+
for(let i of Object.keys(skills)){
|
|
99
|
+
let skillOrKey = skills[i];
|
|
100
|
+
let skillKey = 'string' === typeof skillOrKey ? skillOrKey : skillOrKey.key;
|
|
101
|
+
delete this.currentSkills[skillKey];
|
|
102
|
+
}
|
|
103
|
+
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_AFTER, this, skills);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async setOwnerSkills(skills)
|
|
107
|
+
{
|
|
108
|
+
if(skills){
|
|
109
|
+
this.currentSkills = skills;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.currentSkills = {};
|
|
113
|
+
for(let i of Object.keys(this.levels)){
|
|
114
|
+
let level = this.levels[i];
|
|
115
|
+
if(this.skillsByLevel && sc.hasOwn(this.skillsByLevel, level.key) && level.key <= this.currentLevel){
|
|
116
|
+
await this.addSkills(this.skillsByLevel[level.key]);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
await this.fireEvent(SkillsEvents.SET_SKILLS, this);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getSkillsByLevelKeys()
|
|
123
|
+
{
|
|
124
|
+
if(!this.skillsByLevel){
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
let skillsByLevelKeys = {};
|
|
128
|
+
for(let i of Object.keys(this.skillsByLevel)){
|
|
129
|
+
let level = this.skillsByLevel[i];
|
|
130
|
+
if(!sc.hasOwn(skillsByLevelKeys, level)){
|
|
131
|
+
skillsByLevelKeys[i] = [];
|
|
132
|
+
}
|
|
133
|
+
for(let a of Object.keys(level)){
|
|
134
|
+
let skill = level[a];
|
|
135
|
+
skillsByLevelKeys[i].push(skill.key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return skillsByLevelKeys;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
module.exports = ClassPath;
|
package/lib/client/receiver.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - Receiver
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const SkillConst = require('../constants');
|
|
8
|
-
const { Logger, sc } = require('@reldens/utils');
|
|
9
|
-
|
|
10
|
-
class Receiver
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
constructor(props)
|
|
14
|
-
{
|
|
15
|
-
if(!sc.hasOwn(props, 'owner')){
|
|
16
|
-
Logger.critical('Undefined owner.');
|
|
17
|
-
}
|
|
18
|
-
if(props.owner && typeof props.owner.getPosition !== 'function'){
|
|
19
|
-
Logger.critical('Undefined owner position method.');
|
|
20
|
-
}
|
|
21
|
-
this.actions = sc.get(props, 'actions', {});
|
|
22
|
-
if(!sc.hasOwn(props, 'avoidDefaults') || !props['avoidDefaults']){
|
|
23
|
-
this.setDefaultMethods();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
setDefaultMethods()
|
|
28
|
-
{
|
|
29
|
-
this.actions[SkillConst.ACTION_INIT_LEVEL_SET_START] = 'onInitLevelSetStart';
|
|
30
|
-
this.actions[SkillConst.ACTION_INIT_LEVEL_SET_END] = 'onInitLevelSetEnd';
|
|
31
|
-
this.actions[SkillConst.ACTION_INIT_CLASS_PATH_END] = 'onInitClassPathEnd';
|
|
32
|
-
this.actions[SkillConst.ACTION_LOADED_OWNER_SKILLS] = 'onLoadedOwnerSkills';
|
|
33
|
-
this.actions[SkillConst.ACTION_SET_SKILLS] = 'onSetSkills';
|
|
34
|
-
this.actions[SkillConst.ACTION_SET_LEVELS] = 'onSetLevels';
|
|
35
|
-
this.actions[SkillConst.ACTION_ADD_SKILLS_BEFORE] = 'onAddSkillsBefore';
|
|
36
|
-
this.actions[SkillConst.ACTION_ADD_SKILLS_AFTER] = 'onAddSkillsAfter';
|
|
37
|
-
this.actions[SkillConst.ACTION_REMOVE_SKILLS_BEFORE] = 'onRemoveSkillsBefore';
|
|
38
|
-
this.actions[SkillConst.ACTION_REMOVE_SKILLS_AFTER] = 'onRemoveSkillsAfter';
|
|
39
|
-
this.actions[SkillConst.ACTION_VALIDATE_BEFORE] = 'onValidateBefore';
|
|
40
|
-
this.actions[SkillConst.ACTION_VALIDATE_SUCCESS] = 'onValidateSuccess';
|
|
41
|
-
this.actions[SkillConst.ACTION_VALIDATE_FAIL] = 'onValidateFail';
|
|
42
|
-
this.actions[SkillConst.ACTION_EXECUTING_SKILL] = 'onExecutingSkill';
|
|
43
|
-
this.actions[SkillConst.ACTION_LEVEL_EXPERIENCE_ADDED] = 'onLevelExperienceAdded';
|
|
44
|
-
this.actions[SkillConst.ACTION_LEVEL_UP] = 'onLevelUp';
|
|
45
|
-
this.actions[SkillConst.ACTION_LEVEL_DOWN] = 'onLevelDown';
|
|
46
|
-
this.actions[SkillConst.ACTION_LEVEL_APPLY_MODIFIERS] = 'onLevelApplyModifiers';
|
|
47
|
-
this.actions[SkillConst.ACTION_SKILL_BEFORE_IN_RANGE] = 'onSkillBeforeInRange';
|
|
48
|
-
this.actions[SkillConst.ACTION_SKILL_AFTER_IN_RANGE] = 'onSkillAfterInRange';
|
|
49
|
-
this.actions[SkillConst.ACTION_SKILL_BEFORE_EXECUTE] = 'onSkillBeforeExecute';
|
|
50
|
-
this.actions[SkillConst.ACTION_SKILL_AFTER_EXECUTE] = 'onSkillAfterExecute';
|
|
51
|
-
this.actions[SkillConst.ACTION_SKILL_BEFORE_CAST] = 'onSkillBeforeCast';
|
|
52
|
-
this.actions[SkillConst.ACTION_SKILL_AFTER_CAST] = 'onSkillAfterCast';
|
|
53
|
-
this.actions[SkillConst.ACTION_SKILL_ATTACK_APPLY_DAMAGE] = 'onSkillAttackApplyDamage';
|
|
54
|
-
this.actions[SkillConst.ACTION_SKILL_BEFORE_RUN_LOGIC] = 'onSkillBeforeRunLogic';
|
|
55
|
-
this.actions[SkillConst.ACTION_SKILL_AFTER_RUN_LOGIC] = 'onSkillAfterRunLogic';
|
|
56
|
-
this.actions[SkillConst.ACTION_SKILL_PHYSICAL_ATTACK_HIT] = 'onSkillPhysicalAttackHit';
|
|
57
|
-
this.actions[SkillConst.ACTION_SKILL_PHYSICAL_EFFECT_HIT] = 'onSkillPhysicalEffectHit';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
processMessage(message)
|
|
61
|
-
{
|
|
62
|
-
// don't validate the message if the action prefix is not present or at the beginning of the message action:
|
|
63
|
-
if(!this.isValidMessage(message)){
|
|
64
|
-
// Logger.error(['CHECK NOT AN SKILLS ACTION!', message.act]);
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
if(!sc.hasOwn(this.actions, message.act)){
|
|
68
|
-
Logger.error('Skills action not found', message.act);
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if(!sc.isFunction(this[this.actions[message.act]])){
|
|
72
|
-
// for now, I'm leaving this a silent return (will probably end up making the error log configurable):
|
|
73
|
-
Logger.error('Skills action is not a function', message.act);
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
this[this.actions[message.act]](message);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
isValidMessage(message)
|
|
80
|
-
{
|
|
81
|
-
return 0 === message.act.indexOf(SkillConst.ACTIONS_PREF);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = Receiver;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - Receiver
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const SkillConst = require('../constants');
|
|
8
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
9
|
+
|
|
10
|
+
class Receiver
|
|
11
|
+
{
|
|
12
|
+
|
|
13
|
+
constructor(props)
|
|
14
|
+
{
|
|
15
|
+
if(!sc.hasOwn(props, 'owner')){
|
|
16
|
+
Logger.critical('Undefined owner.');
|
|
17
|
+
}
|
|
18
|
+
if(props.owner && typeof props.owner.getPosition !== 'function'){
|
|
19
|
+
Logger.critical('Undefined owner position method.');
|
|
20
|
+
}
|
|
21
|
+
this.actions = sc.get(props, 'actions', {});
|
|
22
|
+
if(!sc.hasOwn(props, 'avoidDefaults') || !props['avoidDefaults']){
|
|
23
|
+
this.setDefaultMethods();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
setDefaultMethods()
|
|
28
|
+
{
|
|
29
|
+
this.actions[SkillConst.ACTION_INIT_LEVEL_SET_START] = 'onInitLevelSetStart';
|
|
30
|
+
this.actions[SkillConst.ACTION_INIT_LEVEL_SET_END] = 'onInitLevelSetEnd';
|
|
31
|
+
this.actions[SkillConst.ACTION_INIT_CLASS_PATH_END] = 'onInitClassPathEnd';
|
|
32
|
+
this.actions[SkillConst.ACTION_LOADED_OWNER_SKILLS] = 'onLoadedOwnerSkills';
|
|
33
|
+
this.actions[SkillConst.ACTION_SET_SKILLS] = 'onSetSkills';
|
|
34
|
+
this.actions[SkillConst.ACTION_SET_LEVELS] = 'onSetLevels';
|
|
35
|
+
this.actions[SkillConst.ACTION_ADD_SKILLS_BEFORE] = 'onAddSkillsBefore';
|
|
36
|
+
this.actions[SkillConst.ACTION_ADD_SKILLS_AFTER] = 'onAddSkillsAfter';
|
|
37
|
+
this.actions[SkillConst.ACTION_REMOVE_SKILLS_BEFORE] = 'onRemoveSkillsBefore';
|
|
38
|
+
this.actions[SkillConst.ACTION_REMOVE_SKILLS_AFTER] = 'onRemoveSkillsAfter';
|
|
39
|
+
this.actions[SkillConst.ACTION_VALIDATE_BEFORE] = 'onValidateBefore';
|
|
40
|
+
this.actions[SkillConst.ACTION_VALIDATE_SUCCESS] = 'onValidateSuccess';
|
|
41
|
+
this.actions[SkillConst.ACTION_VALIDATE_FAIL] = 'onValidateFail';
|
|
42
|
+
this.actions[SkillConst.ACTION_EXECUTING_SKILL] = 'onExecutingSkill';
|
|
43
|
+
this.actions[SkillConst.ACTION_LEVEL_EXPERIENCE_ADDED] = 'onLevelExperienceAdded';
|
|
44
|
+
this.actions[SkillConst.ACTION_LEVEL_UP] = 'onLevelUp';
|
|
45
|
+
this.actions[SkillConst.ACTION_LEVEL_DOWN] = 'onLevelDown';
|
|
46
|
+
this.actions[SkillConst.ACTION_LEVEL_APPLY_MODIFIERS] = 'onLevelApplyModifiers';
|
|
47
|
+
this.actions[SkillConst.ACTION_SKILL_BEFORE_IN_RANGE] = 'onSkillBeforeInRange';
|
|
48
|
+
this.actions[SkillConst.ACTION_SKILL_AFTER_IN_RANGE] = 'onSkillAfterInRange';
|
|
49
|
+
this.actions[SkillConst.ACTION_SKILL_BEFORE_EXECUTE] = 'onSkillBeforeExecute';
|
|
50
|
+
this.actions[SkillConst.ACTION_SKILL_AFTER_EXECUTE] = 'onSkillAfterExecute';
|
|
51
|
+
this.actions[SkillConst.ACTION_SKILL_BEFORE_CAST] = 'onSkillBeforeCast';
|
|
52
|
+
this.actions[SkillConst.ACTION_SKILL_AFTER_CAST] = 'onSkillAfterCast';
|
|
53
|
+
this.actions[SkillConst.ACTION_SKILL_ATTACK_APPLY_DAMAGE] = 'onSkillAttackApplyDamage';
|
|
54
|
+
this.actions[SkillConst.ACTION_SKILL_BEFORE_RUN_LOGIC] = 'onSkillBeforeRunLogic';
|
|
55
|
+
this.actions[SkillConst.ACTION_SKILL_AFTER_RUN_LOGIC] = 'onSkillAfterRunLogic';
|
|
56
|
+
this.actions[SkillConst.ACTION_SKILL_PHYSICAL_ATTACK_HIT] = 'onSkillPhysicalAttackHit';
|
|
57
|
+
this.actions[SkillConst.ACTION_SKILL_PHYSICAL_EFFECT_HIT] = 'onSkillPhysicalEffectHit';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
processMessage(message)
|
|
61
|
+
{
|
|
62
|
+
// don't validate the message if the action prefix is not present or at the beginning of the message action:
|
|
63
|
+
if(!this.isValidMessage(message)){
|
|
64
|
+
// Logger.error(['CHECK NOT AN SKILLS ACTION!', message.act]);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if(!sc.hasOwn(this.actions, message.act)){
|
|
68
|
+
Logger.error('Skills action not found', message.act);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if(!sc.isFunction(this[this.actions[message.act]])){
|
|
72
|
+
// for now, I'm leaving this a silent return (will probably end up making the error log configurable):
|
|
73
|
+
Logger.error('Skills action is not a function', message.act);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
this[this.actions[message.act]](message);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isValidMessage(message)
|
|
80
|
+
{
|
|
81
|
+
return 0 === message.act.indexOf(SkillConst.ACTIONS_PREF);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = Receiver;
|
package/lib/constants.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills constants
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const actionPref = 'rski.';
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
SKILL: {
|
|
11
|
-
TYPE: {
|
|
12
|
-
BASE: 1,
|
|
13
|
-
ATTACK: 2,
|
|
14
|
-
EFFECT: 3,
|
|
15
|
-
PHYSICAL_ATTACK: 4,
|
|
16
|
-
PHYSICAL_EFFECT: 5,
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
MODELS_PREFIX: 'skills_',
|
|
20
|
-
BEHAVIOR_SEND: 'send',
|
|
21
|
-
BEHAVIOR_BROADCAST: 'broadcast',
|
|
22
|
-
BEHAVIOR_BOTH: 'both',
|
|
23
|
-
ACTIONS_PREF: actionPref,
|
|
24
|
-
ACTION_INIT_LEVEL_SET_START: actionPref+'ILss',
|
|
25
|
-
ACTION_INIT_LEVEL_SET_END: actionPref+'ILse',
|
|
26
|
-
ACTION_INIT_CLASS_PATH_END: actionPref+'ICpe',
|
|
27
|
-
ACTION_LOADED_OWNER_SKILLS: actionPref+'Los',
|
|
28
|
-
ACTION_SET_SKILLS: actionPref+'Sk',
|
|
29
|
-
ACTION_SET_LEVELS: actionPref+'Sl',
|
|
30
|
-
ACTION_ADD_SKILLS_BEFORE: actionPref+'Asb',
|
|
31
|
-
ACTION_ADD_SKILLS_AFTER: actionPref+'Asa',
|
|
32
|
-
ACTION_REMOVE_SKILLS_BEFORE: actionPref+'Rsb',
|
|
33
|
-
ACTION_REMOVE_SKILLS_AFTER: actionPref+'Rsa',
|
|
34
|
-
ACTION_VALIDATE_BEFORE: actionPref+'Bv',
|
|
35
|
-
ACTION_VALIDATE_SUCCESS: actionPref+'Vs',
|
|
36
|
-
ACTION_VALIDATE_FAIL: actionPref+'Vf',
|
|
37
|
-
ACTION_EXECUTING_SKILL: actionPref+'Es',
|
|
38
|
-
ACTION_LEVEL_EXPERIENCE_ADDED: actionPref+'Ea',
|
|
39
|
-
ACTION_LEVEL_UP: actionPref+'Lu',
|
|
40
|
-
ACTION_LEVEL_DOWN: actionPref+'Ld',
|
|
41
|
-
ACTION_LEVEL_APPLY_MODIFIERS: actionPref+'Apm',
|
|
42
|
-
ACTION_SKILL_BEFORE_IN_RANGE: actionPref+'Bir',
|
|
43
|
-
ACTION_SKILL_AFTER_IN_RANGE: actionPref+'Air',
|
|
44
|
-
ACTION_SKILL_BEFORE_EXECUTE: actionPref+'Be',
|
|
45
|
-
ACTION_SKILL_AFTER_EXECUTE: actionPref+'Ae',
|
|
46
|
-
ACTION_SKILL_BEFORE_CAST: actionPref+'Bc',
|
|
47
|
-
ACTION_SKILL_AFTER_CAST: actionPref+'Ac',
|
|
48
|
-
ACTION_SKILL_ATTACK_APPLY_DAMAGE: actionPref+'Ad',
|
|
49
|
-
ACTION_SKILL_BEFORE_RUN_LOGIC: actionPref+'Brl',
|
|
50
|
-
ACTION_SKILL_AFTER_RUN_LOGIC: actionPref+'Arl',
|
|
51
|
-
ACTION_SKILL_PHYSICAL_ATTACK_HIT: actionPref+'Pah',
|
|
52
|
-
ACTION_SKILL_PHYSICAL_EFFECT_HIT: actionPref+'Peh',
|
|
53
|
-
SKILL_STATES: {
|
|
54
|
-
PHYSICAL_SKILL_INVALID_TARGET: 'physicalSkillInvalidTarget',
|
|
55
|
-
PHYSICAL_SKILL_RUN_LOGIC: 'physicalSkillRunLogic',
|
|
56
|
-
OUT_OF_RANGE: 'outOfRange',
|
|
57
|
-
CAN_NOT_ACTIVATE: 'canNotActivate',
|
|
58
|
-
DODGED: 'dodged',
|
|
59
|
-
APPLYING_DAMAGE: 'applyingDamage',
|
|
60
|
-
APPLIED_DAMAGE: 'appliedDamage',
|
|
61
|
-
APPLIED_CRITICAL_DAMAGE: 'appliedCriticalDamage',
|
|
62
|
-
APPLYING_EFFECTS: 'applyingEffects',
|
|
63
|
-
APPLIED_EFFECTS: 'appliedEffects',
|
|
64
|
-
EXECUTE_PHYSICAL_ATTACK: 'executePhysicalAttack',
|
|
65
|
-
TARGET_NOT_AVAILABLE: 'targetNotAvailable'
|
|
66
|
-
}
|
|
67
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills constants
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const actionPref = 'rski.';
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
SKILL: {
|
|
11
|
+
TYPE: {
|
|
12
|
+
BASE: 1,
|
|
13
|
+
ATTACK: 2,
|
|
14
|
+
EFFECT: 3,
|
|
15
|
+
PHYSICAL_ATTACK: 4,
|
|
16
|
+
PHYSICAL_EFFECT: 5,
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
MODELS_PREFIX: 'skills_',
|
|
20
|
+
BEHAVIOR_SEND: 'send',
|
|
21
|
+
BEHAVIOR_BROADCAST: 'broadcast',
|
|
22
|
+
BEHAVIOR_BOTH: 'both',
|
|
23
|
+
ACTIONS_PREF: actionPref,
|
|
24
|
+
ACTION_INIT_LEVEL_SET_START: actionPref+'ILss',
|
|
25
|
+
ACTION_INIT_LEVEL_SET_END: actionPref+'ILse',
|
|
26
|
+
ACTION_INIT_CLASS_PATH_END: actionPref+'ICpe',
|
|
27
|
+
ACTION_LOADED_OWNER_SKILLS: actionPref+'Los',
|
|
28
|
+
ACTION_SET_SKILLS: actionPref+'Sk',
|
|
29
|
+
ACTION_SET_LEVELS: actionPref+'Sl',
|
|
30
|
+
ACTION_ADD_SKILLS_BEFORE: actionPref+'Asb',
|
|
31
|
+
ACTION_ADD_SKILLS_AFTER: actionPref+'Asa',
|
|
32
|
+
ACTION_REMOVE_SKILLS_BEFORE: actionPref+'Rsb',
|
|
33
|
+
ACTION_REMOVE_SKILLS_AFTER: actionPref+'Rsa',
|
|
34
|
+
ACTION_VALIDATE_BEFORE: actionPref+'Bv',
|
|
35
|
+
ACTION_VALIDATE_SUCCESS: actionPref+'Vs',
|
|
36
|
+
ACTION_VALIDATE_FAIL: actionPref+'Vf',
|
|
37
|
+
ACTION_EXECUTING_SKILL: actionPref+'Es',
|
|
38
|
+
ACTION_LEVEL_EXPERIENCE_ADDED: actionPref+'Ea',
|
|
39
|
+
ACTION_LEVEL_UP: actionPref+'Lu',
|
|
40
|
+
ACTION_LEVEL_DOWN: actionPref+'Ld',
|
|
41
|
+
ACTION_LEVEL_APPLY_MODIFIERS: actionPref+'Apm',
|
|
42
|
+
ACTION_SKILL_BEFORE_IN_RANGE: actionPref+'Bir',
|
|
43
|
+
ACTION_SKILL_AFTER_IN_RANGE: actionPref+'Air',
|
|
44
|
+
ACTION_SKILL_BEFORE_EXECUTE: actionPref+'Be',
|
|
45
|
+
ACTION_SKILL_AFTER_EXECUTE: actionPref+'Ae',
|
|
46
|
+
ACTION_SKILL_BEFORE_CAST: actionPref+'Bc',
|
|
47
|
+
ACTION_SKILL_AFTER_CAST: actionPref+'Ac',
|
|
48
|
+
ACTION_SKILL_ATTACK_APPLY_DAMAGE: actionPref+'Ad',
|
|
49
|
+
ACTION_SKILL_BEFORE_RUN_LOGIC: actionPref+'Brl',
|
|
50
|
+
ACTION_SKILL_AFTER_RUN_LOGIC: actionPref+'Arl',
|
|
51
|
+
ACTION_SKILL_PHYSICAL_ATTACK_HIT: actionPref+'Pah',
|
|
52
|
+
ACTION_SKILL_PHYSICAL_EFFECT_HIT: actionPref+'Peh',
|
|
53
|
+
SKILL_STATES: {
|
|
54
|
+
PHYSICAL_SKILL_INVALID_TARGET: 'physicalSkillInvalidTarget',
|
|
55
|
+
PHYSICAL_SKILL_RUN_LOGIC: 'physicalSkillRunLogic',
|
|
56
|
+
OUT_OF_RANGE: 'outOfRange',
|
|
57
|
+
CAN_NOT_ACTIVATE: 'canNotActivate',
|
|
58
|
+
DODGED: 'dodged',
|
|
59
|
+
APPLYING_DAMAGE: 'applyingDamage',
|
|
60
|
+
APPLIED_DAMAGE: 'appliedDamage',
|
|
61
|
+
APPLIED_CRITICAL_DAMAGE: 'appliedCriticalDamage',
|
|
62
|
+
APPLYING_EFFECTS: 'applyingEffects',
|
|
63
|
+
APPLIED_EFFECTS: 'appliedEffects',
|
|
64
|
+
EXECUTE_PHYSICAL_ATTACK: 'executePhysicalAttack',
|
|
65
|
+
TARGET_NOT_AVAILABLE: 'targetNotAvailable'
|
|
66
|
+
}
|
|
67
|
+
};
|