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

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 (103) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/LICENSE +19 -0
  3. package/README.md +392 -22
  4. package/dist/{ai.server.d.ts → client/ai.server.d.ts} +90 -28
  5. package/dist/client/animations.d.ts +16 -0
  6. package/dist/{client.d.ts → client/client.d.ts} +3 -2
  7. package/dist/{config.d.ts → client/config.d.ts} +2 -0
  8. package/dist/client/core/attack-profile.d.ts +9 -0
  9. package/dist/client/core/attack-runtime.d.ts +20 -0
  10. package/dist/client/core/context.d.ts +5 -0
  11. package/dist/client/core/defaults.d.ts +81 -0
  12. package/dist/client/core/enemy-attack-profiles.d.ts +6 -0
  13. package/dist/client/core/equipment.d.ts +2 -0
  14. package/dist/client/core/hit-reaction.d.ts +5 -0
  15. package/dist/client/core/hit.d.ts +2 -0
  16. package/dist/client/enemies/factory.d.ts +7 -0
  17. package/dist/client/index.d.ts +21 -0
  18. package/dist/client/index.js +24 -31
  19. package/dist/client/index10.js +61 -0
  20. package/dist/client/index11.js +55 -0
  21. package/dist/client/index12.js +106 -0
  22. package/dist/client/index13.js +143 -0
  23. package/dist/client/index14.js +25 -0
  24. package/dist/client/index15.js +72 -0
  25. package/dist/client/index16.js +1343 -0
  26. package/dist/client/index17.js +13 -0
  27. package/dist/client/index18.js +60 -0
  28. package/dist/client/index19.js +10 -0
  29. package/dist/client/index2.js +30 -45
  30. package/dist/client/index20.js +504 -0
  31. package/dist/client/index3.js +45 -1288
  32. package/dist/client/index4.js +105 -330
  33. package/dist/client/index5.js +84 -291
  34. package/dist/client/index6.js +309 -95
  35. package/dist/client/index7.js +35 -59
  36. package/dist/client/index8.js +101 -54
  37. package/dist/client/index9.js +79 -30
  38. package/dist/{server.d.ts → client/server.d.ts} +12 -4
  39. package/dist/client/ui/state.d.ts +35 -0
  40. package/dist/server/ai.server.d.ts +569 -0
  41. package/dist/server/animations.d.ts +16 -0
  42. package/dist/server/config.d.ts +5 -0
  43. package/dist/server/core/attack-profile.d.ts +9 -0
  44. package/dist/server/core/attack-runtime.d.ts +20 -0
  45. package/dist/server/core/context.d.ts +5 -0
  46. package/dist/server/core/defaults.d.ts +81 -0
  47. package/dist/server/core/enemy-attack-profiles.d.ts +6 -0
  48. package/dist/server/core/equipment.d.ts +2 -0
  49. package/dist/server/core/hit-reaction.d.ts +5 -0
  50. package/dist/server/core/hit.d.ts +2 -0
  51. package/dist/server/enemies/factory.d.ts +7 -0
  52. package/dist/server/index.d.ts +21 -0
  53. package/dist/server/index.js +23 -31
  54. package/dist/server/index10.js +1342 -0
  55. package/dist/server/index11.js +37 -0
  56. package/dist/server/index12.js +60 -0
  57. package/dist/server/index13.js +13 -0
  58. package/dist/server/index14.js +503 -0
  59. package/dist/server/index15.js +10 -0
  60. package/dist/server/index2.js +59 -332
  61. package/dist/server/index3.js +29 -1286
  62. package/dist/server/index4.js +45 -53
  63. package/dist/server/index5.js +107 -29
  64. package/dist/server/index6.js +143 -0
  65. package/dist/server/index7.js +25 -0
  66. package/dist/server/index8.js +72 -0
  67. package/dist/server/index9.js +55 -0
  68. package/dist/server/server.d.ts +106 -0
  69. package/dist/server/targeting.d.ts +19 -0
  70. package/package.json +15 -15
  71. package/src/ai.server.spec.ts +120 -0
  72. package/src/ai.server.ts +515 -91
  73. package/src/animations.ts +149 -0
  74. package/src/canvas-engine-shim.ts +4 -0
  75. package/src/client.ts +130 -2
  76. package/src/components/action-bar.ce +7 -5
  77. package/src/components/attack-preview.ce +90 -0
  78. package/src/config.ts +61 -0
  79. package/src/core/attack-profile.spec.ts +118 -0
  80. package/src/core/attack-profile.ts +100 -0
  81. package/src/core/attack-runtime.spec.ts +103 -0
  82. package/src/core/attack-runtime.ts +83 -0
  83. package/src/core/context.ts +35 -0
  84. package/src/core/contracts.ts +126 -0
  85. package/src/core/defaults.ts +162 -0
  86. package/src/core/enemy-attack-profiles.spec.ts +35 -0
  87. package/src/core/enemy-attack-profiles.ts +103 -0
  88. package/src/core/equipment.spec.ts +37 -0
  89. package/src/core/equipment.ts +17 -0
  90. package/src/core/hit-reaction.spec.ts +43 -0
  91. package/src/core/hit-reaction.ts +70 -0
  92. package/src/core/hit.spec.ts +111 -0
  93. package/src/core/hit.ts +92 -0
  94. package/src/enemies/factory.ts +25 -0
  95. package/src/index.ts +94 -1
  96. package/src/server.ts +427 -93
  97. package/src/targeting.spec.ts +24 -0
  98. package/src/types/canvas-engine.d.ts +4 -0
  99. package/src/types.ts +148 -0
  100. package/src/ui/state.ts +57 -0
  101. package/dist/index.d.ts +0 -11
  102. package/dist/ui/state.d.ts +0 -18
  103. /package/dist/{targeting.d.ts → client/targeting.d.ts} +0 -0
package/src/types.ts CHANGED
@@ -1,9 +1,63 @@
1
+ import type {
2
+ ActionBattleAiBehavior,
3
+ ActionBattleCombatSystem,
4
+ ActionBattleHitHooks,
5
+ ActionBattleHitbox,
6
+ } from "./core/contracts";
7
+
1
8
  export type ActionBattleAoeMask = string[] | string;
2
9
 
3
10
  export type ActionBattleActionBarMode = "items" | "skills" | "both";
4
11
 
5
12
  export type ActionBattleTargetingAffects = "events" | "players" | "both";
6
13
 
14
+ export type ActionBattleAnimationKey =
15
+ | "attack"
16
+ | "hurt"
17
+ | "die"
18
+ | "castSkill"
19
+ | "castSpell";
20
+
21
+ export type ActionBattleAnimationResult =
22
+ | string
23
+ | {
24
+ animationName?: string;
25
+ graphic?: string | string[];
26
+ repeat?: number;
27
+ waitEnd?: boolean;
28
+ delayMs?: number;
29
+ }
30
+ | null
31
+ | undefined;
32
+
33
+ export type ActionBattleAnimationEntity = {
34
+ setGraphicAnimation(animationName: string, repeat: number): void;
35
+ setGraphicAnimation(
36
+ animationName: string,
37
+ graphic: string | string[],
38
+ repeat: number
39
+ ): void;
40
+ [key: string]: any;
41
+ };
42
+
43
+ export interface ActionBattleAnimationContext {
44
+ skill?: any;
45
+ attacker?: ActionBattleAnimationEntity;
46
+ target?: ActionBattleAnimationEntity;
47
+ }
48
+
49
+ export type ActionBattleAnimationResolver = (
50
+ entity: ActionBattleAnimationEntity,
51
+ context?: ActionBattleAnimationContext
52
+ ) => ActionBattleAnimationResult;
53
+
54
+ export type ActionBattleAnimationOptions = Partial<
55
+ Record<
56
+ ActionBattleAnimationKey,
57
+ ActionBattleAnimationResult | ActionBattleAnimationResolver
58
+ >
59
+ >;
60
+
7
61
  export interface ActionBattleSkillTargeting {
8
62
  range: number;
9
63
  aoeMask?: ActionBattleAoeMask;
@@ -35,6 +89,61 @@ export interface ActionBattleUiOptions {
35
89
  targeting?: ActionBattleUiTargetingOptions;
36
90
  }
37
91
 
92
+ export type ActionBattleAttackDirection =
93
+ | "up"
94
+ | "down"
95
+ | "left"
96
+ | "right"
97
+ | "default";
98
+
99
+ export interface ActionBattleAttackHitboxConfig {
100
+ offsetX: number;
101
+ offsetY: number;
102
+ width: number;
103
+ height: number;
104
+ }
105
+
106
+ export type ActionBattleAttackHitboxMap = Partial<
107
+ Record<ActionBattleAttackDirection, ActionBattleAttackHitboxConfig>
108
+ >;
109
+
110
+ export type ActionBattleAttackHitPolicy =
111
+ | "oncePerTarget"
112
+ | "allowRepeatHits";
113
+
114
+ export interface ActionBattleHitReactionProfile {
115
+ invincibilityMs?: number;
116
+ hitstunMs?: number;
117
+ staggerPower?: number;
118
+ }
119
+
120
+ export interface NormalizedActionBattleHitReactionProfile {
121
+ invincibilityMs: number;
122
+ hitstunMs: number;
123
+ staggerPower: number;
124
+ }
125
+
126
+ export interface ActionBattleAttackProfile {
127
+ id?: string;
128
+ startupMs?: number;
129
+ activeMs?: number;
130
+ recoveryMs?: number;
131
+ cooldownMs?: number;
132
+ movementLock?: boolean;
133
+ directionLock?: boolean;
134
+ animationKey?: ActionBattleAnimationKey;
135
+ hitPolicy?: ActionBattleAttackHitPolicy;
136
+ reaction?: ActionBattleHitReactionProfile;
137
+ hitboxes?: ActionBattleAttackHitboxMap;
138
+ }
139
+
140
+ export interface NormalizedActionBattleAttackProfile
141
+ extends Required<Omit<ActionBattleAttackProfile, "hitboxes" | "reaction">> {
142
+ reaction: NormalizedActionBattleHitReactionProfile;
143
+ hitboxes?: ActionBattleAttackHitboxMap;
144
+ totalDurationMs: number;
145
+ }
146
+
38
147
  export interface ActionBattleSkillOptions {
39
148
  getTargeting?: ActionBattleSkillTargetingResolver;
40
149
  defaultAoeMask?: ActionBattleAoeMask;
@@ -45,10 +154,49 @@ export interface ActionBattleTargetingOptions {
45
154
  allowEmptyTarget?: boolean;
46
155
  }
47
156
 
157
+ export interface ActionBattleDebugOptions {
158
+ attacks?: boolean;
159
+ }
160
+
161
+ export interface ActionBattleAttackOptions {
162
+ profile?: ActionBattleAttackProfile;
163
+ lockMovement?: boolean;
164
+ lockDurationMs?: number;
165
+ showPreview?: boolean;
166
+ previewDurationMs?: number;
167
+ previewColor?: number;
168
+ previewAccentColor?: number;
169
+ hitboxes?: ActionBattleAttackHitboxMap;
170
+ resolveHitboxes?: (context: {
171
+ player: any;
172
+ direction: string;
173
+ defaultHitboxes: ActionBattleHitbox[];
174
+ }) => ActionBattleHitbox[];
175
+ }
176
+
177
+ export interface ActionBattleCombatOptions {
178
+ damage?: ActionBattleCombatSystem["resolveDamage"];
179
+ knockback?: ActionBattleCombatSystem["resolveKnockback"];
180
+ hooks?: ActionBattleHitHooks;
181
+ }
182
+
183
+ export interface ActionBattleAiSystemOptions {
184
+ behaviors?: Record<string, ActionBattleAiBehavior>;
185
+ }
186
+
187
+ export interface ActionBattleSystemOptions {
188
+ combat?: ActionBattleCombatOptions;
189
+ ai?: ActionBattleAiSystemOptions;
190
+ }
191
+
48
192
  export interface ActionBattleOptions {
49
193
  ui?: ActionBattleUiOptions;
50
194
  skills?: ActionBattleSkillOptions;
51
195
  targeting?: ActionBattleTargetingOptions;
196
+ attack?: ActionBattleAttackOptions;
197
+ debug?: ActionBattleDebugOptions;
198
+ animations?: ActionBattleAnimationOptions;
199
+ systems?: ActionBattleSystemOptions;
52
200
  }
53
201
 
54
202
  export interface ActionBattleActionBarItem {
package/src/ui/state.ts CHANGED
@@ -2,6 +2,16 @@ import { signal } from "canvasengine";
2
2
  import { ActionBattleActionBarSkill, ActionBattleOptions } from "../types";
3
3
  import { DEFAULT_ACTION_BATTLE_OPTIONS, normalizeActionBattleOptions } from "../config";
4
4
 
5
+ export interface ActionBattleAttackPreviewState {
6
+ active: boolean;
7
+ id: number;
8
+ direction: string;
9
+ startedAt: number;
10
+ durationMs: number;
11
+ color: number;
12
+ accentColor: number;
13
+ }
14
+
5
15
  export interface ActionBattleTargetingState {
6
16
  active: boolean;
7
17
  skill: ActionBattleActionBarSkill | null;
@@ -18,6 +28,16 @@ const defaultTargetingState: ActionBattleTargetingState = {
18
28
  aoeMask: DEFAULT_ACTION_BATTLE_OPTIONS.skills?.defaultAoeMask || ["#"],
19
29
  };
20
30
 
31
+ const defaultAttackPreviewState: ActionBattleAttackPreviewState = {
32
+ active: false,
33
+ id: 0,
34
+ direction: "down",
35
+ startedAt: 0,
36
+ durationMs: 180,
37
+ color: 0xfff3b0,
38
+ accentColor: 0xffffff,
39
+ };
40
+
21
41
  export const actionBattleUiOptions = signal(
22
42
  normalizeActionBattleOptions({}).ui || {}
23
43
  );
@@ -28,6 +48,10 @@ export const actionBattleSkillOptions = signal(
28
48
  export const actionBattleTargetingState = signal<ActionBattleTargetingState>({
29
49
  ...defaultTargetingState,
30
50
  });
51
+ export const actionBattleAttackPreviewState =
52
+ signal<ActionBattleAttackPreviewState>({
53
+ ...defaultAttackPreviewState,
54
+ });
31
55
 
32
56
  export const setActionBattleOptions = (options: ActionBattleOptions = {}) => {
33
57
  const normalized = normalizeActionBattleOptions(options);
@@ -66,3 +90,36 @@ export const moveTargetingOffset = (dx: number, dy: number) => {
66
90
  offset: next,
67
91
  });
68
92
  };
93
+
94
+ export const startAttackPreview = (options: {
95
+ direction: string;
96
+ durationMs?: number;
97
+ color?: number;
98
+ accentColor?: number;
99
+ }) => {
100
+ const current = actionBattleAttackPreviewState();
101
+ const id = current.id + 1;
102
+ const durationMs = Math.max(
103
+ 1,
104
+ options.durationMs ?? defaultAttackPreviewState.durationMs
105
+ );
106
+ actionBattleAttackPreviewState.set({
107
+ active: true,
108
+ id,
109
+ direction: options.direction,
110
+ startedAt: Date.now(),
111
+ durationMs,
112
+ color: options.color ?? defaultAttackPreviewState.color,
113
+ accentColor: options.accentColor ?? defaultAttackPreviewState.accentColor,
114
+ });
115
+ return id;
116
+ };
117
+
118
+ export const stopAttackPreview = (id?: number) => {
119
+ const current = actionBattleAttackPreviewState();
120
+ if (id !== undefined && current.id !== id) return;
121
+ actionBattleAttackPreviewState.set({
122
+ ...current,
123
+ active: false,
124
+ });
125
+ };
package/dist/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { ActionBattleOptions } from './types';
2
- export { BattleAi, AiState, EnemyType, AttackPattern, AiDebug, DEFAULT_KNOCKBACK } from './ai.server';
3
- export type { HitResult, ApplyHitHooks } from './ai.server';
4
- export type { ActionBattleOptions, ActionBattleActionBarData, ActionBattleActionBarItem, ActionBattleActionBarSkill, ActionBattleSkillTargeting, ActionBattleSkillTargetingResolver, ActionBattleUiOptions, ActionBattleUiActionBarOptions, ActionBattleUiTargetingOptions, } from './types';
5
- export { DEFAULT_PLAYER_ATTACK_HITBOXES, getPlayerWeaponKnockbackForce, applyPlayerHitToEvent, ACTION_BATTLE_ACTION_BAR_GUI_ID, openActionBattleActionBar, updateActionBattleActionBar, createActionBattleServer, } from './server';
6
- export declare function provideActionBattle(options?: ActionBattleOptions): any;
7
- declare const _default: {
8
- server: any;
9
- client: any;
10
- };
11
- export default _default;
@@ -1,18 +0,0 @@
1
- import { ActionBattleActionBarSkill, ActionBattleOptions } from '../types';
2
- export interface ActionBattleTargetingState {
3
- active: boolean;
4
- skill: ActionBattleActionBarSkill | null;
5
- range: number;
6
- offset: {
7
- x: number;
8
- y: number;
9
- };
10
- aoeMask: string[] | string;
11
- }
12
- export declare const actionBattleUiOptions: any;
13
- export declare const actionBattleSkillOptions: any;
14
- export declare const actionBattleTargetingState: any;
15
- export declare const setActionBattleOptions: (options?: ActionBattleOptions) => void;
16
- export declare const startTargeting: (skill: ActionBattleActionBarSkill) => void;
17
- export declare const stopTargeting: () => void;
18
- export declare const moveTargetingOffset: (dx: number, dy: number) => void;
File without changes