@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.
- package/README.md +161 -22
- package/dist/ai.server.d.ts +55 -4
- package/dist/client/index.js +13 -8
- package/dist/client/index10.js +54 -136
- package/dist/client/index11.js +52 -23
- package/dist/client/index12.js +101 -1217
- package/dist/client/index13.js +139 -42
- package/dist/client/index14.js +23 -8
- package/dist/client/index15.js +68 -444
- package/dist/client/index16.js +1343 -0
- package/dist/client/index17.js +13 -0
- package/dist/client/index18.js +60 -0
- package/dist/client/index19.js +10 -0
- package/dist/client/index2.js +25 -87
- package/dist/client/index20.js +504 -0
- package/dist/client/index3.js +45 -83
- package/dist/client/index4.js +98 -297
- package/dist/client/index5.js +81 -33
- package/dist/client/index6.js +284 -78
- package/dist/client/index7.js +33 -74
- package/dist/client/index8.js +95 -55
- package/dist/client/index9.js +75 -96
- package/dist/core/attack-profile.d.ts +9 -0
- package/dist/core/attack-runtime.d.ts +20 -0
- package/dist/core/enemy-attack-profiles.d.ts +6 -0
- package/dist/core/equipment.d.ts +2 -0
- package/dist/core/hit-reaction.d.ts +5 -0
- package/dist/index.d.ts +7 -2
- package/dist/server/index.js +12 -7
- package/dist/server/index10.js +1340 -8
- package/dist/server/index11.js +37 -0
- package/dist/server/index12.js +60 -0
- package/dist/server/index13.js +13 -0
- package/dist/server/index14.js +503 -0
- package/dist/server/index15.js +10 -0
- package/dist/server/index2.js +1 -1
- package/dist/server/index3.js +25 -87
- package/dist/server/index4.js +45 -141
- package/dist/server/index5.js +104 -21
- package/dist/server/index6.js +137 -1215
- package/dist/server/index7.js +22 -34
- package/dist/server/index8.js +70 -44
- package/dist/server/index9.js +44 -437
- package/dist/server.d.ts +8 -2
- package/dist/ui/state.d.ts +5 -5
- package/package.json +5 -5
- package/src/ai.server.spec.ts +120 -0
- package/src/ai.server.ts +362 -56
- package/src/client.ts +21 -12
- package/src/config.ts +17 -2
- package/src/core/attack-profile.spec.ts +118 -0
- package/src/core/attack-profile.ts +100 -0
- package/src/core/attack-runtime.spec.ts +103 -0
- package/src/core/attack-runtime.ts +83 -0
- package/src/core/contracts.ts +3 -0
- package/src/core/enemy-attack-profiles.spec.ts +35 -0
- package/src/core/enemy-attack-profiles.ts +103 -0
- package/src/core/equipment.spec.ts +37 -0
- package/src/core/equipment.ts +17 -0
- package/src/core/hit-reaction.spec.ts +43 -0
- package/src/core/hit-reaction.ts +70 -0
- package/src/core/hit.spec.ts +54 -1
- package/src/core/hit.ts +26 -0
- package/src/index.ts +48 -1
- package/src/server.ts +192 -34
- package/src/types.ts +62 -6
package/dist/server.d.ts
CHANGED
|
@@ -90,11 +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
96
|
export declare const createActionBattleServer: (rawOptions?: ActionBattleOptions) => RpgServer;
|
|
97
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';
|
|
99
105
|
export { AiDebug, AiState, AttackPattern, BattleAi, DEFAULT_KNOCKBACK, EnemyType, } from './ai.server';
|
|
100
|
-
export type { ApplyHitHooks, BattleAiOptions, HitResult } from './ai.server';
|
|
106
|
+
export type { ApplyHitHooks, BattleAiDefeatedCallback, BattleAiDefeatedContext, BattleAiDefeatReward, BattleAiLegacyDefeatedCallback, BattleAiLegacyOptions, BattleAiOptions, BattleAiRewardItem, BattleAiRewards, HitResult, } from './ai.server';
|
package/dist/ui/state.d.ts
CHANGED
|
@@ -18,10 +18,10 @@ export interface ActionBattleTargetingState {
|
|
|
18
18
|
};
|
|
19
19
|
aoeMask: string[] | string;
|
|
20
20
|
}
|
|
21
|
-
export declare const actionBattleUiOptions:
|
|
22
|
-
export declare const actionBattleSkillOptions:
|
|
23
|
-
export declare const actionBattleTargetingState:
|
|
24
|
-
export declare const actionBattleAttackPreviewState:
|
|
21
|
+
export declare const actionBattleUiOptions: any;
|
|
22
|
+
export declare const actionBattleSkillOptions: any;
|
|
23
|
+
export declare const actionBattleTargetingState: any;
|
|
24
|
+
export declare const actionBattleAttackPreviewState: any;
|
|
25
25
|
export declare const setActionBattleOptions: (options?: ActionBattleOptions) => void;
|
|
26
26
|
export declare const startTargeting: (skill: ActionBattleActionBarSkill) => void;
|
|
27
27
|
export declare const stopTargeting: () => void;
|
|
@@ -31,5 +31,5 @@ export declare const startAttackPreview: (options: {
|
|
|
31
31
|
durationMs?: number;
|
|
32
32
|
color?: number;
|
|
33
33
|
accentColor?: number;
|
|
34
|
-
}) =>
|
|
34
|
+
}) => any;
|
|
35
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
|
+
"version": "5.0.0-beta.7",
|
|
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.
|
|
27
|
-
"@rpgjs/common": "5.0.0-beta.
|
|
28
|
-
"@rpgjs/server": "5.0.0-beta.
|
|
29
|
-
"@rpgjs/vite": "5.0.0-beta.
|
|
26
|
+
"@rpgjs/client": "5.0.0-beta.7",
|
|
27
|
+
"@rpgjs/common": "5.0.0-beta.7",
|
|
28
|
+
"@rpgjs/server": "5.0.0-beta.7",
|
|
29
|
+
"@rpgjs/vite": "5.0.0-beta.7",
|
|
30
30
|
"canvasengine": "*"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { MAXHP } from "@rpgjs/server";
|
|
2
|
+
import { afterEach, describe, expect, test, vi } from "vitest";
|
|
3
|
+
import { BattleAi } from "./ai.server";
|
|
4
|
+
|
|
5
|
+
const createEvent = () => ({
|
|
6
|
+
id: "monster-1",
|
|
7
|
+
hp: 0,
|
|
8
|
+
param: {
|
|
9
|
+
[MAXHP]: 10,
|
|
10
|
+
},
|
|
11
|
+
attachShape: vi.fn(),
|
|
12
|
+
flash: vi.fn(),
|
|
13
|
+
showHit: vi.fn(),
|
|
14
|
+
setGraphicAnimation: vi.fn(),
|
|
15
|
+
stopMoveTo: vi.fn(),
|
|
16
|
+
getCurrentMap: vi.fn(() => ({})),
|
|
17
|
+
remove: vi.fn(),
|
|
18
|
+
x: vi.fn(() => 0),
|
|
19
|
+
y: vi.fn(() => 0),
|
|
20
|
+
direction: vi.fn(() => "down"),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const createPlayer = () => ({
|
|
24
|
+
id: "player-1",
|
|
25
|
+
exp: 0,
|
|
26
|
+
gold: 0,
|
|
27
|
+
addItem: vi.fn(() => ({ name: () => "Potion" })),
|
|
28
|
+
showNotification: vi.fn(),
|
|
29
|
+
getCurrentMap: vi.fn(() => ({
|
|
30
|
+
database: () => ({
|
|
31
|
+
potion: { icon: "potion-icon" },
|
|
32
|
+
}),
|
|
33
|
+
})),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("BattleAi defeat flow", () => {
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
vi.useRealTimers();
|
|
39
|
+
vi.restoreAllMocks();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("awards the attacker and requests a defeated remove transition", () => {
|
|
43
|
+
const event = createEvent();
|
|
44
|
+
const attacker = createPlayer();
|
|
45
|
+
const ai = new BattleAi(event as any, {
|
|
46
|
+
animations: {
|
|
47
|
+
die: {
|
|
48
|
+
animationName: "die",
|
|
49
|
+
repeat: 1,
|
|
50
|
+
delayMs: 700,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
rewards: {
|
|
54
|
+
exp: 25,
|
|
55
|
+
gold: 7,
|
|
56
|
+
items: [{ itemId: "potion", amount: 2, chance: 100 }],
|
|
57
|
+
showNotification: true,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(ai.handleDamage(attacker as any, { damage: 10, defeated: true })).toBe(true);
|
|
62
|
+
|
|
63
|
+
expect(attacker.exp).toBe(25);
|
|
64
|
+
expect(attacker.gold).toBe(7);
|
|
65
|
+
expect(attacker.addItem).toHaveBeenCalledWith("potion", 2);
|
|
66
|
+
expect(event.setGraphicAnimation).not.toHaveBeenCalledWith("die", 1);
|
|
67
|
+
expect(event.remove).toHaveBeenCalledWith({
|
|
68
|
+
reason: "defeated",
|
|
69
|
+
data: {
|
|
70
|
+
animation: expect.objectContaining({
|
|
71
|
+
animationName: "die",
|
|
72
|
+
delayMs: 700,
|
|
73
|
+
}),
|
|
74
|
+
},
|
|
75
|
+
transition: {
|
|
76
|
+
animation: "die",
|
|
77
|
+
graphic: undefined,
|
|
78
|
+
duration: 700,
|
|
79
|
+
},
|
|
80
|
+
timeoutMs: 700,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("supports the context onDefeated callback and manual reward control", () => {
|
|
85
|
+
const event = createEvent();
|
|
86
|
+
const attacker = createPlayer();
|
|
87
|
+
const onDefeated = vi.fn(({ reward }) => {
|
|
88
|
+
expect(reward.awarded).toBe(false);
|
|
89
|
+
reward.giveTo(attacker as any);
|
|
90
|
+
expect(reward.awarded).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
const ai = new BattleAi(event as any, {
|
|
93
|
+
autoAwardRewards: false,
|
|
94
|
+
rewards: {
|
|
95
|
+
exp: 10,
|
|
96
|
+
},
|
|
97
|
+
onDefeated,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
ai.handleDamage(attacker as any, { damage: 10, defeated: true });
|
|
101
|
+
|
|
102
|
+
expect(onDefeated).toHaveBeenCalledWith(
|
|
103
|
+
expect.objectContaining({
|
|
104
|
+
event,
|
|
105
|
+
attacker,
|
|
106
|
+
reward: expect.any(Object),
|
|
107
|
+
remove: expect.any(Function),
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
expect(attacker.exp).toBe(10);
|
|
111
|
+
expect(event.remove).toHaveBeenCalledWith({
|
|
112
|
+
reason: "defeated",
|
|
113
|
+
data: {
|
|
114
|
+
animation: null,
|
|
115
|
+
},
|
|
116
|
+
transition: undefined,
|
|
117
|
+
timeoutMs: 0,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|