@reldens/skills 0.44.0 → 0.46.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/CLAUDE.md +488 -0
- package/README.md +322 -10
- package/lib/server.js +1 -24
- package/lib/skill.js +4 -4
- package/package.json +3 -4
- package/lib/server/data-server-validator.js +0 -29
- package/lib/server/storage/class-path-generator.js +0 -48
- package/lib/server/storage/conditions-generator.js +0 -29
- package/lib/server/storage/levels-generator.js +0 -41
- package/lib/server/storage/models/mikro-orm/class-path-level-labels-model.js +0 -86
- package/lib/server/storage/models/mikro-orm/class-path-level-skills-model.js +0 -98
- package/lib/server/storage/models/mikro-orm/class-path-model.js +0 -105
- package/lib/server/storage/models/mikro-orm/level-model.js +0 -88
- package/lib/server/storage/models/mikro-orm/level-modifiers-model.js +0 -119
- package/lib/server/storage/models/mikro-orm/levels-set-model.js +0 -79
- package/lib/server/storage/models/mikro-orm/owners-class-path-model.js +0 -79
- package/lib/server/storage/models/mikro-orm/registered-models-mikro-orm.js +0 -39
- package/lib/server/storage/models/mikro-orm/skill-attack-model.js +0 -156
- package/lib/server/storage/models/mikro-orm/skill-group-relation-model.js +0 -82
- package/lib/server/storage/models/mikro-orm/skill-model.js +0 -236
- package/lib/server/storage/models/mikro-orm/skill-owner-conditions-model.js +0 -83
- package/lib/server/storage/models/mikro-orm/skill-owner-effects-model.js +0 -119
- package/lib/server/storage/models/mikro-orm/skill-physical-data-model.js +0 -83
- package/lib/server/storage/models/mikro-orm/skill-target-effects-model.js +0 -125
- package/lib/server/storage/models/mikro-orm/skills-groups-model.js +0 -77
- package/lib/server/storage/models/objection-js/class-path-level-labels-model.js +0 -44
- package/lib/server/storage/models/objection-js/class-path-level-skills-model.js +0 -53
- package/lib/server/storage/models/objection-js/class-path-model.js +0 -85
- package/lib/server/storage/models/objection-js/level-model.js +0 -44
- package/lib/server/storage/models/objection-js/level-modifiers-model.js +0 -35
- package/lib/server/storage/models/objection-js/levels-set-model.js +0 -44
- package/lib/server/storage/models/objection-js/owners-class-path-model.js +0 -35
- package/lib/server/storage/models/objection-js/registered-models-objection-js.js +0 -39
- package/lib/server/storage/models/objection-js/skill-attack-model.js +0 -35
- package/lib/server/storage/models/objection-js/skill-group-relation-model.js +0 -44
- package/lib/server/storage/models/objection-js/skill-model.js +0 -89
- package/lib/server/storage/models/objection-js/skill-owner-conditions-model.js +0 -35
- package/lib/server/storage/models/objection-js/skill-owner-effects-model.js +0 -35
- package/lib/server/storage/models/objection-js/skill-physical-data-model.js +0 -35
- package/lib/server/storage/models/objection-js/skill-target-effects-model.js +0 -35
- package/lib/server/storage/models/objection-js/skills-groups-model.js +0 -35
- package/lib/server/storage/models-manager.js +0 -111
- package/lib/server/storage/modifiers-generator.js +0 -28
- package/lib/server/storage/skills-generator.js +0 -102
- package/lib/server/storage-observer.js +0 -89
- package/migrations/production/reldens-skills-install.sql +0 -275
package/README.md
CHANGED
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
The idea behind this package is to provide a comprehensive skills and experience system that can be attached to any target owner.
|
|
7
7
|
This opinionated yet flexible implementation includes class paths, leveling systems, skill trees, and experience management with full event-driven architecture.
|
|
8
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
|
|
9
|
+
The package offers both client and server-side functionality, including automatic level progression, skill validation, damage calculations, physical attacks, effects system, and complete real-time synchronization via Sender/Receiver pattern.
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
## Features
|
|
15
15
|
|
|
16
|
-
- **Level Sets & Experience System**: Automatic level progression with configurable experience requirements
|
|
17
|
-
- **Class Paths & Skill Trees**: Skill progression with level-dependent skill
|
|
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,
|
|
20
|
-
- **Real-time Communication**: Built-in
|
|
21
|
-
- **
|
|
22
|
-
- **
|
|
23
|
-
- **
|
|
16
|
+
- **Level Sets & Experience System**: Automatic level progression with configurable experience requirements, level-based modifiers, and auto-fill ranges
|
|
17
|
+
- **Class Paths & Skill Trees**: Skill progression with level-dependent skill unlocks, dynamic labeling per level, and skill management
|
|
18
|
+
- **Multiple Skill Types**: Base skills, attacks with damage calculation, effects (buffs/debuffs), physical attacks and effects with collision detection
|
|
19
|
+
- **Combat Mechanics**: Critical hits (chance/multiplier/fixed), dodge calculations, range validation, attack vs defense properties, and aim vs dodge systems
|
|
20
|
+
- **Real-time Communication**: Built-in Sender/Receiver architecture for server-client synchronization with compressed message format
|
|
21
|
+
- **Event-Driven Architecture**: Comprehensive event system with 30+ events for custom logic integration, all namespaced by owner
|
|
22
|
+
- **Modular Design**: Flexible configuration with custom conditions, modifiers, extensible skill logic, and physics integration
|
|
23
|
+
- **Standalone Package**: Can be used independently from main Reldens platform with any entity that implements `getPosition()` method
|
|
24
24
|
|
|
25
25
|
Need something specific?
|
|
26
26
|
|
|
@@ -28,13 +28,325 @@ Need something specific?
|
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @reldens/skills
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Basic Skill Example
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
const { Skill } = require('@reldens/skills');
|
|
43
|
+
|
|
44
|
+
// Create a simple skill
|
|
45
|
+
let healSkill = new Skill({
|
|
46
|
+
key: 'heal',
|
|
47
|
+
owner: playerEntity, // Must have getPosition() method
|
|
48
|
+
range: 100,
|
|
49
|
+
castTime: 1000, // 1 second cast time
|
|
50
|
+
skillDelay: 5000 // 5 second cooldown
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Execute the skill
|
|
54
|
+
await healSkill.execute(targetEntity);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Attack Skill with Damage
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const { Attack } = require('@reldens/skills/lib/types/attack');
|
|
61
|
+
|
|
62
|
+
let fireballSkill = new Attack({
|
|
63
|
+
key: 'fireball',
|
|
64
|
+
owner: playerEntity,
|
|
65
|
+
affectedProperty: 'hp', // Property to damage
|
|
66
|
+
hitDamage: 50,
|
|
67
|
+
range: 200,
|
|
68
|
+
attackProperties: ['atk', 'magicPower'], // Owner properties for attack
|
|
69
|
+
defenseProperties: ['def', 'magicResist'], // Target properties for defense
|
|
70
|
+
aimProperties: ['accuracy'],
|
|
71
|
+
dodgeProperties: ['agility'],
|
|
72
|
+
criticalChance: 20, // 20% chance
|
|
73
|
+
criticalMultiplier: 2 // 2x damage on crit
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await fireballSkill.execute(enemy);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Level System with Auto-Progression
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
const { LevelsSet, Level } = require('@reldens/skills');
|
|
83
|
+
|
|
84
|
+
let levels = {
|
|
85
|
+
1: new Level({key: 1, modifiers: [], requiredExperience: 0}),
|
|
86
|
+
5: new Level({key: 5, modifiers: [], requiredExperience: 1000})
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
let levelsSet = new LevelsSet({owner: playerEntity});
|
|
90
|
+
await levelsSet.init({
|
|
91
|
+
owner: playerEntity,
|
|
92
|
+
levels: levels,
|
|
93
|
+
currentLevel: 1,
|
|
94
|
+
currentExp: 0,
|
|
95
|
+
autoFillRanges: true, // Auto-generate levels 2, 3, 4
|
|
96
|
+
increaseLevelsWithExperience: true // Auto level up
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Add experience (will auto-level up at 1000 XP)
|
|
100
|
+
await levelsSet.addExperience(500);
|
|
101
|
+
await levelsSet.addExperience(600); // Levels up to 5!
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Class Path with Skill Tree
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
const { ClassPath } = require('@reldens/skills');
|
|
108
|
+
|
|
109
|
+
let classPath = new ClassPath({owner: playerEntity});
|
|
110
|
+
await classPath.init({
|
|
111
|
+
owner: playerEntity,
|
|
112
|
+
key: 'warrior',
|
|
113
|
+
label: 'Warrior',
|
|
114
|
+
levels: levels,
|
|
115
|
+
currentLevel: 1,
|
|
116
|
+
labelsByLevel: {
|
|
117
|
+
1: 'Novice Warrior',
|
|
118
|
+
5: 'Experienced Warrior',
|
|
119
|
+
10: 'Master Warrior'
|
|
120
|
+
},
|
|
121
|
+
skillsByLevel: {
|
|
122
|
+
1: [swordSlashSkill],
|
|
123
|
+
5: [shieldBlockSkill, battleCrySkill],
|
|
124
|
+
10: [whirlwindSkill]
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Player starts with swordSlashSkill
|
|
129
|
+
// At level 5: gains shieldBlockSkill and battleCrySkill
|
|
130
|
+
// At level 10: gains whirlwindSkill
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Server-Side with Client Sync
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
const { SkillsServer } = require('@reldens/skills');
|
|
137
|
+
|
|
138
|
+
let skillsServer = new SkillsServer({
|
|
139
|
+
owner: playerEntity,
|
|
140
|
+
client: roomClient, // Colyseus client with send() and broadcast()
|
|
141
|
+
key: 'mage',
|
|
142
|
+
levels: levels,
|
|
143
|
+
skillsByLevel: {
|
|
144
|
+
1: [fireballSkill, iceSpearSkill]
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Automatically syncs to client:
|
|
149
|
+
// - Initial class data (level, label, XP, skills)
|
|
150
|
+
// - Level ups
|
|
151
|
+
// - XP gains
|
|
152
|
+
// - Skill casts
|
|
153
|
+
// - Damage application
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Client-Side Receiver
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
const { Receiver } = require('@reldens/skills/lib/client/receiver');
|
|
160
|
+
|
|
161
|
+
class SkillsUI extends Receiver
|
|
162
|
+
{
|
|
163
|
+
constructor(props)
|
|
164
|
+
{
|
|
165
|
+
super(props);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
onLevelUp(message)
|
|
169
|
+
{
|
|
170
|
+
// message.data = {lvl: 5, lab: 'Experienced Warrior', skl: ['sword', 'shield'], ne: 2000}
|
|
171
|
+
updateLevelDisplay(message.data.lvl);
|
|
172
|
+
updateSkillBar(message.data.skl);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
onLevelExperienceAdded(message)
|
|
176
|
+
{
|
|
177
|
+
// message.data = {exp: 1500}
|
|
178
|
+
updateXPBar(message.data.exp);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
onSkillAttackApplyDamage(message)
|
|
182
|
+
{
|
|
183
|
+
// message.data = {d: 85}
|
|
184
|
+
showDamageNumber(message.data.d);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let receiver = new SkillsUI({owner: playerEntity});
|
|
189
|
+
gameClient.onMessage('*', (msg) => receiver.processMessage(msg));
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Event Hooks
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
const SkillsEvents = require('@reldens/skills/lib/skills-events');
|
|
196
|
+
|
|
197
|
+
// Listen to level up
|
|
198
|
+
classPath.listenEvent(SkillsEvents.LEVEL_UP, async (classPath) => {
|
|
199
|
+
console.log(`Leveled up to ${classPath.currentLevel}!`);
|
|
200
|
+
awardAchievement('level_up');
|
|
201
|
+
}, 'levelUpListener', classPath.getOwnerEventKey());
|
|
202
|
+
|
|
203
|
+
// Listen to skill execution
|
|
204
|
+
skill.listenEvent(SkillsEvents.SKILL_AFTER_EXECUTE, async (skill, target) => {
|
|
205
|
+
console.log(`Skill ${skill.key} executed on ${target.name}`);
|
|
206
|
+
playAnimation(skill.key);
|
|
207
|
+
}, 'skillExecListener', skill.getOwnerEventKey());
|
|
208
|
+
|
|
209
|
+
// Listen to damage application
|
|
210
|
+
attackSkill.listenEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, async (skill, target, damage) => {
|
|
211
|
+
console.log(`Dealt ${damage} damage to ${target.name}`);
|
|
212
|
+
showFloatingText(damage, target.position);
|
|
213
|
+
}, 'damageListener', attackSkill.getOwnerEventKey());
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Core Concepts
|
|
219
|
+
|
|
220
|
+
### Skill Types
|
|
221
|
+
|
|
222
|
+
1. **Skill** (`lib/skill.js`): Base class with validation, range checking, cooldowns, cast time
|
|
223
|
+
2. **Attack** (`lib/types/attack.js`): Damage calculation with atk/def, aim/dodge, critical hits
|
|
224
|
+
3. **Effect** (`lib/types/effect.js`): Applies modifiers to target (buffs/debuffs)
|
|
225
|
+
4. **PhysicalAttack** (`lib/types/physical-attack.js`): Physics-enabled attack with collision detection
|
|
226
|
+
5. **PhysicalEffect** (`lib/types/physical-effect.js`): Physics-enabled effect with collision detection
|
|
227
|
+
|
|
228
|
+
### Level Progression
|
|
229
|
+
|
|
230
|
+
- **Level**: Single level with modifiers and required XP
|
|
231
|
+
- **LevelsSet**: Manages multiple levels, XP tracking, auto-leveling
|
|
232
|
+
- **ClassPath**: Extends LevelsSet with skill trees and dynamic labels
|
|
233
|
+
|
|
234
|
+
### Communication
|
|
235
|
+
|
|
236
|
+
- **Sender** (`lib/server/sender.js`): Broadcasts skill/level events to clients with compressed messages
|
|
237
|
+
- **Receiver** (`lib/client/receiver.js`): Processes server messages and maps to handler methods
|
|
238
|
+
|
|
239
|
+
### Events
|
|
240
|
+
|
|
241
|
+
30+ events covering:
|
|
242
|
+
- Level progression (level up/down, XP added, modifiers applied)
|
|
243
|
+
- Class paths (init, skills added/removed)
|
|
244
|
+
- Skill execution (validate, cast, execute, damage/effects applied)
|
|
245
|
+
- Range checking, physical collisions
|
|
246
|
+
|
|
247
|
+
All events are namespaced by owner for multiplayer support.
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## API Reference
|
|
252
|
+
|
|
253
|
+
### Skill Class
|
|
254
|
+
|
|
255
|
+
**Constructor Properties**:
|
|
256
|
+
- `key` (required): Unique skill identifier
|
|
257
|
+
- `owner` (required): Entity with `getPosition()` method
|
|
258
|
+
- `target`: Target entity (or pass in execute)
|
|
259
|
+
- `range`: Skill range (0 = infinite)
|
|
260
|
+
- `rangeAutomaticValidation`: Validate range before execution
|
|
261
|
+
- `allowSelfTarget`: Allow targeting owner
|
|
262
|
+
- `castTime`: Cast time in milliseconds
|
|
263
|
+
- `skillDelay`: Cooldown in milliseconds
|
|
264
|
+
- `usesLimit`: Max uses (0 = unlimited)
|
|
265
|
+
- `ownerConditions`: Array of Condition instances
|
|
266
|
+
- `ownerEffects`: Array of modifiers for owner
|
|
267
|
+
- `criticalChance`: 0-100 crit chance
|
|
268
|
+
- `criticalMultiplier`: Damage multiplier on crit
|
|
269
|
+
- `criticalFixedValue`: Fixed damage added on crit
|
|
270
|
+
|
|
271
|
+
**Methods**:
|
|
272
|
+
- `validate()`: Check if skill can be activated
|
|
273
|
+
- `execute(target)`: Execute the skill
|
|
274
|
+
- `runSkillLogic()`: Override for custom logic
|
|
275
|
+
- `onExecuteConditions()`: Override for custom validation
|
|
276
|
+
- `validateRange(target)`: Check if target in range
|
|
277
|
+
- `applyModifiers(modifiers, target)`: Apply modifiers with critical
|
|
278
|
+
- `fireEvent(eventName, ...args)`: Fire namespaced event
|
|
279
|
+
- `listenEvent(eventName, callback, removeKey, masterKey)`: Listen to event
|
|
280
|
+
|
|
281
|
+
### Attack Class
|
|
282
|
+
|
|
283
|
+
Extends Skill with additional properties:
|
|
284
|
+
- `affectedProperty` (required): Property to damage (e.g., 'hp')
|
|
285
|
+
- `hitDamage`: Base damage at 100%
|
|
286
|
+
- `applyDirectDamage`: Skip calculations
|
|
287
|
+
- `attackProperties`: Owner atk property names
|
|
288
|
+
- `defenseProperties`: Target def property names
|
|
289
|
+
- `aimProperties`: Owner aim property names
|
|
290
|
+
- `dodgeProperties`: Target dodge property names
|
|
291
|
+
- `dodgeFullEnabled`: Enable full dodge
|
|
292
|
+
- `dodgeOverAimSuccess`: Dodge threshold multiplier
|
|
293
|
+
- `damageAffected`: Apply dodge/aim to damage
|
|
294
|
+
- `criticalAffected`: Apply dodge/aim to critical
|
|
295
|
+
- `allowEffectBelowZero`: Allow negative values
|
|
296
|
+
|
|
297
|
+
### LevelsSet Class
|
|
298
|
+
|
|
299
|
+
**Constructor Properties**:
|
|
300
|
+
- `owner` (required): Entity with `getPosition()` method
|
|
301
|
+
- `events`: EventsManager instance
|
|
302
|
+
|
|
303
|
+
**Init Properties**:
|
|
304
|
+
- `levels` (required): Object of Level instances
|
|
305
|
+
- `currentLevel`: Starting level
|
|
306
|
+
- `currentExp`: Starting XP
|
|
307
|
+
- `autoFillRanges`: Auto-generate intermediate levels
|
|
308
|
+
- `autoFillExperienceMultiplier`: XP multiplier for auto-gen (default: 1.5)
|
|
309
|
+
- `increaseLevelsWithExperience`: Auto level up when XP threshold met
|
|
310
|
+
- `levelsByExperience`: Custom level order array
|
|
311
|
+
- `setRequiredExperienceLimit`: Cap XP at max level
|
|
312
|
+
|
|
313
|
+
**Methods**:
|
|
314
|
+
- `init(props)`: Initialize level set
|
|
315
|
+
- `levelUp()`: Increase level, apply modifiers
|
|
316
|
+
- `levelDown()`: Decrease level, revert modifiers
|
|
317
|
+
- `addExperience(number)`: Add XP, auto-level if enabled
|
|
318
|
+
- `getNextLevelExperience()`: Get XP for next level
|
|
319
|
+
- `getLevelInstance(levelKey)`: Get Level by key
|
|
320
|
+
|
|
321
|
+
### ClassPath Class
|
|
322
|
+
|
|
323
|
+
Extends LevelsSet with additional properties:
|
|
324
|
+
- `key` (required): Class identifier
|
|
325
|
+
- `label`: Display name
|
|
326
|
+
- `labelsByLevel`: {levelKey: 'label'} object
|
|
327
|
+
- `currentLabel`: Active label
|
|
328
|
+
- `skillsByLevel`: {levelKey: [Skill instances]} object
|
|
329
|
+
- `currentSkills`: Active skills object
|
|
330
|
+
- `affectedProperty`: Property for class skills
|
|
331
|
+
|
|
332
|
+
**Methods**:
|
|
333
|
+
- `addSkills(skills)`: Add skills to current set
|
|
334
|
+
- `removeSkills(skills)`: Remove skills by keys
|
|
335
|
+
- `setOwnerSkills(skills)`: Initialize skills based on level
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
31
339
|
## Documentation
|
|
32
340
|
|
|
33
341
|
[https://www.reldens.com/documentation/skills](https://www.reldens.com/documentation/skills)
|
|
34
342
|
|
|
35
|
-
|
|
36
343
|
---
|
|
37
344
|
|
|
345
|
+
## License
|
|
346
|
+
|
|
347
|
+
MIT
|
|
348
|
+
|
|
349
|
+
---
|
|
38
350
|
|
|
39
351
|
### [Reldens](https://github.com/damian-pastorini/reldens/ "Reldens")
|
|
40
352
|
|
package/lib/server.js
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
const ClassPath = require('./class-path');
|
|
8
8
|
const Sender = require('./server/sender');
|
|
9
|
-
const { StorageObserver } = require('./server/storage-observer');
|
|
10
|
-
const { DataServerValidator } = require('./server/data-server-validator');
|
|
11
9
|
const { Logger, sc } = require('@reldens/utils');
|
|
12
10
|
|
|
13
11
|
class SkillsServer
|
|
@@ -16,8 +14,6 @@ class SkillsServer
|
|
|
16
14
|
constructor(props)
|
|
17
15
|
{
|
|
18
16
|
this.classPath = false;
|
|
19
|
-
this.dataServer = false;
|
|
20
|
-
this.storageObserver = false;
|
|
21
17
|
this.client = false;
|
|
22
18
|
this.setupServer(props);
|
|
23
19
|
}
|
|
@@ -34,27 +30,8 @@ class SkillsServer
|
|
|
34
30
|
}
|
|
35
31
|
this.classPath = sc.hasOwn(props, 'classPath') ? props.classPath : new ClassPath(props);
|
|
36
32
|
this.classPath.setOwner(props);
|
|
37
|
-
// check if the storage was activated:
|
|
38
|
-
if(sc.isTrue(props, 'persistence')){
|
|
39
|
-
// check if the owner has the required persisData methods in the case the storage is active:
|
|
40
|
-
if(!sc.hasOwn(props.owner, 'persistData') || typeof props.owner.persistData !== 'function'){
|
|
41
|
-
Logger.critical('Required method "persistData" not found in SkillsServer props.owner.');
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
this.dataServer = DataServerValidator.getValidDataServer(props);
|
|
45
|
-
let storageObserverProps = {
|
|
46
|
-
classPath: this.classPath,
|
|
47
|
-
dataServer: this.dataServer
|
|
48
|
-
};
|
|
49
|
-
let modelsManager = sc.get(props, 'modelsManager', false);
|
|
50
|
-
if(modelsManager){
|
|
51
|
-
storageObserverProps.modelsManager = modelsManager;
|
|
52
|
-
}
|
|
53
|
-
this.storageObserver = new StorageObserver(storageObserverProps);
|
|
54
|
-
this.storageObserver.registerListeners();
|
|
55
|
-
}
|
|
56
33
|
if(sc.hasOwn(props, 'client')){
|
|
57
|
-
// @NOTE: client must implement the "send" method which will be used to send the current action data.
|
|
34
|
+
// @NOTE: a client must implement the "send" method which will be used to send the current action data.
|
|
58
35
|
if(typeof props.client.send !== 'function'){
|
|
59
36
|
Logger.critical('Required method "send" not found in SkillsServer props.client.');
|
|
60
37
|
return false;
|
package/lib/skill.js
CHANGED
|
@@ -55,16 +55,16 @@ class Skill
|
|
|
55
55
|
this.lastState = '';
|
|
56
56
|
this.groups = sc.get(props, 'groups', []);
|
|
57
57
|
this.lastAppliedModifiers = {};
|
|
58
|
-
// if enabled range will be validated just before execution to get the owner and target realtime positions:
|
|
58
|
+
// if enabled, range will be validated just before execution to get the owner and target realtime positions:
|
|
59
59
|
this.rangeAutomaticValidation = sc.get(props, 'rangeAutomaticValidation', false);
|
|
60
|
-
// @NOTE: if automatic range validation is enabled the rangePropertyX and rangePropertyY will be required and
|
|
60
|
+
// @NOTE: if automatic range validation is enabled, the rangePropertyX and rangePropertyY will be required and
|
|
61
61
|
// used for both (owner and target) by default.
|
|
62
62
|
this.rangePropertyX = sc.get(props, 'rangePropertyX', false);
|
|
63
63
|
this.rangePropertyY = sc.get(props, 'rangePropertyY', false);
|
|
64
64
|
// specify if you like to use a different range property for the target:
|
|
65
65
|
this.rangeTargetPropertyX = sc.get(props, 'rangeTargetPropertyX', false);
|
|
66
66
|
this.rangeTargetPropertyY = sc.get(props, 'rangeTargetPropertyY', false);
|
|
67
|
-
// allow
|
|
67
|
+
// allow targeting the same owner:
|
|
68
68
|
this.allowSelfTarget = sc.get(props, 'allowSelfTarget', false);
|
|
69
69
|
// we can use a fixed target or pass the target on execution:
|
|
70
70
|
this.target = sc.get(props, 'target', false);
|
|
@@ -94,7 +94,7 @@ class Skill
|
|
|
94
94
|
this.fireEvent(SkillsEvents.VALIDATE_BEFORE, this).catch((err) => {
|
|
95
95
|
Logger.error(err);
|
|
96
96
|
});
|
|
97
|
-
// the delay is the time in milliseconds until player can use the skill again:
|
|
97
|
+
// the delay is the time in milliseconds until the player can use the skill again:
|
|
98
98
|
if(!this.canActivate || this.owner.isCasting){
|
|
99
99
|
this.lastState = SkillsConst.SKILL_STATES.CAN_NOT_ACTIVATE;
|
|
100
100
|
// @NOTE: player could be running an attack already.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reldens/skills",
|
|
3
3
|
"scope": "@reldens",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.46.0",
|
|
5
5
|
"description": "Reldens - Skills",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
"url": "https://github.com/damian-pastorini/reldens-skills/issues"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@reldens/modifiers": "^0.
|
|
44
|
-
"@reldens/
|
|
45
|
-
"@reldens/utils": "^0.53.0"
|
|
43
|
+
"@reldens/modifiers": "^0.32.0",
|
|
44
|
+
"@reldens/utils": "^0.54.0"
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - DataServerValidator
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { ErrorManager, sc } = require('@reldens/utils');
|
|
8
|
-
|
|
9
|
-
class DataServerValidator
|
|
10
|
-
{
|
|
11
|
-
|
|
12
|
-
static getValidDataServer(props)
|
|
13
|
-
{
|
|
14
|
-
let dataServer = sc.get(props, 'dataServer', false);
|
|
15
|
-
if(false === dataServer){
|
|
16
|
-
ErrorManager.error('Data Server instance not found.', props);
|
|
17
|
-
}
|
|
18
|
-
if(!sc.isFunction(dataServer.connect) || !sc.isFunction(dataServer.generateEntities)){
|
|
19
|
-
ErrorManager.error(
|
|
20
|
-
'Data Server property found but the instance required methods are not available.',
|
|
21
|
-
dataServer
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return dataServer;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports.DataServerValidator = DataServerValidator;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - ClassPathGenerator
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const ClassPath = require('../../class-path');
|
|
8
|
-
const { LevelsGenerator } = require('./levels-generator');
|
|
9
|
-
const { sc } = require('@reldens/utils');
|
|
10
|
-
|
|
11
|
-
class ClassPathGenerator
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
static fromClassPathModels(classPathModels, classPathClasses)
|
|
15
|
-
{
|
|
16
|
-
if(!sc.isArray(classPathModels) || 0 === classPathModels.length){
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
let classPathsById = {};
|
|
20
|
-
let classPathsByKey = {};
|
|
21
|
-
let activeClassPathModels = classPathModels.filter(classPathModel => classPathModel.enabled);
|
|
22
|
-
for(let classPathModel of activeClassPathModels){
|
|
23
|
-
let classPathData = {class: sc.get(classPathClasses, classPathModel.key, ClassPath), data: classPathModel};
|
|
24
|
-
classPathModel.classPathLevels = LevelsGenerator.fromLevelsModels(
|
|
25
|
-
classPathModel.skills_levels_set.skills_levels_set_levels
|
|
26
|
-
);
|
|
27
|
-
classPathModel.labelsByLevel = this.extractLabelsByLevels(classPathModel.skills_class_path_level_labels);
|
|
28
|
-
classPathsById[classPathModel.id] = classPathData;
|
|
29
|
-
classPathsByKey[classPathModel.key] = classPathData;
|
|
30
|
-
}
|
|
31
|
-
return {classPathModels: activeClassPathModels, classPathsById, classPathsByKey};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static extractLabelsByLevels(levelLabelsModel)
|
|
35
|
-
{
|
|
36
|
-
if(!sc.isArray(levelLabelsModel) || 0 === levelLabelsModel.length){
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
let labelsByLevel = {};
|
|
40
|
-
for(let labelData of levelLabelsModel){
|
|
41
|
-
labelsByLevel[labelData['label_level'].key] = labelData.label;
|
|
42
|
-
}
|
|
43
|
-
return labelsByLevel;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
module.exports.ClassPathGenerator = ClassPathGenerator;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - ConditionsGenerator
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { Condition } = require('@reldens/modifiers');
|
|
8
|
-
const { sc } = require('@reldens/utils');
|
|
9
|
-
|
|
10
|
-
class ConditionsGenerator
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
static fromConditionsModels(conditionsModels)
|
|
14
|
-
{
|
|
15
|
-
if(!sc.isArray(conditionsModels) || 0 === conditionsModels.length){
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
let conditions = [];
|
|
19
|
-
for(let conditionModel of conditionsModels){
|
|
20
|
-
conditionModel['propertyKey'] = conditionModel['property_key'];
|
|
21
|
-
let condition = new Condition(conditionModel);
|
|
22
|
-
conditions.push(condition);
|
|
23
|
-
}
|
|
24
|
-
return conditions;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports.ConditionsGenerator = ConditionsGenerator;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - LevelsGenerator
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const Level = require('../../level');
|
|
8
|
-
const { Modifier } = require('@reldens/modifiers');
|
|
9
|
-
const { sc } = require('@reldens/utils');
|
|
10
|
-
|
|
11
|
-
class LevelsGenerator
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
static fromLevelsModels(levelsModels)
|
|
15
|
-
{
|
|
16
|
-
let levels = {};
|
|
17
|
-
for(let levelData of levelsModels){
|
|
18
|
-
levelData.modifiers = this.extractModifiers(levelData['level_modifiers']);
|
|
19
|
-
let levelKey = parseInt(levelData['key']);
|
|
20
|
-
levelData.key = levelKey;
|
|
21
|
-
levels[levelKey] = new Level(levelData);
|
|
22
|
-
}
|
|
23
|
-
return levels;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static extractModifiers(modifiersModels)
|
|
27
|
-
{
|
|
28
|
-
if(!sc.isArray(modifiersModels) || 0 === modifiersModels.length){
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
let levelModifiers = [];
|
|
32
|
-
for(let modifierData of modifiersModels){
|
|
33
|
-
let modifier = new Modifier(modifierData);
|
|
34
|
-
levelModifiers.push(modifier);
|
|
35
|
-
}
|
|
36
|
-
return levelModifiers;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
module.exports.LevelsGenerator = LevelsGenerator;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Reldens - Skills - ClassPathLevelLabelsModel
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const { MikroOrmCore } = require('@reldens/storage');
|
|
8
|
-
const { EntitySchema } = MikroOrmCore;
|
|
9
|
-
|
|
10
|
-
class ClassPathLevelLabelsModel
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
beforeDestroyCalled = 0;
|
|
14
|
-
afterDestroyCalled = 0;
|
|
15
|
-
|
|
16
|
-
constructor(class_path_id, level_id, label)
|
|
17
|
-
{
|
|
18
|
-
this.class_path_id = class_path_id;
|
|
19
|
-
this.level_id = level_id;
|
|
20
|
-
this.label = label;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static createByProps(props)
|
|
24
|
-
{
|
|
25
|
-
const {class_path_id, level_id, label} = props;
|
|
26
|
-
return new this(class_path_id, level_id, label);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static relationMappings()
|
|
30
|
-
{
|
|
31
|
-
return {
|
|
32
|
-
class_path: {
|
|
33
|
-
type: 'ClassPathModel',
|
|
34
|
-
entityName: 'classPath',
|
|
35
|
-
reference: 'm:1',
|
|
36
|
-
join: {
|
|
37
|
-
from: 'class_path_id',
|
|
38
|
-
to: 'id'
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
label_level: {
|
|
42
|
-
type: 'LevelModel',
|
|
43
|
-
entityName: 'level',
|
|
44
|
-
reference: 'm:1',
|
|
45
|
-
join: {
|
|
46
|
-
from: 'level_id',
|
|
47
|
-
to: 'id'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const schema = new EntitySchema({
|
|
56
|
-
class: ClassPathLevelLabelsModel,
|
|
57
|
-
properties: {
|
|
58
|
-
_id: {
|
|
59
|
-
primary: true,
|
|
60
|
-
type: 'ObjectID'
|
|
61
|
-
},
|
|
62
|
-
id: {
|
|
63
|
-
type: 'string',
|
|
64
|
-
serializedPrimaryKey: true
|
|
65
|
-
},
|
|
66
|
-
class_path_id: {
|
|
67
|
-
type: 'ClassPathModel',
|
|
68
|
-
reference: 'm:1',
|
|
69
|
-
nullable: true
|
|
70
|
-
},
|
|
71
|
-
level_id: {
|
|
72
|
-
type: 'LevelModel',
|
|
73
|
-
reference: 'm:1',
|
|
74
|
-
nullable: true
|
|
75
|
-
},
|
|
76
|
-
label: {
|
|
77
|
-
type: 'string'
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
module.exports = {
|
|
83
|
-
ClassPathLevelLabelsModel,
|
|
84
|
-
entity: ClassPathLevelLabelsModel,
|
|
85
|
-
schema
|
|
86
|
-
};
|