@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.
Files changed (41) hide show
  1. package/.claude/architecture.md +472 -0
  2. package/.claude/class-hierarchy.md +982 -0
  3. package/.claude/event-system-architecture.md +475 -0
  4. package/.claude/level-progression.md +1259 -0
  5. package/.claude/skill-execution-flow.md +979 -0
  6. package/.claude/testing-guide.md +356 -0
  7. package/.claude/testing-patterns.md +1096 -0
  8. package/CLAUDE.md +164 -29
  9. package/lib/class-path.js +13 -10
  10. package/lib/client/receiver.js +1 -3
  11. package/lib/levels-set.js +24 -17
  12. package/lib/server/sender.js +1 -1
  13. package/lib/skill.js +19 -16
  14. package/lib/types/attack.js +28 -11
  15. package/lib/types/effect.js +10 -4
  16. package/lib/types/physical-attack.js +2 -2
  17. package/lib/types/physical-effect.js +2 -2
  18. package/lib/types/physical-properties-validator.js +1 -1
  19. package/lib/types/physical-skill-runner.js +5 -5
  20. package/package.json +9 -3
  21. package/tests/fixtures/levels/base-levels.js +89 -0
  22. package/tests/fixtures/mocks/mock-client.js +44 -0
  23. package/tests/fixtures/mocks/mock-owner.js +60 -0
  24. package/tests/fixtures/mocks/mock-target.js +50 -0
  25. package/tests/fixtures/skills/base-skills.js +80 -0
  26. package/tests/run-tests.js +88 -0
  27. package/tests/unit/client/test-receiver.js +249 -0
  28. package/tests/unit/server/test-sender.js +527 -0
  29. package/tests/unit/test-class-path.js +1239 -0
  30. package/tests/unit/test-level.js +176 -0
  31. package/tests/unit/test-levels-set.js +1227 -0
  32. package/tests/unit/test-server.js +266 -0
  33. package/tests/unit/test-skill.js +1302 -0
  34. package/tests/unit/types/test-attack.js +1195 -0
  35. package/tests/unit/types/test-effect.js +587 -0
  36. package/tests/unit/types/test-physical-attack.js +564 -0
  37. package/tests/unit/types/test-physical-effect.js +769 -0
  38. package/tests/unit/types/test-physical-properties-validator.js +203 -0
  39. package/tests/unit/types/test-physical-skill-runner.js +348 -0
  40. package/tests/utils/test-helpers.js +122 -0
  41. package/migrations/production/reldens-skills-install.sql +0 -275
@@ -11,7 +11,7 @@ class PhysicalPropertiesValidator
11
11
 
12
12
  static validate(props)
13
13
  {
14
- if(typeof props.owner.executePhysicalSkill !== 'function'){
14
+ if(!props.owner || typeof props.owner.executePhysicalSkill !== 'function'){
15
15
  Logger.error('Missing executePhysicalSkill required method.');
16
16
  return false;
17
17
  }
@@ -11,13 +11,13 @@ class PhysicalSkillRunner
11
11
 
12
12
  static async runSkillLogic(skill)
13
13
  {
14
- this.lastState = null;
14
+ skill.lastState = null;
15
15
  if(!skill.validateRange(skill.target)){
16
- this.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
16
+ skill.lastState = SkillsConst.SKILL_STATES.OUT_OF_RANGE;
17
17
  // @NOTE: out of range, the owner or the target could have moved away.
18
18
  return false;
19
19
  }
20
- this.lastState = SkillsConst.SKILL_STATES.EXECUTE_PHYSICAL_ATTACK;
20
+ skill.lastState = SkillsConst.SKILL_STATES.EXECUTE_PHYSICAL_ATTACK;
21
21
  await skill.owner.executePhysicalSkill(skill.target, skill);
22
22
  return false;
23
23
  }
@@ -26,13 +26,13 @@ class PhysicalSkillRunner
26
26
  {
27
27
  await skill.fireEvent(skillType, skill, target);
28
28
  if(skill.validateTargetOnHit && target !== skill.target){
29
- this.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_INVALID_TARGET;
29
+ skill.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_INVALID_TARGET;
30
30
  return false;
31
31
  }
32
32
  if('function' !== typeof runSkillLogicCallback){
33
33
  return false;
34
34
  }
35
- this.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_RUN_LOGIC;
35
+ skill.lastState = SkillsConst.SKILL_STATES.PHYSICAL_SKILL_RUN_LOGIC;
36
36
  return await runSkillLogicCallback(target);
37
37
  }
38
38
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/skills",
3
3
  "scope": "@reldens",
4
- "version": "0.45.0",
4
+ "version": "0.47.0",
5
5
  "description": "Reldens - Skills",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  "keywords": [
16
16
  "reldens",
17
17
  "skill",
18
- "hability",
18
+ "ability",
19
19
  "attack",
20
20
  "defense",
21
21
  "magic",
@@ -39,8 +39,14 @@
39
39
  "bugs": {
40
40
  "url": "https://github.com/damian-pastorini/reldens-skills/issues"
41
41
  },
42
+ "scripts": {
43
+ "test": "node tests/run-tests.js",
44
+ "test:watch": "node --watch tests/run-tests.js",
45
+ "test:filter": "node tests/run-tests.js --filter=",
46
+ "test:coverage": "node --test --experimental-test-coverage tests/run-tests.js"
47
+ },
42
48
  "dependencies": {
43
- "@reldens/modifiers": "^0.32.0",
49
+ "@reldens/modifiers": "^0.33.0",
44
50
  "@reldens/utils": "^0.54.0"
45
51
  }
46
52
  }
@@ -0,0 +1,89 @@
1
+ /**
2
+ *
3
+ * Reldens - Base Levels Fixtures
4
+ *
5
+ */
6
+
7
+ const Level = require('../../../lib/level');
8
+ const { Modifier, ModifierConst } = require('@reldens/modifiers');
9
+
10
+ module.exports.BaseLevelsFixtures = {
11
+ createBasicLevel: (key = 1, requiredExperience = 0) => {
12
+ return new Level({
13
+ key: key,
14
+ label: 'Level '+key,
15
+ requiredExperience: requiredExperience,
16
+ modifiers: []
17
+ });
18
+ },
19
+ createLevelWithModifiers: (key = 1, requiredExperience = 0) => {
20
+ return new Level({
21
+ key: key,
22
+ label: 'Level '+key,
23
+ requiredExperience: requiredExperience,
24
+ modifiers: [
25
+ new Modifier({
26
+ key: 'hp-increase',
27
+ propertyKey: 'stats/maxHp',
28
+ operation: ModifierConst.OPS.INC,
29
+ value: 10
30
+ }),
31
+ new Modifier({
32
+ key: 'atk-increase',
33
+ propertyKey: 'stats/atk',
34
+ operation: ModifierConst.OPS.INC,
35
+ value: 2
36
+ })
37
+ ]
38
+ });
39
+ },
40
+ createLevelSet: () => {
41
+ return {
42
+ 1: new Level({
43
+ key: 1,
44
+ label: 'Level 1',
45
+ requiredExperience: 0,
46
+ modifiers: []
47
+ }),
48
+ 2: new Level({
49
+ key: 2,
50
+ label: 'Level 2',
51
+ requiredExperience: 100,
52
+ modifiers: [
53
+ new Modifier({
54
+ key: 'hp-inc-lvl2',
55
+ propertyKey: 'stats/maxHp',
56
+ operation: ModifierConst.OPS.INC,
57
+ value: 10
58
+ })
59
+ ]
60
+ }),
61
+ 3: new Level({
62
+ key: 3,
63
+ label: 'Level 3',
64
+ requiredExperience: 250,
65
+ modifiers: [
66
+ new Modifier({
67
+ key: 'hp-inc-lvl3',
68
+ propertyKey: 'stats/maxHp',
69
+ operation: ModifierConst.OPS.INC,
70
+ value: 15
71
+ })
72
+ ]
73
+ }),
74
+ 5: new Level({
75
+ key: 5,
76
+ label: 'Level 5',
77
+ requiredExperience: 500,
78
+ modifiers: [
79
+ new Modifier({
80
+ key: 'hp-inc-lvl5',
81
+ propertyKey: 'stats/maxHp',
82
+ operation: ModifierConst.OPS.INC,
83
+ value: 25
84
+ })
85
+ ]
86
+ })
87
+ };
88
+ }
89
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ *
3
+ * Reldens - Mock Client
4
+ *
5
+ */
6
+
7
+ class MockClient
8
+ {
9
+
10
+ constructor()
11
+ {
12
+ this.sentMessages = [];
13
+ this.broadcastMessages = [];
14
+ }
15
+
16
+ send(message)
17
+ {
18
+ this.sentMessages.push(message);
19
+ }
20
+
21
+ broadcast(message)
22
+ {
23
+ this.broadcastMessages.push(message);
24
+ }
25
+
26
+ clearMessages()
27
+ {
28
+ this.sentMessages.length = 0;
29
+ this.broadcastMessages.length = 0;
30
+ }
31
+
32
+ getLastSentMessage()
33
+ {
34
+ return this.sentMessages[this.sentMessages.length - 1];
35
+ }
36
+
37
+ getLastBroadcastMessage()
38
+ {
39
+ return this.broadcastMessages[this.broadcastMessages.length - 1];
40
+ }
41
+
42
+ }
43
+
44
+ module.exports.MockClient = MockClient;
@@ -0,0 +1,60 @@
1
+ /**
2
+ *
3
+ * Reldens - Mock Owner
4
+ *
5
+ */
6
+
7
+ const { EventsManagerSingleton } = require('@reldens/utils');
8
+
9
+ class MockOwner
10
+ {
11
+
12
+ constructor(id = 'mock-owner-1', position = { x: 100, y: 100 })
13
+ {
14
+ this.id = id;
15
+ this.events = EventsManagerSingleton;
16
+ this.eventsPrefix = 'skills.ownerId.'+id;
17
+ this.position = position;
18
+ this.stats = {
19
+ atk: 10,
20
+ def: 5,
21
+ hp: 100,
22
+ maxHp: 100,
23
+ mp: 50,
24
+ maxMp: 50,
25
+ aim: 15,
26
+ dodge: 8,
27
+ stamina: 100
28
+ };
29
+ this.isCasting = false;
30
+ this.castingTimer = false;
31
+ this.currentSkills = {};
32
+ }
33
+
34
+ getPosition()
35
+ {
36
+ return this.position;
37
+ }
38
+
39
+ setPosition(x, y)
40
+ {
41
+ this.position.x = x;
42
+ this.position.y = y;
43
+ }
44
+
45
+ updateStat(key, value)
46
+ {
47
+ if(!this.stats[key]){
48
+ this.stats[key] = 0;
49
+ }
50
+ this.stats[key] = value;
51
+ }
52
+
53
+ eventUniqueKey()
54
+ {
55
+ return 'skills.ownerId.'+this.id+'.uKey.'+Date.now();
56
+ }
57
+
58
+ }
59
+
60
+ module.exports.MockOwner = MockOwner;
@@ -0,0 +1,50 @@
1
+ /**
2
+ *
3
+ * Reldens - Mock Target
4
+ *
5
+ */
6
+
7
+ class MockTarget
8
+ {
9
+
10
+ constructor(id = 'mock-target-1', position = { x: 110, y: 110 })
11
+ {
12
+ this.id = id;
13
+ this.position = position;
14
+ this.stats = {
15
+ atk: 8,
16
+ def: 6,
17
+ hp: 80,
18
+ maxHp: 80,
19
+ mp: 40,
20
+ maxMp: 40,
21
+ aim: 12,
22
+ dodge: 10,
23
+ stamina: 80,
24
+ speed: 0,
25
+ undefinedProp: 0
26
+ };
27
+ }
28
+
29
+ getPosition()
30
+ {
31
+ return this.position;
32
+ }
33
+
34
+ setPosition(x, y)
35
+ {
36
+ this.position.x = x;
37
+ this.position.y = y;
38
+ }
39
+
40
+ updateStat(key, value)
41
+ {
42
+ if(!this.stats[key]){
43
+ this.stats[key] = 0;
44
+ }
45
+ this.stats[key] = value;
46
+ }
47
+
48
+ }
49
+
50
+ module.exports.MockTarget = MockTarget;
@@ -0,0 +1,80 @@
1
+ /**
2
+ *
3
+ * Reldens - Base Skills Fixtures
4
+ *
5
+ */
6
+
7
+ const { Modifier, ModifierConst } = require('@reldens/modifiers');
8
+
9
+ module.exports.BaseSkillsFixtures = {
10
+ basicSkill: {
11
+ key: 'test-basic-skill',
12
+ skillDelay: 0,
13
+ castTime: 0,
14
+ range: 0,
15
+ allowSelfTarget: false,
16
+ criticalChance: 0,
17
+ criticalMultiplier: 1,
18
+ criticalFixedValue: 0,
19
+ usesLimit: 0
20
+ },
21
+ attackSkill: {
22
+ key: 'test-attack-skill',
23
+ skillDelay: 1000,
24
+ castTime: 0,
25
+ range: 50,
26
+ affectedProperty: 'stats/hp',
27
+ hitDamage: 10,
28
+ attackProperties: ['stats/atk'],
29
+ defenseProperties: ['stats/def'],
30
+ aimProperties: ['stats/aim'],
31
+ dodgeProperties: ['stats/dodge'],
32
+ criticalChance: 20,
33
+ criticalMultiplier: 1.5
34
+ },
35
+ effectSkill: {
36
+ key: 'test-effect-skill',
37
+ skillDelay: 2000,
38
+ castTime: 500,
39
+ range: 30,
40
+ targetEffects: []
41
+ },
42
+ physicalAttackSkill: {
43
+ key: 'test-physical-attack',
44
+ skillDelay: 800,
45
+ range: 0,
46
+ affectedProperty: 'stats/hp',
47
+ hitDamage: 15,
48
+ magnitude: 100,
49
+ objectWidth: 10,
50
+ objectHeight: 10,
51
+ attackProperties: ['stats/atk'],
52
+ defenseProperties: ['stats/def'],
53
+ aimProperties: ['stats/aim'],
54
+ dodgeProperties: ['stats/dodge']
55
+ },
56
+ rangedSkill: {
57
+ key: 'test-ranged-skill',
58
+ skillDelay: 1500,
59
+ range: 100,
60
+ rangeAutomaticValidation: true,
61
+ rangePropertyX: 'position/x',
62
+ rangePropertyY: 'position/y',
63
+ affectedProperty: 'stats/hp',
64
+ hitDamage: 8
65
+ },
66
+ buffSkill: {
67
+ key: 'test-buff-skill',
68
+ skillDelay: 3000,
69
+ range: 0,
70
+ allowSelfTarget: true,
71
+ targetEffects: [
72
+ new Modifier({
73
+ key: 'atk-buff',
74
+ propertyKey: 'stats/atk',
75
+ operation: ModifierConst.OPS.INC,
76
+ value: 5
77
+ })
78
+ ]
79
+ }
80
+ };
@@ -0,0 +1,88 @@
1
+ /**
2
+ *
3
+ * Reldens - Skills Test Runner
4
+ *
5
+ */
6
+
7
+ const { sc } = require('@reldens/utils');
8
+ const { run } = require('node:test');
9
+ const { spec } = require('node:test/reporters');
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ async function runTests()
14
+ {
15
+ process.stderr.write('='.repeat(60)+'\n');
16
+ process.stderr.write('@RELDENS/SKILLS - UNIT TESTS\n');
17
+ process.stderr.write('='.repeat(60)+'\n');
18
+ process.stderr.write('Test execution started: '+sc.formatDate(new Date())+'\n\n');
19
+ let filter = null;
20
+ let breakOnError = false;
21
+ for(let arg of process.argv){
22
+ if(arg.startsWith('--filter=')){
23
+ filter = arg.split('=')[1];
24
+ process.stderr.write('Filter applied: '+filter+'\n');
25
+ }
26
+ if(arg === '--break-on-error'){
27
+ breakOnError = true;
28
+ process.stderr.write('Break on error enabled\n');
29
+ }
30
+ }
31
+ let testFiles = await getTestFiles(path.join(__dirname, 'unit'));
32
+ if(filter){
33
+ testFiles = testFiles.filter(file => file.includes(filter));
34
+ }
35
+ if(0 === testFiles.length){
36
+ let filterMsg = filter ? ' matching filter: '+filter : '';
37
+ process.stderr.write('No test files found'+filterMsg+'\n');
38
+ process.exit(1);
39
+ }
40
+ process.stderr.write('Found '+testFiles.length+' test file(s)\n\n');
41
+ let testStream = run({
42
+ files: testFiles,
43
+ concurrency: true
44
+ });
45
+ testStream.compose(spec).pipe(process.stdout);
46
+ testStream.on('test:fail', () => {
47
+ process.exitCode = 1;
48
+ });
49
+ }
50
+
51
+ async function getTestFiles(directory)
52
+ {
53
+ let files = [];
54
+ if(!fs.existsSync(directory)){
55
+ return files;
56
+ }
57
+ let items = fs.readdirSync(directory);
58
+ for(let item of items){
59
+ let fullPath = path.join(directory, item);
60
+ let stat = fs.statSync(fullPath);
61
+ if(stat.isDirectory()){
62
+ let subFiles = await getTestFiles(fullPath);
63
+ files = files.concat(subFiles);
64
+ continue;
65
+ }
66
+ if(item.startsWith('test-') && item.endsWith('.js')){
67
+ files.push(fullPath);
68
+ }
69
+ }
70
+ return files;
71
+ }
72
+
73
+ process.on('unhandledRejection', (reason, promise) => {
74
+ process.stderr.write('Unhandled Rejection at: '+promise+' reason: '+reason+'\n');
75
+ process.exit(1);
76
+ });
77
+
78
+ process.on('uncaughtException', (error) => {
79
+ process.stderr.write('Uncaught Exception: '+error.message+'\n');
80
+ process.stderr.write(error.stack+'\n');
81
+ process.exit(1);
82
+ });
83
+
84
+ runTests().catch(error => {
85
+ process.stderr.write('Test runner error: '+error.message+'\n');
86
+ process.stderr.write(error.stack+'\n');
87
+ process.exit(1);
88
+ });