@reldens/skills 0.45.0 → 0.47.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/architecture.md +472 -0
- package/.claude/class-hierarchy.md +982 -0
- package/.claude/event-system-architecture.md +475 -0
- package/.claude/level-progression.md +1259 -0
- package/.claude/skill-execution-flow.md +979 -0
- package/.claude/testing-guide.md +356 -0
- package/.claude/testing-patterns.md +1096 -0
- package/CLAUDE.md +164 -29
- package/lib/class-path.js +13 -10
- package/lib/client/receiver.js +1 -3
- package/lib/levels-set.js +24 -17
- package/lib/server/sender.js +1 -1
- package/lib/skill.js +19 -16
- package/lib/types/attack.js +28 -11
- package/lib/types/effect.js +10 -4
- package/lib/types/physical-attack.js +2 -2
- package/lib/types/physical-effect.js +2 -2
- package/lib/types/physical-properties-validator.js +1 -1
- package/lib/types/physical-skill-runner.js +5 -5
- package/package.json +9 -3
- package/tests/fixtures/levels/base-levels.js +89 -0
- package/tests/fixtures/mocks/mock-client.js +44 -0
- package/tests/fixtures/mocks/mock-owner.js +60 -0
- package/tests/fixtures/mocks/mock-target.js +50 -0
- package/tests/fixtures/skills/base-skills.js +80 -0
- package/tests/run-tests.js +88 -0
- package/tests/unit/client/test-receiver.js +249 -0
- package/tests/unit/server/test-sender.js +527 -0
- package/tests/unit/test-class-path.js +1239 -0
- package/tests/unit/test-level.js +176 -0
- package/tests/unit/test-levels-set.js +1227 -0
- package/tests/unit/test-server.js +266 -0
- package/tests/unit/test-skill.js +1302 -0
- package/tests/unit/types/test-attack.js +1195 -0
- package/tests/unit/types/test-effect.js +587 -0
- package/tests/unit/types/test-physical-attack.js +564 -0
- package/tests/unit/types/test-physical-effect.js +769 -0
- package/tests/unit/types/test-physical-properties-validator.js +203 -0
- package/tests/unit/types/test-physical-skill-runner.js +348 -0
- package/tests/utils/test-helpers.js +122 -0
- package/migrations/production/reldens-skills-install.sql +0 -275
package/CLAUDE.md
CHANGED
|
@@ -2,35 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
4
|
|
|
5
|
-
## File Access Permissions
|
|
6
|
-
|
|
7
|
-
**IMPORTANT: These permissions must be approved by the user at the beginning of each session.**
|
|
8
|
-
|
|
9
|
-
Once approved, you are granted the following permissions for files under `D:\dap\work\reldens\npm-packages\reldens-skills`:
|
|
10
|
-
|
|
11
|
-
✅ **ALLOWED**:
|
|
12
|
-
- Read ANY file under `D:\dap\work\reldens\npm-packages\reldens-skills`
|
|
13
|
-
- Create NEW files under `D:\dap\work\reldens\npm-packages\reldens-skills`
|
|
14
|
-
|
|
15
|
-
❌ **FORBIDDEN**:
|
|
16
|
-
- Edit or modify EXISTING files
|
|
17
|
-
- Delete files
|
|
18
|
-
- Move files
|
|
19
|
-
|
|
20
|
-
**When modifications to existing files are needed:**
|
|
21
|
-
- Provide complete NEW file artifacts with the full updated content
|
|
22
|
-
- User will manually replace the existing files with the new content
|
|
23
|
-
- Never use the Edit tool on existing files
|
|
24
|
-
|
|
25
|
-
## Code Rules & Standards
|
|
26
|
-
|
|
27
|
-
1. Read and follow ALL coding rules from `D:\dap\work\reldens\_source\ai-coding-rules.md`.
|
|
28
|
-
2. Apply the code rules to every single line of code you provide.
|
|
29
|
-
3. Self-audit every response against the rules before sending.
|
|
30
|
-
|
|
31
5
|
## Package Overview
|
|
32
6
|
|
|
33
|
-
**@reldens/skills** (v0.
|
|
7
|
+
**@reldens/skills** (v0.47.0) is a comprehensive skills, leveling, and combat system that provides:
|
|
34
8
|
- Level sets with automatic progression and experience management
|
|
35
9
|
- Class paths with skill trees and level-dependent unlocks
|
|
36
10
|
- Multiple skill types (base, attack, effect, physical variants)
|
|
@@ -41,11 +15,32 @@ Once approved, you are granted the following permissions for files under `D:\dap
|
|
|
41
15
|
|
|
42
16
|
This package is part of the Reldens MMORPG Platform ecosystem and can be attached to any entity owner with position methods.
|
|
43
17
|
|
|
18
|
+
## Comprehensive Documentation
|
|
19
|
+
|
|
20
|
+
**Detailed technical documentation is available in the `.claude/` directory:**
|
|
21
|
+
|
|
22
|
+
- **[Event System Architecture](.claude/event-system-architecture.md)** - Complete event system documentation including EventsManagerSingleton, removeKey registry, event naming, and testing anti-patterns
|
|
23
|
+
- **[Skill Execution Flow](.claude/skill-execution-flow.md)** - Step-by-step skill execution phases, type-specific logic, and complete sequence diagrams
|
|
24
|
+
- **[Testing Patterns](.claude/testing-patterns.md)** - Best practices, anti-patterns, and critical lessons learned from test suite debugging
|
|
25
|
+
- **[Level Progression](.claude/level-progression.md)** - Complete leveling system guide including auto-fill, experience management, and class paths
|
|
26
|
+
- **[Class Hierarchy](.claude/class-hierarchy.md)** - Architecture reference with inheritance, composition, and integration patterns
|
|
27
|
+
|
|
28
|
+
**Always consult these documents when working with the corresponding systems.**
|
|
29
|
+
|
|
44
30
|
## Key Commands
|
|
45
31
|
|
|
46
32
|
```bash
|
|
47
|
-
# Run tests
|
|
33
|
+
# Run all tests
|
|
48
34
|
npm test
|
|
35
|
+
|
|
36
|
+
# Run tests in watch mode
|
|
37
|
+
npm run test:watch
|
|
38
|
+
|
|
39
|
+
# Run specific tests with filter
|
|
40
|
+
npm run test:filter=skill
|
|
41
|
+
|
|
42
|
+
# Run tests with coverage
|
|
43
|
+
npm run test:coverage
|
|
49
44
|
```
|
|
50
45
|
|
|
51
46
|
## Architecture
|
|
@@ -251,6 +246,13 @@ lib/
|
|
|
251
246
|
|
|
252
247
|
All events are prefixed with `reldens.skills.` and appended with owner event key.
|
|
253
248
|
|
|
249
|
+
**IMPORTANT:** See `.claude/event-system-architecture.md` for complete event system documentation including:
|
|
250
|
+
- EventsManagerSingleton architecture and removeKey registry
|
|
251
|
+
- Event naming conventions (owner-namespaced)
|
|
252
|
+
- Listener registration patterns
|
|
253
|
+
- Testing anti-patterns and race conditions
|
|
254
|
+
- Critical rules for event usage
|
|
255
|
+
|
|
254
256
|
**Level Set Events** (fired by LevelsSet):
|
|
255
257
|
- `INIT_LEVEL_SET_START`: Before level set initialization
|
|
256
258
|
- `INIT_LEVEL_SET_END`: After level set initialization
|
|
@@ -336,9 +338,141 @@ All action constants use `rski.` prefix (Reldens Skills) for network messages:
|
|
|
336
338
|
|
|
337
339
|
## Dependencies
|
|
338
340
|
|
|
339
|
-
- **@reldens/modifiers** (^0.
|
|
341
|
+
- **@reldens/modifiers** (^0.33.0): Provides PropertyManager, Condition, Calculator, and modifier system
|
|
340
342
|
- **@reldens/utils** (^0.54.0): Provides Shortcuts (sc), Logger, EventsManagerSingleton, InteractionArea
|
|
341
343
|
|
|
344
|
+
## Test Suite
|
|
345
|
+
|
|
346
|
+
The package includes a comprehensive test suite using Node.js built-in test runner.
|
|
347
|
+
|
|
348
|
+
**See `.claude/testing-patterns.md` for comprehensive testing best practices, anti-patterns, and lessons learned.**
|
|
349
|
+
|
|
350
|
+
### Test Structure
|
|
351
|
+
|
|
352
|
+
```
|
|
353
|
+
tests/
|
|
354
|
+
├── run-tests.js # Test runner with filtering and coverage support
|
|
355
|
+
├── utils/
|
|
356
|
+
│ └── test-helpers.js # Helper functions for tests
|
|
357
|
+
├── fixtures/
|
|
358
|
+
│ ├── mocks/ # Mock classes (MockOwner, MockTarget, MockClient)
|
|
359
|
+
│ ├── skills/ # Skill test data fixtures
|
|
360
|
+
│ └── levels/ # Level test data fixtures
|
|
361
|
+
└── unit/
|
|
362
|
+
├── test-skill.js # Skill class tests
|
|
363
|
+
├── test-level.js # Level class tests
|
|
364
|
+
├── test-levels-set.js # LevelsSet class tests
|
|
365
|
+
├── test-class-path.js # ClassPath class tests
|
|
366
|
+
├── test-server.js # SkillsServer tests
|
|
367
|
+
├── types/
|
|
368
|
+
│ ├── test-attack.js # Attack skill type tests
|
|
369
|
+
│ ├── test-effect.js # Effect skill type tests
|
|
370
|
+
│ ├── test-physical-attack.js # PhysicalAttack tests
|
|
371
|
+
│ └── test-physical-effect.js # PhysicalEffect tests
|
|
372
|
+
├── server/
|
|
373
|
+
│ └── test-sender.js # Sender tests
|
|
374
|
+
└── client/
|
|
375
|
+
└── test-receiver.js # Receiver tests
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Running Tests
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
# Run all tests
|
|
382
|
+
npm test
|
|
383
|
+
|
|
384
|
+
# Watch mode for development
|
|
385
|
+
npm run test:watch
|
|
386
|
+
|
|
387
|
+
# Filter specific tests
|
|
388
|
+
npm run test:filter=attack # Run only attack-related tests
|
|
389
|
+
npm run test:filter=skill # Run only skill tests
|
|
390
|
+
|
|
391
|
+
# Coverage report
|
|
392
|
+
npm run test:coverage
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Test Patterns
|
|
396
|
+
|
|
397
|
+
- **Unit Tests**: Test individual classes and methods in isolation
|
|
398
|
+
- **Mock Objects**: Use MockOwner, MockTarget, and MockClient for testing
|
|
399
|
+
- **Fixtures**: Reusable test data in fixtures directory
|
|
400
|
+
- **Event Testing**: Verify event firing and listening
|
|
401
|
+
- **Async Testing**: Proper handling of async/await patterns
|
|
402
|
+
- **Edge Cases**: Test boundary conditions and error states
|
|
403
|
+
|
|
404
|
+
### Critical Testing Rules
|
|
405
|
+
|
|
406
|
+
#### Rule #1: NEVER Test Through Events Unless Testing the Event System
|
|
407
|
+
|
|
408
|
+
**❌ WRONG:**
|
|
409
|
+
```javascript
|
|
410
|
+
it('should send level up message', async () => {
|
|
411
|
+
await classPath.levelUp(); // Fires event asynchronously
|
|
412
|
+
assert.strictEqual(mockClient.sentMessages.length, 1); // Race condition!
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
**✅ CORRECT:**
|
|
417
|
+
```javascript
|
|
418
|
+
it('should send level up message', async () => {
|
|
419
|
+
await sender.sendLevelUpData(classPath); // Direct method call
|
|
420
|
+
assert.strictEqual(mockClient.sentMessages.length, 1); // Deterministic
|
|
421
|
+
});
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
#### Rule #2: NEVER Use sleep() to Fix Race Conditions
|
|
425
|
+
|
|
426
|
+
**❌ WRONG:**
|
|
427
|
+
```javascript
|
|
428
|
+
await classPath.levelUp();
|
|
429
|
+
await TestHelpers.sleep(10); // DON'T DO THIS!
|
|
430
|
+
assert.strictEqual(mockClient.sentMessages.length, 1);
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
**✅ CORRECT (for testing methods):**
|
|
434
|
+
```javascript
|
|
435
|
+
await sender.sendLevelUpData(classPath); // Direct method call
|
|
436
|
+
assert.strictEqual(mockClient.sentMessages.length, 1);
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**✅ CORRECT (for testing timers):**
|
|
440
|
+
```javascript
|
|
441
|
+
it('should restore canActivate after delay', async () => {
|
|
442
|
+
skill.validate();
|
|
443
|
+
await TestHelpers.sleep(150); // Testing actual timer feature
|
|
444
|
+
assert.strictEqual(skill.canActivate, true);
|
|
445
|
+
});
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
#### Rule #3: ALWAYS Use Unique removeKeys
|
|
449
|
+
|
|
450
|
+
**❌ WRONG:**
|
|
451
|
+
```javascript
|
|
452
|
+
// Test 1
|
|
453
|
+
classPath.listenEvent(SkillsEvents.ADD_SKILLS_BEFORE, callback, 'before-listener');
|
|
454
|
+
|
|
455
|
+
// Test 2 (after clearEventListeners)
|
|
456
|
+
classPath.listenEvent(SkillsEvents.REMOVE_SKILLS_BEFORE, callback, 'before-listener');
|
|
457
|
+
// ❌ removeKey collision - registration fails silently
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
**✅ CORRECT:**
|
|
461
|
+
```javascript
|
|
462
|
+
// Test 1
|
|
463
|
+
classPath.listenEvent(SkillsEvents.ADD_SKILLS_BEFORE, callback, 'add-before-listener');
|
|
464
|
+
|
|
465
|
+
// Test 2
|
|
466
|
+
classPath.listenEvent(SkillsEvents.REMOVE_SKILLS_BEFORE, callback, 'remove-before-listener');
|
|
467
|
+
// ✓ Unique removeKeys
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
**Summary:**
|
|
471
|
+
- ❌ Don't test through events (use direct method calls)
|
|
472
|
+
- ❌ Don't use `sleep()` to fix race conditions
|
|
473
|
+
- ✅ Do use `sleep()` to test timer features (skillDelay, castTime)
|
|
474
|
+
- ✅ Always use unique removeKeys across all tests
|
|
475
|
+
|
|
342
476
|
## Common Development Patterns
|
|
343
477
|
|
|
344
478
|
### Creating a Custom Skill
|
|
@@ -486,3 +620,4 @@ When working on code issues:
|
|
|
486
620
|
- Verify file contents before creating patches
|
|
487
621
|
- Never jump to early conclusions
|
|
488
622
|
- A variable with an unexpected value is not an issue, it is the result of a previous issue
|
|
623
|
+
- Consult `.claude/` documentation for detailed technical information on each system
|
package/lib/class-path.js
CHANGED
|
@@ -14,21 +14,22 @@ class ClassPath extends LevelsSet
|
|
|
14
14
|
async init(props)
|
|
15
15
|
{
|
|
16
16
|
await super.init(props);
|
|
17
|
-
|
|
17
|
+
let key = sc.get(props, 'key');
|
|
18
|
+
if(!key){
|
|
18
19
|
Logger.critical('Undefined key for class path.');
|
|
19
20
|
return false;
|
|
20
21
|
}
|
|
21
22
|
// key is the code for class-path itself and label y the name that can be used for display:
|
|
22
|
-
this.key =
|
|
23
|
+
this.key = key;
|
|
23
24
|
// the label will be the default display name for the class path:
|
|
24
|
-
this.label = sc.
|
|
25
|
+
this.label = sc.get(props, 'label', key);
|
|
25
26
|
// labelsByLevel can be an object of {levelKey: 'path level label'}, the current path level display name.
|
|
26
27
|
// for example: the path "Warrior" (this.label), at level 10 could become "Experienced Warrior".
|
|
27
|
-
this.labelsByLevel = sc.
|
|
28
|
+
this.labelsByLevel = sc.get(props, 'labelsByLevel', false);
|
|
28
29
|
// the current label is used for the current object instance:
|
|
29
|
-
this.currentLabel = sc.
|
|
30
|
+
this.currentLabel = sc.get(props, 'currentLabel', this.getCurrentLabel());
|
|
30
31
|
// skillsByLevel can be an object of {levelKey: [skillInstances]}, these will be all the skills available.
|
|
31
|
-
this.skillsByLevel = sc.
|
|
32
|
+
this.skillsByLevel = sc.get(props, 'skillsByLevel', false);
|
|
32
33
|
this.skillsByLevelKeys = this.getSkillsByLevelKeys();
|
|
33
34
|
// the set of skills for the current object instance:
|
|
34
35
|
await this.setOwnerSkills(sc.get(props, 'currentSkills', false));
|
|
@@ -71,10 +72,10 @@ class ClassPath extends LevelsSet
|
|
|
71
72
|
async levelDown()
|
|
72
73
|
{
|
|
73
74
|
// @NOTE: the level will be decreased in the parent LevelSet call.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await this.removeSkills(this.skillsByLevel[previousLevel]);
|
|
75
|
+
if(sc.hasOwn(this.skillsByLevel, this.currentLevel)){
|
|
76
|
+
await this.removeSkills(this.skillsByLevel[this.currentLevel]);
|
|
77
77
|
}
|
|
78
|
+
let previousLevel = this.currentLevel - 1;
|
|
78
79
|
if(sc.hasOwn(this.labelsByLevel, previousLevel)){
|
|
79
80
|
this.currentLabel = this.labelsByLevel[previousLevel];
|
|
80
81
|
}
|
|
@@ -94,7 +95,9 @@ class ClassPath extends LevelsSet
|
|
|
94
95
|
async removeSkills(skills)
|
|
95
96
|
{
|
|
96
97
|
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_BEFORE, this, skills);
|
|
97
|
-
for(let
|
|
98
|
+
for(let i of Object.keys(skills)){
|
|
99
|
+
let skillOrKey = skills[i];
|
|
100
|
+
let skillKey = 'string' === typeof skillOrKey ? skillOrKey : skillOrKey.key;
|
|
98
101
|
delete this.currentSkills[skillKey];
|
|
99
102
|
}
|
|
100
103
|
await this.fireEvent(SkillsEvents.REMOVE_SKILLS_AFTER, this, skills);
|
package/lib/client/receiver.js
CHANGED
|
@@ -14,11 +14,9 @@ class Receiver
|
|
|
14
14
|
{
|
|
15
15
|
if(!sc.hasOwn(props, 'owner')){
|
|
16
16
|
Logger.critical('Undefined owner.');
|
|
17
|
-
return false;
|
|
18
17
|
}
|
|
19
|
-
if(typeof props.owner.getPosition !== 'function'){
|
|
18
|
+
if(props.owner && typeof props.owner.getPosition !== 'function'){
|
|
20
19
|
Logger.critical('Undefined owner position method.');
|
|
21
|
-
return false;
|
|
22
20
|
}
|
|
23
21
|
this.actions = sc.get(props, 'actions', {});
|
|
24
22
|
if(!sc.hasOwn(props, 'avoidDefaults') || !props['avoidDefaults']){
|
package/lib/levels-set.js
CHANGED
|
@@ -19,36 +19,38 @@ class LevelsSet
|
|
|
19
19
|
|
|
20
20
|
setOwner(props)
|
|
21
21
|
{
|
|
22
|
-
|
|
22
|
+
let owner = sc.get(props, 'owner');
|
|
23
|
+
if(!owner){
|
|
23
24
|
Logger.critical('Undefined owner for levels.');
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
26
27
|
// @NOTE: getPosition must return an object with x and y props, like {x: 123, y: 456}.
|
|
27
|
-
if(typeof
|
|
28
|
+
if('function' !== typeof owner.getPosition){
|
|
28
29
|
Logger.critical('Undefined owner position method.');
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
|
-
this.owner =
|
|
32
|
-
this.ownerIdProperty = sc.
|
|
32
|
+
this.owner = owner;
|
|
33
|
+
this.ownerIdProperty = sc.get(props, 'ownerIdProperty', 'id');
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
async init(props)
|
|
36
37
|
{
|
|
37
|
-
if(!
|
|
38
|
+
if(!this.owner){
|
|
38
39
|
Logger.critical('Undefined owner for levels.');
|
|
39
40
|
return false;
|
|
40
41
|
}
|
|
41
|
-
if(typeof this.owner.getPosition
|
|
42
|
+
if('function' !== typeof this.owner.getPosition){
|
|
42
43
|
Logger.critical('Undefined owner position method.');
|
|
43
44
|
return false;
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
let levels = sc.get(props, 'levels', {});
|
|
47
|
+
if(!levels || !Object.keys(levels).length){
|
|
46
48
|
Logger.critical('Levels were not specified.');
|
|
47
49
|
return false;
|
|
48
50
|
}
|
|
49
51
|
// fireEvent has to be executed after the owner was set since it will call the owner data to relate the events:
|
|
50
52
|
await this.fireEvent(SkillsEvents.INIT_LEVEL_SET_START, this);
|
|
51
|
-
// @NOTE: if autoFillRanges is enabled you could have the first level with key = 1 and the next with key = 5,
|
|
53
|
+
// @NOTE: if autoFillRanges is enabled, you could have the first level with key = 1 and the next with key = 5,
|
|
52
54
|
// this way the setLevels will fill up levels 2, 3 and 4 with the same level Object so the same level modifiers
|
|
53
55
|
// will be applied automatically (same calculation for multiple levels).
|
|
54
56
|
this.autoFillRanges = sc.get(props, 'autoFillRanges', false);
|
|
@@ -56,15 +58,16 @@ class LevelsSet
|
|
|
56
58
|
this.currentLevel = sc.get(props, 'currentLevel', 0);
|
|
57
59
|
this.currentExp = sc.get(props, 'currentExp', 0);
|
|
58
60
|
this.setRequiredExperienceLimit = sc.get(props, 'setRequiredExperienceLimit', false);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
this.ownerIdProperty = sc.get(props, 'ownerIdProperty', 'id');
|
|
62
|
+
// set levels is almost the last thing to happen here; first we need to validate all the other parameters:
|
|
63
|
+
this.levels = await this.setLevels(levels);
|
|
64
|
+
// @NOTE: if you set up levelsByExperience and autoFillRanges at the same time, the levels autogenerated will be
|
|
62
65
|
// skipped because the experience on those will be lowed one. For example, level 1 required experience = 10p,
|
|
63
|
-
// level 5 required experience = 20p
|
|
64
|
-
// player
|
|
66
|
+
// level 5 required experience = 20p; levels 2, 3 and 4 are auto-generated with required exp. = 20p, so when the
|
|
67
|
+
// player reaches 20p of experience, it will jump to level 5. In summary, you shouldn't mix these options unless
|
|
65
68
|
// you expect the described behavior.
|
|
66
69
|
this.increaseLevelsWithExperience = sc.get(props, 'increaseLevelsWithExperience', true);
|
|
67
|
-
// unless specified, levels by experience must just be sorted by their key attribute (without
|
|
70
|
+
// unless specified, levels by experience must just be sorted by their key attribute (without autofill):
|
|
68
71
|
this.levelsByExperience = sc.get(props, 'levelsByExperience', this.sortLevelsBy(this.levels));
|
|
69
72
|
await this.fireEvent(SkillsEvents.INIT_LEVEL_SET_END, this);
|
|
70
73
|
}
|
|
@@ -152,7 +155,7 @@ class LevelsSet
|
|
|
152
155
|
return false;
|
|
153
156
|
}
|
|
154
157
|
await this.fireEvent(SkillsEvents.LEVEL_APPLY_MODIFIERS, this, currentLevelInstance);
|
|
155
|
-
if(!currentLevelInstance.modifiers){
|
|
158
|
+
if(!currentLevelInstance.modifiers || 0 === currentLevelInstance.modifiers.length){
|
|
156
159
|
return false;
|
|
157
160
|
}
|
|
158
161
|
for(let modifier of currentLevelInstance.modifiers){
|
|
@@ -162,7 +165,7 @@ class LevelsSet
|
|
|
162
165
|
|
|
163
166
|
getLevelInstance(level)
|
|
164
167
|
{
|
|
165
|
-
// @NOTE: if you only specify 1 level the same calculation will be used for all the levels.
|
|
168
|
+
// @NOTE: if you only specify 1 level, the same calculation will be used for all the levels.
|
|
166
169
|
return sc.get(this.levels, level, false);
|
|
167
170
|
}
|
|
168
171
|
|
|
@@ -175,7 +178,11 @@ class LevelsSet
|
|
|
175
178
|
let nextLevel = this.levels[nextLevelKey];
|
|
176
179
|
let nextLevelExp = 0;
|
|
177
180
|
let isLevelUp = false;
|
|
178
|
-
if(
|
|
181
|
+
if(
|
|
182
|
+
this.increaseLevelsWithExperience
|
|
183
|
+
&& sc.hasOwn(this.levels, this.currentLevel)
|
|
184
|
+
&& nextLevel && newTotalExp >= nextLevel.requiredExperience
|
|
185
|
+
){
|
|
179
186
|
for(let levelByExp of this.levelsByExperience.slice(nextLevelIndex)){
|
|
180
187
|
if(newTotalExp >= this.levels[levelByExp].requiredExperience){
|
|
181
188
|
isLevelUp = true;
|
package/lib/server/sender.js
CHANGED
|
@@ -161,7 +161,7 @@ class Sender
|
|
|
161
161
|
async runBehaviors(messageData, actionName, behavior, ownerId)
|
|
162
162
|
{
|
|
163
163
|
// @NOTE: since the sender is a new instance for each SkillsServer, but it's listening on a single EventsManager
|
|
164
|
-
// which fires the event for every player then we need to check if the current event fired was related to the
|
|
164
|
+
// which fires the event for every player, then we need to check if the current event fired was related to the
|
|
165
165
|
// current player.
|
|
166
166
|
if(this.classPath.getOwnerId() !== ownerId){
|
|
167
167
|
Logger.critical('Skill owners miss match, please review.');
|
package/lib/skill.js
CHANGED
|
@@ -107,13 +107,12 @@ class Skill
|
|
|
107
107
|
if(0 < this.usesLimit && this.uses >= this.usesLimit){
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
110
|
+
this.canActivate = true;
|
|
110
111
|
if(0 < this.skillDelay){
|
|
111
112
|
this.canActivate = false;
|
|
112
113
|
this.skillActivationTimer = setTimeout(()=> {
|
|
113
114
|
this.canActivate = true;
|
|
114
115
|
}, this.skillDelay);
|
|
115
|
-
} else {
|
|
116
|
-
this.canActivate = true;
|
|
117
116
|
}
|
|
118
117
|
// with this event we could modify the isValid property if required:
|
|
119
118
|
// @TODO - BETA - Replace catch.
|
|
@@ -204,26 +203,30 @@ class Skill
|
|
|
204
203
|
){
|
|
205
204
|
return false;
|
|
206
205
|
}
|
|
207
|
-
let skillLogicResult = false;
|
|
208
206
|
if(this.ownerEffects){
|
|
209
207
|
this.applyModifiers(this.ownerEffects, this.owner, true);
|
|
210
208
|
await this.fireEvent(SkillsEvents.SKILL_APPLY_OWNER_EFFECTS, this, target);
|
|
211
209
|
}
|
|
210
|
+
let skillLogicResult = await this.applySkillLogicOnTarget(target);
|
|
211
|
+
this.uses++;
|
|
212
|
+
await this.onExecuteRewards();
|
|
213
|
+
await this.fireEvent(SkillsEvents.SKILL_AFTER_EXECUTE, this, target);
|
|
214
|
+
return skillLogicResult;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async applySkillLogicOnTarget(target)
|
|
218
|
+
{
|
|
212
219
|
if(0 < this.castTime){
|
|
213
220
|
await this.fireEvent(SkillsEvents.SKILL_BEFORE_CAST, this, target);
|
|
214
221
|
this.owner.isCasting = true;
|
|
215
|
-
this.owner.castingTimer = setTimeout(() => {
|
|
216
|
-
skillLogicResult = this.finishExecution(target);
|
|
222
|
+
this.owner.castingTimer = setTimeout(async () => {
|
|
223
|
+
let skillLogicResult = await this.finishExecution(target);
|
|
217
224
|
this.owner.isCasting = false;
|
|
218
|
-
this.fireEvent(SkillsEvents.SKILL_AFTER_CAST, this, target, skillLogicResult);
|
|
225
|
+
await this.fireEvent(SkillsEvents.SKILL_AFTER_CAST, this, target, skillLogicResult);
|
|
219
226
|
}, this.castTime);
|
|
220
|
-
|
|
221
|
-
skillLogicResult = await this.finishExecution(target);
|
|
227
|
+
return false;
|
|
222
228
|
}
|
|
223
|
-
this.
|
|
224
|
-
await this.onExecuteRewards();
|
|
225
|
-
await this.fireEvent(SkillsEvents.SKILL_AFTER_EXECUTE, this, target);
|
|
226
|
-
return skillLogicResult;
|
|
229
|
+
return await this.finishExecution(target);
|
|
227
230
|
}
|
|
228
231
|
|
|
229
232
|
async isValidRange(target)
|
|
@@ -264,10 +267,10 @@ class Skill
|
|
|
264
267
|
if(!this.isCritical()){
|
|
265
268
|
return normalValue;
|
|
266
269
|
}
|
|
267
|
-
if(this.criticalMultiplier){
|
|
270
|
+
if(sc.isNumber(this.criticalMultiplier)){
|
|
268
271
|
normalValue = normalValue * this.criticalMultiplier;
|
|
269
272
|
}
|
|
270
|
-
if(this.criticalFixedValue){
|
|
273
|
+
if(sc.isNumber(this.criticalFixedValue)){
|
|
271
274
|
normalValue = normalValue + this.criticalFixedValue;
|
|
272
275
|
}
|
|
273
276
|
return normalValue;
|
|
@@ -283,7 +286,7 @@ class Skill
|
|
|
283
286
|
if(this.criticalChance <= 0){
|
|
284
287
|
return false;
|
|
285
288
|
}
|
|
286
|
-
return
|
|
289
|
+
return sc.randomInteger(1, 100) <= this.criticalChance;
|
|
287
290
|
}
|
|
288
291
|
|
|
289
292
|
applyModifiers(modifiersObjectList, target, avoidCritical = false)
|
|
@@ -294,7 +297,7 @@ class Skill
|
|
|
294
297
|
modifier.target = target;
|
|
295
298
|
let newValue = modifier.getModifiedValue();
|
|
296
299
|
if(!avoidCritical){
|
|
297
|
-
newValue = this.
|
|
300
|
+
newValue = newValue + this.getCriticalDiff(modifier.value);
|
|
298
301
|
}
|
|
299
302
|
modifier.setOwnerProperty(modifier.propertyKey, newValue);
|
|
300
303
|
this.lastAppliedModifiers[modifier.propertyKey] = newValue;
|
package/lib/types/attack.js
CHANGED
|
@@ -18,12 +18,13 @@ class Attack extends Skill
|
|
|
18
18
|
{
|
|
19
19
|
super(props);
|
|
20
20
|
this.type = SkillsConst.SKILL.TYPE.ATTACK;
|
|
21
|
-
|
|
21
|
+
let affectedProperty = sc.get(props, 'affectedProperty', false);
|
|
22
|
+
if(!affectedProperty){
|
|
22
23
|
Logger.error('Missing skill affectedProperty to which the result damage will be applied.');
|
|
23
24
|
this.isReady = false;
|
|
24
25
|
}
|
|
25
26
|
// the affected property is the one to which the damage calculation will have effect:
|
|
26
|
-
this.affectedProperty =
|
|
27
|
+
this.affectedProperty = affectedProperty;
|
|
27
28
|
this.allowEffectBelowZero = sc.get(props, 'allowEffectBelowZero', false);
|
|
28
29
|
// hit damage value at 100%:
|
|
29
30
|
this.hitDamage = sc.get(props, 'hitDamage', 0);
|
|
@@ -51,7 +52,11 @@ class Attack extends Skill
|
|
|
51
52
|
async runSkillLogic()
|
|
52
53
|
{
|
|
53
54
|
this.lastState = null;
|
|
54
|
-
if(!this.
|
|
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())){
|
|
55
60
|
// out of range, the owner or the target could move away
|
|
56
61
|
this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
|
|
57
62
|
return false;
|
|
@@ -101,16 +106,19 @@ class Attack extends Skill
|
|
|
101
106
|
this.setAffectedPropertyValue(target, modifiedValue);
|
|
102
107
|
this.lastState = SkillsConst.SKILL_STATES.APPLIED_DAMAGE;
|
|
103
108
|
await this.fireEvent(SkillsEvents.SKILL_ATTACK_APPLY_DAMAGE, this, target, damage, modifiedValue);
|
|
109
|
+
return true;
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
calculateCriticalDamage(damage, targetDodge, ownerAim, dodgeAimDiff)
|
|
107
113
|
{
|
|
108
114
|
let criticalValue = this.getCriticalDiff(damage);
|
|
109
|
-
if
|
|
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){
|
|
110
118
|
return criticalValue;
|
|
111
119
|
}
|
|
112
120
|
this.lastState = SkillsConst.SKILL_STATES.APPLIED_CRITICAL_DAMAGE;
|
|
113
|
-
// calculate dodge proportion over critical damage and remove it from the critical total:
|
|
121
|
+
// calculate the dodge proportion over critical damage and remove it from the critical total:
|
|
114
122
|
return criticalValue - (Math.floor((criticalValue * dodgeAimDiff / 100)));
|
|
115
123
|
}
|
|
116
124
|
|
|
@@ -133,16 +141,16 @@ class Attack extends Skill
|
|
|
133
141
|
damage = damage - reduceDamage;
|
|
134
142
|
}
|
|
135
143
|
if(this.damageAffected && targetDodge > ownerAim){
|
|
136
|
-
// calculate dodge proportion over damage and remove it from the total:
|
|
144
|
+
// calculate a dodge proportion over damage and remove it from the total:
|
|
137
145
|
let damageProportion = Math.floor((damage * dodgeAimDiff / 100));
|
|
138
146
|
damage = damage - damageProportion;
|
|
139
147
|
}
|
|
140
148
|
return damage;
|
|
141
149
|
}
|
|
142
150
|
|
|
143
|
-
getPropertiesTotal(
|
|
151
|
+
getPropertiesTotal(objectInstance, propertiesArray)
|
|
144
152
|
{
|
|
145
|
-
if(!
|
|
153
|
+
if(!objectInstance){
|
|
146
154
|
Logger.warning('Missing object to get properties total.');
|
|
147
155
|
return false;
|
|
148
156
|
}
|
|
@@ -152,7 +160,7 @@ class Attack extends Skill
|
|
|
152
160
|
try {
|
|
153
161
|
let totalValue = 0;
|
|
154
162
|
for(let prop of propertiesArray){
|
|
155
|
-
let propValue = this.propertyManager.getPropertyValue(
|
|
163
|
+
let propValue = this.propertyManager.getPropertyValue(objectInstance, prop);
|
|
156
164
|
totalValue = sc.hasOwn(this.propertiesTotalOperators, prop)
|
|
157
165
|
? this.calculator.calculateNewValue(totalValue, this.propertiesTotalOperators[prop], propValue)
|
|
158
166
|
: totalValue + propValue;
|
|
@@ -166,6 +174,15 @@ class Attack extends Skill
|
|
|
166
174
|
|
|
167
175
|
getDiffProportion(totalValue, upProportionValue)
|
|
168
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
|
+
}
|
|
169
186
|
let propertiesDiff = upProportionValue - totalValue;
|
|
170
187
|
return ((propertiesDiff * 100) / totalValue);
|
|
171
188
|
}
|
|
@@ -175,9 +192,9 @@ class Attack extends Skill
|
|
|
175
192
|
return this.propertyManager.getPropertyValue(target, this.affectedProperty);
|
|
176
193
|
}
|
|
177
194
|
|
|
178
|
-
setAffectedPropertyValue(target,
|
|
195
|
+
setAffectedPropertyValue(target, value)
|
|
179
196
|
{
|
|
180
|
-
return this.propertyManager.setOwnerProperty(target, this.affectedProperty,
|
|
197
|
+
return this.propertyManager.setOwnerProperty(target, this.affectedProperty, value);
|
|
181
198
|
}
|
|
182
199
|
|
|
183
200
|
}
|
package/lib/types/effect.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
const Skill = require('../skill');
|
|
10
10
|
const SkillsEvents = require('../skills-events');
|
|
11
11
|
const SkillsConst = require('../constants');
|
|
12
|
-
const {
|
|
12
|
+
const { Logger, sc } = require('@reldens/utils');
|
|
13
13
|
|
|
14
14
|
class Effect extends Skill
|
|
15
15
|
{
|
|
@@ -18,17 +18,22 @@ class Effect extends Skill
|
|
|
18
18
|
{
|
|
19
19
|
super(props);
|
|
20
20
|
this.type = SkillsConst.SKILL.TYPE.EFFECT;
|
|
21
|
-
|
|
21
|
+
let targetEffects = sc.get(props, 'targetEffects');
|
|
22
|
+
if(!targetEffects){
|
|
22
23
|
Logger.error('Missing targetEffects for skill.');
|
|
23
24
|
this.isReady = false;
|
|
24
25
|
}
|
|
25
|
-
this.targetEffects =
|
|
26
|
+
this.targetEffects = targetEffects;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
async runSkillLogic()
|
|
29
30
|
{
|
|
30
31
|
this.lastState = null;
|
|
31
|
-
if(!this.
|
|
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())){
|
|
32
37
|
this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
|
|
33
38
|
// out of range, the owner or the target could move away
|
|
34
39
|
return false;
|
|
@@ -39,6 +44,7 @@ class Effect extends Skill
|
|
|
39
44
|
this.applyModifiers(this.targetEffects, this.target);
|
|
40
45
|
this.lastState = SkillsConst.SKILL_STATES.APPLIED_EFFECTS;
|
|
41
46
|
await this.fireEvent(SkillsEvents.SKILL_EFFECT_TARGET_MODIFIERS, this);
|
|
47
|
+
return true;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
}
|
|
@@ -36,8 +36,8 @@ class PhysicalAttack extends Attack
|
|
|
36
36
|
|
|
37
37
|
async executeOnHit(target)
|
|
38
38
|
{
|
|
39
|
-
return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT, (
|
|
40
|
-
super.runSkillLogic(
|
|
39
|
+
return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_ATTACK_HIT, async () => {
|
|
40
|
+
return await super.runSkillLogic();
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -36,8 +36,8 @@ class PhysicalEffect extends Effect
|
|
|
36
36
|
|
|
37
37
|
async executeOnHit(target)
|
|
38
38
|
{
|
|
39
|
-
return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT, (
|
|
40
|
-
super.runSkillLogic(
|
|
39
|
+
return PhysicalSkillRunner.executeOnHit(target, this, SkillsEvents.SKILL_PHYSICAL_EFFECT_HIT, async () => {
|
|
40
|
+
return await super.runSkillLogic();
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|