@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,72 +1,206 @@
1
- import { normalizeActionBattleAttackProfile } from "./index3.js";
2
- //#region src/core/enemy-attack-profiles.ts
3
- var DEFAULT_ACTION_BATTLE_ENEMY_ATTACK_PROFILES = {
4
- melee: {
5
- id: "enemy-melee",
6
- startupMs: 120,
7
- activeMs: 100,
8
- recoveryMs: 220,
9
- cooldownMs: 440,
10
- reaction: {
11
- invincibilityMs: 250,
12
- hitstunMs: 120,
13
- staggerPower: 1
14
- }
1
+ import { getActionBattleOptions } from "./index4.js";
2
+ import { playActionBattleAnimation } from "./index14.js";
3
+ //#region src/visual.ts
4
+ var ACTION_BATTLE_CLIENT_VISUAL_ID = "action-battle.visual";
5
+ var ACTION_BATTLE_HIT_FX_COMPONENT_ID = "action-battle-hit-fx";
6
+ var previewStarter;
7
+ function setActionBattlePreviewStarter(starter) {
8
+ previewStarter = starter;
9
+ }
10
+ var entityId = (entity) => typeof entity?.id === "string" ? entity.id : void 0;
11
+ var serializeSkill = (skill) => {
12
+ const id = skill?.id;
13
+ if (typeof id === "string") return { id };
14
+ if (typeof id === "function") {
15
+ const value = id.call(skill);
16
+ if (typeof value === "string") return { id: value };
17
+ }
18
+ };
19
+ var serializeResult = (result) => {
20
+ if (!result) return void 0;
21
+ return {
22
+ damage: result.damage,
23
+ knockbackForce: result.knockbackForce,
24
+ knockbackDuration: result.knockbackDuration,
25
+ defeated: result.defeated,
26
+ attackerId: entityId(result.attacker),
27
+ targetId: entityId(result.target),
28
+ rawDamage: result.rawDamage,
29
+ reaction: result.reaction,
30
+ cancelled: result.cancelled,
31
+ metadata: result.metadata
32
+ };
33
+ };
34
+ var serializeActionBattleVisualContext = (context) => ({
35
+ moment: context.moment,
36
+ objectId: entityId(context.entity),
37
+ sourceId: entityId(context.attacker ?? context.entity),
38
+ targetId: entityId(context.target),
39
+ damage: context.damage,
40
+ defeated: context.defeated,
41
+ result: serializeResult(context.result),
42
+ skill: serializeSkill(context.skill),
43
+ pattern: context.pattern,
44
+ animations: context.animations,
45
+ animationDefaults: context.animationDefaults
46
+ });
47
+ function emitActionBattleClientVisual(context) {
48
+ if (getActionBattleOptions().visual === "none") return;
49
+ const map = (context.entity ?? context.target ?? context.attacker)?.getCurrentMap?.();
50
+ if (!map?.clientVisual) return;
51
+ map.clientVisual(ACTION_BATTLE_CLIENT_VISUAL_ID, serializeActionBattleVisualContext(context));
52
+ }
53
+ function createActionBattleClientVisuals(options = getActionBattleOptions()) {
54
+ return { [ACTION_BATTLE_CLIENT_VISUAL_ID]: (context) => {
55
+ const data = context.data ?? {};
56
+ playActionBattleVisual(options.visual, {
57
+ moment: data.moment,
58
+ entity: context.object ?? context.source ?? context.target,
59
+ target: context.target,
60
+ attacker: context.source,
61
+ damage: data.damage,
62
+ defeated: data.defeated,
63
+ result: data.result,
64
+ skill: data.skill,
65
+ pattern: data.pattern,
66
+ animations: data.animations ?? options.animations,
67
+ animationDefaults: data.animationDefaults
68
+ });
69
+ } };
70
+ }
71
+ var callGraphic = (entity, keyOrOptions, context) => {
72
+ if (!entity || keyOrOptions == null) return;
73
+ if (typeof keyOrOptions === "string") {
74
+ playActionBattleAnimation(keyOrOptions, entity, context?.animations ?? getActionBattleOptions().animations, {
75
+ attacker: context?.attacker,
76
+ target: context?.target,
77
+ skill: context?.skill
78
+ }, context?.animationDefaults);
79
+ return;
80
+ }
81
+ const animationName = keyOrOptions.animationName;
82
+ if (!animationName) return;
83
+ const repeat = keyOrOptions.repeat ?? 1;
84
+ const graphic = keyOrOptions.graphic;
85
+ if (typeof entity.setGraphicAnimation === "function") {
86
+ if (graphic !== void 0) entity.setGraphicAnimation(animationName, graphic, repeat);
87
+ else entity.setGraphicAnimation(animationName, repeat);
88
+ return;
89
+ }
90
+ if (typeof entity.setAnimation === "function") if (graphic !== void 0) entity.setAnimation(animationName, graphic, repeat);
91
+ else entity.setAnimation(animationName, repeat);
92
+ };
93
+ var createHelpers = (context) => ({
94
+ graphic(entity, keyOrOptions) {
95
+ callGraphic(entity, keyOrOptions, context);
15
96
  },
16
- combo: {
17
- id: "enemy-combo",
18
- startupMs: 80,
19
- activeMs: 80,
20
- recoveryMs: 140,
21
- cooldownMs: 300,
22
- reaction: {
23
- invincibilityMs: 180,
24
- hitstunMs: 90,
25
- staggerPower: .75
26
- }
97
+ flash(entity, options = {}) {
98
+ entity?.flash?.({
99
+ type: "tint",
100
+ tint: "red",
101
+ duration: 200,
102
+ cycles: 1,
103
+ ...options
104
+ });
27
105
  },
28
- charged: {
29
- id: "enemy-charged",
30
- startupMs: 800,
31
- activeMs: 140,
32
- recoveryMs: 320,
33
- cooldownMs: 1260,
34
- reaction: {
35
- invincibilityMs: 350,
36
- hitstunMs: 220,
37
- staggerPower: 2
106
+ damageText(entity, damageOrText) {
107
+ if (typeof damageOrText === "string") {
108
+ if (entity?.showHit) {
109
+ entity.showHit(damageOrText);
110
+ return;
111
+ }
112
+ entity?.showComponentAnimation?.("hit", {
113
+ text: damageOrText,
114
+ direction: entity?.direction?.() ?? entity?.direction
115
+ });
116
+ return;
38
117
  }
39
- },
40
- zone: {
41
- id: "enemy-zone",
42
- startupMs: 450,
43
- activeMs: 180,
44
- recoveryMs: 320,
45
- cooldownMs: 950,
46
- reaction: {
47
- invincibilityMs: 300,
48
- hitstunMs: 160,
49
- staggerPower: 1.25
118
+ const damage = damageOrText ?? context.damage ?? context.result?.damage;
119
+ if (damage === void 0) return;
120
+ const text = `-${damage}`;
121
+ if (entity?.showHit) {
122
+ entity.showHit(text);
123
+ return;
50
124
  }
125
+ entity?.showComponentAnimation?.("hit", {
126
+ text,
127
+ direction: entity?.direction?.() ?? entity?.direction
128
+ });
51
129
  },
52
- dashAttack: {
53
- id: "enemy-dash",
54
- startupMs: 180,
55
- activeMs: 120,
56
- recoveryMs: 260,
57
- cooldownMs: 560,
58
- reaction: {
59
- invincibilityMs: 280,
60
- hitstunMs: 150,
61
- staggerPower: 1.2
62
- }
130
+ component(entity, id, params = {}) {
131
+ entity?.showComponentAnimation?.(id, params);
132
+ },
133
+ preview(entity, options = {}) {
134
+ previewStarter?.(entity, options);
135
+ }
136
+ });
137
+ var classicParts = {
138
+ attack({ entity }, fx) {
139
+ fx.graphic(entity, "attack");
140
+ },
141
+ castSkill({ entity }, fx) {
142
+ fx.graphic(entity, "castSkill");
143
+ },
144
+ preview({ entity }, fx) {
145
+ fx.preview(entity);
146
+ },
147
+ hit({ target, damage }, fx) {
148
+ fx.flash(target);
149
+ fx.damageText(target, damage);
150
+ },
151
+ hurt({ entity, target }, fx) {
152
+ const hurtTarget = target ?? entity;
153
+ fx.flash(hurtTarget);
154
+ fx.damageText(hurtTarget);
155
+ fx.graphic(hurtTarget, "hurt");
156
+ },
157
+ defeat({ entity, target }, fx) {
158
+ fx.graphic(target ?? entity, "die");
159
+ }
160
+ };
161
+ var fxParts = {
162
+ ...classicParts,
163
+ hit(context, fx) {
164
+ classicParts.hit?.(context, fx);
165
+ fx.component(context.target, ACTION_BATTLE_HIT_FX_COMPONENT_ID, {
166
+ name: "hitSpark",
167
+ scale: .8,
168
+ zIndex: 1e3
169
+ });
170
+ },
171
+ hurt(context, fx) {
172
+ classicParts.hurt?.(context, fx);
173
+ fx.component(context.target ?? context.entity, ACTION_BATTLE_HIT_FX_COMPONENT_ID, {
174
+ name: "hitSpark",
175
+ scale: .8,
176
+ zIndex: 1e3
177
+ });
63
178
  }
64
179
  };
65
- function normalizeActionBattleEnemyAttackProfiles(overrides = {}) {
66
- return Object.fromEntries(Object.entries(DEFAULT_ACTION_BATTLE_ENEMY_ATTACK_PROFILES).map(([key, defaultProfile]) => [key, normalizeActionBattleAttackProfile({
67
- ...defaultProfile,
68
- ...overrides[key]
69
- })]));
180
+ var resolveParts = (input) => {
181
+ const visual = input ?? "classic";
182
+ if (visual === "none") return null;
183
+ if (visual === "classic") return classicParts;
184
+ if (visual === "fx") return fxParts;
185
+ if (typeof visual === "function") return null;
186
+ return visual;
187
+ };
188
+ function createActionBattleVisual(input = "classic") {
189
+ if (typeof input === "function") return input;
190
+ const parts = resolveParts(input);
191
+ const composer = (context) => {
192
+ if (!parts) return;
193
+ const part = parts[context.moment];
194
+ if (!part) return;
195
+ part(context, createHelpers(context));
196
+ };
197
+ composer.__actionBattleUsesFx = input === "fx";
198
+ return composer;
199
+ }
200
+ var createClassicActionBattleVisual = () => createActionBattleVisual("classic");
201
+ var createFxActionBattleVisual = () => createActionBattleVisual("fx");
202
+ function playActionBattleVisual(visual, context) {
203
+ (typeof visual === "function" ? visual : createActionBattleVisual(visual))(context);
70
204
  }
71
205
  //#endregion
72
- export { DEFAULT_ACTION_BATTLE_ENEMY_ATTACK_PROFILES, normalizeActionBattleEnemyAttackProfiles };
206
+ export { ACTION_BATTLE_CLIENT_VISUAL_ID, ACTION_BATTLE_HIT_FX_COMPONENT_ID, createActionBattleClientVisuals, createActionBattleVisual, createClassicActionBattleVisual, createFxActionBattleVisual, emitActionBattleClientVisual, playActionBattleVisual, setActionBattlePreviewStarter };