@reldens/skills 0.16.0 → 0.16.2
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/lib/constants.js +14 -1
- package/lib/server/storage/models-manager.js +2 -0
- package/lib/server/storage/skills-generator.js +2 -0
- package/lib/skill.js +2 -0
- package/lib/types/attack.js +6 -1
- package/lib/types/effect.js +3 -0
- package/lib/types/physical-properties-validator.js +1 -1
- package/lib/types/physical-skill-runner.js +7 -1
- package/package.json +1 -1
package/lib/constants.js
CHANGED
|
@@ -45,5 +45,18 @@ module.exports = {
|
|
|
45
45
|
ACTION_SKILL_BEFORE_RUN_LOGIC: actionPref+'Brl',
|
|
46
46
|
ACTION_SKILL_AFTER_RUN_LOGIC: actionPref+'Arl',
|
|
47
47
|
ACTION_SKILL_PHYSICAL_ATTACK_HIT: actionPref+'Pah',
|
|
48
|
-
ACTION_SKILL_PHYSICAL_EFFECT_HIT: actionPref+'Peh'
|
|
48
|
+
ACTION_SKILL_PHYSICAL_EFFECT_HIT: actionPref+'Peh',
|
|
49
|
+
SKILL_STATES: {
|
|
50
|
+
PHYSICAL_SKILL_INVALID_TARGET: 'physicalSkillInvalidTarget',
|
|
51
|
+
PHYSICAL_SKILL_RUN_LOGIC: 'physicalSkillRunLogic',
|
|
52
|
+
OUT_OF_RANGE: 'outOfRange',
|
|
53
|
+
CAN_NOT_ACTIVATE: 'canNotActivate',
|
|
54
|
+
DODGED: 'dodged',
|
|
55
|
+
APPLYING_DAMAGE: 'applyingDamage',
|
|
56
|
+
APPLIED_DAMAGE: 'appliedDamage',
|
|
57
|
+
APPLIED_CRITICAL_DAMAGE: 'appliedCriticalDamage',
|
|
58
|
+
APPLYING_EFFECTS: 'applyingEffects',
|
|
59
|
+
APPLIED_EFFECTS: 'appliedEffects',
|
|
60
|
+
EXECUTE_PHYSICAL_ATTACK: 'executePhysicalAttack'
|
|
61
|
+
}
|
|
49
62
|
};
|
|
@@ -56,6 +56,8 @@ class ModelsManager
|
|
|
56
56
|
// This way we will be able to use the get method, save the entity in a variable and call the relations list
|
|
57
57
|
// from it.
|
|
58
58
|
let skillsModels = await this.getEntity('skill').loadAllWithRelations([
|
|
59
|
+
'skill_attack',
|
|
60
|
+
'skill_physical_data',
|
|
59
61
|
'skill_owner_conditions',
|
|
60
62
|
'skill_owner_effects',
|
|
61
63
|
'skill_target_effects'
|
|
@@ -24,6 +24,8 @@ class SkillsGenerator
|
|
|
24
24
|
}
|
|
25
25
|
// force to use the same events manager instance used on the main package:
|
|
26
26
|
skillModel.events = events;
|
|
27
|
+
this.enrichWithAttackData(skillModel);
|
|
28
|
+
this.enrichWithPhysicalData(skillModel);
|
|
27
29
|
skillsList[skillModel.key] = {class: skillClass, data: skillModel};
|
|
28
30
|
}
|
|
29
31
|
return {skillsModels, skillsList};
|
package/lib/skill.js
CHANGED
|
@@ -46,6 +46,7 @@ class Skill
|
|
|
46
46
|
this.uses = 0;
|
|
47
47
|
this.canActivate = sc.get(props, 'canActivate', true);
|
|
48
48
|
this.range = sc.get(props, 'range', 0);
|
|
49
|
+
this.lastState = '';
|
|
49
50
|
// if enabled range will be validated just before execution to get the owner and target realtime positions:
|
|
50
51
|
this.rangeAutomaticValidation = sc.get(props, 'rangeAutomaticValidation', false);
|
|
51
52
|
// @NOTE: if automatic range validation is enabled the rangePropertyX and rangePropertyY will be required and
|
|
@@ -85,6 +86,7 @@ class Skill
|
|
|
85
86
|
});
|
|
86
87
|
// the delay is the time in milliseconds until player can use the skill again:
|
|
87
88
|
if(!this.canActivate || this.owner.isCasting){
|
|
89
|
+
this.lastState = SkillsConst.SKILL_STATES.CAN_NOT_ACTIVATE;
|
|
88
90
|
// @NOTE: player could be running an attack already.
|
|
89
91
|
return false;
|
|
90
92
|
}
|
package/lib/types/attack.js
CHANGED
|
@@ -50,9 +50,11 @@ class Attack extends Skill
|
|
|
50
50
|
async runSkillLogic()
|
|
51
51
|
{
|
|
52
52
|
if(!this.validateRange(this.target)){
|
|
53
|
-
// out of range, the owner or the target could
|
|
53
|
+
// out of range, the owner or the target could move away
|
|
54
|
+
this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
|
|
54
55
|
return false;
|
|
55
56
|
}
|
|
57
|
+
this.lastState = SkillsConst.SKILL_STATES.APPLYING_DAMAGE;
|
|
56
58
|
return await this.applyDamageTo(this.target);
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -64,6 +66,7 @@ class Attack extends Skill
|
|
|
64
66
|
let ownerAim = this.getPropertiesTotal(this.owner, this.aimProperties);
|
|
65
67
|
let targetDodge = this.getPropertiesTotal(target, this.dodgeProperties);
|
|
66
68
|
if(this.dodgeFullEnabled && targetDodge > (ownerAim * this.dodgeOverAimSuccess)){
|
|
69
|
+
this.lastState = SkillsConst.SKILL_STATES.DODGED;
|
|
67
70
|
return false;
|
|
68
71
|
}
|
|
69
72
|
let affectedPropertyValue = this.getAffectedPropertyValue(target);
|
|
@@ -82,6 +85,7 @@ class Attack extends Skill
|
|
|
82
85
|
? 0
|
|
83
86
|
: affectedPropertyValue - damage;
|
|
84
87
|
this.setAffectedPropertyValue(target, modifiedValue);
|
|
88
|
+
this.lastState = SkillsConst.SKILL_STATES.APPLIED_DAMAGE;
|
|
85
89
|
await this.fireEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, this, target, damage, modifiedValue);
|
|
86
90
|
}
|
|
87
91
|
|
|
@@ -91,6 +95,7 @@ class Attack extends Skill
|
|
|
91
95
|
if(!this.criticalAffected || targetDodge > ownerAim){
|
|
92
96
|
return criticalValue;
|
|
93
97
|
}
|
|
98
|
+
this.lastState = SkillsConst.SKILL_STATES.APPLIED_CRITICAL_DAMAGE;
|
|
94
99
|
// calculate dodge proportion over critical damage and remove it from the critical total:
|
|
95
100
|
return criticalValue - (Math.floor((criticalValue * dodgeAimDiff / 100)));
|
|
96
101
|
}
|
package/lib/types/effect.js
CHANGED
|
@@ -27,12 +27,15 @@ class Effect extends Skill
|
|
|
27
27
|
async runSkillLogic()
|
|
28
28
|
{
|
|
29
29
|
if(!this.validateRange(this.target)){
|
|
30
|
+
this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
|
|
30
31
|
// out of range, the owner or the target could moved away
|
|
31
32
|
return false;
|
|
32
33
|
}
|
|
34
|
+
this.lastState = SkillsConst.SKILL_STATES.APPLYING_EFFECTS;
|
|
33
35
|
// @NOTE: the difference between the normal skills modifiers and the effects are the critical chance applied
|
|
34
36
|
// to the modifiers here.
|
|
35
37
|
this.applyModifiers(this.targetEffects, this.target);
|
|
38
|
+
this.lastState = SkillsConst.SKILL_STATES.APPLIED_EFFECTS;
|
|
36
39
|
await this.fireEvent(SkillsEvents.SKILL_EFFECT_TARGET_MODIFIERS, this);
|
|
37
40
|
}
|
|
38
41
|
|
|
@@ -12,7 +12,7 @@ class PhysicalPropertiesValidator
|
|
|
12
12
|
static validate(props)
|
|
13
13
|
{
|
|
14
14
|
if(typeof props.owner.executePhysicalSkill !== 'function'){
|
|
15
|
-
ErrorManager.error('Missing
|
|
15
|
+
ErrorManager.error('Missing executePhysicalSkill required method.');
|
|
16
16
|
}
|
|
17
17
|
if(!sc.hasOwn(props, 'magnitude')){
|
|
18
18
|
ErrorManager.error('Missing magnitude property.');
|
|
@@ -4,15 +4,19 @@
|
|
|
4
4
|
*
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const SkillsConst = require('@reldens/skills/lib/constants');
|
|
8
|
+
|
|
7
9
|
class PhysicalSkillRunner
|
|
8
10
|
{
|
|
9
11
|
|
|
10
12
|
static async runSkillLogic(skill)
|
|
11
13
|
{
|
|
12
14
|
if(!skill.validateRange(skill.target)){
|
|
13
|
-
|
|
15
|
+
this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
|
|
16
|
+
// @NOTE: out of range, the owner or the target could have moved away.
|
|
14
17
|
return false;
|
|
15
18
|
}
|
|
19
|
+
this.lastState = SkillsConst.SKILL_STATES.EXECUTE_PHYSICAL_ATTACK;
|
|
16
20
|
await skill.owner.executePhysicalSkill(skill.target, skill);
|
|
17
21
|
return false;
|
|
18
22
|
}
|
|
@@ -21,11 +25,13 @@ class PhysicalSkillRunner
|
|
|
21
25
|
{
|
|
22
26
|
await skill.fireEvent(skillType, skill, target);
|
|
23
27
|
if(skill.validateTargetOnHit && target !== skill.target){
|
|
28
|
+
this.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_INVALID_TARGET;
|
|
24
29
|
return false;
|
|
25
30
|
}
|
|
26
31
|
if('function' !== typeof runSkillLogicCallback){
|
|
27
32
|
return false;
|
|
28
33
|
}
|
|
34
|
+
this.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_RUN_LOGIC;
|
|
29
35
|
return await runSkillLogicCallback(target);
|
|
30
36
|
}
|
|
31
37
|
|