@rpgjs/action-battle 5.0.0-beta.10 → 5.0.0-beta.12

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 (111) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/client/ai.server.d.ts +45 -8
  3. package/dist/client/attack-input.d.ts +3 -0
  4. package/dist/client/core/action-use.d.ts +18 -0
  5. package/dist/client/core/ai-behavior-tree.d.ts +99 -0
  6. package/dist/client/core/attack-runtime.d.ts +2 -0
  7. package/dist/client/core/defaults.d.ts +2 -1
  8. package/dist/client/core/equipment.d.ts +1 -0
  9. package/dist/client/core/targets.d.ts +15 -0
  10. package/dist/client/enemies/factory.d.ts +2 -0
  11. package/dist/client/index.d.ts +12 -7
  12. package/dist/client/index.js +16 -11
  13. package/dist/client/index10.js +32 -56
  14. package/dist/client/index11.js +99 -52
  15. package/dist/client/index12.js +76 -103
  16. package/dist/client/index13.js +72 -135
  17. package/dist/client/index14.js +67 -23
  18. package/dist/client/index15.js +197 -63
  19. package/dist/client/index16.js +112 -1337
  20. package/dist/client/index17.js +193 -7
  21. package/dist/client/index18.js +32 -58
  22. package/dist/client/index19.js +70 -8
  23. package/dist/client/index20.js +57 -501
  24. package/dist/client/index21.js +69 -0
  25. package/dist/client/index22.js +225 -0
  26. package/dist/client/index23.js +16 -0
  27. package/dist/client/index24.js +25 -0
  28. package/dist/client/index25.js +107 -0
  29. package/dist/client/index26.js +1707 -0
  30. package/dist/client/index27.js +12 -0
  31. package/dist/client/index28.js +589 -0
  32. package/dist/client/index4.js +79 -38
  33. package/dist/client/index6.js +65 -306
  34. package/dist/client/index7.js +33 -33
  35. package/dist/client/index8.js +24 -100
  36. package/dist/client/index9.js +293 -61
  37. package/dist/client/locomotion.d.ts +16 -0
  38. package/dist/client/movement.d.ts +14 -0
  39. package/dist/client/server.d.ts +7 -3
  40. package/dist/client/ui.d.ts +22 -0
  41. package/dist/client/visual.d.ts +15 -0
  42. package/dist/server/ai.server.d.ts +45 -8
  43. package/dist/server/attack-input.d.ts +3 -0
  44. package/dist/server/core/action-use.d.ts +18 -0
  45. package/dist/server/core/ai-behavior-tree.d.ts +99 -0
  46. package/dist/server/core/attack-runtime.d.ts +2 -0
  47. package/dist/server/core/defaults.d.ts +2 -1
  48. package/dist/server/core/equipment.d.ts +1 -0
  49. package/dist/server/core/targets.d.ts +15 -0
  50. package/dist/server/enemies/factory.d.ts +2 -0
  51. package/dist/server/index.d.ts +12 -7
  52. package/dist/server/index.js +14 -9
  53. package/dist/server/index10.js +64 -1336
  54. package/dist/server/index11.js +33 -33
  55. package/dist/server/index13.js +66 -11
  56. package/dist/server/index14.js +206 -484
  57. package/dist/server/index15.js +15 -9
  58. package/dist/server/index16.js +26 -0
  59. package/dist/server/index17.js +25 -0
  60. package/dist/server/index18.js +107 -0
  61. package/dist/server/index19.js +1707 -0
  62. package/dist/server/index2.js +10 -2
  63. package/dist/server/index20.js +37 -0
  64. package/dist/server/index21.js +588 -0
  65. package/dist/server/index22.js +78 -0
  66. package/dist/server/index23.js +12 -0
  67. package/dist/server/index5.js +79 -38
  68. package/dist/server/index6.js +192 -129
  69. package/dist/server/index7.js +198 -24
  70. package/dist/server/index8.js +28 -66
  71. package/dist/server/index9.js +68 -51
  72. package/dist/server/locomotion.d.ts +16 -0
  73. package/dist/server/movement.d.ts +14 -0
  74. package/dist/server/server.d.ts +7 -3
  75. package/dist/server/ui.d.ts +22 -0
  76. package/dist/server/visual.d.ts +15 -0
  77. package/package.json +10 -10
  78. package/src/ai.server.spec.ts +233 -0
  79. package/src/ai.server.ts +627 -108
  80. package/src/animations.spec.ts +40 -0
  81. package/src/animations.ts +31 -9
  82. package/src/attack-input.spec.ts +51 -0
  83. package/src/attack-input.ts +59 -0
  84. package/src/client.ts +75 -62
  85. package/src/components/action-bar.ce +2 -2
  86. package/src/config.ts +84 -37
  87. package/src/core/action-use.spec.ts +317 -0
  88. package/src/core/action-use.ts +386 -0
  89. package/src/core/ai-behavior-tree.spec.ts +116 -0
  90. package/src/core/ai-behavior-tree.ts +272 -0
  91. package/src/core/attack-profile.spec.ts +46 -0
  92. package/src/core/attack-runtime.spec.ts +35 -0
  93. package/src/core/attack-runtime.ts +32 -0
  94. package/src/core/context.ts +9 -0
  95. package/src/core/contracts.ts +146 -1
  96. package/src/core/defaults.ts +56 -0
  97. package/src/core/equipment.ts +9 -5
  98. package/src/core/targets.spec.ts +112 -0
  99. package/src/core/targets.ts +147 -0
  100. package/src/enemies/factory.ts +8 -0
  101. package/src/index.ts +111 -2
  102. package/src/locomotion.spec.ts +51 -0
  103. package/src/locomotion.ts +48 -0
  104. package/src/movement.spec.ts +78 -0
  105. package/src/movement.ts +46 -0
  106. package/src/server.ts +242 -66
  107. package/src/types.ts +105 -35
  108. package/src/ui.ts +113 -0
  109. package/src/visual.spec.ts +166 -0
  110. package/src/visual.ts +285 -0
  111. package/README.md +0 -1242
@@ -1,37 +1,37 @@
1
- //#region src/targeting.ts
2
- var normalizeMaskRows = (mask) => {
3
- if (!mask) return ["#"];
4
- if (Array.isArray(mask)) return mask;
5
- return mask.trim().split("\n").map((row) => row.replace(/\r/g, ""));
1
+ //#region src/attack-input.ts
2
+ var ACTION_BATTLE_DIRECTIONS = new Set([
3
+ "up",
4
+ "down",
5
+ "left",
6
+ "right"
7
+ ]);
8
+ var normalizeDirection = (value) => {
9
+ if (typeof value !== "string") return void 0;
10
+ return ACTION_BATTLE_DIRECTIONS.has(value) ? value : void 0;
6
11
  };
7
- var parseAoeMask = (mask) => {
8
- const rows = normalizeMaskRows(mask);
9
- const height = rows.length;
10
- const width = rows.reduce((max, row) => Math.max(max, row.length), 0);
11
- const centerX = Math.floor(width / 2);
12
- const centerY = Math.floor(height / 2);
13
- const cells = [];
14
- rows.forEach((row, y) => {
15
- for (let x = 0; x < row.length; x++) {
16
- const char = row[x];
17
- if (char && char !== "." && char !== " ") cells.push({
18
- dx: x - centerX,
19
- dy: y - centerY
20
- });
12
+ var resolveActionBattleAttackDirection = (entity, input) => {
13
+ const payloadDirection = normalizeDirection(input?.data?.direction) ?? normalizeDirection(input?.data?.attackDirection) ?? normalizeDirection(input?.direction);
14
+ if (payloadDirection) return payloadDirection;
15
+ if (typeof entity?.getDirection === "function") {
16
+ const direction = normalizeDirection(entity.getDirection());
17
+ if (direction) return direction;
18
+ }
19
+ if (typeof entity?.direction === "function") {
20
+ const direction = normalizeDirection(entity.direction());
21
+ if (direction) return direction;
22
+ }
23
+ return normalizeDirection(entity?.direction) ?? "down";
24
+ };
25
+ var applyActionBattleAttackDirection = (entity, direction) => {
26
+ if (typeof entity?.changeDirection === "function") {
27
+ const previousDirectionFixed = entity.directionFixed;
28
+ if (previousDirectionFixed === true) entity.directionFixed = false;
29
+ try {
30
+ entity.changeDirection(direction);
31
+ } finally {
32
+ if (previousDirectionFixed === true) entity.directionFixed = previousDirectionFixed;
21
33
  }
22
- });
23
- if (cells.length === 0) cells.push({
24
- dx: 0,
25
- dy: 0
26
- });
27
- return {
28
- width,
29
- height,
30
- centerX,
31
- centerY,
32
- cells
33
- };
34
+ }
34
35
  };
35
- var manhattanDistance = (a, b) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
36
36
  //#endregion
37
- export { manhattanDistance, parseAoeMask };
37
+ export { applyActionBattleAttackDirection, resolveActionBattleAttackDirection };
@@ -1,13 +1,68 @@
1
- //#region src/core/equipment.ts
2
- var resolveItemId = (item) => item?.id?.() ?? item?.id;
3
- function resolveActionBattleWeaponAttackProfile(entity) {
4
- const equipments = entity?.equipments?.() || [];
5
- for (const item of equipments) {
6
- const itemId = resolveItemId(item);
7
- const itemData = entity?.databaseById?.(itemId);
8
- if (itemData?._type === "weapon" && itemData.attackProfile) return itemData.attackProfile;
1
+ import { RpgEvent, RpgPlayer } from "@rpgjs/server";
2
+ //#region src/core/targets.ts
3
+ var ACTION_BATTLE_PLAYER_FACTION = "players";
4
+ var ACTION_BATTLE_ENEMY_FACTION = "enemies";
5
+ var getBattleAi = (entity) => entity?.battleAi;
6
+ var getActionBattleEntityKind = (entity) => {
7
+ if (getBattleAi(entity)) return "event";
8
+ if (entity instanceof RpgEvent) return "event";
9
+ if (typeof entity?.attachShape === "function") return "event";
10
+ if (entity instanceof RpgPlayer) return "player";
11
+ return "player";
12
+ };
13
+ var isActionBattlePlayer = (entity) => getActionBattleEntityKind(entity) === "player";
14
+ var isActionBattleEvent = (entity) => getActionBattleEntityKind(entity) === "event";
15
+ var isActionBattleCombatEntity = (entity) => {
16
+ if (!entity) return false;
17
+ if (isActionBattlePlayer(entity)) return true;
18
+ return !!getBattleAi(entity);
19
+ };
20
+ var getActionBattleFaction = (entity, options = {}) => {
21
+ const configured = options.getFaction?.(entity);
22
+ if (configured !== void 0) return configured;
23
+ const battleAi = getBattleAi(entity);
24
+ if (battleAi && typeof battleAi.getFaction === "function") {
25
+ const faction = battleAi.getFaction();
26
+ if (faction !== void 0) return faction;
9
27
  }
10
- return null;
11
- }
28
+ const entityFaction = entity.actionBattleFaction ?? entity.faction;
29
+ if (entityFaction !== void 0) return String(entityFaction);
30
+ if (isActionBattlePlayer(entity)) return ACTION_BATTLE_PLAYER_FACTION;
31
+ if (battleAi) return ACTION_BATTLE_ENEMY_FACTION;
32
+ };
33
+ var getActionBattleTargets = (entity, fallback) => {
34
+ const battleAi = getBattleAi(entity);
35
+ if (battleAi && typeof battleAi.getTargets === "function") return battleAi.getTargets();
36
+ return entity.actionBattleTargets ?? fallback;
37
+ };
38
+ var isActionBattleTargetDefeated = (target) => {
39
+ if (!target) return true;
40
+ const hp = target.hp;
41
+ return typeof hp === "number" && hp <= 0;
42
+ };
43
+ var matchesActionBattleTargetSelector = (selector, context) => {
44
+ if (!selector) return false;
45
+ if (typeof selector === "function") return selector(context);
46
+ if (selector === "all") return true;
47
+ if (selector === "players") return isActionBattlePlayer(context.target);
48
+ if (selector === "events") return isActionBattleEvent(context.target);
49
+ if (selector === "hostile") return !!context.attackerFaction && !!context.targetFaction && context.attackerFaction !== context.targetFaction;
50
+ if (Array.isArray(selector)) return !!context.targetFaction && selector.includes(context.targetFaction);
51
+ return false;
52
+ };
53
+ var canActionBattleTarget = (attacker, target, selector, options = {}) => {
54
+ if (attacker === target) return false;
55
+ if (!isActionBattleCombatEntity(target)) return false;
56
+ if (isActionBattleTargetDefeated(target)) return false;
57
+ const context = {
58
+ attacker,
59
+ target,
60
+ attackerFaction: getActionBattleFaction(attacker, options),
61
+ targetFaction: getActionBattleFaction(target, options)
62
+ };
63
+ const allowed = options.canTarget?.(context);
64
+ if (allowed !== void 0) return allowed;
65
+ return matchesActionBattleTargetSelector(selector, context);
66
+ };
12
67
  //#endregion
13
- export { resolveActionBattleWeaponAttackProfile };
68
+ export { ACTION_BATTLE_ENEMY_FACTION, ACTION_BATTLE_PLAYER_FACTION, canActionBattleTarget, getActionBattleFaction, getActionBattleTargets, isActionBattleCombatEntity, isActionBattleEvent, isActionBattlePlayer, isActionBattleTargetDefeated, matchesActionBattleTargetSelector };