@reldens/skills 0.56.0 → 0.59.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,45 +1,45 @@
1
- /**
2
- *
3
- * Reldens - Skills - Events list
4
- *
5
- */
6
-
7
- // @NOTE: events names are long because these need to be descriptive.
8
-
9
- let pref = 'reldens.skills.';
10
-
11
- module.exports = {
12
- PREF: pref,
13
- INIT_LEVEL_SET_START: pref+'initLevelSetStart',
14
- INIT_LEVEL_SET_END: pref+'initLevelSetEnd',
15
- INIT_CLASS_PATH_END: pref+'initClassPathEnd',
16
- LOADED_OWNER_SKILLS: pref+'loadedOwnerSkills',
17
- SET_SKILLS: pref+'setSkills',
18
- SET_LEVELS: pref+'setLevels',
19
- GENERATED_LEVELS: pref+'generatedLevels',
20
- ADD_SKILLS_BEFORE: pref+'addSkillBefore',
21
- ADD_SKILLS_AFTER: pref+'addSkillAfter',
22
- REMOVE_SKILLS_BEFORE: pref+'removeSkillBefore',
23
- REMOVE_SKILLS_AFTER: pref+'removeSkillAfter',
24
- VALIDATE_BEFORE: pref+'beforeValidate',
25
- VALIDATE_SUCCESS: pref+'validateSuccess',
26
- VALIDATE_FAIL: pref+'validateFail',
27
- EXECUTING_SKILL: pref+'executingSkill',
28
- LEVEL_EXPERIENCE_ADDED: pref+'experienceAdded',
29
- LEVEL_UP: pref+'levelUp',
30
- LEVEL_DOWN: pref+'levelDown',
31
- LEVEL_APPLY_MODIFIERS: pref+'levelApplyModifiers',
32
- SKILL_BEFORE_IN_RANGE: pref+'beforeIsInRange',
33
- SKILL_AFTER_IN_RANGE: pref+'afterIsInRange',
34
- SKILL_BEFORE_EXECUTE: pref+'beforeExecute',
35
- SKILL_AFTER_EXECUTE: pref+'afterExecute',
36
- SKILL_BEFORE_CAST: pref+'beforeCast',
37
- SKILL_AFTER_CAST: pref+'afterCast',
38
- SKILL_BEFORE_RUN_LOGIC: pref+'beforeRunLogic',
39
- SKILL_AFTER_RUN_LOGIC: pref+'afterRanLogic',
40
- SKILL_APPLY_OWNER_EFFECTS: pref+'applyOwnerEffects',
41
- SKILL_ATTACK_APPLY_DAMAGE: pref+'attackApplyDamage',
42
- SKILL_EFFECT_TARGET_MODIFIERS: pref+'effectTargetModifiers',
43
- SKILL_PHYSICAL_ATTACK_HIT: pref+'physicalAttackOnHit',
44
- SKILL_PHYSICAL_EFFECT_HIT: pref+'physicalEffectOnHit'
45
- };
1
+ /**
2
+ *
3
+ * Reldens - Skills - Events list
4
+ *
5
+ */
6
+
7
+ // @NOTE: events names are long because these need to be descriptive.
8
+
9
+ let pref = 'reldens.skills.';
10
+
11
+ module.exports = {
12
+ PREF: pref,
13
+ INIT_LEVEL_SET_START: pref+'initLevelSetStart',
14
+ INIT_LEVEL_SET_END: pref+'initLevelSetEnd',
15
+ INIT_CLASS_PATH_END: pref+'initClassPathEnd',
16
+ LOADED_OWNER_SKILLS: pref+'loadedOwnerSkills',
17
+ SET_SKILLS: pref+'setSkills',
18
+ SET_LEVELS: pref+'setLevels',
19
+ GENERATED_LEVELS: pref+'generatedLevels',
20
+ ADD_SKILLS_BEFORE: pref+'addSkillBefore',
21
+ ADD_SKILLS_AFTER: pref+'addSkillAfter',
22
+ REMOVE_SKILLS_BEFORE: pref+'removeSkillBefore',
23
+ REMOVE_SKILLS_AFTER: pref+'removeSkillAfter',
24
+ VALIDATE_BEFORE: pref+'beforeValidate',
25
+ VALIDATE_SUCCESS: pref+'validateSuccess',
26
+ VALIDATE_FAIL: pref+'validateFail',
27
+ EXECUTING_SKILL: pref+'executingSkill',
28
+ LEVEL_EXPERIENCE_ADDED: pref+'experienceAdded',
29
+ LEVEL_UP: pref+'levelUp',
30
+ LEVEL_DOWN: pref+'levelDown',
31
+ LEVEL_APPLY_MODIFIERS: pref+'levelApplyModifiers',
32
+ SKILL_BEFORE_IN_RANGE: pref+'beforeIsInRange',
33
+ SKILL_AFTER_IN_RANGE: pref+'afterIsInRange',
34
+ SKILL_BEFORE_EXECUTE: pref+'beforeExecute',
35
+ SKILL_AFTER_EXECUTE: pref+'afterExecute',
36
+ SKILL_BEFORE_CAST: pref+'beforeCast',
37
+ SKILL_AFTER_CAST: pref+'afterCast',
38
+ SKILL_BEFORE_RUN_LOGIC: pref+'beforeRunLogic',
39
+ SKILL_AFTER_RUN_LOGIC: pref+'afterRanLogic',
40
+ SKILL_APPLY_OWNER_EFFECTS: pref+'applyOwnerEffects',
41
+ SKILL_ATTACK_APPLY_DAMAGE: pref+'attackApplyDamage',
42
+ SKILL_EFFECT_TARGET_MODIFIERS: pref+'effectTargetModifiers',
43
+ SKILL_PHYSICAL_ATTACK_HIT: pref+'physicalAttackOnHit',
44
+ SKILL_PHYSICAL_EFFECT_HIT: pref+'physicalEffectOnHit'
45
+ };
@@ -1,202 +1,202 @@
1
- /**
2
- *
3
- * Reldens - Skills - Attack
4
- *
5
- * This class provides a skill with damage calculation properties and methods.
6
- *
7
- */
8
-
9
- const Skill = require('../skill');
10
- const SkillsEvents = require('../skills-events');
11
- const SkillsConst = require('../constants');
12
- const { Logger, sc } = require('@reldens/utils');
13
-
14
- class Attack extends Skill
15
- {
16
-
17
- constructor(props)
18
- {
19
- super(props);
20
- this.type = SkillsConst.SKILL.TYPE.ATTACK;
21
- let affectedProperty = sc.get(props, 'affectedProperty', false);
22
- if(!affectedProperty){
23
- Logger.error('Missing skill affectedProperty to which the result damage will be applied.');
24
- this.isReady = false;
25
- }
26
- // the affected property is the one to which the damage calculation will have effect:
27
- this.affectedProperty = affectedProperty;
28
- this.allowEffectBelowZero = sc.get(props, 'allowEffectBelowZero', false);
29
- // hit damage value at 100%:
30
- this.hitDamage = sc.get(props, 'hitDamage', 0);
31
- this.applyDirectDamage = sc.get(props, 'applyDirectDamage', false);
32
- // all properties are obtained from the skill owner and the target to calculate the damage:
33
- this.attackProperties = sc.get(props, 'attackProperties', []);
34
- this.defenseProperties = sc.get(props, 'defenseProperties', []);
35
- // aim and dodge properties are used to determine if the skill could fail:
36
- this.aimProperties = sc.get(props, 'aimProperties', []);
37
- this.dodgeProperties = sc.get(props, 'dodgeProperties', []);
38
- // dodgeFullEnabled will make the attack fail if: dodge > ownerAim * dodgeOverAimSuccess
39
- this.dodgeFullEnabled = sc.get(props, 'dodgeFullEnabled', true);
40
- this.dodgeOverAimSuccess = sc.get(props, 'dodgeOverAimSuccess', 1);
41
- // specify if the damage or the critical will be affected by the aim and dodge properties:
42
- this.damageAffected = sc.get(props, 'damageAffected', false);
43
- this.criticalAffected = sc.get(props, 'criticalAffected', false);
44
- // properties total calculator operators:
45
- // example: {
46
- // {key: 'propName1', op: ModifierConst.OPS.INC},
47
- // {key: 'propName2', op: ModifierConst.OPS.DEC}
48
- // }
49
- this.propertiesTotalOperators = sc.get(props, 'propertiesTotalOperators', {});
50
- }
51
-
52
- async runSkillLogic()
53
- {
54
- this.lastState = null;
55
- if(!this.target || !this.owner){
56
- this.lastState = SkillsConst.SKILL_STATES.TARGET_NOT_AVAILABLE;
57
- return false;
58
- }
59
- if(!this.isInRange(this.owner.getPosition(), this.target.getPosition())){
60
- // out of range, the owner or the target could move away
61
- this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
62
- return false;
63
- }
64
- this.lastState = SkillsConst.SKILL_STATES.APPLYING_DAMAGE;
65
- return await this.applyDamageTo(this.target);
66
- }
67
-
68
- async applyDamageTo(target)
69
- {
70
- if(!target){
71
- this.lastState = SkillsConst.SKILL_STATES.TARGET_NOT_AVAILABLE;
72
- return false;
73
- }
74
- // @NOTE: both owner and target properties values has to be calculated at the time the skill is executed, that
75
- // is why we are getting the target always as parameter.
76
- // check if the skill can be dodged:
77
- let ownerAim = this.getPropertiesTotal(this.owner, this.aimProperties);
78
- if(false === ownerAim){
79
- Logger.debug('Missing owner aim properties.', this.owner);
80
- return false;
81
- }
82
- let targetDodge = this.getPropertiesTotal(target, this.dodgeProperties);
83
- if(false === targetDodge){
84
- Logger.debug('Missing target dodge properties.', target);
85
- return false;
86
- }
87
- if(this.dodgeFullEnabled && targetDodge > (ownerAim * this.dodgeOverAimSuccess)){
88
- this.lastState = SkillsConst.SKILL_STATES.DODGED;
89
- return false;
90
- }
91
- let affectedPropertyValue = this.getAffectedPropertyValue(target);
92
- if(!this.allowEffectBelowZero && 0 >= affectedPropertyValue){
93
- return false;
94
- }
95
- // dodge proportion:
96
- let dodgeAimDiff = this.getDiffProportion(ownerAim, targetDodge);
97
- let damage = this.applyDirectDamage
98
- ? this.hitDamage // 100%
99
- : this.calculateProportionDamage(target, this.hitDamage, targetDodge, ownerAim, dodgeAimDiff);
100
- // critical calculation:
101
- damage = damage + this.calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff);
102
- // avoid getting below 0:
103
- let modifiedValue = (!this.allowEffectBelowZero && affectedPropertyValue < damage)
104
- ? 0
105
- : affectedPropertyValue - damage;
106
- this.setAffectedPropertyValue(target, modifiedValue);
107
- this.lastState = SkillsConst.SKILL_STATES.APPLIED_DAMAGE;
108
- await this.fireEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, this, target, damage, modifiedValue);
109
- return true;
110
- }
111
-
112
- calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff)
113
- {
114
- let criticalValue = this.getCriticalDiff(damage);
115
- // if criticalAffected is false OR dodge is NOT greater than aim, return full critical value
116
- // if criticalAffected is true AND dodge > aim, apply dodge reduction to critical
117
- if(!this.criticalAffected || targetDodge <= ownerAim){
118
- return criticalValue;
119
- }
120
- this.lastState = SkillsConst.SKILL_STATES.APPLIED_CRITICAL_DAMAGE;
121
- // calculate the dodge proportion over critical damage and remove it from the critical total:
122
- return criticalValue - (Math.floor((criticalValue * dodgeAimDiff / 100)));
123
- }
124
-
125
- calculateProportionDamage(target, damage, targetDodge, ownerAim, dodgeAimDiff)
126
- {
127
- let ownerAtk = this.getPropertiesTotal(this.owner, this.attackProperties);
128
- let targetDef = this.getPropertiesTotal(target, this.defenseProperties);
129
- // atk and def calculation to affect the hit damage:
130
- let diff = ownerAtk - targetDef;
131
- if(diff > 0){
132
- let p = diff < targetDef ? (diff * 100 / targetDef) : 99;
133
- p = p > 99 ? 99 : p; // maximum modifier percentage to add.
134
- let additionalDamage = Math.ceil((p * damage / 100));
135
- damage = damage + additionalDamage;
136
- }
137
- if(diff < 0){
138
- let p = -diff < ownerAtk ? (-diff * 100 / ownerAtk) : 99;
139
- p = p > 99 ? 99 : p; // maximum modifier percentage to remove.
140
- let reduceDamage = Math.floor((p * damage / 100));
141
- damage = damage - reduceDamage;
142
- }
143
- if(this.damageAffected && targetDodge > ownerAim){
144
- // calculate a dodge proportion over damage and remove it from the total:
145
- let damageProportion = Math.floor((damage * dodgeAimDiff / 100));
146
- damage = damage - damageProportion;
147
- }
148
- return damage;
149
- }
150
-
151
- getPropertiesTotal(objectInstance, propertiesArray)
152
- {
153
- if(!objectInstance){
154
- Logger.warning('Missing object to get properties total.');
155
- return false;
156
- }
157
- if(0 === propertiesArray.length){
158
- return 0;
159
- }
160
- try {
161
- let totalValue = 0;
162
- for(let prop of propertiesArray){
163
- let propValue = this.propertyManager.getPropertyValue(objectInstance, prop);
164
- totalValue = sc.hasOwn(this.propertiesTotalOperators, prop)
165
- ? this.calculator.calculateNewValue(totalValue, this.propertiesTotalOperators[prop], propValue)
166
- : totalValue + propValue;
167
- }
168
- return totalValue;
169
- } catch (error) {
170
- Logger.debug(error.message);
171
- return false;
172
- }
173
- }
174
-
175
- getDiffProportion(totalValue, upProportionValue)
176
- {
177
- // prevent division by zero when totalValue (for example, "aim") is 0:
178
- if(0 === totalValue){
179
- // if both "aim" and "dodge" are 0, no advantage either way so we return 0% reduction:
180
- if(0 === upProportionValue){
181
- return 0;
182
- }
183
- // if aim is 0 but dodge > 0, target has maximum advantage so we return 100% reduction:
184
- return 100;
185
- }
186
- let propertiesDiff = upProportionValue - totalValue;
187
- return ((propertiesDiff * 100) / totalValue);
188
- }
189
-
190
- getAffectedPropertyValue(target)
191
- {
192
- return this.propertyManager.getPropertyValue(target, this.affectedProperty);
193
- }
194
-
195
- setAffectedPropertyValue(target, value)
196
- {
197
- return this.propertyManager.setOwnerProperty(target, this.affectedProperty, value);
198
- }
199
-
200
- }
201
-
202
- module.exports = Attack;
1
+ /**
2
+ *
3
+ * Reldens - Skills - Attack
4
+ *
5
+ * This class provides a skill with damage calculation properties and methods.
6
+ *
7
+ */
8
+
9
+ const Skill = require('../skill');
10
+ const SkillsEvents = require('../skills-events');
11
+ const SkillsConst = require('../constants');
12
+ const { Logger, sc } = require('@reldens/utils');
13
+
14
+ class Attack extends Skill
15
+ {
16
+
17
+ constructor(props)
18
+ {
19
+ super(props);
20
+ this.type = SkillsConst.SKILL.TYPE.ATTACK;
21
+ let affectedProperty = sc.get(props, 'affectedProperty', false);
22
+ if(!affectedProperty){
23
+ Logger.error('Missing skill affectedProperty to which the result damage will be applied.');
24
+ this.isReady = false;
25
+ }
26
+ // the affected property is the one to which the damage calculation will have effect:
27
+ this.affectedProperty = affectedProperty;
28
+ this.allowEffectBelowZero = sc.get(props, 'allowEffectBelowZero', false);
29
+ // hit damage value at 100%:
30
+ this.hitDamage = sc.get(props, 'hitDamage', 0);
31
+ this.applyDirectDamage = sc.get(props, 'applyDirectDamage', false);
32
+ // all properties are obtained from the skill owner and the target to calculate the damage:
33
+ this.attackProperties = sc.get(props, 'attackProperties', []);
34
+ this.defenseProperties = sc.get(props, 'defenseProperties', []);
35
+ // aim and dodge properties are used to determine if the skill could fail:
36
+ this.aimProperties = sc.get(props, 'aimProperties', []);
37
+ this.dodgeProperties = sc.get(props, 'dodgeProperties', []);
38
+ // dodgeFullEnabled will make the attack fail if: dodge > ownerAim * dodgeOverAimSuccess
39
+ this.dodgeFullEnabled = sc.get(props, 'dodgeFullEnabled', true);
40
+ this.dodgeOverAimSuccess = sc.get(props, 'dodgeOverAimSuccess', 1);
41
+ // specify if the damage or the critical will be affected by the aim and dodge properties:
42
+ this.damageAffected = sc.get(props, 'damageAffected', false);
43
+ this.criticalAffected = sc.get(props, 'criticalAffected', false);
44
+ // properties total calculator operators:
45
+ // example: {
46
+ // {key: 'propName1', op: ModifierConst.OPS.INC},
47
+ // {key: 'propName2', op: ModifierConst.OPS.DEC}
48
+ // }
49
+ this.propertiesTotalOperators = sc.get(props, 'propertiesTotalOperators', {});
50
+ }
51
+
52
+ async runSkillLogic()
53
+ {
54
+ this.lastState = null;
55
+ if(!this.target || !this.owner){
56
+ this.lastState = SkillsConst.SKILL_STATES.TARGET_NOT_AVAILABLE;
57
+ return false;
58
+ }
59
+ if(!this.isInRange(this.owner.getPosition(), this.target.getPosition())){
60
+ // out of range, the owner or the target could move away
61
+ this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
62
+ return false;
63
+ }
64
+ this.lastState = SkillsConst.SKILL_STATES.APPLYING_DAMAGE;
65
+ return await this.applyDamageTo(this.target);
66
+ }
67
+
68
+ async applyDamageTo(target)
69
+ {
70
+ if(!target){
71
+ this.lastState = SkillsConst.SKILL_STATES.TARGET_NOT_AVAILABLE;
72
+ return false;
73
+ }
74
+ // @NOTE: both owner and target properties values has to be calculated at the time the skill is executed, that
75
+ // is why we are getting the target always as parameter.
76
+ // check if the skill can be dodged:
77
+ let ownerAim = this.getPropertiesTotal(this.owner, this.aimProperties);
78
+ if(false === ownerAim){
79
+ Logger.debug('Missing owner aim properties.', this.owner);
80
+ return false;
81
+ }
82
+ let targetDodge = this.getPropertiesTotal(target, this.dodgeProperties);
83
+ if(false === targetDodge){
84
+ Logger.debug('Missing target dodge properties.', target);
85
+ return false;
86
+ }
87
+ if(this.dodgeFullEnabled && targetDodge > (ownerAim * this.dodgeOverAimSuccess)){
88
+ this.lastState = SkillsConst.SKILL_STATES.DODGED;
89
+ return false;
90
+ }
91
+ let affectedPropertyValue = this.getAffectedPropertyValue(target);
92
+ if(!this.allowEffectBelowZero && 0 >= affectedPropertyValue){
93
+ return false;
94
+ }
95
+ // dodge proportion:
96
+ let dodgeAimDiff = this.getDiffProportion(ownerAim, targetDodge);
97
+ let damage = this.applyDirectDamage
98
+ ? this.hitDamage // 100%
99
+ : this.calculateProportionDamage(target, this.hitDamage, targetDodge, ownerAim, dodgeAimDiff);
100
+ // critical calculation:
101
+ damage = damage + this.calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff);
102
+ // avoid getting below 0:
103
+ let modifiedValue = (!this.allowEffectBelowZero && affectedPropertyValue < damage)
104
+ ? 0
105
+ : affectedPropertyValue - damage;
106
+ this.setAffectedPropertyValue(target, modifiedValue);
107
+ this.lastState = SkillsConst.SKILL_STATES.APPLIED_DAMAGE;
108
+ await this.fireEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, this, target, damage, modifiedValue);
109
+ return true;
110
+ }
111
+
112
+ calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff)
113
+ {
114
+ let criticalValue = this.getCriticalDiff(damage);
115
+ // if criticalAffected is false OR dodge is NOT greater than aim, return full critical value
116
+ // if criticalAffected is true AND dodge > aim, apply dodge reduction to critical
117
+ if(!this.criticalAffected || targetDodge <= ownerAim){
118
+ return criticalValue;
119
+ }
120
+ this.lastState = SkillsConst.SKILL_STATES.APPLIED_CRITICAL_DAMAGE;
121
+ // calculate the dodge proportion over critical damage and remove it from the critical total:
122
+ return criticalValue - (Math.floor((criticalValue * dodgeAimDiff / 100)));
123
+ }
124
+
125
+ calculateProportionDamage(target, damage, targetDodge, ownerAim, dodgeAimDiff)
126
+ {
127
+ let ownerAtk = this.getPropertiesTotal(this.owner, this.attackProperties);
128
+ let targetDef = this.getPropertiesTotal(target, this.defenseProperties);
129
+ // atk and def calculation to affect the hit damage:
130
+ let diff = ownerAtk - targetDef;
131
+ if(diff > 0){
132
+ let p = diff < targetDef ? (diff * 100 / targetDef) : 99;
133
+ p = p > 99 ? 99 : p; // maximum modifier percentage to add.
134
+ let additionalDamage = Math.ceil((p * damage / 100));
135
+ damage = damage + additionalDamage;
136
+ }
137
+ if(diff < 0){
138
+ let p = -diff < ownerAtk ? (-diff * 100 / ownerAtk) : 99;
139
+ p = p > 99 ? 99 : p; // maximum modifier percentage to remove.
140
+ let reduceDamage = Math.floor((p * damage / 100));
141
+ damage = damage - reduceDamage;
142
+ }
143
+ if(this.damageAffected && targetDodge > ownerAim){
144
+ // calculate a dodge proportion over damage and remove it from the total:
145
+ let damageProportion = Math.floor((damage * dodgeAimDiff / 100));
146
+ damage = damage - damageProportion;
147
+ }
148
+ return damage;
149
+ }
150
+
151
+ getPropertiesTotal(objectInstance, propertiesArray)
152
+ {
153
+ if(!objectInstance){
154
+ Logger.warning('Missing object to get properties total.');
155
+ return false;
156
+ }
157
+ if(0 === propertiesArray.length){
158
+ return 0;
159
+ }
160
+ try {
161
+ let totalValue = 0;
162
+ for(let prop of propertiesArray){
163
+ let propValue = this.propertyManager.getPropertyValue(objectInstance, prop);
164
+ totalValue = sc.hasOwn(this.propertiesTotalOperators, prop)
165
+ ? this.calculator.calculateNewValue(totalValue, this.propertiesTotalOperators[prop], propValue)
166
+ : totalValue + propValue;
167
+ }
168
+ return totalValue;
169
+ } catch (error) {
170
+ Logger.debug(error.message);
171
+ return false;
172
+ }
173
+ }
174
+
175
+ getDiffProportion(totalValue, upProportionValue)
176
+ {
177
+ // prevent division by zero when totalValue (for example, "aim") is 0:
178
+ if(0 === totalValue){
179
+ // if both "aim" and "dodge" are 0, no advantage either way so we return 0% reduction:
180
+ if(0 === upProportionValue){
181
+ return 0;
182
+ }
183
+ // if aim is 0 but dodge > 0, target has maximum advantage so we return 100% reduction:
184
+ return 100;
185
+ }
186
+ let propertiesDiff = upProportionValue - totalValue;
187
+ return ((propertiesDiff * 100) / totalValue);
188
+ }
189
+
190
+ getAffectedPropertyValue(target)
191
+ {
192
+ return this.propertyManager.getPropertyValue(target, this.affectedProperty);
193
+ }
194
+
195
+ setAffectedPropertyValue(target, value)
196
+ {
197
+ return this.propertyManager.setOwnerProperty(target, this.affectedProperty, value);
198
+ }
199
+
200
+ }
201
+
202
+ module.exports = Attack;
@@ -1,52 +1,52 @@
1
- /**
2
- *
3
- * Reldens - Skills - Effect
4
- *
5
- * This class provides a skill with modifiers that will be applied on the target object when the skill is executed.
6
- *
7
- */
8
-
9
- const Skill = require('../skill');
10
- const SkillsEvents = require('../skills-events');
11
- const SkillsConst = require('../constants');
12
- const { Logger, sc } = require('@reldens/utils');
13
-
14
- class Effect extends Skill
15
- {
16
-
17
- constructor(props)
18
- {
19
- super(props);
20
- this.type = SkillsConst.SKILL.TYPE.EFFECT;
21
- let targetEffects = sc.get(props, 'targetEffects');
22
- if(!targetEffects){
23
- Logger.error('Missing targetEffects for skill.');
24
- this.isReady = false;
25
- }
26
- this.targetEffects = targetEffects;
27
- }
28
-
29
- async runSkillLogic()
30
- {
31
- this.lastState = null;
32
- if(!this.target || !this.owner){
33
- this.lastState = SkillsConst.SKILL_STATES.TARGET_NOT_AVAILABLE;
34
- return false;
35
- }
36
- if(!this.isInRange(this.owner.getPosition(), this.target.getPosition())){
37
- this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
38
- // out of range, the owner or the target could move away
39
- return false;
40
- }
41
- this.lastState = SkillsConst.SKILL_STATES.APPLYING_EFFECTS;
42
- // @NOTE: the difference between the normal skills modifiers and the effects are the critical chance applied
43
- // to the modifiers here.
44
- this.applyModifiers(this.targetEffects, this.target);
45
- this.lastState = SkillsConst.SKILL_STATES.APPLIED_EFFECTS;
46
- await this.fireEvent(SkillsEvents.SKILL_EFFECT_TARGET_MODIFIERS, this);
47
- return true;
48
- }
49
-
50
- }
51
-
52
- module.exports = Effect;
1
+ /**
2
+ *
3
+ * Reldens - Skills - Effect
4
+ *
5
+ * This class provides a skill with modifiers that will be applied on the target object when the skill is executed.
6
+ *
7
+ */
8
+
9
+ const Skill = require('../skill');
10
+ const SkillsEvents = require('../skills-events');
11
+ const SkillsConst = require('../constants');
12
+ const { Logger, sc } = require('@reldens/utils');
13
+
14
+ class Effect extends Skill
15
+ {
16
+
17
+ constructor(props)
18
+ {
19
+ super(props);
20
+ this.type = SkillsConst.SKILL.TYPE.EFFECT;
21
+ let targetEffects = sc.get(props, 'targetEffects');
22
+ if(!targetEffects){
23
+ Logger.error('Missing targetEffects for skill.');
24
+ this.isReady = false;
25
+ }
26
+ this.targetEffects = targetEffects;
27
+ }
28
+
29
+ async runSkillLogic()
30
+ {
31
+ this.lastState = null;
32
+ if(!this.target || !this.owner){
33
+ this.lastState = SkillsConst.SKILL_STATES.TARGET_NOT_AVAILABLE;
34
+ return false;
35
+ }
36
+ if(!this.isInRange(this.owner.getPosition(), this.target.getPosition())){
37
+ this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
38
+ // out of range, the owner or the target could move away
39
+ return false;
40
+ }
41
+ this.lastState = SkillsConst.SKILL_STATES.APPLYING_EFFECTS;
42
+ // @NOTE: the difference between the normal skills modifiers and the effects are the critical chance applied
43
+ // to the modifiers here.
44
+ this.applyModifiers(this.targetEffects, this.target);
45
+ this.lastState = SkillsConst.SKILL_STATES.APPLIED_EFFECTS;
46
+ await this.fireEvent(SkillsEvents.SKILL_EFFECT_TARGET_MODIFIERS, this);
47
+ return true;
48
+ }
49
+
50
+ }
51
+
52
+ module.exports = Effect;