@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/lib/server/sender.js
CHANGED
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - Sender
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const SkillsConst = require('../constants');
|
|
8
|
-
const SkillsEvents = require('../skills-events');
|
|
9
|
-
const { Logger, sc } = require('@reldens/utils');
|
|
10
|
-
|
|
11
|
-
class Sender
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
constructor(classPath, client = false)
|
|
15
|
-
{
|
|
16
|
-
this.classPath = classPath;
|
|
17
|
-
this.client = client;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
validateClient()
|
|
21
|
-
{
|
|
22
|
-
if(!this.client){
|
|
23
|
-
Logger.critical('Undefined client for Sender.');
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
registerListeners()
|
|
30
|
-
{
|
|
31
|
-
if(!this.validateClient()){
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
let ownerEventKey = this.classPath.getOwnerEventKey();
|
|
35
|
-
this.classPath.listenEvent(
|
|
36
|
-
SkillsEvents.INIT_CLASS_PATH_END,
|
|
37
|
-
this.sendInitClassPathData.bind(this),
|
|
38
|
-
this.classPath.getOwnerUniqueEventKey('initClassPathEndSender'),
|
|
39
|
-
ownerEventKey
|
|
40
|
-
);
|
|
41
|
-
this.classPath.listenEvent(
|
|
42
|
-
SkillsEvents.LEVEL_UP,
|
|
43
|
-
this.sendLevelUpData.bind(this),
|
|
44
|
-
this.classPath.getOwnerUniqueEventKey('levelUpSender'),
|
|
45
|
-
ownerEventKey
|
|
46
|
-
);
|
|
47
|
-
this.classPath.listenEvent(
|
|
48
|
-
SkillsEvents.LEVEL_EXPERIENCE_ADDED,
|
|
49
|
-
this.sendLevelExperienceAdded.bind(this),
|
|
50
|
-
this.classPath.getOwnerUniqueEventKey('expAddSender'),
|
|
51
|
-
ownerEventKey
|
|
52
|
-
);
|
|
53
|
-
this.classPath.listenEvent(
|
|
54
|
-
SkillsEvents.SKILL_BEFORE_CAST,
|
|
55
|
-
this.sendSkillBeforeCastData.bind(this),
|
|
56
|
-
this.classPath.getOwnerUniqueEventKey('skillBeforeCastSender'),
|
|
57
|
-
ownerEventKey
|
|
58
|
-
);
|
|
59
|
-
this.classPath.listenEvent(
|
|
60
|
-
SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE,
|
|
61
|
-
this.sendSkillAttackApplyDamage.bind(this),
|
|
62
|
-
this.classPath.getOwnerUniqueEventKey('skillAttackApplyDamageSender'),
|
|
63
|
-
ownerEventKey
|
|
64
|
-
);
|
|
65
|
-
// @TODO - BETA - Skill cast and damage were missing, do we need to include other events?
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async sendInitClassPathData(classPath)
|
|
69
|
-
{
|
|
70
|
-
let messageData = {
|
|
71
|
-
lvl: classPath.currentLevel,
|
|
72
|
-
lab: classPath.currentLabel,
|
|
73
|
-
exp: classPath.currentExp,
|
|
74
|
-
skl: Object.keys(classPath.currentSkills),
|
|
75
|
-
};
|
|
76
|
-
let nextLevelExp = classPath.getNextLevelExperience();
|
|
77
|
-
if(nextLevelExp > 0){
|
|
78
|
-
messageData.ne = nextLevelExp;
|
|
79
|
-
}
|
|
80
|
-
// @NOTE: we could send just this.currentLabel but better check if there's a specific one for this level and
|
|
81
|
-
// don't send extra information we already have on the client.
|
|
82
|
-
if(classPath.labelsByLevel[classPath.currentLevel]){
|
|
83
|
-
messageData.nl = classPath.labelsByLevel[classPath.currentLevel];
|
|
84
|
-
}
|
|
85
|
-
await this.runBehaviors(
|
|
86
|
-
messageData,
|
|
87
|
-
SkillsConst.ACTION_INIT_CLASS_PATH_END,
|
|
88
|
-
SkillsConst.BEHAVIOR_SEND,
|
|
89
|
-
classPath.getOwnerId()
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async sendLevelUpData(classPath)
|
|
94
|
-
{
|
|
95
|
-
let messageData = {
|
|
96
|
-
lvl: classPath.currentLevel,
|
|
97
|
-
lab: classPath.currentLabel
|
|
98
|
-
};
|
|
99
|
-
if(classPath.skillsByLevelKeys[classPath.currentLevel]){
|
|
100
|
-
// new skills:
|
|
101
|
-
messageData.skl = classPath.skillsByLevelKeys[classPath.currentLevel];
|
|
102
|
-
}
|
|
103
|
-
let nextLevelExp = classPath.getNextLevelExperience();
|
|
104
|
-
if(nextLevelExp > 0){
|
|
105
|
-
// new exp:
|
|
106
|
-
messageData.ne = nextLevelExp;
|
|
107
|
-
}
|
|
108
|
-
await this.runBehaviors(
|
|
109
|
-
messageData,
|
|
110
|
-
SkillsConst.ACTION_LEVEL_UP,
|
|
111
|
-
SkillsConst.BEHAVIOR_SEND,
|
|
112
|
-
classPath.getOwnerId()
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async sendLevelExperienceAdded(classPath)
|
|
117
|
-
{
|
|
118
|
-
let messageData = {
|
|
119
|
-
exp: classPath.currentExp
|
|
120
|
-
};
|
|
121
|
-
await this.runBehaviors(
|
|
122
|
-
messageData,
|
|
123
|
-
SkillsConst.ACTION_LEVEL_EXPERIENCE_ADDED,
|
|
124
|
-
SkillsConst.BEHAVIOR_SEND,
|
|
125
|
-
classPath.getOwnerId()
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async sendSkillBeforeCastData(skill, target)
|
|
130
|
-
{
|
|
131
|
-
let messageData = Object.assign({
|
|
132
|
-
skillKey: skill.key
|
|
133
|
-
},
|
|
134
|
-
skill.owner.getPosition()
|
|
135
|
-
);
|
|
136
|
-
if(sc.isFunction(skill.owner.getSkillExtraData)){
|
|
137
|
-
Object.assign(messageData, {extraData: skill.owner.getSkillExtraData({skill, target})});
|
|
138
|
-
}
|
|
139
|
-
await this.runBehaviors(
|
|
140
|
-
messageData,
|
|
141
|
-
SkillsConst.ACTION_SKILL_BEFORE_CAST,
|
|
142
|
-
SkillsConst.BEHAVIOR_BROADCAST,
|
|
143
|
-
skill.getOwnerId()
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async sendSkillAttackApplyDamage(skill, target, damage, newValue)
|
|
148
|
-
{
|
|
149
|
-
let messageData = {d: damage};
|
|
150
|
-
if(sc.isFunction(skill.owner.getSkillExtraData)){
|
|
151
|
-
Object.assign(messageData, {extraData: skill.owner.getSkillExtraData({skill, target})});
|
|
152
|
-
}
|
|
153
|
-
await this.runBehaviors(
|
|
154
|
-
messageData,
|
|
155
|
-
SkillsConst.ACTION_SKILL_ATTACK_APPLY_DAMAGE,
|
|
156
|
-
SkillsConst.BEHAVIOR_BROADCAST,
|
|
157
|
-
skill.getOwnerId()
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async runBehaviors(messageData, actionName, behavior, ownerId)
|
|
162
|
-
{
|
|
163
|
-
// @NOTE: since the sender is a new instance for each SkillsServer, but it's listening on a single EventsManager
|
|
164
|
-
// which fires the event for every player, then we need to check if the current event fired was related to the
|
|
165
|
-
// current player.
|
|
166
|
-
if(this.classPath.getOwnerId() !== ownerId){
|
|
167
|
-
Logger.critical('Skill owners miss match, please review.');
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
if(behavior === SkillsConst.BEHAVIOR_BROADCAST || behavior === SkillsConst.BEHAVIOR_BOTH){
|
|
171
|
-
await this.client.broadcast({act: actionName, owner: ownerId, data: messageData});
|
|
172
|
-
}
|
|
173
|
-
if(behavior === SkillsConst.BEHAVIOR_SEND || behavior === SkillsConst.BEHAVIOR_BOTH){
|
|
174
|
-
await this.client.send({act: actionName, owner: ownerId, data: messageData});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
module.exports = Sender;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - Sender
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const SkillsConst = require('../constants');
|
|
8
|
+
const SkillsEvents = require('../skills-events');
|
|
9
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
10
|
+
|
|
11
|
+
class Sender
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
constructor(classPath, client = false)
|
|
15
|
+
{
|
|
16
|
+
this.classPath = classPath;
|
|
17
|
+
this.client = client;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
validateClient()
|
|
21
|
+
{
|
|
22
|
+
if(!this.client){
|
|
23
|
+
Logger.critical('Undefined client for Sender.');
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
registerListeners()
|
|
30
|
+
{
|
|
31
|
+
if(!this.validateClient()){
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let ownerEventKey = this.classPath.getOwnerEventKey();
|
|
35
|
+
this.classPath.listenEvent(
|
|
36
|
+
SkillsEvents.INIT_CLASS_PATH_END,
|
|
37
|
+
this.sendInitClassPathData.bind(this),
|
|
38
|
+
this.classPath.getOwnerUniqueEventKey('initClassPathEndSender'),
|
|
39
|
+
ownerEventKey
|
|
40
|
+
);
|
|
41
|
+
this.classPath.listenEvent(
|
|
42
|
+
SkillsEvents.LEVEL_UP,
|
|
43
|
+
this.sendLevelUpData.bind(this),
|
|
44
|
+
this.classPath.getOwnerUniqueEventKey('levelUpSender'),
|
|
45
|
+
ownerEventKey
|
|
46
|
+
);
|
|
47
|
+
this.classPath.listenEvent(
|
|
48
|
+
SkillsEvents.LEVEL_EXPERIENCE_ADDED,
|
|
49
|
+
this.sendLevelExperienceAdded.bind(this),
|
|
50
|
+
this.classPath.getOwnerUniqueEventKey('expAddSender'),
|
|
51
|
+
ownerEventKey
|
|
52
|
+
);
|
|
53
|
+
this.classPath.listenEvent(
|
|
54
|
+
SkillsEvents.SKILL_BEFORE_CAST,
|
|
55
|
+
this.sendSkillBeforeCastData.bind(this),
|
|
56
|
+
this.classPath.getOwnerUniqueEventKey('skillBeforeCastSender'),
|
|
57
|
+
ownerEventKey
|
|
58
|
+
);
|
|
59
|
+
this.classPath.listenEvent(
|
|
60
|
+
SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE,
|
|
61
|
+
this.sendSkillAttackApplyDamage.bind(this),
|
|
62
|
+
this.classPath.getOwnerUniqueEventKey('skillAttackApplyDamageSender'),
|
|
63
|
+
ownerEventKey
|
|
64
|
+
);
|
|
65
|
+
// @TODO - BETA - Skill cast and damage were missing, do we need to include other events?
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async sendInitClassPathData(classPath)
|
|
69
|
+
{
|
|
70
|
+
let messageData = {
|
|
71
|
+
lvl: classPath.currentLevel,
|
|
72
|
+
lab: classPath.currentLabel,
|
|
73
|
+
exp: classPath.currentExp,
|
|
74
|
+
skl: Object.keys(classPath.currentSkills),
|
|
75
|
+
};
|
|
76
|
+
let nextLevelExp = classPath.getNextLevelExperience();
|
|
77
|
+
if(nextLevelExp > 0){
|
|
78
|
+
messageData.ne = nextLevelExp;
|
|
79
|
+
}
|
|
80
|
+
// @NOTE: we could send just this.currentLabel but better check if there's a specific one for this level and
|
|
81
|
+
// don't send extra information we already have on the client.
|
|
82
|
+
if(classPath.labelsByLevel[classPath.currentLevel]){
|
|
83
|
+
messageData.nl = classPath.labelsByLevel[classPath.currentLevel];
|
|
84
|
+
}
|
|
85
|
+
await this.runBehaviors(
|
|
86
|
+
messageData,
|
|
87
|
+
SkillsConst.ACTION_INIT_CLASS_PATH_END,
|
|
88
|
+
SkillsConst.BEHAVIOR_SEND,
|
|
89
|
+
classPath.getOwnerId()
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async sendLevelUpData(classPath)
|
|
94
|
+
{
|
|
95
|
+
let messageData = {
|
|
96
|
+
lvl: classPath.currentLevel,
|
|
97
|
+
lab: classPath.currentLabel
|
|
98
|
+
};
|
|
99
|
+
if(classPath.skillsByLevelKeys[classPath.currentLevel]){
|
|
100
|
+
// new skills:
|
|
101
|
+
messageData.skl = classPath.skillsByLevelKeys[classPath.currentLevel];
|
|
102
|
+
}
|
|
103
|
+
let nextLevelExp = classPath.getNextLevelExperience();
|
|
104
|
+
if(nextLevelExp > 0){
|
|
105
|
+
// new exp:
|
|
106
|
+
messageData.ne = nextLevelExp;
|
|
107
|
+
}
|
|
108
|
+
await this.runBehaviors(
|
|
109
|
+
messageData,
|
|
110
|
+
SkillsConst.ACTION_LEVEL_UP,
|
|
111
|
+
SkillsConst.BEHAVIOR_SEND,
|
|
112
|
+
classPath.getOwnerId()
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async sendLevelExperienceAdded(classPath)
|
|
117
|
+
{
|
|
118
|
+
let messageData = {
|
|
119
|
+
exp: classPath.currentExp
|
|
120
|
+
};
|
|
121
|
+
await this.runBehaviors(
|
|
122
|
+
messageData,
|
|
123
|
+
SkillsConst.ACTION_LEVEL_EXPERIENCE_ADDED,
|
|
124
|
+
SkillsConst.BEHAVIOR_SEND,
|
|
125
|
+
classPath.getOwnerId()
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async sendSkillBeforeCastData(skill, target)
|
|
130
|
+
{
|
|
131
|
+
let messageData = Object.assign({
|
|
132
|
+
skillKey: skill.key
|
|
133
|
+
},
|
|
134
|
+
skill.owner.getPosition()
|
|
135
|
+
);
|
|
136
|
+
if(sc.isFunction(skill.owner.getSkillExtraData)){
|
|
137
|
+
Object.assign(messageData, {extraData: skill.owner.getSkillExtraData({skill, target})});
|
|
138
|
+
}
|
|
139
|
+
await this.runBehaviors(
|
|
140
|
+
messageData,
|
|
141
|
+
SkillsConst.ACTION_SKILL_BEFORE_CAST,
|
|
142
|
+
SkillsConst.BEHAVIOR_BROADCAST,
|
|
143
|
+
skill.getOwnerId()
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async sendSkillAttackApplyDamage(skill, target, damage, newValue)
|
|
148
|
+
{
|
|
149
|
+
let messageData = {d: damage};
|
|
150
|
+
if(sc.isFunction(skill.owner.getSkillExtraData)){
|
|
151
|
+
Object.assign(messageData, {extraData: skill.owner.getSkillExtraData({skill, target})});
|
|
152
|
+
}
|
|
153
|
+
await this.runBehaviors(
|
|
154
|
+
messageData,
|
|
155
|
+
SkillsConst.ACTION_SKILL_ATTACK_APPLY_DAMAGE,
|
|
156
|
+
SkillsConst.BEHAVIOR_BROADCAST,
|
|
157
|
+
skill.getOwnerId()
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async runBehaviors(messageData, actionName, behavior, ownerId)
|
|
162
|
+
{
|
|
163
|
+
// @NOTE: since the sender is a new instance for each SkillsServer, but it's listening on a single EventsManager
|
|
164
|
+
// which fires the event for every player, then we need to check if the current event fired was related to the
|
|
165
|
+
// current player.
|
|
166
|
+
if(this.classPath.getOwnerId() !== ownerId){
|
|
167
|
+
Logger.critical('Skill owners miss match, please review.');
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if(behavior === SkillsConst.BEHAVIOR_BROADCAST || behavior === SkillsConst.BEHAVIOR_BOTH){
|
|
171
|
+
await this.client.broadcast({act: actionName, owner: ownerId, data: messageData});
|
|
172
|
+
}
|
|
173
|
+
if(behavior === SkillsConst.BEHAVIOR_SEND || behavior === SkillsConst.BEHAVIOR_BOTH){
|
|
174
|
+
await this.client.send({act: actionName, owner: ownerId, data: messageData});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
module.exports = Sender;
|
package/lib/server.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - Server Package
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const ClassPath = require('./class-path');
|
|
8
|
-
const Sender = require('./server/sender');
|
|
9
|
-
const { Logger, sc } = require('@reldens/utils');
|
|
10
|
-
|
|
11
|
-
class SkillsServer
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
constructor(props)
|
|
15
|
-
{
|
|
16
|
-
this.classPath = false;
|
|
17
|
-
this.client = false;
|
|
18
|
-
this.setupServer(props);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
setupServer(props)
|
|
22
|
-
{
|
|
23
|
-
if(!sc.hasOwn(props, 'owner')){
|
|
24
|
-
Logger.critical('Undefined owner.');
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
if(typeof props.owner.getPosition !== 'function'){
|
|
28
|
-
Logger.critical('Undefined owner position method.');
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
this.classPath = sc.hasOwn(props, 'classPath') ? props.classPath : new ClassPath(props);
|
|
32
|
-
this.classPath.setOwner(props);
|
|
33
|
-
if(sc.hasOwn(props, 'client')){
|
|
34
|
-
// @NOTE: a client must implement the "send" method which will be used to send the current action data.
|
|
35
|
-
if(typeof props.client.send !== 'function'){
|
|
36
|
-
Logger.critical('Required method "send" not found in SkillsServer props.client.');
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
if(typeof props.client.broadcast !== 'function'){
|
|
40
|
-
Logger.critical('Property "broadcast" found in SkillsServer props.client but is not a function.');
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
this.client = new Sender(this.classPath, props.client);
|
|
44
|
-
this.client.registerListeners();
|
|
45
|
-
}
|
|
46
|
-
this.classPath.init(props).catch((err) => {
|
|
47
|
-
Logger.critical('Broken class. '+err);
|
|
48
|
-
return false;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = SkillsServer;
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Reldens - Skills - Server Package
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const ClassPath = require('./class-path');
|
|
8
|
+
const Sender = require('./server/sender');
|
|
9
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
10
|
+
|
|
11
|
+
class SkillsServer
|
|
12
|
+
{
|
|
13
|
+
|
|
14
|
+
constructor(props)
|
|
15
|
+
{
|
|
16
|
+
this.classPath = false;
|
|
17
|
+
this.client = false;
|
|
18
|
+
this.setupServer(props);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setupServer(props)
|
|
22
|
+
{
|
|
23
|
+
if(!sc.hasOwn(props, 'owner')){
|
|
24
|
+
Logger.critical('Undefined owner.');
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if(typeof props.owner.getPosition !== 'function'){
|
|
28
|
+
Logger.critical('Undefined owner position method.');
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
this.classPath = sc.hasOwn(props, 'classPath') ? props.classPath : new ClassPath(props);
|
|
32
|
+
this.classPath.setOwner(props);
|
|
33
|
+
if(sc.hasOwn(props, 'client')){
|
|
34
|
+
// @NOTE: a client must implement the "send" method which will be used to send the current action data.
|
|
35
|
+
if(typeof props.client.send !== 'function'){
|
|
36
|
+
Logger.critical('Required method "send" not found in SkillsServer props.client.');
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if(typeof props.client.broadcast !== 'function'){
|
|
40
|
+
Logger.critical('Property "broadcast" found in SkillsServer props.client but is not a function.');
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
this.client = new Sender(this.classPath, props.client);
|
|
44
|
+
this.client.registerListeners();
|
|
45
|
+
}
|
|
46
|
+
this.classPath.init(props).catch((err) => {
|
|
47
|
+
Logger.critical('Broken class. '+err);
|
|
48
|
+
return false;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = SkillsServer;
|