@reldens/skills 0.5.0-beta.5 → 0.10.0-beta.21

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.
Files changed (36) hide show
  1. package/index.js +0 -1
  2. package/lib/class-path.js +7 -2
  3. package/lib/client/receiver.js +2 -2
  4. package/lib/level.js +8 -4
  5. package/lib/levels-set.js +7 -2
  6. package/lib/server/data-server-validator.js +30 -0
  7. package/lib/server/sender.js +1 -1
  8. package/lib/server/storage/models/{class-path-level-labels.js → objection-js/class-path-level-labels-model.js} +7 -7
  9. package/lib/server/storage/models/{class-path-level-skills.js → objection-js/class-path-level-skills-model.js} +9 -9
  10. package/lib/server/storage/models/{class-path.js → objection-js/class-path-model.js} +11 -11
  11. package/lib/server/storage/models/{level.js → objection-js/level-model.js} +7 -7
  12. package/lib/server/storage/models/{level-modifiers.js → objection-js/level-modifiers-model.js} +5 -5
  13. package/lib/server/storage/models/{levels-set.js → objection-js/levels-set-model.js} +7 -7
  14. package/lib/server/storage/models/objection-js/owners-class-path-model.js +35 -0
  15. package/lib/server/storage/models/{registered-entities.js → objection-js/registered-entities-objection-js.js} +14 -14
  16. package/lib/server/storage/models/{skill-attack.js → objection-js/skill-attack.js} +5 -5
  17. package/lib/server/storage/models/{skill-group-relation.js → objection-js/skill-group-relation.js} +7 -7
  18. package/lib/server/storage/models/{skill.js → objection-js/skill-model.js} +15 -15
  19. package/lib/server/storage/models/{skill-owner-conditions.js → objection-js/skill-owner-conditions-model.js} +5 -5
  20. package/lib/server/storage/models/{skill-owner-effects.js → objection-js/skill-owner-effects-model.js} +5 -5
  21. package/lib/server/storage/models/{skill-physical-data.js → objection-js/skill-physical-data-model.js} +5 -5
  22. package/lib/server/storage/models/{skill-target-effects.js → objection-js/skill-target-effects-model.js} +5 -5
  23. package/lib/server/storage/models/{skills-groups.js → objection-js/skills-groups-model.js} +4 -4
  24. package/lib/server/storage/models-manager.js +15 -27
  25. package/lib/server/storage-observer.js +4 -4
  26. package/lib/server.js +3 -1
  27. package/lib/skill.js +47 -37
  28. package/lib/types/attack.js +4 -6
  29. package/lib/types/effect.js +2 -2
  30. package/lib/types/physical-attack.js +8 -27
  31. package/lib/types/physical-effect.js +8 -27
  32. package/lib/types/physical-properties-validator.js +30 -0
  33. package/lib/types/physical-skill-runner.js +31 -0
  34. package/package.json +4 -4
  35. package/lib/server/storage/models/index.js +0 -34
  36. package/lib/server/storage/models/owners-class-path.js +0 -49
@@ -4,10 +4,10 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ModelClassDeprecated } = require('@reldens/storage');
8
- const SkillsConst = require('../../../constants');
7
+ const { ObjectionJsRawModel } = require('@reldens/storage');
8
+ const SkillsConst = require('../../../../constants');
9
9
 
10
- class SkillOwnerEffectsModel extends ModelClassDeprecated
10
+ class SkillOwnerEffectsModel extends ObjectionJsRawModel
11
11
  {
12
12
 
13
13
  static get tableName()
@@ -17,10 +17,10 @@ class SkillOwnerEffectsModel extends ModelClassDeprecated
17
17
 
18
18
  static get relationMappings()
19
19
  {
20
- const { SkillModel } = require('./skill');
20
+ const { SkillModel } = require('./skill-model');
21
21
  return {
22
22
  level_id: {
23
- relation: ModelClassDeprecated.BelongsToOneRelation,
23
+ relation: this.BelongsToOneRelation,
24
24
  modelClass: SkillModel,
25
25
  join: {
26
26
  from: this.tableName+'.skill_id',
@@ -4,10 +4,10 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ModelClassDeprecated } = require('@reldens/storage');
8
- const SkillsConst = require('../../../constants');
7
+ const { ObjectionJsRawModel } = require('@reldens/storage');
8
+ const SkillsConst = require('../../../../constants');
9
9
 
10
- class SkillPhysicalDataModel extends ModelClassDeprecated
10
+ class SkillPhysicalDataModel extends ObjectionJsRawModel
11
11
  {
12
12
 
13
13
  static get tableName()
@@ -17,10 +17,10 @@ class SkillPhysicalDataModel extends ModelClassDeprecated
17
17
 
18
18
  static get relationMappings()
19
19
  {
20
- const { SkillModel } = require('./skill');
20
+ const { SkillModel } = require('./skill-model');
21
21
  return {
22
22
  parent_skill: {
23
- relation: ModelClassDeprecated.HasOneRelation,
23
+ relation: this.HasOneRelation,
24
24
  modelClass: SkillModel,
25
25
  join: {
26
26
  from: this.tableName+'.skill_id',
@@ -4,10 +4,10 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ModelClassDeprecated } = require('@reldens/storage');
8
- const SkillsConst = require('../../../constants');
7
+ const { ObjectionJsRawModel } = require('@reldens/storage');
8
+ const SkillsConst = require('../../../../constants');
9
9
 
10
- class SkillTargetEffectsModel extends ModelClassDeprecated
10
+ class SkillTargetEffectsModel extends ObjectionJsRawModel
11
11
  {
12
12
 
13
13
  static get tableName()
@@ -17,10 +17,10 @@ class SkillTargetEffectsModel extends ModelClassDeprecated
17
17
 
18
18
  static get relationMappings()
19
19
  {
20
- const { SkillModel } = require('./skill');
20
+ const { SkillModel } = require('./skill-model');
21
21
  return {
22
22
  skill_id: {
23
- relation: ModelClassDeprecated.BelongsToOneRelation,
23
+ relation: this.BelongsToOneRelation,
24
24
  modelClass: SkillModel,
25
25
  join: {
26
26
  from: this.tableName+'.skill_id',
@@ -4,10 +4,10 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ModelClassDeprecated } = require('@reldens/storage');
8
- const SkillsConst = require('../../../constants');
7
+ const { ObjectionJsRawModel } = require('@reldens/storage');
8
+ const SkillsConst = require('../../../../constants');
9
9
 
10
- class SkillsGroupsModel extends ModelClassDeprecated
10
+ class SkillsGroupsModel extends ObjectionJsRawModel
11
11
  {
12
12
 
13
13
  static get tableName()
@@ -20,7 +20,7 @@ class SkillsGroupsModel extends ModelClassDeprecated
20
20
  const { SkillGroupRelationModel } = require('./skill-group-relation');
21
21
  return {
22
22
  level_id: {
23
- relation: ModelClassDeprecated.BelongsToOneRelation,
23
+ relation: this.BelongsToOneRelation,
24
24
  modelClass: SkillGroupRelationModel,
25
25
  join: {
26
26
  from: this.tableName+'.group_id',
@@ -4,47 +4,40 @@
4
4
  *
5
5
  */
6
6
 
7
- const { ErrorManager, Logger, EventsManagerSingleton, sc } = require('@reldens/utils');
8
- const { ObjectionJsDataServer } = require('@reldens/storage');
9
- const { Modifier, Condition } = require('@reldens/modifiers');
10
7
  const ClassPath = require('../../class-path');
11
8
  const Level = require('../../level');
12
- const RegisteredModels = require('./models/index');
13
- const { rawRegisteredEntities } = require('./models/registered-entities');
9
+ const { DataServerValidator } = require('../data-server-validator');
10
+ const { Modifier, Condition } = require('@reldens/modifiers');
11
+ const { ErrorManager, Logger, EventsManagerSingleton, sc } = require('@reldens/utils');
14
12
 
15
13
  class ModelsManager
16
14
  {
17
15
 
18
16
  constructor(props)
19
17
  {
20
- let dataServerConfig = sc.getDef(props, 'dataServerConfig', {});
21
- if(!sc.hasOwn(dataServerConfig, 'rawEntities')){
22
- dataServerConfig.rawEntities = rawRegisteredEntities;
23
- }
24
- this.dataServer = sc.hasOwn(props, 'dataServer') ? props.dataServer
25
- : new ObjectionJsDataServer(dataServerConfig);
26
- if(!this.dataServer.initialized){
27
- this.dataServer.connect();
28
- }
18
+ this.dataServer = DataServerValidator.getValidDataServer(props, this);
29
19
  this.events = (props && sc.hasOwn(props, 'events')) ? props.events : EventsManagerSingleton;
30
- this.models = RegisteredModels;
20
+ }
21
+
22
+ getEntity(entityName)
23
+ {
24
+ return this.dataServer.entityManager.get(entityName);
31
25
  }
32
26
 
33
27
  async loadOwnerClassPath(ownerId)
34
28
  {
35
- return this.dataServer.entityManager.get('ownersClassPath')
36
- .loadOneByWithRelations('owner_id', ownerId, '[owner_full_class_path]');
29
+ return this.getEntity('ownersClassPath').loadOneByWithRelations('owner_id', ownerId, '[owner_full_class_path]');
37
30
  }
38
31
 
39
32
  async updateLevel(levelsSet)
40
33
  {
41
- return this.dataServer.entityManager.get('ownersClassClassPath')
34
+ return this.getEntity('ownersClassClassPath')
42
35
  .updateBy('owner_id', levelsSet.getOwnerId(), {currentLevel: levelsSet.currentLevel})
43
36
  }
44
37
 
45
38
  async updateExperience(levelsSet)
46
39
  {
47
- return this.dataServer.entityManager.get('ownersClassClassPath')
40
+ return this.getEntity('ownersClassClassPath')
48
41
  .updateBy('owner_id', levelsSet.getOwnerId(), {currentExp: levelsSet.currentExp})
49
42
  }
50
43
 
@@ -52,10 +45,10 @@ class ModelsManager
52
45
  async prepareSkillsInstancesList(skillsClasses)
53
46
  {
54
47
  let result = {};
55
- // @TODO - BETA: replace relations by constants on the registered-entities definition.
48
+ // @TODO - BETA - Replace relations by constants on the registered-entities definition.
56
49
  // This way we will be able to use the get method, save the entity in a variable and call the relations
57
50
  // list from it.
58
- let skillsModels = await this.dataServer.entityManager.get('skill').loadAllWithRelations([
51
+ let skillsModels = await this.getEntity('skill').loadAllWithRelations([
59
52
  'skill_owner_conditions',
60
53
  'skill_owner_effects',
61
54
  'skill_target_effects'
@@ -80,7 +73,7 @@ class ModelsManager
80
73
  async prepareClassPathInstancesList(classPathClasses)
81
74
  {
82
75
  let result = {};
83
- let classPathModels = await this.dataServer.entityManager.get('classPath').executeCustomQuery('fullPathData');
76
+ let classPathModels = await this.getEntity('classPath').executeCustomQuery('fullPathData');
84
77
  if(sc.isArray(classPathModels) && classPathModels.length){
85
78
  let classPathsById = {};
86
79
  let classPathsByKey = {};
@@ -157,11 +150,6 @@ class ModelsManager
157
150
  autoSortLevels: currentClassPath.data.skills_levels_set.autoSortLevels,
158
151
  currentLevel: currentPlayerClassPath.currentLevel,
159
152
  currentExp: currentPlayerClassPath.currentExp,
160
- // use the same events manager instance from the skills server:
161
- events: this.events,
162
- // activate storage:
163
- persistence: true,
164
- dataServer: this.dataServer
165
153
  };
166
154
  }
167
155
 
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  const { ModelsManager } = require('./storage/models-manager');
8
+ const { DataServerValidator } = require('./data-server-validator');
8
9
  const SkillsEvents = require('../skills-events');
9
10
  const { Logger, sc } = require('@reldens/utils');
10
11
 
@@ -17,13 +18,12 @@ class StorageObserver
17
18
  if(!this.classPath){
18
19
  Logger.error('Class Path data undefined for Storage Observer.');
19
20
  }
20
- let modelsManagerConfig = {};
21
+ let modelsManagerConfig = sc.getDef(props, 'modelsManagerConfig', {});
21
22
  if(this.classPath.events){
22
23
  modelsManagerConfig['events'] = this.classPath.events;
23
24
  }
24
- if(props.dataServer){
25
- modelsManagerConfig['dataServer'] = props.dataServer;
26
- }
25
+ this.dataServer = DataServerValidator.getValidDataServer(props, this);
26
+ modelsManagerConfig['dataServer'] = this.dataServer;
27
27
  this.modelsManager = sc.getDef(props, 'modelsManager', new ModelsManager(modelsManagerConfig));
28
28
  }
29
29
 
package/lib/server.js CHANGED
@@ -7,6 +7,7 @@
7
7
  const ClassPath = require('./class-path');
8
8
  const Sender = require('./server/sender');
9
9
  const { StorageObserver } = require('./server/storage-observer');
10
+ const { DataServerValidator } = require('./server/data-server-validator');
10
11
  const { ErrorManager, sc } = require('@reldens/utils');
11
12
 
12
13
  class SkillsServer
@@ -29,10 +30,11 @@ class SkillsServer
29
30
  if(!sc.hasOwn(props.owner, 'persistData') || typeof props.owner.persistData !== 'function'){
30
31
  ErrorManager.error('Required method "persistData" not found in SkillsServer props.owner.');
31
32
  }
33
+ this.dataServer = DataServerValidator.getValidDataServer(props, this);
32
34
  this.storageObserver = new StorageObserver({
33
35
  classPath: this.classPath,
34
36
  modelsManager,
35
- dataServer: props.dataServer
37
+ dataServer: this.dataServer
36
38
  });
37
39
  this.storageObserver.registerListeners();
38
40
  }
package/lib/skill.js CHANGED
@@ -1,15 +1,13 @@
1
1
  /**
2
2
  *
3
- * Reldens - Skill
4
- *
5
- * Base skill class.
3
+ * Reldens - Skills - Skill
6
4
  *
7
5
  */
8
6
 
9
- const { InteractionArea, EventsManagerSingleton, ErrorManager, sc } = require('@reldens/utils');
10
- const { PropertyManager, Condition, Calculator } = require('@reldens/modifiers');
11
7
  const SkillsConst = require('./constants');
12
8
  const SkillsEvents = require('./skills-events');
9
+ const { PropertyManager, Condition, Calculator } = require('@reldens/modifiers');
10
+ const { InteractionArea, EventsManagerSingleton, ErrorManager, Logger, sc } = require('@reldens/utils');
13
11
 
14
12
  class Skill
15
13
  {
@@ -27,11 +25,11 @@ class Skill
27
25
  }
28
26
  this.key = props.key;
29
27
  this.owner = props.owner;
30
- this.ownerIdProperty = sc.hasOwn(props, 'ownerIdProperty') ? props.ownerIdProperty : 'id';
28
+ this.ownerIdProperty = sc.getDef(props, 'ownerIdProperty', 'id');
31
29
  this.type = SkillsConst.SKILL_TYPE_BASE;
32
- this.customData = sc.hasOwn(props, 'customData') ? props.customData : false;
33
- this.autoValidation = sc.hasOwn(props, 'autoValidation') ? props.autoValidation : false;
34
- this.skillDelay = sc.hasOwn(props, 'skillDelay') ? props.skillDelay : 0;
30
+ this.customData = sc.getDef(props, 'customData', false);
31
+ this.autoValidation = sc.getDef(props, 'autoValidation', false);
32
+ this.skillDelay = sc.getDef(props, 'skillDelay', 0);
35
33
  // @TODO - BETA - Include the following properties and behaviors for skills.
36
34
  // this.targetConditions = sc.hasOwn(props, 'targetConditions') ? props.targetConditions : [];
37
35
  // this.skillDelayModifiers = []; // modifiers array to reduce or increase the skillDelay time.
@@ -41,39 +39,36 @@ class Skill
41
39
  // this.afterSkillTime = 0; // time between the skill end and linkedSkill starts, if 0, will run automatically.
42
40
  // this.failChance = 0; // the 0-100% chance of the skill execution fails.
43
41
  // this.failChanceCallback = () => {}; // a callback to customize the fail chance calculation.
44
- this.castTime = sc.hasOwn(props, 'castTime') ? props.castTime : 0;
42
+ this.castTime = sc.getDef(props, 'castTime', 0);
45
43
  this.owner.isCasting = false;
46
44
  this.isValid = true;
47
- this.usesLimit = sc.hasOwn(props, 'usesLimit') ? props.usesLimit : 0;
45
+ this.usesLimit = sc.getDef(props, 'usesLimit', 0);
48
46
  this.uses = 0;
49
- this.canActivate = sc.hasOwn(props, 'canActivate') ? props.canActivate : true;
50
- this.range = sc.hasOwn(props, 'range') ? props.range : 0;
47
+ this.canActivate = sc.getDef(props, 'canActivate', true);
48
+ this.range = sc.getDef(props, 'range', 0);
51
49
  // if enabled range will be validated just before execution to get the owner and target realtime positions:
52
- this.rangeAutomaticValidation = sc.hasOwn(props, 'rangeAutomaticValidation') ?
53
- props.rangeAutomaticValidation : false;
50
+ this.rangeAutomaticValidation = sc.getDef(props, 'rangeAutomaticValidation', false);
54
51
  // @NOTE: if automatic range validation is enabled the rangePropertyX and rangePropertyY will be required and
55
52
  // used for both (owner and target) by default.
56
- this.rangePropertyX = sc.hasOwn(props, 'rangePropertyX') ? props.rangePropertyX : false;
57
- this.rangePropertyY = sc.hasOwn(props, 'rangePropertyY') ? props.rangePropertyY : false;
53
+ this.rangePropertyX = sc.getDef(props, 'rangePropertyX', false);
54
+ this.rangePropertyY = sc.getDef(props, 'rangePropertyY', false);
58
55
  // specify if you like to use a different range property for the target:
59
- this.rangeTargetPropertyX = sc.hasOwn(props, 'rangeTargetPropertyX') ?
60
- props.rangeTargetPropertyX : false;
61
- this.rangeTargetPropertyY = sc.hasOwn(props, 'rangeTargetPropertyY') ?
62
- props.rangeTargetPropertyY : false;
56
+ this.rangeTargetPropertyX = sc.getDef(props, 'rangeTargetPropertyX', false);
57
+ this.rangeTargetPropertyY = sc.getDef(props, 'rangeTargetPropertyY', false);
63
58
  // allow to target the same owner:
64
- this.allowSelfTarget = sc.hasOwn(props, 'allowSelfTarget') ? props.allowSelfTarget : false;
59
+ this.allowSelfTarget = sc.getDef(props, 'allowSelfTarget', false);
65
60
  // we can use a fixed target or pass the target on execution:
66
- this.target = sc.hasOwn(props, 'target') ? props.target : false;
67
- this.events = sc.hasOwn(props, 'events') ? props.events : EventsManagerSingleton;
68
- this.ownerConditions = sc.hasOwn(props, 'ownerConditions') ? props.ownerConditions : [];
61
+ this.target = sc.getDef(props, 'target', false);
62
+ this.events = sc.getDef(props, 'events', EventsManagerSingleton);
63
+ this.ownerConditions = sc.getDef(props, 'ownerConditions', []);
69
64
  // owner effects will be applied when the skill is executed:
70
- this.ownerEffects = sc.hasOwn(props, 'ownerEffects') ? props.ownerEffects : [];
65
+ this.ownerEffects = sc.getDef(props, 'ownerEffects', []);
71
66
  // groups:
72
- this.groups = sc.hasOwn(props, 'groups') ? props.groups : [];
67
+ this.groups = sc.getDef(props, 'groups', []);
73
68
  // critical multiplier and critical chance are to specify how and if a skill hit is critical:
74
- this.criticalChance = sc.hasOwn(props, 'criticalChance') ? props.criticalChance : 0;
75
- this.criticalMultiplier = sc.hasOwn(props, 'criticalMultiplier') ? props.criticalMultiplier : 1;
76
- this.criticalFixedValue = sc.hasOwn(props, 'criticalFixedValue') ? props.criticalFixedValue : 0;
69
+ this.criticalChance = sc.getDef(props, 'criticalChance', 0);
70
+ this.criticalMultiplier = sc.getDef(props, 'criticalMultiplier', 1);
71
+ this.criticalFixedValue = sc.getDef(props, 'criticalFixedValue', 0);
77
72
  // helper:
78
73
  this.propertyManager = new PropertyManager();
79
74
  this.calculator = new Calculator();
@@ -84,7 +79,10 @@ class Skill
84
79
  // @NOTE: the following is tricky, we use the isValid = true so developers can change it and return a different
85
80
  // isValid value after the event "validateSuccess".
86
81
  this.isValid = true;
87
- this.fireEvent(SkillsEvents.VALIDATE_BEFORE, this);
82
+ // @TODO - BETA - Replace catch.
83
+ this.fireEvent(SkillsEvents.VALIDATE_BEFORE, this).catch((err) => {
84
+ Logger.error(err);
85
+ });
88
86
  // the delay is the time in milliseconds until player can use the skill again:
89
87
  if(!this.canActivate || this.owner.isCasting){
90
88
  // @NOTE: player could be running an attack already.
@@ -106,7 +104,10 @@ class Skill
106
104
  this.canActivate = true;
107
105
  }
108
106
  // with this event we could modify the isValid property if required:
109
- this.fireEvent(SkillsEvents.VALIDATE_SUCCESS, this);
107
+ // @TODO - BETA - Replace catch.
108
+ this.fireEvent(SkillsEvents.VALIDATE_SUCCESS, this).catch((err) => {
109
+ Logger.error(err);
110
+ });
110
111
  return this.isValid;
111
112
  }
112
113
 
@@ -117,7 +118,10 @@ class Skill
117
118
  ErrorManager.error(['Wrong Condition instance.', (typeof condition), 'was specified.']);
118
119
  }
119
120
  if(!condition.isValidOn(this.owner)){
120
- this.fireEvent(SkillsEvents.VALIDATE_FAIL, this, condition);
121
+ // @TODO - BETA - Replace catch.
122
+ this.fireEvent(SkillsEvents.VALIDATE_FAIL, this, condition).catch((err) => {
123
+ Logger.error(err);
124
+ });
121
125
  return false;
122
126
  }
123
127
  }
@@ -142,7 +146,10 @@ class Skill
142
146
 
143
147
  isInRange(ownerPosition, targetPosition)
144
148
  {
145
- this.fireEvent(SkillsEvents.SKILL_BEFORE_IN_RANGE, this);
149
+ // @TODO - BETA - Replace catch.
150
+ this.fireEvent(SkillsEvents.SKILL_BEFORE_IN_RANGE, this).catch((err) => {
151
+ Logger.error(err);
152
+ });
146
153
  // if range is 0 then the attack range is infinity:
147
154
  if(this.range === 0){
148
155
  return true;
@@ -151,7 +158,10 @@ class Skill
151
158
  let interactionArea = new InteractionArea();
152
159
  interactionArea.setupInteractionArea(this.range, targetPosition.x, targetPosition.y);
153
160
  let interactionResult = interactionArea.isValidInteraction(ownerPosition.x, ownerPosition.y);
154
- this.fireEvent(SkillsEvents.SKILL_AFTER_IN_RANGE, this, interactionResult);
161
+ // @TODO - BETA - Replace catch.
162
+ this.fireEvent(SkillsEvents.SKILL_AFTER_IN_RANGE, this, interactionResult).catch((err) => {
163
+ Logger.error(err);
164
+ });
155
165
  return interactionResult;
156
166
  }
157
167
 
@@ -211,7 +221,7 @@ class Skill
211
221
 
212
222
  onExecuteConditions()
213
223
  {
214
- // implement your custom conditions here.
224
+ // implement any custom conditions here.
215
225
  return true;
216
226
  }
217
227
 
@@ -223,7 +233,7 @@ class Skill
223
233
 
224
234
  async onExecuteRewards()
225
235
  {
226
- // implement your custom rewards here.
236
+ // implement any custom rewards here.
227
237
  }
228
238
 
229
239
  applyCriticalValue(normalValue)
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  *
3
- * Reldens - Attack
3
+ * Reldens - Skills - Attack
4
4
  *
5
5
  * This class provides a skill with damage calculation properties and methods.
6
6
  *
7
7
  */
8
8
 
9
- const { ErrorManager, sc } = require('@reldens/utils');
10
9
  const Skill = require('../skill');
11
10
  const SkillsEvents = require('../skills-events');
12
11
  const SkillsConst = require('../constants');
12
+ const { ErrorManager, sc } = require('@reldens/utils');
13
13
 
14
14
  class Attack extends Skill
15
15
  {
@@ -23,8 +23,7 @@ class Attack extends Skill
23
23
  }
24
24
  // the affected property is the one to which the damage calculation will have effect:
25
25
  this.affectedProperty = props.affectedProperty;
26
- this.allowEffectBelowZero = sc.hasOwn(props, 'allowEffectBelowZero')
27
- ? props.allowEffectBelowZero : false;
26
+ this.allowEffectBelowZero = sc.getDef(props, 'allowEffectBelowZero', false);
28
27
  // hit damage value at 100%:
29
28
  this.hitDamage = sc.hasOwn(props, 'hitDamage') ? props.hitDamage : 0;
30
29
  this.applyDirectDamage = sc.hasOwn(props, 'applyDirectDamage') ? props.applyDirectDamage : false;
@@ -45,8 +44,7 @@ class Attack extends Skill
45
44
  // {key: 'propName1', op: ModifierConst.OPS.INC},
46
45
  // {key: 'propName2', op: ModifierConst.OPS.DEC}
47
46
  // }
48
- this.propertiesTotalOperators = sc.hasOwn(props, 'propertiesTotalOperators')
49
- ? props.propertiesTotalOperators : {};
47
+ this.propertiesTotalOperators = sc.getDef(props, 'propertiesTotalOperators', {});
50
48
  }
51
49
 
52
50
  async runSkillLogic()
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  *
3
- * Reldens - Effect
3
+ * Reldens - Skills - Effect
4
4
  *
5
5
  * This class provides a skill with modifiers that will be applied on the target object when the skill is executed.
6
6
  *
7
7
  */
8
8
 
9
- const { ErrorManager, sc } = require('@reldens/utils');
10
9
  const Skill = require('../skill');
11
10
  const SkillsEvents = require('../skills-events');
12
11
  const SkillsConst = require('../constants');
12
+ const { ErrorManager, sc } = require('@reldens/utils');
13
13
 
14
14
  class Effect extends Skill
15
15
  {
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  *
3
- * Reldens - Physical Attack
3
+ * Reldens - Skills - Physical Attack
4
4
  *
5
5
  * This attack will require a world object and collisions to validate the target and execute the skill on hit.
6
6
  *
7
7
  */
8
8
 
9
- const { ErrorManager, sc } = require('@reldens/utils');
10
9
  const Attack = require('./attack');
10
+ const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
11
+ const { PhysicalSkillRunner } = require('./physical-skill-runner');
11
12
  const SkillsConst = require('../constants');
12
13
  const SkillsEvents = require('../skills-events');
14
+ const { sc } = require('@reldens/utils');
13
15
 
14
16
  class PhysicalAttack extends Attack
15
17
  {
@@ -18,43 +20,22 @@ class PhysicalAttack extends Attack
18
20
  {
19
21
  super(props);
20
22
  this.type = SkillsConst.SKILL_TYPE_PHYSICAL_ATTACK;
21
- if(typeof props.owner.executePhysicalSkill !== 'function'){
22
- ErrorManager.error('Missing executePhysicalAttack required method.');
23
- }
24
- if(!sc.hasOwn(props, 'magnitude')){
25
- ErrorManager.error('Missing magnitude property.');
26
- }
27
- if(!sc.hasOwn(props, 'objectWidth')){
28
- ErrorManager.error('Missing objectWidth property.');
29
- }
30
- if(!sc.hasOwn(props, 'objectHeight')){
31
- ErrorManager.error('Missing objectHeight property.');
32
- }
23
+ PhysicalPropertiesValidator.validate(props);
33
24
  this.magnitude = props.magnitude;
34
25
  this.objectWidth = props.objectWidth;
35
26
  this.objectHeight = props.objectHeight;
36
- this.validateTargetOnHit = sc.hasOwn(props, 'validateTargetOnHit') ?
37
- props.validateTargetOnHit : false;
27
+ this.validateTargetOnHit = sc.getDef(props, 'validateTargetOnHit', false);
38
28
  // @TODO - BETA - Include range limit validation and automatic physic body destroy.
39
29
  }
40
30
 
41
31
  async runSkillLogic()
42
32
  {
43
- if(!this.validateRange(this.target)){
44
- // out of range, the owner or the target could moved away
45
- return false;
46
- }
47
- await this.owner.executePhysicalSkill(this.target, this);
48
- return false;
33
+ return PhysicalSkillRunner.runSkillLogic(this);
49
34
  }
50
35
 
51
36
  async executeOnHit(target)
52
37
  {
53
- await this.fireEvent(SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT, this, target);
54
- if(!this.validateTargetOnHit || target === this.target){
55
- return await super.runSkillLogic(target);
56
- }
57
- return false;
38
+ return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT);
58
39
  }
59
40
 
60
41
  }
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  *
3
- * Reldens - Physical Effect
3
+ * Reldens - Skills - Physical Effect
4
4
  *
5
5
  * This attack will require a world object and collisions to validate the target and execute the skill on hit.
6
6
  *
7
7
  */
8
8
 
9
- const { ErrorManager, sc } = require('@reldens/utils');
9
+ const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
10
+ const { PhysicalSkillRunner } = require('./physical-skill-runner');
10
11
  const Effect = require('./effect');
11
12
  const SkillsConst = require('../constants');
12
13
  const SkillsEvents = require('../skills-events');
14
+ const { sc } = require('@reldens/utils');
13
15
 
14
16
  class PhysicalEffect extends Effect
15
17
  {
@@ -18,43 +20,22 @@ class PhysicalEffect extends Effect
18
20
  {
19
21
  super(props);
20
22
  this.type = SkillsConst.SKILL_TYPE_PHYSICAL_EFFECT;
21
- if(typeof props.owner.executePhysicalSkill !== 'function'){
22
- ErrorManager.error('Missing executePhysicalAttack required method.');
23
- }
24
- if(!sc.hasOwn(props, 'magnitude')){
25
- ErrorManager.error('Missing magnitude property.');
26
- }
27
- if(!sc.hasOwn(props, 'objectWidth')){
28
- ErrorManager.error('Missing objectWidth property.');
29
- }
30
- if(!sc.hasOwn(props, 'objectHeight')){
31
- ErrorManager.error('Missing objectHeight property.');
32
- }
23
+ PhysicalPropertiesValidator.validate(props);
33
24
  this.magnitude = props.magnitude;
34
25
  this.objectWidth = props.objectWidth;
35
26
  this.objectHeight = props.objectHeight;
36
- this.validateTargetOnHit = sc.hasOwn(props, 'validateTargetOnHit') ?
37
- props.validateTargetOnHit : false;
27
+ this.validateTargetOnHit = sc.getDef(props, 'validateTargetOnHit', false);
38
28
  // @TODO - BETA - Include range limit validation and automatic physic body destroy.
39
29
  }
40
30
 
41
31
  async runSkillLogic()
42
32
  {
43
- if(!this.validateRange(this.target)){
44
- // out of range, the owner or the target could moved away
45
- return false;
46
- }
47
- await this.owner.executePhysicalSkill(this.target, this);
48
- return false;
33
+ return PhysicalSkillRunner.runSkillLogic(this);
49
34
  }
50
35
 
51
36
  async executeOnHit(target)
52
37
  {
53
- await this.fireEvent(SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT, this, target);
54
- if(!this.validateTargetOnHit || target === this.target){
55
- return super.runSkillLogic(target);
56
- }
57
- return false;
38
+ return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT);
58
39
  }
59
40
 
60
41
  }
@@ -0,0 +1,30 @@
1
+ /**
2
+ *
3
+ * Reldens - Skills - PhysicalPropertiesValidator
4
+ *
5
+ */
6
+
7
+ const { ErrorManager, sc } = require('@reldens/utils');
8
+
9
+ class PhysicalPropertiesValidator
10
+ {
11
+
12
+ static validate(props)
13
+ {
14
+ if(typeof props.owner.executePhysicalSkill !== 'function'){
15
+ ErrorManager.error('Missing executePhysicalAttack required method.');
16
+ }
17
+ if(!sc.hasOwn(props, 'magnitude')){
18
+ ErrorManager.error('Missing magnitude property.');
19
+ }
20
+ if(!sc.hasOwn(props, 'objectWidth')){
21
+ ErrorManager.error('Missing objectWidth property.');
22
+ }
23
+ if(!sc.hasOwn(props, 'objectHeight')){
24
+ ErrorManager.error('Missing objectHeight property.');
25
+ }
26
+ }
27
+
28
+ }
29
+
30
+ module.exports.PhysicalPropertiesValidator = PhysicalPropertiesValidator;