@rpgjs/action-battle 5.0.0-beta.5 → 5.0.0-beta.7

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 (66) hide show
  1. package/README.md +161 -22
  2. package/dist/ai.server.d.ts +55 -4
  3. package/dist/client/index.js +13 -8
  4. package/dist/client/index10.js +54 -136
  5. package/dist/client/index11.js +52 -23
  6. package/dist/client/index12.js +101 -1217
  7. package/dist/client/index13.js +139 -42
  8. package/dist/client/index14.js +23 -8
  9. package/dist/client/index15.js +68 -444
  10. package/dist/client/index16.js +1343 -0
  11. package/dist/client/index17.js +13 -0
  12. package/dist/client/index18.js +60 -0
  13. package/dist/client/index19.js +10 -0
  14. package/dist/client/index2.js +25 -87
  15. package/dist/client/index20.js +504 -0
  16. package/dist/client/index3.js +45 -83
  17. package/dist/client/index4.js +98 -297
  18. package/dist/client/index5.js +81 -33
  19. package/dist/client/index6.js +284 -78
  20. package/dist/client/index7.js +33 -74
  21. package/dist/client/index8.js +95 -55
  22. package/dist/client/index9.js +75 -96
  23. package/dist/core/attack-profile.d.ts +9 -0
  24. package/dist/core/attack-runtime.d.ts +20 -0
  25. package/dist/core/enemy-attack-profiles.d.ts +6 -0
  26. package/dist/core/equipment.d.ts +2 -0
  27. package/dist/core/hit-reaction.d.ts +5 -0
  28. package/dist/index.d.ts +7 -2
  29. package/dist/server/index.js +12 -7
  30. package/dist/server/index10.js +1340 -8
  31. package/dist/server/index11.js +37 -0
  32. package/dist/server/index12.js +60 -0
  33. package/dist/server/index13.js +13 -0
  34. package/dist/server/index14.js +503 -0
  35. package/dist/server/index15.js +10 -0
  36. package/dist/server/index2.js +1 -1
  37. package/dist/server/index3.js +25 -87
  38. package/dist/server/index4.js +45 -141
  39. package/dist/server/index5.js +104 -21
  40. package/dist/server/index6.js +137 -1215
  41. package/dist/server/index7.js +22 -34
  42. package/dist/server/index8.js +70 -44
  43. package/dist/server/index9.js +44 -437
  44. package/dist/server.d.ts +8 -2
  45. package/dist/ui/state.d.ts +5 -5
  46. package/package.json +5 -5
  47. package/src/ai.server.spec.ts +120 -0
  48. package/src/ai.server.ts +362 -56
  49. package/src/client.ts +21 -12
  50. package/src/config.ts +17 -2
  51. package/src/core/attack-profile.spec.ts +118 -0
  52. package/src/core/attack-profile.ts +100 -0
  53. package/src/core/attack-runtime.spec.ts +103 -0
  54. package/src/core/attack-runtime.ts +83 -0
  55. package/src/core/contracts.ts +3 -0
  56. package/src/core/enemy-attack-profiles.spec.ts +35 -0
  57. package/src/core/enemy-attack-profiles.ts +103 -0
  58. package/src/core/equipment.spec.ts +37 -0
  59. package/src/core/equipment.ts +17 -0
  60. package/src/core/hit-reaction.spec.ts +43 -0
  61. package/src/core/hit-reaction.ts +70 -0
  62. package/src/core/hit.spec.ts +54 -1
  63. package/src/core/hit.ts +26 -0
  64. package/src/index.ts +48 -1
  65. package/src/server.ts +192 -34
  66. package/src/types.ts +62 -6
@@ -1,25 +1,54 @@
1
- import { defaultActionBattleSystems } from "./index10.js";
2
- //#region src/core/context.ts
3
- var mergeSystems = (options = {}) => ({
4
- combat: {
5
- ...defaultActionBattleSystems.combat,
6
- resolveDamage: options.systems?.combat?.damage ?? defaultActionBattleSystems.combat.resolveDamage,
7
- resolveKnockback: options.systems?.combat?.knockback ?? defaultActionBattleSystems.combat.resolveKnockback,
8
- hooks: {
9
- ...defaultActionBattleSystems.combat.hooks,
10
- ...options.systems?.combat?.hooks
11
- }
12
- },
13
- ai: { behaviors: {
14
- ...defaultActionBattleSystems.ai.behaviors,
15
- ...options.systems?.ai?.behaviors
16
- } }
17
- });
18
- var currentActionBattleSystems = mergeSystems();
19
- var setActionBattleSystems = (options = {}) => {
20
- currentActionBattleSystems = mergeSystems(options);
1
+ import { normalizeActionBattleAttackProfile } from "./index3.js";
2
+ //#region src/core/attack-runtime.ts
3
+ var ACTION_BATTLE_HITBOX_FRAME_MS = 16;
4
+ function getNormalizedActionBattleAttackProfile(options = {}) {
5
+ const attack = options.attack ?? {};
6
+ return normalizeActionBattleAttackProfile(attack.profile, {
7
+ lockMovement: attack.lockMovement,
8
+ lockDurationMs: attack.lockDurationMs,
9
+ hitboxes: attack.hitboxes
10
+ });
11
+ }
12
+ function resolveActionBattleHitboxSpeed(profile, hitboxCount) {
13
+ const positions = Math.max(1, Math.floor(hitboxCount));
14
+ const activeFrames = Math.max(1, Math.ceil(profile.activeMs / 16));
15
+ return Math.max(1, Math.ceil(activeFrames / positions));
16
+ }
17
+ function scheduleActionBattleStartup(profile, callback, scheduler = setTimeout) {
18
+ if (profile.startupMs <= 0) {
19
+ callback();
20
+ return null;
21
+ }
22
+ return scheduler(callback, profile.startupMs);
23
+ }
24
+ var attackIdCounter = 0;
25
+ function createActionBattleAttackId(attackerId, profileId) {
26
+ attackIdCounter++;
27
+ return `${attackerId ?? "unknown"}:${profileId}:${Date.now()}:${attackIdCounter}`;
28
+ }
29
+ var getTargetKey = (target) => {
30
+ if (!target || target.id === void 0 || target.id === null) return null;
31
+ return String(target.id);
32
+ };
33
+ var ActionBattleHitTracker = class {
34
+ hitTargets = /* @__PURE__ */ new Set();
35
+ constructor(hitPolicy) {
36
+ this.hitPolicy = hitPolicy;
37
+ }
38
+ canHit(target) {
39
+ if (this.hitPolicy === "allowRepeatHits") return true;
40
+ const key = getTargetKey(target);
41
+ return !key || !this.hitTargets.has(key);
42
+ }
43
+ recordHit(target) {
44
+ const key = getTargetKey(target);
45
+ if (key) this.hitTargets.add(key);
46
+ }
47
+ tryHit(target) {
48
+ if (!this.canHit(target)) return false;
49
+ this.recordHit(target);
50
+ return true;
51
+ }
21
52
  };
22
- var getActionBattleSystems = () => currentActionBattleSystems;
23
- var createActionBattleSystems = mergeSystems;
24
53
  //#endregion
25
- export { createActionBattleSystems, getActionBattleSystems, setActionBattleSystems };
54
+ export { ACTION_BATTLE_HITBOX_FRAME_MS, ActionBattleHitTracker, createActionBattleAttackId, getNormalizedActionBattleAttackProfile, resolveActionBattleHitboxSpeed, scheduleActionBattleStartup };