@rpgjs/action-battle 5.0.0-beta.11 → 5.0.0-beta.13

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 +57 -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 +3 -2
  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 +203 -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 +70 -0
  25. package/dist/client/index22.js +226 -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 +1949 -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 +57 -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 +3 -2
  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 +67 -11
  56. package/dist/server/index14.js +207 -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 +1949 -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 +208 -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 +5 -5
  78. package/src/ai.server.spec.ts +380 -1
  79. package/src/ai.server.ts +963 -137
  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/config.ts +84 -37
  86. package/src/core/action-use.spec.ts +317 -0
  87. package/src/core/action-use.ts +387 -0
  88. package/src/core/ai-behavior-tree.spec.ts +116 -0
  89. package/src/core/ai-behavior-tree.ts +272 -0
  90. package/src/core/attack-profile.spec.ts +46 -0
  91. package/src/core/attack-runtime.spec.ts +35 -0
  92. package/src/core/attack-runtime.ts +32 -0
  93. package/src/core/context.ts +9 -0
  94. package/src/core/contracts.ts +146 -1
  95. package/src/core/defaults.ts +72 -1
  96. package/src/core/equipment.ts +9 -5
  97. package/src/core/hit.spec.ts +21 -0
  98. package/src/core/targets.spec.ts +124 -0
  99. package/src/core/targets.ts +150 -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,10 +1,16 @@
1
- import { BattleAi } from "./index10.js";
2
- //#region src/enemies/factory.ts
3
- var createActionEnemy = (event, presetOrOptions, presets = {}) => {
4
- const options = typeof presetOrOptions === "string" ? presets[presetOrOptions] : presetOrOptions;
5
- if (!options) throw new Error(`Action battle enemy preset not found: ${presetOrOptions}`);
6
- options.stats?.(event);
7
- return new BattleAi(event, options);
8
- };
1
+ //#region src/core/equipment.ts
2
+ var resolveItemId = (item) => item?.id?.() ?? item?.id;
3
+ function resolveActionBattleWeapon(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") return itemData;
9
+ }
10
+ return null;
11
+ }
12
+ function resolveActionBattleWeaponAttackProfile(entity) {
13
+ return resolveActionBattleWeapon(entity)?.attackProfile ?? null;
14
+ }
9
15
  //#endregion
10
- export { createActionEnemy };
16
+ export { resolveActionBattleWeapon, resolveActionBattleWeaponAttackProfile };
@@ -0,0 +1,26 @@
1
+ //#region src/locomotion.ts
2
+ var withActionBattleAnimationUnlocked = (entity, callback) => {
3
+ if (!entity) return callback();
4
+ const previousAnimationFixed = entity.animationFixed;
5
+ entity.animationFixed = false;
6
+ try {
7
+ return callback();
8
+ } finally {
9
+ entity.animationFixed = previousAnimationFixed;
10
+ }
11
+ };
12
+ /**
13
+ * Force a locomotion animation even when an action lock temporarily froze
14
+ * animation changes. This keeps server state and local rendering coherent
15
+ * after attack recovery interrupts movement.
16
+ */
17
+ var forceActionBattleLocomotionAnimation = (entity, animationName) => {
18
+ if (!entity) return;
19
+ withActionBattleAnimationUnlocked(entity, () => {
20
+ if (typeof entity.resetAnimationState === "function") entity.resetAnimationState();
21
+ if (typeof entity.setGraphicAnimation === "function") entity.setGraphicAnimation(animationName);
22
+ else if (typeof entity.animationName?.set === "function") entity.animationName.set(animationName);
23
+ });
24
+ };
25
+ //#endregion
26
+ export { forceActionBattleLocomotionAnimation, withActionBattleAnimationUnlocked };
@@ -0,0 +1,25 @@
1
+ //#region src/movement.ts
2
+ var UNRESOLVED_ENTITY_MESSAGE = "unable to resolve entity";
3
+ var isActionBattleMovementResolutionError = (error) => {
4
+ return (error instanceof Error ? error.message : String(error ?? "")).includes(UNRESOLVED_ENTITY_MESSAGE);
5
+ };
6
+ var hasActionBattlePhysicsBody = (entity) => {
7
+ if (!entity) return false;
8
+ const map = entity.getCurrentMap?.();
9
+ if (!map) return false;
10
+ if (typeof map.getBody !== "function" || !entity.id) return true;
11
+ return Boolean(map.getBody(entity.id));
12
+ };
13
+ var safeActionBattleDash = (entity, direction, additionalSpeed, duration) => {
14
+ if (!entity || typeof entity.dash !== "function") return false;
15
+ if (!hasActionBattlePhysicsBody(entity)) return false;
16
+ try {
17
+ entity.dash(direction, additionalSpeed, duration);
18
+ return true;
19
+ } catch (error) {
20
+ if (isActionBattleMovementResolutionError(error)) return false;
21
+ throw error;
22
+ }
23
+ };
24
+ //#endregion
25
+ export { safeActionBattleDash };
@@ -0,0 +1,107 @@
1
+ //#region src/core/ai-behavior-tree.ts
2
+ var isTreeNode = (input) => Boolean(input && typeof input.tick === "function");
3
+ var normalizeTreeResult = (result) => result ?? { status: "failure" };
4
+ var runIntentInput = (input, context) => {
5
+ if (isTreeNode(input)) return input.tick(context);
6
+ return {
7
+ status: "success",
8
+ intent: typeof input === "function" ? input(context) : input
9
+ };
10
+ };
11
+ var defineAiTree = (input) => {
12
+ if (isTreeNode(input)) return input;
13
+ return { tick(context) {
14
+ return normalizeTreeResult(input(context));
15
+ } };
16
+ };
17
+ var selector = (children) => ({ tick(context) {
18
+ for (const child of children) {
19
+ const result = defineAiTree(child).tick(context);
20
+ if (result.status !== "failure") return result;
21
+ }
22
+ return { status: "failure" };
23
+ } });
24
+ var sequence = (children) => ({ tick(context) {
25
+ let last = { status: "success" };
26
+ for (const child of children) {
27
+ last = defineAiTree(child).tick(context);
28
+ if (last.status !== "success") return last;
29
+ }
30
+ return last;
31
+ } });
32
+ var condition = (predicate) => ({ tick(context) {
33
+ return { status: predicate(context) ? "success" : "failure" };
34
+ } });
35
+ var action = (input, status = "success") => ({ tick(context) {
36
+ return {
37
+ ...runIntentInput(input, context),
38
+ status
39
+ };
40
+ } });
41
+ var decision = (resolve) => ({ tick(context) {
42
+ return {
43
+ status: "success",
44
+ decision: typeof resolve === "function" ? resolve(context) : resolve
45
+ };
46
+ } });
47
+ var rule = (predicate, then) => ({
48
+ condition: predicate,
49
+ then
50
+ });
51
+ var defineAiBehavior = (behavior) => {
52
+ const branches = [...(behavior.when ?? []).map((entry) => sequence([condition(entry.condition), action(entry.then)]))];
53
+ if (behavior.otherwise) branches.push(action(behavior.otherwise));
54
+ return selector(branches);
55
+ };
56
+ var hpBelow = (ratio) => {
57
+ return ({ self }) => self.hpPercent !== null && self.hpPercent < ratio;
58
+ };
59
+ var targetVisible = () => {
60
+ return ({ targetInfo }) => Boolean(targetInfo?.visible);
61
+ };
62
+ var targetInRange = (range) => {
63
+ return ({ self, targetInfo }) => {
64
+ if (!targetInfo) return false;
65
+ return targetInfo.distance <= (range ?? self.attackRange);
66
+ };
67
+ };
68
+ var distanceLessThan = (distance) => {
69
+ return ({ targetInfo }) => targetInfo !== null && targetInfo.distance < distance;
70
+ };
71
+ var inState = (state) => {
72
+ return ({ self }) => self.state === state;
73
+ };
74
+ var isEnemyType = (enemyType) => {
75
+ return ({ self }) => self.enemyType === enemyType;
76
+ };
77
+ var idle = () => ({ type: "idle" });
78
+ var patrol = () => ({ type: "patrol" });
79
+ var faceTarget = () => ({ type: "faceTarget" });
80
+ var chase = () => ({ type: "moveToTarget" });
81
+ var moveToTarget = chase;
82
+ var flee = () => ({ type: "fleeFromTarget" });
83
+ var fleeFromTarget = flee;
84
+ var keepDistance = (distance, tolerance) => ({
85
+ type: "keepDistance",
86
+ distance,
87
+ tolerance
88
+ });
89
+ var useAttack = (pattern) => ({
90
+ type: "useAttack",
91
+ pattern
92
+ });
93
+ var useSkill = (skill) => ({
94
+ type: "useSkill",
95
+ skill
96
+ });
97
+ var setMode = (mode) => ({
98
+ type: "setMode",
99
+ mode,
100
+ consume: false
101
+ });
102
+ var ifHpBelow = (ratio, then) => rule(hpBelow(ratio), then);
103
+ var ifTargetVisible = (then) => rule(targetVisible(), then);
104
+ var ifTargetInRange = (then, range) => rule(targetInRange(range), then);
105
+ var ifDistanceLessThan = (distance, then) => rule(distanceLessThan(distance), then);
106
+ //#endregion
107
+ export { action, chase, condition, decision, defineAiBehavior, defineAiTree, distanceLessThan, faceTarget, flee, fleeFromTarget, hpBelow, idle, ifDistanceLessThan, ifHpBelow, ifTargetInRange, ifTargetVisible, inState, isEnemyType, keepDistance, moveToTarget, patrol, rule, selector, sequence, setMode, targetInRange, targetVisible, useAttack, useSkill };