@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
@@ -1,30 +1,79 @@
1
- const normalizeMaskRows = (mask) => {
2
- if (!mask) return ["#"];
3
- if (Array.isArray(mask)) return mask;
4
- return mask.trim().split("\n").map((row) => row.replace(/\r/g, ""));
5
- };
6
- const parseAoeMask = (mask) => {
7
- const rows = normalizeMaskRows(mask);
8
- const height = rows.length;
9
- const width = rows.reduce((max, row) => Math.max(max, row.length), 0);
10
- const centerX = Math.floor(width / 2);
11
- const centerY = Math.floor(height / 2);
12
- const cells = [];
13
- rows.forEach((row, y) => {
14
- for (let x = 0; x < row.length; x++) {
15
- const char = row[x];
16
- if (char && char !== "." && char !== " ") {
17
- cells.push({ dx: x - centerX, dy: y - centerY });
18
- }
19
- }
20
- });
21
- if (cells.length === 0) {
22
- cells.push({ dx: 0, dy: 0 });
23
- }
24
- return { width, height, centerX, centerY, cells };
25
- };
26
- const manhattanDistance = (a, b) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
27
- export {
28
- manhattanDistance,
29
- parseAoeMask
30
- };
1
+ import { actionBattleAttackPreviewState } from "./index5.js";
2
+ import { RpgClientEngine, inject } from "@rpgjs/client";
3
+ import { Container, Graphics, computed, cond, h, signal, tick, useDefineProps, useProps } from "canvasengine";
4
+ //#region src/components/attack-preview.ce
5
+ function component($$props) {
6
+ useProps($$props);
7
+ const { object } = useDefineProps($$props)();
8
+ const engine = inject(RpgClientEngine);
9
+ const now = signal(Date.now());
10
+ tick(() => {
11
+ if (actionBattleAttackPreviewState().active) now.set(Date.now());
12
+ });
13
+ const isCurrentPlayer = computed(() => {
14
+ if (!object?.id) return false;
15
+ return (typeof object.id === "function" ? object.id() : object.id) === engine.playerId;
16
+ });
17
+ const preview = computed(() => actionBattleAttackPreviewState());
18
+ const progress = computed(() => {
19
+ const state = preview();
20
+ if (!state.active) return 1;
21
+ const elapsed = now() - state.startedAt;
22
+ return Math.max(0, Math.min(1, elapsed / state.durationMs));
23
+ });
24
+ const shouldRender = computed(() => {
25
+ const state = preview();
26
+ return isCurrentPlayer() && state.active && progress() < 1;
27
+ });
28
+ const getHitbox = () => object.hitbox?.() || {
29
+ w: 32,
30
+ h: 32
31
+ };
32
+ const drawRect = (g, x, y, width, height, color, alpha) => {
33
+ g.rect(x, y, width, height);
34
+ g.fill({
35
+ color,
36
+ alpha
37
+ });
38
+ };
39
+ const drawSlash = (g) => {
40
+ g.clear();
41
+ if (!shouldRender()) return;
42
+ const state = preview();
43
+ const p = progress();
44
+ const alpha = Math.sin(Math.PI * p);
45
+ if (alpha <= 0) return;
46
+ const hitbox = getHitbox();
47
+ const width = hitbox.w || 32;
48
+ const height = hitbox.h || 32;
49
+ const reach = 16 + 18 * p;
50
+ const thickness = 4 + 3 * (1 - p);
51
+ const color = state.color;
52
+ const accent = state.accentColor;
53
+ if (state.direction === "left") {
54
+ drawRect(g, -reach - 6, height * .24, reach, thickness, accent, alpha * .55);
55
+ drawRect(g, -reach - 10, height * .46, reach + 4, thickness + 2, color, alpha);
56
+ drawRect(g, -reach - 6, height * .7, reach, thickness, accent, alpha * .4);
57
+ return;
58
+ }
59
+ if (state.direction === "right") {
60
+ drawRect(g, width + 6, height * .24, reach, thickness, accent, alpha * .55);
61
+ drawRect(g, width + 6, height * .46, reach + 4, thickness + 2, color, alpha);
62
+ drawRect(g, width + 6, height * .7, reach, thickness, accent, alpha * .4);
63
+ return;
64
+ }
65
+ if (state.direction === "up") {
66
+ drawRect(g, width * .24, -reach - 6, thickness, reach, accent, alpha * .55);
67
+ drawRect(g, width * .46, -reach - 10, thickness + 2, reach + 4, color, alpha);
68
+ drawRect(g, width * .7, -reach - 6, thickness, reach, accent, alpha * .4);
69
+ return;
70
+ }
71
+ drawRect(g, width * .24, height + 6, thickness, reach, accent, alpha * .55);
72
+ drawRect(g, width * .46, height + 6, thickness + 2, reach + 4, color, alpha);
73
+ drawRect(g, width * .7, height + 6, thickness, reach, accent, alpha * .4);
74
+ };
75
+ return h(Container, null, cond(shouldRender, () => h(Graphics, { draw: drawSlash })));
76
+ }
77
+ var __ce_component = component;
78
+ //#endregion
79
+ export { __ce_component as default };
@@ -1,4 +1,4 @@
1
- import { RpgEvent, RpgPlayer } from '@rpgjs/server';
1
+ import { RpgEvent, RpgPlayer, RpgServer } from '@rpgjs/server';
2
2
  import { HitResult, ApplyHitHooks } from './ai.server';
3
3
  import { ActionBattleOptions } from './types';
4
4
  export declare const ACTION_BATTLE_ACTION_BAR_GUI_ID = "action-battle-action-bar";
@@ -90,9 +90,17 @@ export declare function getPlayerWeaponKnockbackForce(player: RpgPlayer): number
90
90
  * });
91
91
  * ```
92
92
  */
93
- export declare function applyPlayerHitToEvent(player: RpgPlayer, target: RpgEvent, hooks?: ApplyHitHooks): HitResult | undefined;
93
+ export declare function applyPlayerHitToEvent(player: RpgPlayer, target: RpgEvent, hooks?: ApplyHitHooks, metadata?: Record<string, any>): HitResult | undefined;
94
94
  export declare const openActionBattleActionBar: (player: RpgPlayer, rawOptions?: ActionBattleOptions) => void;
95
95
  export declare const updateActionBattleActionBar: (player: RpgPlayer, rawOptions?: ActionBattleOptions) => void;
96
- export declare const createActionBattleServer: (rawOptions?: ActionBattleOptions) => any;
97
- declare const _default: any;
96
+ export declare const createActionBattleServer: (rawOptions?: ActionBattleOptions) => RpgServer;
97
+ declare const _default: RpgServer;
98
98
  export default _default;
99
+ export { ACTION_BATTLE_HITBOX_FRAME_MS, ActionBattleHitTracker, createActionBattleAttackId, getNormalizedActionBattleAttackProfile, resolveActionBattleHitboxSpeed, scheduleActionBattleStartup, } from './core/attack-runtime';
100
+ export { DEFAULT_ACTION_BATTLE_ATTACK_PROFILE, normalizeActionBattleAttackProfile, type ActionBattleAttackProfileFallbacks, } from './core/attack-profile';
101
+ export type { ActionBattleAttackDirection, ActionBattleAttackHitboxConfig, ActionBattleAttackHitboxMap, ActionBattleAttackHitPolicy, ActionBattleAttackProfile, ActionBattleDebugOptions, ActionBattleHitReactionProfile, NormalizedActionBattleHitReactionProfile, NormalizedActionBattleAttackProfile, } from './types';
102
+ export { DEFAULT_ACTION_BATTLE_HIT_REACTION, isActionBattleEntityInvincible, normalizeActionBattleHitReaction, setActionBattleInvincibility, } from './core/hit-reaction';
103
+ export { DEFAULT_ACTION_BATTLE_ENEMY_ATTACK_PROFILES, normalizeActionBattleEnemyAttackProfiles, type ActionBattleEnemyAttackProfileKey, type ActionBattleEnemyAttackProfileMap, type NormalizedActionBattleEnemyAttackProfileMap, } from './core/enemy-attack-profiles';
104
+ export { resolveActionBattleWeaponAttackProfile } from './core/equipment';
105
+ export { AiDebug, AiState, AttackPattern, BattleAi, DEFAULT_KNOCKBACK, EnemyType, } from './ai.server';
106
+ export type { ApplyHitHooks, BattleAiDefeatedCallback, BattleAiDefeatedContext, BattleAiDefeatReward, BattleAiLegacyDefeatedCallback, BattleAiLegacyOptions, BattleAiOptions, BattleAiRewardItem, BattleAiRewards, HitResult, } from './ai.server';
@@ -0,0 +1,35 @@
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
+ }
11
+ export interface ActionBattleTargetingState {
12
+ active: boolean;
13
+ skill: ActionBattleActionBarSkill | null;
14
+ range: number;
15
+ offset: {
16
+ x: number;
17
+ y: number;
18
+ };
19
+ aoeMask: string[] | string;
20
+ }
21
+ export declare const actionBattleUiOptions: import('canvasengine').WritableObjectSignal<import('..').ActionBattleUiOptions>;
22
+ export declare const actionBattleSkillOptions: import('canvasengine').WritableObjectSignal<import('../types').ActionBattleSkillOptions>;
23
+ export declare const actionBattleTargetingState: import('canvasengine').WritableObjectSignal<ActionBattleTargetingState>;
24
+ export declare const actionBattleAttackPreviewState: import('canvasengine').WritableObjectSignal<ActionBattleAttackPreviewState>;
25
+ export declare const setActionBattleOptions: (options?: ActionBattleOptions) => void;
26
+ export declare const startTargeting: (skill: ActionBattleActionBarSkill) => void;
27
+ export declare const stopTargeting: () => void;
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;