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

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 (52) hide show
  1. package/README.md +137 -0
  2. package/dist/ai.server.d.ts +8 -1
  3. package/dist/client/index.js +8 -4
  4. package/dist/client/index10.js +97 -330
  5. package/dist/client/index11.js +25 -0
  6. package/dist/client/index12.js +1222 -0
  7. package/dist/client/index13.js +46 -0
  8. package/dist/client/index14.js +10 -0
  9. package/dist/client/index15.js +448 -0
  10. package/dist/client/index2.js +30 -0
  11. package/dist/client/index3.js +33 -1
  12. package/dist/client/index4.js +7 -3
  13. package/dist/client/index7.js +76 -32
  14. package/dist/client/index8.js +24 -4
  15. package/dist/client/index9.js +94 -1165
  16. package/dist/core/context.d.ts +5 -0
  17. package/dist/core/defaults.d.ts +81 -0
  18. package/dist/core/hit.d.ts +2 -0
  19. package/dist/enemies/factory.d.ts +7 -0
  20. package/dist/index.d.ts +6 -1
  21. package/dist/server/index.js +7 -3
  22. package/dist/server/index10.js +10 -0
  23. package/dist/server/index2.js +23 -3
  24. package/dist/server/index3.js +30 -0
  25. package/dist/server/index4.js +137 -1163
  26. package/dist/server/index5.js +22 -34
  27. package/dist/server/index6.js +1190 -345
  28. package/dist/server/index7.js +37 -0
  29. package/dist/server/index8.js +46 -0
  30. package/dist/server/index9.js +447 -0
  31. package/dist/server.d.ts +2 -0
  32. package/dist/ui/state.d.ts +17 -0
  33. package/package.json +5 -5
  34. package/src/ai.server.ts +91 -24
  35. package/src/animations.ts +43 -4
  36. package/src/canvas-engine-shim.ts +4 -0
  37. package/src/client.ts +122 -2
  38. package/src/components/action-bar.ce +5 -3
  39. package/src/components/attack-preview.ce +90 -0
  40. package/src/config.ts +30 -0
  41. package/src/core/context.ts +35 -0
  42. package/src/core/contracts.ts +123 -0
  43. package/src/core/defaults.ts +162 -0
  44. package/src/core/hit.spec.ts +58 -0
  45. package/src/core/hit.ts +66 -0
  46. package/src/enemies/factory.ts +25 -0
  47. package/src/index.ts +40 -0
  48. package/src/server.ts +235 -71
  49. package/src/targeting.spec.ts +24 -0
  50. package/src/types/canvas-engine.d.ts +4 -0
  51. package/src/types.ts +46 -1
  52. package/src/ui/state.ts +57 -0
@@ -0,0 +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, ""));
6
+ };
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
+ });
21
+ }
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
+ };
35
+ var manhattanDistance = (a, b) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
36
+ //#endregion
37
+ export { manhattanDistance, parseAoeMask };
@@ -0,0 +1,46 @@
1
+ //#region src/core/hit.ts
2
+ var applyActionBattleHit = (system, context) => {
3
+ let hitContext = { ...context };
4
+ const before = system.hooks?.beforeHit?.(hitContext);
5
+ if (before === false) return {
6
+ damage: 0,
7
+ knockbackForce: 0,
8
+ knockbackDuration: 0,
9
+ defeated: false,
10
+ attacker: hitContext.attacker,
11
+ target: hitContext.target,
12
+ cancelled: true,
13
+ metadata: hitContext.metadata
14
+ };
15
+ if (before) hitContext = before;
16
+ const damage = hitContext.damage ?? system.resolveDamage({
17
+ attacker: hitContext.attacker,
18
+ target: hitContext.target,
19
+ skill: hitContext.skill,
20
+ pattern: hitContext.pattern
21
+ });
22
+ hitContext.damage = damage;
23
+ const afterDamage = system.hooks?.afterDamage?.(hitContext);
24
+ if (afterDamage) hitContext = afterDamage;
25
+ const knockback = hitContext.knockback ?? system.resolveKnockback({
26
+ attacker: hitContext.attacker,
27
+ target: hitContext.target,
28
+ damage
29
+ });
30
+ hitContext.knockback = knockback;
31
+ if (!damage.defeated && knockback.force > 0 && knockback.direction) hitContext.target.knockback?.(knockback.direction, knockback.force, knockback.duration);
32
+ const result = {
33
+ damage: damage.damage,
34
+ knockbackForce: knockback.force,
35
+ knockbackDuration: knockback.duration,
36
+ defeated: damage.defeated,
37
+ attacker: hitContext.attacker,
38
+ target: hitContext.target,
39
+ rawDamage: damage.raw,
40
+ metadata: hitContext.metadata
41
+ };
42
+ system.hooks?.afterHit?.(result);
43
+ return result;
44
+ };
45
+ //#endregion
46
+ export { applyActionBattleHit };
@@ -0,0 +1,447 @@
1
+ import { playActionBattleAnimation } from "./index2.js";
2
+ import { normalizeActionBattleOptions, setActionBattleOptions } from "./index3.js";
3
+ import { DEFAULT_ZELDA_PLAYER_HITBOXES } from "./index4.js";
4
+ import { getActionBattleSystems, setActionBattleSystems } from "./index5.js";
5
+ import { DEFAULT_KNOCKBACK } from "./index6.js";
6
+ import { manhattanDistance, parseAoeMask } from "./index7.js";
7
+ import { applyActionBattleHit } from "./index8.js";
8
+ import { RpgEvent } from "@rpgjs/server";
9
+ import { Control, defineModule } from "@rpgjs/common";
10
+ //#region src/server.ts
11
+ var ACTION_BATTLE_ACTION_BAR_GUI_ID = "action-battle-action-bar";
12
+ var DEFAULT_ATTACK_LOCK_DURATION_MS = 350;
13
+ /**
14
+ * Default player attack hitboxes offsets for each direction
15
+ *
16
+ * These hitboxes define the attack areas relative to the player's position
17
+ * for each cardinal direction. They are converted to absolute coordinates
18
+ * when creating the moving hitbox.
19
+ */
20
+ var DEFAULT_PLAYER_ATTACK_HITBOXES = { ...DEFAULT_ZELDA_PLAYER_HITBOXES };
21
+ var beginPlayerAttackLock = (player, map, durationMs) => {
22
+ if (durationMs <= 0) return true;
23
+ const runtimePlayer = player;
24
+ const now = Date.now();
25
+ if (typeof runtimePlayer.__actionBattleAttackLockedUntil === "number" && runtimePlayer.__actionBattleAttackLockedUntil > now) return false;
26
+ const lockId = (runtimePlayer.__actionBattleAttackLockId ?? 0) + 1;
27
+ runtimePlayer.__actionBattleAttackLockId = lockId;
28
+ runtimePlayer.__actionBattleAttackLockedUntil = now + durationMs;
29
+ const previousCanMove = typeof player.canMove === "function" ? player.canMove() : true;
30
+ const previousDirectionFixed = player.directionFixed;
31
+ const previousAnimationFixed = player.animationFixed;
32
+ player.pendingInputs = [];
33
+ player.lastProcessedInputTs = 0;
34
+ map?.stopMovement?.(player);
35
+ player.canMove.set(false);
36
+ player.directionFixed = true;
37
+ setTimeout(() => {
38
+ if (runtimePlayer.__actionBattleAttackLockId !== lockId) return;
39
+ runtimePlayer.__actionBattleAttackLockedUntil = 0;
40
+ player.canMove.set(previousCanMove);
41
+ player.directionFixed = previousDirectionFixed;
42
+ player.animationFixed = previousAnimationFixed;
43
+ }, durationMs);
44
+ return true;
45
+ };
46
+ var isBattleEvent = (event) => !!event.battleAi;
47
+ var rectsOverlap = (a, b) => a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
48
+ var eventRect = (event) => {
49
+ const hitbox = typeof event.hitbox === "function" ? event.hitbox() : event.hitbox;
50
+ return {
51
+ x: event.x(),
52
+ y: event.y(),
53
+ width: hitbox?.w ?? 32,
54
+ height: hitbox?.h ?? 32
55
+ };
56
+ };
57
+ var getVisibleActionEvents = (player, map, hitboxes) => {
58
+ if (!map) return [];
59
+ const eventsById = /* @__PURE__ */ new Map();
60
+ const addEvent = (event) => {
61
+ if (!event) return;
62
+ if (!(typeof map.isEventVisibleForPlayer === "function" ? map.isEventVisibleForPlayer(event, player) : true)) return;
63
+ eventsById.set(event.id, event);
64
+ };
65
+ const collisions = map.getCollisions?.(player.id);
66
+ if (Array.isArray(collisions)) collisions.forEach((id) => addEvent(map.getEvent(id)));
67
+ for (const event of map.getEvents()) {
68
+ const rect = eventRect(event);
69
+ if (hitboxes.some((hitbox) => rectsOverlap(hitbox, rect))) addEvent(event);
70
+ }
71
+ return Array.from(eventsById.values());
72
+ };
73
+ var isActionReservedForNormalEvent = (player, map, hitboxes) => {
74
+ const events = getVisibleActionEvents(player, map, hitboxes);
75
+ return events.length > 0 && !events.some(isBattleEvent);
76
+ };
77
+ /**
78
+ * Get knockback force from player's equipped weapon
79
+ *
80
+ * Retrieves the knockbackForce property from the player's equipped weapon.
81
+ * Falls back to DEFAULT_KNOCKBACK.force if no weapon or property is set.
82
+ *
83
+ * @param player - The player to get weapon knockback from
84
+ * @returns Knockback force value
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * // Player with weapon having knockbackForce: 80
89
+ * const force = getPlayerWeaponKnockbackForce(player); // 80
90
+ *
91
+ * // No weapon equipped
92
+ * const force = getPlayerWeaponKnockbackForce(player); // 50 (default)
93
+ * ```
94
+ */
95
+ function getPlayerWeaponKnockbackForce(player) {
96
+ try {
97
+ const equipments = player.equipments?.() || [];
98
+ for (const item of equipments) {
99
+ const itemData = player.databaseById?.(item.id());
100
+ if (itemData?._type === "weapon" && itemData.knockbackForce !== void 0) return itemData.knockbackForce;
101
+ }
102
+ } catch {}
103
+ return DEFAULT_KNOCKBACK.force;
104
+ }
105
+ /**
106
+ * Apply hit from player to target (event with AI)
107
+ *
108
+ * Handles damage calculation, knockback based on weapon, and visual effects.
109
+ * Can be customized using hooks.
110
+ *
111
+ * @param player - The attacking player
112
+ * @param target - The event being hit
113
+ * @param hooks - Optional hooks for customizing hit behavior
114
+ * @returns Hit result if AI exists, undefined otherwise
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * // Basic hit
119
+ * const result = applyPlayerHitToEvent(player, event);
120
+ *
121
+ * // With custom hooks
122
+ * const result = applyPlayerHitToEvent(player, event, {
123
+ * onBeforeHit(result) {
124
+ * result.knockbackForce *= 2; // Double knockback
125
+ * return result;
126
+ * },
127
+ * onAfterHit(result) {
128
+ * if (result.defeated) {
129
+ * player.gold += 10;
130
+ * }
131
+ * }
132
+ * });
133
+ * ```
134
+ */
135
+ function applyPlayerHitToEvent(player, target, hooks) {
136
+ const ai = target.battleAi;
137
+ if (!ai) return void 0;
138
+ const systems = getActionBattleSystems();
139
+ const result = applyActionBattleHit({
140
+ ...systems.combat,
141
+ hooks: hooks ? {
142
+ ...systems.combat.hooks,
143
+ beforeHit(context) {
144
+ const before = systems.combat.hooks?.beforeHit?.(context);
145
+ if (before === false) return false;
146
+ const nextContext = before || context;
147
+ const legacyResult = toLegacyHitResult(nextContext);
148
+ const modified = hooks.onBeforeHit?.(legacyResult);
149
+ if (!modified) return nextContext;
150
+ return {
151
+ ...nextContext,
152
+ damage: {
153
+ damage: modified.damage,
154
+ defeated: modified.defeated,
155
+ raw: nextContext.damage?.raw
156
+ },
157
+ knockback: {
158
+ force: modified.knockbackForce,
159
+ duration: modified.knockbackDuration,
160
+ direction: nextContext.knockback?.direction
161
+ }
162
+ };
163
+ },
164
+ afterHit(result) {
165
+ systems.combat.hooks?.afterHit?.(result);
166
+ hooks.onAfterHit?.(result);
167
+ }
168
+ } : systems.combat.hooks
169
+ }, {
170
+ attacker: player,
171
+ target
172
+ });
173
+ if (!result.cancelled) ai.handleDamage(player, {
174
+ damage: result.damage,
175
+ defeated: result.defeated,
176
+ raw: result.rawDamage
177
+ });
178
+ return result;
179
+ }
180
+ var toLegacyHitResult = (context) => ({
181
+ damage: context.damage?.damage ?? 0,
182
+ knockbackForce: context.knockback?.force ?? getPlayerWeaponKnockbackForce(context.attacker),
183
+ knockbackDuration: context.knockback?.duration ?? DEFAULT_KNOCKBACK.duration,
184
+ defeated: context.damage?.defeated ?? false,
185
+ attacker: context.attacker,
186
+ target: context.target
187
+ });
188
+ var resolvePlayerAttackHitboxes = (player, directionKey, options) => {
189
+ const configuredHitboxes = {
190
+ ...DEFAULT_PLAYER_ATTACK_HITBOXES,
191
+ ...options.attack?.hitboxes
192
+ };
193
+ const hitboxConfig = configuredHitboxes[directionKey] || configuredHitboxes.default;
194
+ const defaultHitboxes = [{
195
+ x: player.x() + hitboxConfig.offsetX,
196
+ y: player.y() + hitboxConfig.offsetY,
197
+ width: hitboxConfig.width,
198
+ height: hitboxConfig.height
199
+ }];
200
+ return options.attack?.resolveHitboxes?.({
201
+ player,
202
+ direction: directionKey,
203
+ defaultHitboxes
204
+ }) ?? defaultHitboxes;
205
+ };
206
+ var resolveSignal = (value) => typeof value === "function" ? value() : value;
207
+ var resolveItemData = (player, itemId) => {
208
+ try {
209
+ return player.databaseById?.(itemId);
210
+ } catch {
211
+ return null;
212
+ }
213
+ };
214
+ var resolveSkillData = (player, skillId) => {
215
+ try {
216
+ return player.databaseById?.(skillId);
217
+ } catch {
218
+ return null;
219
+ }
220
+ };
221
+ var resolveSkillTargeting = (player, skillId, options) => {
222
+ const skillsOptions = options.skills;
223
+ const skillData = resolveSkillData(player, skillId);
224
+ if (skillsOptions?.getTargeting) return skillsOptions.getTargeting(skillData);
225
+ const range = skillData?.range ?? skillData?.targeting?.range ?? skillData?.targeting?.distance;
226
+ const aoeMask = skillData?.aoeMask ?? skillData?.targeting?.aoeMask ?? skillData?.targeting?.mask;
227
+ if (range === void 0 && aoeMask === void 0) return null;
228
+ return {
229
+ range: range ?? 0,
230
+ aoeMask
231
+ };
232
+ };
233
+ var normalizeMaskRows = (mask) => {
234
+ if (!mask) return [];
235
+ if (Array.isArray(mask)) return mask;
236
+ return mask.trim().split("\n").map((row) => row.replace(/\r/g, ""));
237
+ };
238
+ var buildActionBarData = (player, options) => {
239
+ return {
240
+ items: (player.items?.() || []).map((item) => {
241
+ const id = item.id?.() ?? item.id;
242
+ const data = resolveItemData(player, id);
243
+ const name = resolveSignal(data?.name) ?? resolveSignal(item.name) ?? id;
244
+ const description = resolveSignal(data?.description) ?? resolveSignal(item.description) ?? "";
245
+ const icon = resolveSignal(data?.icon) ?? resolveSignal(item.icon);
246
+ const quantity = resolveSignal(item.quantity) ?? 1;
247
+ const consumable = resolveSignal(data?.consumable);
248
+ const itemType = resolveSignal(data?._type);
249
+ return {
250
+ id,
251
+ name,
252
+ description,
253
+ icon,
254
+ quantity,
255
+ usable: quantity > 0 && consumable !== false && (itemType ? itemType === "item" : true)
256
+ };
257
+ }),
258
+ skills: (player.skills?.() || []).map((skill) => {
259
+ const id = skill.id?.() ?? skill.id;
260
+ const data = resolveSkillData(player, id) || skill;
261
+ const name = resolveSignal(data?.name) ?? resolveSignal(skill.name) ?? id;
262
+ const description = resolveSignal(data?.description) ?? resolveSignal(skill.description) ?? "";
263
+ const icon = resolveSignal(data?.icon) ?? resolveSignal(skill.icon);
264
+ const spCost = resolveSignal(data?.spCost) ?? resolveSignal(skill.spCost) ?? 0;
265
+ const usable = spCost <= player.sp;
266
+ const targeting = resolveSkillTargeting(player, id, options);
267
+ const skillEntry = {
268
+ id,
269
+ name,
270
+ description,
271
+ icon,
272
+ spCost,
273
+ usable,
274
+ range: targeting?.range ?? 0
275
+ };
276
+ if (targeting) {
277
+ const mask = targeting.aoeMask ?? options.skills?.defaultAoeMask;
278
+ if (mask) skillEntry.aoeMask = normalizeMaskRows(mask);
279
+ }
280
+ return skillEntry;
281
+ })
282
+ };
283
+ };
284
+ var ensureActionBarGui = (player, options) => {
285
+ const gui = player.getGui?.("action-battle-action-bar") || player.gui("action-battle-action-bar");
286
+ if (!gui.__actionBattleReady) {
287
+ gui.__actionBattleReady = true;
288
+ gui.on("useItem", ({ id }) => {
289
+ try {
290
+ player.useItem(id);
291
+ } catch {}
292
+ gui.update(buildActionBarData(player, options));
293
+ });
294
+ gui.on("useSkill", ({ id, target }) => {
295
+ handleActionBattleSkillUse(player, id, target, options);
296
+ gui.update(buildActionBarData(player, options));
297
+ });
298
+ gui.on("refresh", () => {
299
+ gui.update(buildActionBarData(player, options));
300
+ });
301
+ }
302
+ return gui;
303
+ };
304
+ var openActionBattleActionBar = (player, rawOptions = {}) => {
305
+ const options = normalizeActionBattleOptions(rawOptions);
306
+ ensureActionBarGui(player, options).open(buildActionBarData(player, options));
307
+ };
308
+ var updateActionBattleActionBar = (player, rawOptions = {}) => {
309
+ const options = normalizeActionBattleOptions(rawOptions);
310
+ const gui = player.getGui?.(ACTION_BATTLE_ACTION_BAR_GUI_ID);
311
+ if (gui) gui.update(buildActionBarData(player, options));
312
+ };
313
+ var getTileSize = (map) => ({
314
+ width: map?.tileWidth ?? 32,
315
+ height: map?.tileHeight ?? 32
316
+ });
317
+ var getEntityTile = (entity, tileSize) => {
318
+ const hitbox = entity.hitbox?.() || {
319
+ w: tileSize.width,
320
+ h: tileSize.height
321
+ };
322
+ return {
323
+ x: Math.floor((entity.x() + hitbox.w / 2) / tileSize.width),
324
+ y: Math.floor((entity.y() + hitbox.h / 2) / tileSize.height)
325
+ };
326
+ };
327
+ var handleActionBattleSkillUse = (player, skillId, target, options) => {
328
+ const skillData = resolveSkillData(player, skillId);
329
+ const map = player.getCurrentMap();
330
+ if (!map) {
331
+ playActionBattleAnimation("castSkill", player, options.animations, { skill: skillData });
332
+ player.useSkill(skillId);
333
+ return;
334
+ }
335
+ const targeting = resolveSkillTargeting(player, skillId, options);
336
+ if (!targeting || !target) {
337
+ playActionBattleAnimation("castSkill", player, options.animations, { skill: skillData });
338
+ player.useSkill(skillId);
339
+ return;
340
+ }
341
+ const tileSize = getTileSize(map);
342
+ const origin = getEntityTile(player, tileSize);
343
+ const targetTile = {
344
+ x: target.x,
345
+ y: target.y
346
+ };
347
+ if (manhattanDistance(origin, targetTile) > targeting.range) return;
348
+ const mask = parseAoeMask(targeting.aoeMask || options.skills?.defaultAoeMask);
349
+ const affected = /* @__PURE__ */ new Set();
350
+ mask.cells.forEach((cell) => {
351
+ const x = targetTile.x + cell.dx;
352
+ const y = targetTile.y + cell.dy;
353
+ affected.add(`${x},${y}`);
354
+ });
355
+ const targets = [];
356
+ const affects = options.targeting?.affects || "events";
357
+ if (affects === "events" || affects === "both") map.getEvents().forEach((event) => {
358
+ const tile = getEntityTile(event, tileSize);
359
+ if (affected.has(`${tile.x},${tile.y}`)) targets.push(event);
360
+ });
361
+ if (affects === "players" || affects === "both") map.getPlayers().forEach((other) => {
362
+ if (other.id === player.id) return;
363
+ const tile = getEntityTile(other, tileSize);
364
+ if (affected.has(`${tile.x},${tile.y}`)) targets.push(other);
365
+ });
366
+ if (!options.targeting?.allowEmptyTarget && targets.length === 0) return;
367
+ playActionBattleAnimation("castSkill", player, options.animations, {
368
+ skill: skillData,
369
+ target: targets[0]
370
+ });
371
+ player.useSkill(skillId, targets);
372
+ };
373
+ var createActionBattleServer = (rawOptions = {}) => {
374
+ const options = normalizeActionBattleOptions(rawOptions);
375
+ setActionBattleOptions(options);
376
+ setActionBattleSystems(options);
377
+ return defineModule({
378
+ player: {
379
+ /**
380
+ * Handle player input for combat actions
381
+ *
382
+ * When a player presses the action key, create an attack hitbox
383
+ * that can damage AI enemies within range and knockback the event.
384
+ * Knockback force is based on the player's equipped weapon.
385
+ * Triggers attack animation and visual effects.
386
+ *
387
+ * @param player - The player performing the action
388
+ * @param input - Input data containing pressed keys
389
+ */
390
+ onInput(player, input) {
391
+ if (input.action == Control.Action) {
392
+ const map = player.getCurrentMap();
393
+ const hitboxes = resolvePlayerAttackHitboxes(player, player.getDirection(), options);
394
+ if (isActionReservedForNormalEvent(player, map, hitboxes)) return;
395
+ const lockMovement = options.attack?.lockMovement !== false;
396
+ const lockDurationMs = options.attack?.lockDurationMs ?? DEFAULT_ATTACK_LOCK_DURATION_MS;
397
+ let movementLocked = false;
398
+ if (lockMovement && !beginPlayerAttackLock(player, map, Math.max(0, lockDurationMs))) return;
399
+ movementLocked = lockMovement && lockDurationMs > 0;
400
+ playActionBattleAnimation("attack", player, options.animations);
401
+ if (movementLocked) player.animationFixed = true;
402
+ map?.createMovingHitbox(hitboxes, { speed: 3 }).subscribe({ next(hits) {
403
+ hits.forEach((hit) => {
404
+ if (hit instanceof RpgEvent) {
405
+ if (applyPlayerHitToEvent(player, hit)?.defeated) console.log(`Player ${player.id} defeated AI ${hit.id}`);
406
+ }
407
+ });
408
+ } });
409
+ }
410
+ },
411
+ onConnected(player) {
412
+ if (options.ui?.actionBar?.enabled && options.ui?.actionBar?.autoOpen) openActionBattleActionBar(player, options);
413
+ }
414
+ },
415
+ event: {
416
+ /**
417
+ * Handle player detection when entering AI vision
418
+ *
419
+ * Called when a player enters an AI event's vision range.
420
+ * The AI will start pursuing and attacking the player.
421
+ *
422
+ * @param event - The AI event
423
+ * @param player - The player entering vision
424
+ * @param shape - The vision shape
425
+ */
426
+ onDetectInShape(event, player, shape) {
427
+ event.battleAi?.onDetectInShape(player, shape);
428
+ },
429
+ /**
430
+ * Handle player leaving AI vision
431
+ *
432
+ * Called when a player leaves an AI event's vision range.
433
+ * The AI will stop pursuing the player.
434
+ *
435
+ * @param event - The AI event
436
+ * @param player - The player leaving vision
437
+ * @param shape - The vision shape
438
+ */
439
+ onDetectOutShape(event, player, shape) {
440
+ event.battleAi?.onDetectOutShape(player, shape);
441
+ }
442
+ }
443
+ });
444
+ };
445
+ var server_default = createActionBattleServer();
446
+ //#endregion
447
+ export { ACTION_BATTLE_ACTION_BAR_GUI_ID, DEFAULT_PLAYER_ATTACK_HITBOXES, applyPlayerHitToEvent, createActionBattleServer, server_default as default, getPlayerWeaponKnockbackForce, openActionBattleActionBar, updateActionBattleActionBar };
package/dist/server.d.ts CHANGED
@@ -96,3 +96,5 @@ export declare const updateActionBattleActionBar: (player: RpgPlayer, rawOptions
96
96
  export declare const createActionBattleServer: (rawOptions?: ActionBattleOptions) => RpgServer;
97
97
  declare const _default: RpgServer;
98
98
  export default _default;
99
+ export { AiDebug, AiState, AttackPattern, BattleAi, DEFAULT_KNOCKBACK, EnemyType, } from './ai.server';
100
+ export type { ApplyHitHooks, BattleAiOptions, HitResult } from './ai.server';
@@ -1,4 +1,13 @@
1
1
  import { ActionBattleActionBarSkill, ActionBattleOptions } from '../types';
2
+ export interface ActionBattleAttackPreviewState {
3
+ active: boolean;
4
+ id: number;
5
+ direction: string;
6
+ startedAt: number;
7
+ durationMs: number;
8
+ color: number;
9
+ accentColor: number;
10
+ }
2
11
  export interface ActionBattleTargetingState {
3
12
  active: boolean;
4
13
  skill: ActionBattleActionBarSkill | null;
@@ -12,7 +21,15 @@ export interface ActionBattleTargetingState {
12
21
  export declare const actionBattleUiOptions: import('canvasengine').WritableObjectSignal<import('..').ActionBattleUiOptions>;
13
22
  export declare const actionBattleSkillOptions: import('canvasengine').WritableObjectSignal<import('../types').ActionBattleSkillOptions>;
14
23
  export declare const actionBattleTargetingState: import('canvasengine').WritableObjectSignal<ActionBattleTargetingState>;
24
+ export declare const actionBattleAttackPreviewState: import('canvasengine').WritableObjectSignal<ActionBattleAttackPreviewState>;
15
25
  export declare const setActionBattleOptions: (options?: ActionBattleOptions) => void;
16
26
  export declare const startTargeting: (skill: ActionBattleActionBarSkill) => void;
17
27
  export declare const stopTargeting: () => void;
18
28
  export declare const moveTargetingOffset: (dx: number, dy: number) => void;
29
+ export declare const startAttackPreview: (options: {
30
+ direction: string;
31
+ durationMs?: number;
32
+ color?: number;
33
+ accentColor?: number;
34
+ }) => number;
35
+ export declare const stopAttackPreview: (id?: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpgjs/action-battle",
3
- "version": "5.0.0-beta.3",
3
+ "version": "5.0.0-beta.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -23,10 +23,10 @@
23
23
  "description": "RPGJS is a framework for creating RPG/MMORPG games",
24
24
  "peerDependencies": {
25
25
  "@canvasengine/presets": "*",
26
- "@rpgjs/client": "5.0.0-beta.3",
27
- "@rpgjs/common": "5.0.0-beta.3",
28
- "@rpgjs/server": "5.0.0-beta.3",
29
- "@rpgjs/vite": "5.0.0-beta.3",
26
+ "@rpgjs/client": "5.0.0-beta.5",
27
+ "@rpgjs/common": "5.0.0-beta.5",
28
+ "@rpgjs/server": "5.0.0-beta.5",
29
+ "@rpgjs/vite": "5.0.0-beta.5",
30
30
  "canvasengine": "*"
31
31
  },
32
32
  "publishConfig": {