@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.
@@ -1,46 +1,46 @@
1
- /**
2
- *
3
- * Reldens - Skills - Physical Attack
4
- *
5
- * This attack will require a world object and collisions to validate the target and execute the skill on hit.
6
- *
7
- */
8
-
9
- const Attack = require('./attack');
10
- const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
11
- const { PhysicalSkillRunner } = require('./physical-skill-runner');
12
- const SkillsConst = require('../constants');
13
- const SkillsEvents = require('../skills-events');
14
- const { sc } = require('@reldens/utils');
15
-
16
- class PhysicalAttack extends Attack
17
- {
18
-
19
- constructor(props)
20
- {
21
- super(props);
22
- this.type = SkillsConst.SKILL.TYPE.PHYSICAL_ATTACK;
23
- this.parentType = SkillsConst.SKILL.TYPE.ATTACK;
24
- this.isReady = PhysicalPropertiesValidator.validate(props);
25
- this.magnitude = props.magnitude;
26
- this.objectWidth = props.objectWidth;
27
- this.objectHeight = props.objectHeight;
28
- this.validateTargetOnHit = sc.get(props, 'validateTargetOnHit', false);
29
- // @TODO - BETA - Include range limit validation and automatic physic body destroy.
30
- }
31
-
32
- async runSkillLogic()
33
- {
34
- return PhysicalSkillRunner.runSkillLogic(this);
35
- }
36
-
37
- async executeOnHit(target)
38
- {
39
- return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT, async () => {
40
- return await super.runSkillLogic();
41
- });
42
- }
43
-
44
- }
45
-
46
- module.exports = PhysicalAttack;
1
+ /**
2
+ *
3
+ * Reldens - Skills - Physical Attack
4
+ *
5
+ * This attack will require a world object and collisions to validate the target and execute the skill on hit.
6
+ *
7
+ */
8
+
9
+ const Attack = require('./attack');
10
+ const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
11
+ const { PhysicalSkillRunner } = require('./physical-skill-runner');
12
+ const SkillsConst = require('../constants');
13
+ const SkillsEvents = require('../skills-events');
14
+ const { sc } = require('@reldens/utils');
15
+
16
+ class PhysicalAttack extends Attack
17
+ {
18
+
19
+ constructor(props)
20
+ {
21
+ super(props);
22
+ this.type = SkillsConst.SKILL.TYPE.PHYSICAL_ATTACK;
23
+ this.parentType = SkillsConst.SKILL.TYPE.ATTACK;
24
+ this.isReady = PhysicalPropertiesValidator.validate(props);
25
+ this.magnitude = props.magnitude;
26
+ this.objectWidth = props.objectWidth;
27
+ this.objectHeight = props.objectHeight;
28
+ this.validateTargetOnHit = sc.get(props, 'validateTargetOnHit', false);
29
+ // @TODO - BETA - Include range limit validation and automatic physic body destroy.
30
+ }
31
+
32
+ async runSkillLogic()
33
+ {
34
+ return PhysicalSkillRunner.runSkillLogic(this);
35
+ }
36
+
37
+ async executeOnHit(target)
38
+ {
39
+ return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT, async () => {
40
+ return await super.runSkillLogic();
41
+ });
42
+ }
43
+
44
+ }
45
+
46
+ module.exports = PhysicalAttack;
@@ -1,46 +1,46 @@
1
- /**
2
- *
3
- * Reldens - Skills - Physical Effect
4
- *
5
- * This attack will require a world object and collisions to validate the target and execute the skill on hit.
6
- *
7
- */
8
-
9
- const Effect = require('./effect');
10
- const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
11
- const { PhysicalSkillRunner } = require('./physical-skill-runner');
12
- const SkillsConst = require('../constants');
13
- const SkillsEvents = require('../skills-events');
14
- const { sc } = require('@reldens/utils');
15
-
16
- class PhysicalEffect extends Effect
17
- {
18
-
19
- constructor(props)
20
- {
21
- super(props);
22
- this.type = SkillsConst.SKILL.TYPE.PHYSICAL_EFFECT;
23
- this.parentType = SkillsConst.SKILL.TYPE.EFFECT;
24
- this.isReady = PhysicalPropertiesValidator.validate(props);
25
- this.magnitude = props.magnitude;
26
- this.objectWidth = props.objectWidth;
27
- this.objectHeight = props.objectHeight;
28
- this.validateTargetOnHit = sc.get(props, 'validateTargetOnHit', false);
29
- // @TODO - BETA - Include range limit validation and automatic physic body destroy.
30
- }
31
-
32
- async runSkillLogic()
33
- {
34
- return PhysicalSkillRunner.runSkillLogic(this);
35
- }
36
-
37
- async executeOnHit(target)
38
- {
39
- return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT, async () => {
40
- return await super.runSkillLogic();
41
- });
42
- }
43
-
44
- }
45
-
46
- module.exports = PhysicalEffect;
1
+ /**
2
+ *
3
+ * Reldens - Skills - Physical Effect
4
+ *
5
+ * This attack will require a world object and collisions to validate the target and execute the skill on hit.
6
+ *
7
+ */
8
+
9
+ const Effect = require('./effect');
10
+ const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
11
+ const { PhysicalSkillRunner } = require('./physical-skill-runner');
12
+ const SkillsConst = require('../constants');
13
+ const SkillsEvents = require('../skills-events');
14
+ const { sc } = require('@reldens/utils');
15
+
16
+ class PhysicalEffect extends Effect
17
+ {
18
+
19
+ constructor(props)
20
+ {
21
+ super(props);
22
+ this.type = SkillsConst.SKILL.TYPE.PHYSICAL_EFFECT;
23
+ this.parentType = SkillsConst.SKILL.TYPE.EFFECT;
24
+ this.isReady = PhysicalPropertiesValidator.validate(props);
25
+ this.magnitude = props.magnitude;
26
+ this.objectWidth = props.objectWidth;
27
+ this.objectHeight = props.objectHeight;
28
+ this.validateTargetOnHit = sc.get(props, 'validateTargetOnHit', false);
29
+ // @TODO - BETA - Include range limit validation and automatic physic body destroy.
30
+ }
31
+
32
+ async runSkillLogic()
33
+ {
34
+ return PhysicalSkillRunner.runSkillLogic(this);
35
+ }
36
+
37
+ async executeOnHit(target)
38
+ {
39
+ return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT, async () => {
40
+ return await super.runSkillLogic();
41
+ });
42
+ }
43
+
44
+ }
45
+
46
+ module.exports = PhysicalEffect;
@@ -1,35 +1,35 @@
1
- /**
2
- *
3
- * Reldens - Skills - PhysicalPropertiesValidator
4
- *
5
- */
6
-
7
- const { Logger, sc } = require('@reldens/utils');
8
-
9
- class PhysicalPropertiesValidator
10
- {
11
-
12
- static validate(props)
13
- {
14
- if(!props.owner || typeof props.owner.executePhysicalSkill !== 'function'){
15
- Logger.error('Missing executePhysicalSkill required method.');
16
- return false;
17
- }
18
- if(!sc.hasOwn(props, 'magnitude')){
19
- Logger.error('Missing magnitude property.');
20
- return false;
21
- }
22
- if(!sc.hasOwn(props, 'objectWidth')){
23
- Logger.error('Missing objectWidth property.');
24
- return false;
25
- }
26
- if(!sc.hasOwn(props, 'objectHeight')){
27
- Logger.error('Missing objectHeight property.');
28
- return false;
29
- }
30
- return true;
31
- }
32
-
33
- }
34
-
35
- module.exports.PhysicalPropertiesValidator = PhysicalPropertiesValidator;
1
+ /**
2
+ *
3
+ * Reldens - Skills - PhysicalPropertiesValidator
4
+ *
5
+ */
6
+
7
+ const { Logger, sc } = require('@reldens/utils');
8
+
9
+ class PhysicalPropertiesValidator
10
+ {
11
+
12
+ static validate(props)
13
+ {
14
+ if(!props.owner || typeof props.owner.executePhysicalSkill !== 'function'){
15
+ Logger.error('Missing executePhysicalSkill required method.');
16
+ return false;
17
+ }
18
+ if(!sc.hasOwn(props, 'magnitude')){
19
+ Logger.error('Missing magnitude property.');
20
+ return false;
21
+ }
22
+ if(!sc.hasOwn(props, 'objectWidth')){
23
+ Logger.error('Missing objectWidth property.');
24
+ return false;
25
+ }
26
+ if(!sc.hasOwn(props, 'objectHeight')){
27
+ Logger.error('Missing objectHeight property.');
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+
33
+ }
34
+
35
+ module.exports.PhysicalPropertiesValidator = PhysicalPropertiesValidator;
@@ -1,41 +1,41 @@
1
- /**
2
- *
3
- * Reldens - Skills - PhysicalSkillRunner
4
- *
5
- */
6
-
7
- const SkillsConst = require('../constants');
8
-
9
- class PhysicalSkillRunner
10
- {
11
-
12
- static async runSkillLogic(skill)
13
- {
14
- skill.lastState = null;
15
- if(!skill.validateRange(skill.target)){
16
- skill.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
17
- // @NOTE: out of range, the owner or the target could have moved away.
18
- return false;
19
- }
20
- skill.lastState = SkillsConst.SKILL_STATES.EXECUTE_PHYSICAL_ATTACK;
21
- await skill.owner.executePhysicalSkill(skill.target, skill);
22
- return false;
23
- }
24
-
25
- static async executeOnHit(target, skill, skillType, runSkillLogicCallback)
26
- {
27
- await skill.fireEvent(skillType, skill, target);
28
- if(skill.validateTargetOnHit && target !== skill.target){
29
- skill.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_INVALID_TARGET;
30
- return false;
31
- }
32
- if('function' !== typeof runSkillLogicCallback){
33
- return false;
34
- }
35
- skill.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_RUN_LOGIC;
36
- return await runSkillLogicCallback(target);
37
- }
38
-
39
- }
40
-
41
- module.exports.PhysicalSkillRunner = PhysicalSkillRunner;
1
+ /**
2
+ *
3
+ * Reldens - Skills - PhysicalSkillRunner
4
+ *
5
+ */
6
+
7
+ const SkillsConst = require('../constants');
8
+
9
+ class PhysicalSkillRunner
10
+ {
11
+
12
+ static async runSkillLogic(skill)
13
+ {
14
+ skill.lastState = null;
15
+ if(!skill.validateRange(skill.target)){
16
+ skill.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
17
+ // @NOTE: out of range, the owner or the target could have moved away.
18
+ return false;
19
+ }
20
+ skill.lastState = SkillsConst.SKILL_STATES.EXECUTE_PHYSICAL_ATTACK;
21
+ await skill.owner.executePhysicalSkill(skill.target, skill);
22
+ return false;
23
+ }
24
+
25
+ static async executeOnHit(target, skill, skillType, runSkillLogicCallback)
26
+ {
27
+ await skill.fireEvent(skillType, skill, target);
28
+ if(skill.validateTargetOnHit && target !== skill.target){
29
+ skill.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_INVALID_TARGET;
30
+ return false;
31
+ }
32
+ if('function' !== typeof runSkillLogicCallback){
33
+ return false;
34
+ }
35
+ skill.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_RUN_LOGIC;
36
+ return await runSkillLogicCallback(target);
37
+ }
38
+
39
+ }
40
+
41
+ module.exports.PhysicalSkillRunner = PhysicalSkillRunner;
package/package.json CHANGED
@@ -1,52 +1,52 @@
1
- {
2
- "name": "@reldens/skills",
3
- "scope": "@reldens",
4
- "version": "0.56.0",
5
- "description": "Reldens - Skills",
6
- "author": "Damian A. Pastorini",
7
- "license": "MIT",
8
- "homepage": "https://github.com/damian-pastorini/reldens-skills",
9
- "source": true,
10
- "main": "index.js",
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/damian-pastorini/reldens-skills.git"
14
- },
15
- "keywords": [
16
- "reldens",
17
- "skill",
18
- "ability",
19
- "attack",
20
- "defense",
21
- "magic",
22
- "class",
23
- "level",
24
- "path",
25
- "game",
26
- "mmorpg",
27
- "rpg",
28
- "dwd",
29
- "colyseus",
30
- "phaser",
31
- "parcel",
32
- "nodejs",
33
- "mmo",
34
- "multiplayer",
35
- "rol",
36
- "platform",
37
- "framework"
38
- ],
39
- "bugs": {
40
- "url": "https://github.com/damian-pastorini/reldens-skills/issues"
41
- },
42
- "scripts": {
43
- "test": "node tests/run-tests.js",
44
- "test:watch": "node --watch tests/run-tests.js",
45
- "test:filter": "node tests/run-tests.js --filter=",
46
- "test:coverage": "node --test --experimental-test-coverage tests/run-tests.js"
47
- },
48
- "dependencies": {
49
- "@reldens/modifiers": "^0.42.0",
50
- "@reldens/utils": "^0.62.0"
51
- }
52
- }
1
+ {
2
+ "name": "@reldens/skills",
3
+ "scope": "@reldens",
4
+ "version": "0.58.0",
5
+ "description": "Reldens - Skills",
6
+ "author": "Damian A. Pastorini",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/damian-pastorini/reldens-skills",
9
+ "source": true,
10
+ "main": "index.js",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/damian-pastorini/reldens-skills.git"
14
+ },
15
+ "keywords": [
16
+ "reldens",
17
+ "skill",
18
+ "ability",
19
+ "attack",
20
+ "defense",
21
+ "magic",
22
+ "class",
23
+ "level",
24
+ "path",
25
+ "game",
26
+ "mmorpg",
27
+ "rpg",
28
+ "dwd",
29
+ "colyseus",
30
+ "phaser",
31
+ "parcel",
32
+ "nodejs",
33
+ "mmo",
34
+ "multiplayer",
35
+ "rol",
36
+ "platform",
37
+ "framework"
38
+ ],
39
+ "bugs": {
40
+ "url": "https://github.com/damian-pastorini/reldens-skills/issues"
41
+ },
42
+ "scripts": {
43
+ "test": "node tests/run-tests.js",
44
+ "test:watch": "node --watch tests/run-tests.js",
45
+ "test:filter": "node tests/run-tests.js --filter=",
46
+ "test:coverage": "node --test --experimental-test-coverage tests/run-tests.js"
47
+ },
48
+ "dependencies": {
49
+ "@reldens/modifiers": "^0.43.0",
50
+ "@reldens/utils": "^0.63.0"
51
+ }
52
+ }
@@ -569,11 +569,11 @@ describe('ClassPath', () => {
569
569
  assert.strictEqual(eventFired, true);
570
570
  });
571
571
 
572
- it('should fire event without any keys', async () => {
572
+ it('should not register a listener without a remove key', async () => {
573
573
  let eventFired = false;
574
574
  let levels = BaseLevelsFixtures.createLevelSet();
575
575
  let classPath = new ClassPath({owner: mockOwner});
576
- classPath.listenEvent(SkillsEvents.INIT_CLASS_PATH_END, () => {
576
+ let listenerResult = classPath.listenEvent(SkillsEvents.INIT_CLASS_PATH_END, () => {
577
577
  eventFired = true;
578
578
  });
579
579
  await classPath.init({
@@ -582,7 +582,8 @@ describe('ClassPath', () => {
582
582
  currentLevel: 1,
583
583
  currentExp: 0
584
584
  });
585
- assert.strictEqual(eventFired, true);
585
+ assert.strictEqual(listenerResult, false);
586
+ assert.strictEqual(eventFired, false);
586
587
  });
587
588
 
588
589
  it('should handle multiple listeners', async () => {
@@ -301,15 +301,16 @@ describe('LevelsSet', () => {
301
301
  assert.strictEqual(eventFired, true);
302
302
  });
303
303
 
304
- it('should fire SET_LEVELS without any keys', async () => {
304
+ it('should not register a SET_LEVELS listener without a remove key', async () => {
305
305
  let eventFired = false;
306
306
  let levels = BaseLevelsFixtures.createLevelSet();
307
307
  let levelsSet = new LevelsSet({owner: mockOwner});
308
- levelsSet.listenEvent(SkillsEvents.SET_LEVELS, () => {
308
+ let listenerResult = levelsSet.listenEvent(SkillsEvents.SET_LEVELS, () => {
309
309
  eventFired = true;
310
310
  });
311
311
  await levelsSet.init({levels: levels, currentLevel: 1, currentExp: 0});
312
- assert.strictEqual(eventFired, true);
312
+ assert.strictEqual(listenerResult, false);
313
+ assert.strictEqual(eventFired, false);
313
314
  });
314
315
 
315
316
  it('should fire LEVEL_DOWN event', async () => {
@@ -353,15 +353,16 @@ describe('Skill', () => {
353
353
  assert.strictEqual(eventFired, true);
354
354
  });
355
355
 
356
- it('should fire event without any keys', async () => {
356
+ it('should not register a listener without a remove key', async () => {
357
357
  let eventFired = false;
358
358
  let skillData = {...BaseSkillsFixtures.basicSkill, owner: mockOwner};
359
359
  let skill = new Skill(skillData);
360
- skill.listenEvent(SkillsEvents.SKILL_BEFORE_EXECUTE, () => {
360
+ let listenerResult = skill.listenEvent(SkillsEvents.SKILL_BEFORE_EXECUTE, () => {
361
361
  eventFired = true;
362
362
  });
363
363
  await skill.execute(mockTarget);
364
- assert.strictEqual(eventFired, true);
364
+ assert.strictEqual(listenerResult, false);
365
+ assert.strictEqual(eventFired, false);
365
366
  });
366
367
 
367
368
  it('should handle multiple listeners on same event', async () => {
@@ -607,7 +607,7 @@ describe('Attack', () => {
607
607
  assert.strictEqual(eventFired, true);
608
608
  });
609
609
 
610
- it('should fire event without any keys', async () => {
610
+ it('should not register a listener without a remove key', async () => {
611
611
  let eventFired = false;
612
612
  let attackData = {
613
613
  ...BaseSkillsFixtures.attackSkill,
@@ -615,11 +615,12 @@ describe('Attack', () => {
615
615
  range: 0
616
616
  };
617
617
  let attack = new Attack(attackData);
618
- attack.listenEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, () => {
618
+ let listenerResult = attack.listenEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, () => {
619
619
  eventFired = true;
620
620
  });
621
621
  await attack.applyDamageTo(mockTarget);
622
- assert.strictEqual(eventFired, true);
622
+ assert.strictEqual(listenerResult, false);
623
+ assert.strictEqual(eventFired, false);
623
624
  });
624
625
  });
625
626
 
@@ -371,7 +371,7 @@ describe('Effect', () => {
371
371
  assert.strictEqual(eventFired, true);
372
372
  });
373
373
 
374
- it('should fire event without any keys', async () => {
374
+ it('should not register a listener without a remove key', async () => {
375
375
  let eventFired = false;
376
376
  let effectData = {
377
377
  ...BaseSkillsFixtures.effectSkill,
@@ -381,11 +381,12 @@ describe('Effect', () => {
381
381
  };
382
382
  let effect = new Effect(effectData);
383
383
  effect.target = mockTarget;
384
- effect.listenEvent(SkillsEvents.SKILL_EFFECT_TARGET_MODIFIERS, () => {
384
+ let listenerResult = effect.listenEvent(SkillsEvents.SKILL_EFFECT_TARGET_MODIFIERS, () => {
385
385
  eventFired = true;
386
386
  });
387
387
  await effect.runSkillLogic();
388
- assert.strictEqual(eventFired, true);
388
+ assert.strictEqual(listenerResult, false);
389
+ assert.strictEqual(eventFired, false);
389
390
  });
390
391
 
391
392
  it('should handle multiple listeners', async () => {