@reldens/skills 0.10.0-beta.24 → 0.10.0-beta.28

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.
@@ -18,7 +18,7 @@ class Receiver
18
18
  if(typeof props.owner.getPosition !== 'function'){
19
19
  ErrorManager.error('Undefined owner position method.');
20
20
  }
21
- this.actions = sc.getDef(props, 'actions', {});
21
+ this.actions = sc.get(props, 'actions', {});
22
22
  if(!sc.hasOwn(props, 'avoidDefaults') || !props['avoidDefaults']){
23
23
  this.setDefaultMethods();
24
24
  }
package/lib/level.js CHANGED
@@ -16,13 +16,13 @@ class Level
16
16
  ErrorManager.error('Invalid Level key.');
17
17
  }
18
18
  if(!sc.hasOwn(props, 'modifiers') || 0 >= props.modifiers.length){
19
- Logger.error('Modifiers were not specified.', 'Level ID:', props.id, ' - Key:', props.key);
19
+ Logger.error('Level modifiers were not specified.', 'Level ID:', props.id, ' - Key:', props.key);
20
20
  }
21
21
  this.key = parseInt(props.key);
22
22
  this.modifiers = props.modifiers;
23
23
  // label could be used for messages like "you have reached level X!":
24
- this.label = sc.getDef(props, 'label', props.key);
25
- this.requiredExperience = sc.getDef(props, 'requiredExperience', sc.getDef(props, 'required_experience', 0));
24
+ this.label = sc.get(props, 'label', props.key);
25
+ this.requiredExperience = sc.get(props, 'requiredExperience', sc.get(props, 'required_experience', 0));
26
26
  }
27
27
 
28
28
  }
package/lib/levels-set.js CHANGED
@@ -13,7 +13,7 @@ class LevelsSet
13
13
 
14
14
  constructor(props)
15
15
  {
16
- this.events = sc.getDef(props, 'events', EventsManagerSingleton);
16
+ this.events = sc.get(props, 'events', EventsManagerSingleton);
17
17
  }
18
18
 
19
19
  setOwner(props)
@@ -45,10 +45,10 @@ class LevelsSet
45
45
  // @NOTE: if autoFillRanges is enabled you could have the first level with key = 1 and the next with key = 5,
46
46
  // this way the setLevels will fill up levels 2, 3 and 4 with the same level Object so the same level modifiers
47
47
  // will be applied automatically (same calculation for multiple levels).
48
- this.autoFillRanges = sc.getDef(props, 'autoFillRanges', false);
49
- this.autoFillExperienceMultiplier = sc.getDef(props, 'autoFillExperienceMultiplier', 1.5);
50
- this.currentLevel = sc.getDef(props, 'currentLevel', 0);
51
- this.currentExp = sc.getDef(props, 'currentExp', 0);
48
+ this.autoFillRanges = sc.get(props, 'autoFillRanges', false);
49
+ this.autoFillExperienceMultiplier = sc.get(props, 'autoFillExperienceMultiplier', 1.5);
50
+ this.currentLevel = sc.get(props, 'currentLevel', 0);
51
+ this.currentExp = sc.get(props, 'currentExp', 0);
52
52
  // set levels is almost the last thing to happen here, first we need to validate all the other parameters:
53
53
  this.levels = await this.setLevels(props.levels);
54
54
  // @NOTE: if you setup levelsByExperience and autoFillRanges at the same time the levels autogenerated will be
@@ -56,9 +56,9 @@ class LevelsSet
56
56
  // level 5 required experience = 20p, level 2, 3 and 4 are auto-generated with required exp. = 20p, so when the
57
57
  // player reach 20p of experience it will jump to level 5. In summary you shouldn't mix these options unless
58
58
  // you expect the described behavior.
59
- this.increaseLevelsWithExperience = sc.getDef(props, 'increaseLevelsWithExperience', true);
59
+ this.increaseLevelsWithExperience = sc.get(props, 'increaseLevelsWithExperience', true);
60
60
  // unless specified, levels by experience must just be sorted by their key attribute (without auto-fill):
61
- this.levelsByExperience = sc.getDef(props, 'levelsByExperience', this.sortLevelsBy(this.levels));
61
+ this.levelsByExperience = sc.get(props, 'levelsByExperience', this.sortLevelsBy(this.levels));
62
62
  await this.fireEvent(SkillsEvents.INIT_LEVEL_SET_END, this);
63
63
  }
64
64
 
@@ -231,7 +231,7 @@ class LevelsSet
231
231
 
232
232
  getOwnerEventKey()
233
233
  {
234
- return sc.getDef(this.owner, 'eventsPrefix', '')+this.getOwnerId();
234
+ return sc.get(this.owner, 'eventsPrefix', '')+this.getOwnerId();
235
235
  }
236
236
 
237
237
  async fireEvent(eventName, ...args)
@@ -12,7 +12,7 @@ class DataServerValidator
12
12
  static getValidDataServer(props)
13
13
  {
14
14
  // @TODO - BETA - When moving to ES or TS dataServer will be typed and an interface.
15
- let dataServer = sc.getDef(props, 'dataServer', false);
15
+ let dataServer = sc.get(props, 'dataServer', false);
16
16
  if(false === dataServer){
17
17
  ErrorManager.error('Data Server instance not found.', props);
18
18
  }
@@ -26,19 +26,19 @@ class ModelsManager
26
26
 
27
27
  async loadOwnerClassPath(ownerId)
28
28
  {
29
- return this.getEntity('ownersClassPath').loadOneByWithRelations('owner_id', ownerId, '[owner_full_class_path]');
29
+ return await this.getEntity('ownersClassPath').loadOneByWithRelations('owner_id', ownerId, '[owner_full_class_path]');
30
30
  }
31
31
 
32
32
  async updateLevel(levelsSet)
33
33
  {
34
- return this.getEntity('ownersClassClassPath')
34
+ return await this.getEntity('ownersClassPath')
35
35
  .updateBy('owner_id', levelsSet.getOwnerId(), {currentLevel: levelsSet.currentLevel})
36
36
  }
37
37
 
38
38
  async updateExperience(levelsSet)
39
39
  {
40
- return this.getEntity('ownersClassClassPath')
41
- .updateBy('owner_id', levelsSet.getOwnerId(), {currentExp: levelsSet.currentExp})
40
+ return await this.getEntity('ownersClassPath')
41
+ .updateBy('owner_id', levelsSet.getOwnerId(), {currentExp: levelsSet.currentExp});
42
42
  }
43
43
 
44
44
  // @TODO - BETA - Create a skills instances generator class to replace this function.
@@ -18,13 +18,18 @@ class StorageObserver
18
18
  if(!this.classPath){
19
19
  Logger.error('Class Path data undefined for Storage Observer.');
20
20
  }
21
- let modelsManagerConfig = sc.getDef(props, 'modelsManagerConfig', {});
21
+ let modelsManagerConfig = sc.get(props, 'modelsManagerConfig', {});
22
22
  if(this.classPath.events){
23
23
  modelsManagerConfig['events'] = this.classPath.events;
24
24
  }
25
25
  this.dataServer = DataServerValidator.getValidDataServer(props, this);
26
26
  modelsManagerConfig['dataServer'] = this.dataServer;
27
- this.modelsManager = sc.getDef(props, 'modelsManager', new ModelsManager(modelsManagerConfig));
27
+ this.modelsManager = sc.isTrue(props, 'modelsManager') // @NOTE: can't use getDef because it could be false.
28
+ ? props.modelsManager
29
+ : new ModelsManager(modelsManagerConfig);
30
+ if(!this.modelsManager){
31
+ Logger.error('ModelsManager undefined for Skills Storage Observer.');
32
+ }
28
33
  }
29
34
 
30
35
  registerListeners()
package/lib/server.js CHANGED
@@ -8,7 +8,7 @@ const ClassPath = require('./class-path');
8
8
  const Sender = require('./server/sender');
9
9
  const { StorageObserver } = require('./server/storage-observer');
10
10
  const { DataServerValidator } = require('./server/data-server-validator');
11
- const { ErrorManager, sc } = require('@reldens/utils');
11
+ const { ErrorManager, sc, Logger} = require('@reldens/utils');
12
12
 
13
13
  class SkillsServer
14
14
  {
@@ -25,17 +25,20 @@ class SkillsServer
25
25
  this.classPath.setOwner(props);
26
26
  // check if the storage was activated:
27
27
  if(sc.isTrue(props, 'persistence')){
28
- let modelsManager = sc.getDef(props, 'modelsManager', false);
29
28
  // check if the owner has the required persisData methods in the case the storage is active:
30
29
  if(!sc.hasOwn(props.owner, 'persistData') || typeof props.owner.persistData !== 'function'){
31
30
  ErrorManager.error('Required method "persistData" not found in SkillsServer props.owner.');
32
31
  }
33
32
  this.dataServer = DataServerValidator.getValidDataServer(props, this);
34
- this.storageObserver = new StorageObserver({
33
+ let storageObserverProps = {
35
34
  classPath: this.classPath,
36
- modelsManager,
37
35
  dataServer: this.dataServer
38
- });
36
+ };
37
+ let modelsManager = sc.get(props, 'modelsManager', false);
38
+ if(modelsManager){
39
+ storageObserverProps.modelsManager = modelsManager;
40
+ }
41
+ this.storageObserver = new StorageObserver(storageObserverProps);
39
42
  this.storageObserver.registerListeners();
40
43
  }
41
44
  if(sc.hasOwn(props, 'client')){
package/lib/skill.js CHANGED
@@ -25,11 +25,11 @@ class Skill
25
25
  }
26
26
  this.key = props.key;
27
27
  this.owner = props.owner;
28
- this.ownerIdProperty = sc.getDef(props, 'ownerIdProperty', 'id');
28
+ this.ownerIdProperty = sc.get(props, 'ownerIdProperty', 'id');
29
29
  this.type = SkillsConst.SKILL_TYPE_BASE;
30
- this.customData = sc.getDef(props, 'customData', false);
31
- this.autoValidation = sc.getDef(props, 'autoValidation', false);
32
- this.skillDelay = sc.getDef(props, 'skillDelay', 0);
30
+ this.customData = sc.get(props, 'customData', false);
31
+ this.autoValidation = sc.get(props, 'autoValidation', false);
32
+ this.skillDelay = sc.get(props, 'skillDelay', 0);
33
33
  // @TODO - BETA - Include the following properties and behaviors for skills.
34
34
  // this.targetConditions = sc.hasOwn(props, 'targetConditions') ? props.targetConditions : [];
35
35
  // this.skillDelayModifiers = []; // modifiers array to reduce or increase the skillDelay time.
@@ -39,36 +39,36 @@ class Skill
39
39
  // this.afterSkillTime = 0; // time between the skill end and linkedSkill starts, if 0, will run automatically.
40
40
  // this.failChance = 0; // the 0-100% chance of the skill execution fails.
41
41
  // this.failChanceCallback = () => {}; // a callback to customize the fail chance calculation.
42
- this.castTime = sc.getDef(props, 'castTime', 0);
42
+ this.castTime = sc.get(props, 'castTime', 0);
43
43
  this.owner.isCasting = false;
44
44
  this.isValid = true;
45
- this.usesLimit = sc.getDef(props, 'usesLimit', 0);
45
+ this.usesLimit = sc.get(props, 'usesLimit', 0);
46
46
  this.uses = 0;
47
- this.canActivate = sc.getDef(props, 'canActivate', true);
48
- this.range = sc.getDef(props, 'range', 0);
47
+ this.canActivate = sc.get(props, 'canActivate', true);
48
+ this.range = sc.get(props, 'range', 0);
49
49
  // if enabled range will be validated just before execution to get the owner and target realtime positions:
50
- this.rangeAutomaticValidation = sc.getDef(props, 'rangeAutomaticValidation', false);
50
+ this.rangeAutomaticValidation = sc.get(props, 'rangeAutomaticValidation', false);
51
51
  // @NOTE: if automatic range validation is enabled the rangePropertyX and rangePropertyY will be required and
52
52
  // used for both (owner and target) by default.
53
- this.rangePropertyX = sc.getDef(props, 'rangePropertyX', false);
54
- this.rangePropertyY = sc.getDef(props, 'rangePropertyY', false);
53
+ this.rangePropertyX = sc.get(props, 'rangePropertyX', false);
54
+ this.rangePropertyY = sc.get(props, 'rangePropertyY', false);
55
55
  // specify if you like to use a different range property for the target:
56
- this.rangeTargetPropertyX = sc.getDef(props, 'rangeTargetPropertyX', false);
57
- this.rangeTargetPropertyY = sc.getDef(props, 'rangeTargetPropertyY', false);
56
+ this.rangeTargetPropertyX = sc.get(props, 'rangeTargetPropertyX', false);
57
+ this.rangeTargetPropertyY = sc.get(props, 'rangeTargetPropertyY', false);
58
58
  // allow to target the same owner:
59
- this.allowSelfTarget = sc.getDef(props, 'allowSelfTarget', false);
59
+ this.allowSelfTarget = sc.get(props, 'allowSelfTarget', false);
60
60
  // we can use a fixed target or pass the target on execution:
61
- this.target = sc.getDef(props, 'target', false);
62
- this.events = sc.getDef(props, 'events', EventsManagerSingleton);
63
- this.ownerConditions = sc.getDef(props, 'ownerConditions', []);
61
+ this.target = sc.get(props, 'target', false);
62
+ this.events = sc.get(props, 'events', EventsManagerSingleton);
63
+ this.ownerConditions = sc.get(props, 'ownerConditions', []);
64
64
  // owner effects will be applied when the skill is executed:
65
- this.ownerEffects = sc.getDef(props, 'ownerEffects', []);
65
+ this.ownerEffects = sc.get(props, 'ownerEffects', []);
66
66
  // groups:
67
- this.groups = sc.getDef(props, 'groups', []);
67
+ this.groups = sc.get(props, 'groups', []);
68
68
  // critical multiplier and critical chance are to specify how and if a skill hit is critical:
69
- this.criticalChance = sc.getDef(props, 'criticalChance', 0);
70
- this.criticalMultiplier = sc.getDef(props, 'criticalMultiplier', 1);
71
- this.criticalFixedValue = sc.getDef(props, 'criticalFixedValue', 0);
69
+ this.criticalChance = sc.get(props, 'criticalChance', 0);
70
+ this.criticalMultiplier = sc.get(props, 'criticalMultiplier', 1);
71
+ this.criticalFixedValue = sc.get(props, 'criticalFixedValue', 0);
72
72
  // helper:
73
73
  this.propertyManager = new PropertyManager();
74
74
  this.calculator = new Calculator();
@@ -289,7 +289,7 @@ class Skill
289
289
 
290
290
  getOwnerEventKey()
291
291
  {
292
- return sc.getDef(this.owner, 'eventsPrefix', '')+this.getOwnerId();
292
+ return sc.get(this.owner, 'eventsPrefix', '')+this.getOwnerId();
293
293
  }
294
294
 
295
295
  async fireEvent(eventName, ...args)
@@ -23,7 +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.getDef(props, 'allowEffectBelowZero', false);
26
+ this.allowEffectBelowZero = sc.get(props, 'allowEffectBelowZero', false);
27
27
  // hit damage value at 100%:
28
28
  this.hitDamage = sc.hasOwn(props, 'hitDamage') ? props.hitDamage : 0;
29
29
  this.applyDirectDamage = sc.hasOwn(props, 'applyDirectDamage') ? props.applyDirectDamage : false;
@@ -44,7 +44,7 @@ class Attack extends Skill
44
44
  // {key: 'propName1', op: ModifierConst.OPS.INC},
45
45
  // {key: 'propName2', op: ModifierConst.OPS.DEC}
46
46
  // }
47
- this.propertiesTotalOperators = sc.getDef(props, 'propertiesTotalOperators', {});
47
+ this.propertiesTotalOperators = sc.get(props, 'propertiesTotalOperators', {});
48
48
  }
49
49
 
50
50
  async runSkillLogic()
@@ -24,7 +24,7 @@ class PhysicalAttack extends Attack
24
24
  this.magnitude = props.magnitude;
25
25
  this.objectWidth = props.objectWidth;
26
26
  this.objectHeight = props.objectHeight;
27
- this.validateTargetOnHit = sc.getDef(props, 'validateTargetOnHit', false);
27
+ this.validateTargetOnHit = sc.get(props, 'validateTargetOnHit', false);
28
28
  // @TODO - BETA - Include range limit validation and automatic physic body destroy.
29
29
  }
30
30
 
@@ -35,7 +35,9 @@ class PhysicalAttack extends Attack
35
35
 
36
36
  async executeOnHit(target)
37
37
  {
38
- return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT);
38
+ return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT, (target) => {
39
+ super.runSkillLogic(target);
40
+ });
39
41
  }
40
42
 
41
43
  }
@@ -6,9 +6,9 @@
6
6
  *
7
7
  */
8
8
 
9
+ const Effect = require('./effect');
9
10
  const { PhysicalPropertiesValidator } = require('./physical-properties-validator');
10
11
  const { PhysicalSkillRunner } = require('./physical-skill-runner');
11
- const Effect = require('./effect');
12
12
  const SkillsConst = require('../constants');
13
13
  const SkillsEvents = require('../skills-events');
14
14
  const { sc } = require('@reldens/utils');
@@ -24,7 +24,7 @@ class PhysicalEffect extends Effect
24
24
  this.magnitude = props.magnitude;
25
25
  this.objectWidth = props.objectWidth;
26
26
  this.objectHeight = props.objectHeight;
27
- this.validateTargetOnHit = sc.getDef(props, 'validateTargetOnHit', false);
27
+ this.validateTargetOnHit = sc.get(props, 'validateTargetOnHit', false);
28
28
  // @TODO - BETA - Include range limit validation and automatic physic body destroy.
29
29
  }
30
30
 
@@ -35,7 +35,9 @@ class PhysicalEffect extends Effect
35
35
 
36
36
  async executeOnHit(target)
37
37
  {
38
- return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT);
38
+ return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT, (target) => {
39
+ super.runSkillLogic(target);
40
+ });
39
41
  }
40
42
 
41
43
  }
@@ -17,11 +17,14 @@ class PhysicalSkillRunner
17
17
  return false;
18
18
  }
19
19
 
20
- static async executeOnHit(target, skill, skillType)
20
+ static async executeOnHit(target, skill, skillType, runSkillLogicCallback)
21
21
  {
22
22
  await skill.fireEvent(skillType, skill, target);
23
23
  if(!skill.validateTargetOnHit || target === skill.target){
24
- return await super.runSkillLogic(target);
24
+ if('function' !== typeof runSkillLogicCallback){
25
+ return false;
26
+ }
27
+ return await runSkillLogicCallback(target);
25
28
  }
26
29
  return false;
27
30
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/skills",
3
3
  "scope": "@reldens",
4
- "version": "0.10.0-beta.24",
4
+ "version": "0.10.0-beta.28",
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.5.0",
44
- "@reldens/storage": "^0.10.0-beta.24",
45
- "@reldens/utils": "^0.5.0"
43
+ "@reldens/modifiers": "^0.10.0-beta.2",
44
+ "@reldens/storage": "^0.10.0-beta.29",
45
+ "@reldens/utils": "^0.10.0-beta.3"
46
46
  }
47
47
  }