@reldens/skills 0.34.0 → 0.36.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/README.md CHANGED
@@ -3,17 +3,25 @@
3
3
  # Reldens - Skills
4
4
 
5
5
  ## About
6
- The idea behind this package is to provide a skills and experience systems, so you can relate these to a target owner.
7
- Note, though it is an opined implementation it provides a lot of flexibility, and it could be implemented on any project.
8
- The package base features can be used in both server or client side, but we additionally provide some server specific
9
- functions like storage models, SQL scripts for installation, sender and receiver support for communication between
10
- the server and the client.
6
+ The idea behind this package is to provide a comprehensive skills and experience system that can be attached to any target owner.
7
+ This opinionated yet flexible implementation includes class paths, leveling systems, skill trees, and experience management with full event-driven architecture.
8
+
9
+ The package offers both client and server-side functionality, including automatic level progression, skill validation, damage calculations, physical attacks, effects system, and complete database integration.
11
10
 
12
11
 
13
12
  ---
14
13
 
15
14
  ## Features
16
15
 
16
+ - **Level Sets & Experience System**: Automatic level progression with configurable experience requirements and level-based modifiers
17
+ - **Class Paths & Skill Trees**: Skill progression with level-dependent skill unlocked and custom labeling
18
+ - **Multiple Skill Types**: Base skills, attacks with damage calculation, effects, physical attacks with collision detection
19
+ - **Combat Mechanics**: Critical hits, dodge calculations, range validation, and damage/defense property systems
20
+ - **Real-time Communication**: Built-in sender/receiver architecture for server-client synchronization
21
+ - **Database Integration**: Complete storage models, migrations, and SQL scripts for persistent data
22
+ - **Event-Driven Architecture**: Comprehensive event system for custom logic integration and multiplayer broadcasting
23
+ - **Modular Design**: Flexible configuration with custom conditions, modifiers, and extensible skill logic
24
+
17
25
  Need something specific?
18
26
 
19
27
  [Request a feature here: https://www.reldens.com/features-request](https://www.reldens.com/features-request)
package/lib/class-path.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  const LevelsSet = require('./levels-set');
8
8
  const SkillsEvents = require('./skills-events');
9
- const { ErrorManager, sc } = require('@reldens/utils');
9
+ const { Logger, sc } = require('@reldens/utils');
10
10
 
11
11
  class ClassPath extends LevelsSet
12
12
  {
@@ -15,7 +15,8 @@ class ClassPath extends LevelsSet
15
15
  {
16
16
  await super.init(props);
17
17
  if(!sc.hasOwn(props, 'key')){
18
- ErrorManager.error('Undefined key for class path.');
18
+ Logger.critical('Undefined key for class path.');
19
+ return false;
19
20
  }
20
21
  // key is the code for class-path itself and label y the name that can be used for display:
21
22
  this.key = props.key;
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  const SkillConst = require('../constants');
8
- const { ErrorManager, Logger, sc } = require('@reldens/utils');
8
+ const { Logger, sc } = require('@reldens/utils');
9
9
 
10
10
  class Receiver
11
11
  {
@@ -13,10 +13,12 @@ class Receiver
13
13
  constructor(props)
14
14
  {
15
15
  if(!sc.hasOwn(props, 'owner')){
16
- ErrorManager.error('Undefined owner.');
16
+ Logger.critical('Undefined owner.');
17
+ return false;
17
18
  }
18
19
  if(typeof props.owner.getPosition !== 'function'){
19
- ErrorManager.error('Undefined owner position method.');
20
+ Logger.critical('Undefined owner position method.');
21
+ return false;
20
22
  }
21
23
  this.actions = sc.get(props, 'actions', {});
22
24
  if(!sc.hasOwn(props, 'avoidDefaults') || !props['avoidDefaults']){
package/lib/level.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ErrorManager, Logger, sc } = require('@reldens/utils');
7
+ const { Logger, sc } = require('@reldens/utils');
8
8
 
9
9
  class Level
10
10
  {
@@ -13,7 +13,8 @@ class Level
13
13
  {
14
14
  // @NOTE: Level.key will be a unique value in the Levels class and the value must be an integer.
15
15
  if(!sc.hasOwn(props, 'key') || isNaN(props.key)){
16
- ErrorManager.error('Invalid Level key.');
16
+ Logger.critical('Invalid Level key.');
17
+ return false;
17
18
  }
18
19
  if(!sc.hasOwn(props, 'modifiers') || 0 >= props.modifiers.length){
19
20
  Logger.warning('Level modifiers were not specified.', 'Level ID:', props.id, ' - Key:', props.key);
package/lib/levels-set.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  const SkillsEvents = require('./skills-events');
8
8
  const Level = require('./level');
9
- const { EventsManagerSingleton, ErrorManager, Logger, sc } = require('@reldens/utils');
9
+ const { EventsManagerSingleton, Logger, sc } = require('@reldens/utils');
10
10
 
11
11
  class LevelsSet
12
12
  {
@@ -20,11 +20,13 @@ class LevelsSet
20
20
  setOwner(props)
21
21
  {
22
22
  if(!sc.hasOwn(props, 'owner')){
23
- ErrorManager.error('Undefined owner for levels.');
23
+ Logger.critical('Undefined owner for levels.');
24
+ return false;
24
25
  }
25
26
  // @NOTE: getPosition must return an object with x and y props, like {x: 123, y: 456}.
26
27
  if(typeof props.owner.getPosition !== 'function'){
27
- ErrorManager.error('Undefined owner position method.');
28
+ Logger.critical('Undefined owner position method.');
29
+ return false;
28
30
  }
29
31
  this.owner = props.owner;
30
32
  this.ownerIdProperty = sc.hasOwn(props, 'ownerIdProperty') ? props.ownerIdProperty : 'id';
@@ -33,13 +35,16 @@ class LevelsSet
33
35
  async init(props)
34
36
  {
35
37
  if(!sc.hasOwn(this, 'owner')){
36
- ErrorManager.error('Undefined owner for levels.');
38
+ Logger.critical('Undefined owner for levels.');
39
+ return false;
37
40
  }
38
41
  if(typeof this.owner.getPosition !== 'function'){
39
- ErrorManager.error('Undefined owner position method.');
42
+ Logger.critical('Undefined owner position method.');
43
+ return false;
40
44
  }
41
45
  if(!sc.hasOwn(props, 'levels') || !Object.keys(props.levels).length){
42
- ErrorManager.error('Levels were not specified.');
46
+ Logger.critical('Levels were not specified.');
47
+ return false;
43
48
  }
44
49
  // fireEvent has to be executed after the owner was set since it will call the owner data to relate the events:
45
50
  await this.fireEvent(SkillsEvents.INIT_LEVEL_SET_START, this);
@@ -67,7 +67,7 @@ const schema = new EntitySchema({
67
67
  isRequired: true
68
68
  },
69
69
  autoFillExperienceMultiplier: {
70
- type: 'boolean'
70
+ type: 'number'
71
71
  }
72
72
  }
73
73
  });
package/lib/skill.js CHANGED
@@ -7,21 +7,25 @@
7
7
  const SkillsConst = require('./constants');
8
8
  const SkillsEvents = require('./skills-events');
9
9
  const { PropertyManager, Condition, Calculator } = require('@reldens/modifiers');
10
- const { InteractionArea, EventsManagerSingleton, ErrorManager, Logger, sc } = require('@reldens/utils');
10
+ const { InteractionArea, EventsManagerSingleton, Logger, sc } = require('@reldens/utils');
11
11
 
12
12
  class Skill
13
13
  {
14
14
 
15
15
  constructor(props)
16
16
  {
17
+ this.isReady = true;
17
18
  if(!sc.hasOwn(props, 'key')){
18
- ErrorManager.error('Missing skill key.');
19
+ Logger.error('Missing skill key.');
20
+ this.isReady = false;
19
21
  }
20
22
  if(!sc.hasOwn(props, 'owner')){
21
- ErrorManager.error('Missing skill owner.');
23
+ Logger.error('Missing skill owner.');
24
+ this.isReady = false;
22
25
  }
23
26
  if(typeof props.owner.getPosition !== 'function'){
24
- ErrorManager.error('Undefined owner position method.');
27
+ Logger.error('Undefined owner position method.');
28
+ this.isReady = false;
25
29
  }
26
30
  this.key = props.key;
27
31
  this.owner = props.owner;
@@ -79,6 +83,10 @@ class Skill
79
83
 
80
84
  validate()
81
85
  {
86
+ if(!this.isReady){
87
+ Logger.error('Skill is not ready for validation.', this.key);
88
+ return false;
89
+ }
82
90
  // @NOTE: the following is tricky, we use the isValid = true so developers can change it and return a different
83
91
  // isValid value after the event "validateSuccess".
84
92
  this.isValid = true;
@@ -119,7 +127,8 @@ class Skill
119
127
  {
120
128
  for(let condition of this.ownerConditions){
121
129
  if(!(condition instanceof Condition)){
122
- ErrorManager.error(['Wrong Condition instance.', (typeof condition), 'was specified.']);
130
+ Logger.critical('Wrong Condition instance was specified.', (typeof condition));
131
+ return false;
123
132
  }
124
133
  if(!condition.isValidOn(this.owner)){
125
134
  // @TODO - BETA - Replace catch.
@@ -135,7 +144,8 @@ class Skill
135
144
  validateRange(target)
136
145
  {
137
146
  if(!this.rangePropertyX || !this.rangePropertyY){
138
- ErrorManager.error('Missing range properties for validation.');
147
+ Logger.error('Missing range properties for validation.');
148
+ return false;
139
149
  }
140
150
  let ownerPosition = {
141
151
  x: this.propertyManager.getPropertyValue(this.owner, this.rangePropertyX),
@@ -171,12 +181,17 @@ class Skill
171
181
 
172
182
  async execute(target)
173
183
  {
184
+ if(!this.isReady){
185
+ Logger.error('Skill is not ready to be executed.', this.key);
186
+ return false;
187
+ }
174
188
  await this.fireEvent(SkillsEvents.SKILL_BEFORE_EXECUTE, this, target);
175
189
  if(target){
176
190
  this.target = target;
177
191
  }
178
192
  if(!this.target){
179
- ErrorManager.error('Target undefined.');
193
+ Logger.error('Target undefined.');
194
+ return false;
180
195
  }
181
196
  if(
182
197
  // custom conditions:
@@ -9,7 +9,7 @@
9
9
  const Skill = require('../skill');
10
10
  const SkillsEvents = require('../skills-events');
11
11
  const SkillsConst = require('../constants');
12
- const { ErrorManager, sc, Logger} = require('@reldens/utils');
12
+ const { Logger, sc } = require('@reldens/utils');
13
13
 
14
14
  class Attack extends Skill
15
15
  {
@@ -19,26 +19,27 @@ class Attack extends Skill
19
19
  super(props);
20
20
  this.type = SkillsConst.SKILL.TYPE.ATTACK;
21
21
  if(!sc.get(props, 'affectedProperty', false)){
22
- ErrorManager.error('Missing skill affectedProperty to which the result damage will be applied.');
22
+ Logger.error('Missing skill affectedProperty to which the result damage will be applied.');
23
+ this.isReady = false;
23
24
  }
24
25
  // the affected property is the one to which the damage calculation will have effect:
25
26
  this.affectedProperty = props.affectedProperty;
26
27
  this.allowEffectBelowZero = sc.get(props, 'allowEffectBelowZero', false);
27
28
  // hit damage value at 100%:
28
- this.hitDamage = sc.hasOwn(props, 'hitDamage') ? props.hitDamage : 0;
29
- this.applyDirectDamage = sc.hasOwn(props, 'applyDirectDamage') ? props.applyDirectDamage : false;
29
+ this.hitDamage = sc.get(props, 'hitDamage', 0);
30
+ this.applyDirectDamage = sc.get(props, 'applyDirectDamage', false);
30
31
  // all properties are obtained from the skill owner and the target to calculate the damage:
31
- this.attackProperties = sc.hasOwn(props, 'attackProperties') ? props.attackProperties : [];
32
- this.defenseProperties = sc.hasOwn(props, 'defenseProperties') ? props.defenseProperties : [];
32
+ this.attackProperties = sc.get(props, 'attackProperties', []);
33
+ this.defenseProperties = sc.get(props, 'defenseProperties', []);
33
34
  // aim and dodge properties are used to determine if the skill could fail:
34
- this.aimProperties = sc.hasOwn(props, 'aimProperties') ? props.aimProperties : [];
35
- this.dodgeProperties = sc.hasOwn(props, 'dodgeProperties') ? props.dodgeProperties : [];
35
+ this.aimProperties = sc.get(props, 'aimProperties', []);
36
+ this.dodgeProperties = sc.get(props, 'dodgeProperties', []);
36
37
  // dodgeFullEnabled will make the attack fail if: dodge > ownerAim * dodgeOverAimSuccess
37
- this.dodgeFullEnabled = sc.hasOwn(props, 'dodgeFullEnabled') ? props.dodgeFullEnabled : true;
38
- this.dodgeOverAimSuccess = sc.hasOwn(props, 'dodgeOverAimSuccess') ? props.dodgeOverAimSuccess : 1;
38
+ this.dodgeFullEnabled = sc.get(props, 'dodgeFullEnabled', true);
39
+ this.dodgeOverAimSuccess = sc.get(props, 'dodgeOverAimSuccess', 1);
39
40
  // specify if the damage or the critical will be affected by the aim and dodge properties:
40
- this.damageAffected = sc.hasOwn(props, 'damageAffected') ? props.damageAffected : false;
41
- this.criticalAffected = sc.hasOwn(props, 'criticalAffected') ? props.criticalAffected : false;
41
+ this.damageAffected = sc.get(props, 'damageAffected', false);
42
+ this.criticalAffected = sc.get(props, 'criticalAffected', false);
42
43
  // properties total calculator operators:
43
44
  // example: {
44
45
  // {key: 'propName1', op: ModifierConst.OPS.INC},
@@ -9,7 +9,7 @@
9
9
  const Skill = require('../skill');
10
10
  const SkillsEvents = require('../skills-events');
11
11
  const SkillsConst = require('../constants');
12
- const { ErrorManager, sc } = require('@reldens/utils');
12
+ const { ErrorManager, sc, Logger} = require('@reldens/utils');
13
13
 
14
14
  class Effect extends Skill
15
15
  {
@@ -19,7 +19,8 @@ class Effect extends Skill
19
19
  super(props);
20
20
  this.type = SkillsConst.SKILL.TYPE.EFFECT;
21
21
  if(!sc.hasOwn(props, 'targetEffects')){
22
- ErrorManager.error('Missing targetEffects for skill.');
22
+ Logger.error('Missing targetEffects for skill.');
23
+ this.isReady = false;
23
24
  }
24
25
  this.targetEffects = props.targetEffects;
25
26
  }
@@ -21,7 +21,7 @@ class PhysicalAttack extends Attack
21
21
  super(props);
22
22
  this.type = SkillsConst.SKILL.TYPE.PHYSICAL_ATTACK;
23
23
  this.parentType = SkillsConst.SKILL.TYPE.ATTACK;
24
- PhysicalPropertiesValidator.validate(props);
24
+ this.isReady = PhysicalPropertiesValidator.validate(props);
25
25
  this.magnitude = props.magnitude;
26
26
  this.objectWidth = props.objectWidth;
27
27
  this.objectHeight = props.objectHeight;
@@ -21,7 +21,7 @@ class PhysicalEffect extends Effect
21
21
  super(props);
22
22
  this.type = SkillsConst.SKILL.TYPE.PHYSICAL_EFFECT;
23
23
  this.parentType = SkillsConst.SKILL.TYPE.EFFECT;
24
- PhysicalPropertiesValidator.validate(props);
24
+ this.isReady = PhysicalPropertiesValidator.validate(props);
25
25
  this.magnitude = props.magnitude;
26
26
  this.objectWidth = props.objectWidth;
27
27
  this.objectHeight = props.objectHeight;
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ErrorManager, sc } = require('@reldens/utils');
7
+ const { Logger, sc } = require('@reldens/utils');
8
8
 
9
9
  class PhysicalPropertiesValidator
10
10
  {
@@ -12,17 +12,22 @@ class PhysicalPropertiesValidator
12
12
  static validate(props)
13
13
  {
14
14
  if(typeof props.owner.executePhysicalSkill !== 'function'){
15
- ErrorManager.error('Missing executePhysicalSkill required method.');
15
+ Logger.error('Missing executePhysicalSkill required method.');
16
+ return false;
16
17
  }
17
18
  if(!sc.hasOwn(props, 'magnitude')){
18
- ErrorManager.error('Missing magnitude property.');
19
+ Logger.error('Missing magnitude property.');
20
+ return false;
19
21
  }
20
22
  if(!sc.hasOwn(props, 'objectWidth')){
21
- ErrorManager.error('Missing objectWidth property.');
23
+ Logger.error('Missing objectWidth property.');
24
+ return false;
22
25
  }
23
26
  if(!sc.hasOwn(props, 'objectHeight')){
24
- ErrorManager.error('Missing objectHeight property.');
27
+ Logger.error('Missing objectHeight property.');
28
+ return false;
25
29
  }
30
+ return true;
26
31
  }
27
32
 
28
33
  }
@@ -4,7 +4,7 @@
4
4
  *
5
5
  */
6
6
 
7
- const SkillsConst = require('@reldens/skills/lib/constants');
7
+ const SkillsConst = require('../constants');
8
8
 
9
9
  class PhysicalSkillRunner
10
10
  {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/skills",
3
3
  "scope": "@reldens",
4
- "version": "0.34.0",
4
+ "version": "0.36.0",
5
5
  "description": "Reldens - Skills",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -40,8 +40,8 @@
40
40
  "url": "https://github.com/damian-pastorini/reldens-skills/issues"
41
41
  },
42
42
  "dependencies": {
43
- "@reldens/modifiers": "^0.26.0",
44
- "@reldens/storage": "^0.31.0",
45
- "@reldens/utils": "^0.39.0"
43
+ "@reldens/modifiers": "^0.28.0",
44
+ "@reldens/storage": "^0.63.0",
45
+ "@reldens/utils": "^0.51.0"
46
46
  }
47
47
  }