@rpgjs/action-battle 5.0.0-beta.11 → 5.0.0-beta.12
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/CHANGELOG.md +11 -0
- package/dist/client/ai.server.d.ts +45 -8
- package/dist/client/attack-input.d.ts +3 -0
- package/dist/client/core/action-use.d.ts +18 -0
- package/dist/client/core/ai-behavior-tree.d.ts +99 -0
- package/dist/client/core/attack-runtime.d.ts +2 -0
- package/dist/client/core/defaults.d.ts +2 -1
- package/dist/client/core/equipment.d.ts +1 -0
- package/dist/client/core/targets.d.ts +15 -0
- package/dist/client/enemies/factory.d.ts +2 -0
- package/dist/client/index.d.ts +12 -7
- package/dist/client/index.js +16 -11
- package/dist/client/index10.js +32 -56
- package/dist/client/index11.js +99 -52
- package/dist/client/index12.js +76 -103
- package/dist/client/index13.js +72 -135
- package/dist/client/index14.js +67 -23
- package/dist/client/index15.js +197 -63
- package/dist/client/index16.js +112 -1337
- package/dist/client/index17.js +193 -7
- package/dist/client/index18.js +32 -58
- package/dist/client/index19.js +70 -8
- package/dist/client/index20.js +57 -501
- package/dist/client/index21.js +69 -0
- package/dist/client/index22.js +225 -0
- package/dist/client/index23.js +16 -0
- package/dist/client/index24.js +25 -0
- package/dist/client/index25.js +107 -0
- package/dist/client/index26.js +1707 -0
- package/dist/client/index27.js +12 -0
- package/dist/client/index28.js +589 -0
- package/dist/client/index4.js +79 -38
- package/dist/client/index6.js +65 -306
- package/dist/client/index7.js +33 -33
- package/dist/client/index8.js +24 -100
- package/dist/client/index9.js +293 -61
- package/dist/client/locomotion.d.ts +16 -0
- package/dist/client/movement.d.ts +14 -0
- package/dist/client/server.d.ts +7 -3
- package/dist/client/ui.d.ts +22 -0
- package/dist/client/visual.d.ts +15 -0
- package/dist/server/ai.server.d.ts +45 -8
- package/dist/server/attack-input.d.ts +3 -0
- package/dist/server/core/action-use.d.ts +18 -0
- package/dist/server/core/ai-behavior-tree.d.ts +99 -0
- package/dist/server/core/attack-runtime.d.ts +2 -0
- package/dist/server/core/defaults.d.ts +2 -1
- package/dist/server/core/equipment.d.ts +1 -0
- package/dist/server/core/targets.d.ts +15 -0
- package/dist/server/enemies/factory.d.ts +2 -0
- package/dist/server/index.d.ts +12 -7
- package/dist/server/index.js +14 -9
- package/dist/server/index10.js +64 -1336
- package/dist/server/index11.js +33 -33
- package/dist/server/index13.js +66 -11
- package/dist/server/index14.js +206 -484
- package/dist/server/index15.js +15 -9
- package/dist/server/index16.js +26 -0
- package/dist/server/index17.js +25 -0
- package/dist/server/index18.js +107 -0
- package/dist/server/index19.js +1707 -0
- package/dist/server/index2.js +10 -2
- package/dist/server/index20.js +37 -0
- package/dist/server/index21.js +588 -0
- package/dist/server/index22.js +78 -0
- package/dist/server/index23.js +12 -0
- package/dist/server/index5.js +79 -38
- package/dist/server/index6.js +192 -129
- package/dist/server/index7.js +198 -24
- package/dist/server/index8.js +28 -66
- package/dist/server/index9.js +68 -51
- package/dist/server/locomotion.d.ts +16 -0
- package/dist/server/movement.d.ts +14 -0
- package/dist/server/server.d.ts +7 -3
- package/dist/server/ui.d.ts +22 -0
- package/dist/server/visual.d.ts +15 -0
- package/package.json +5 -5
- package/src/ai.server.spec.ts +233 -0
- package/src/ai.server.ts +627 -108
- package/src/animations.spec.ts +40 -0
- package/src/animations.ts +31 -9
- package/src/attack-input.spec.ts +51 -0
- package/src/attack-input.ts +59 -0
- package/src/client.ts +75 -62
- package/src/config.ts +84 -37
- package/src/core/action-use.spec.ts +317 -0
- package/src/core/action-use.ts +386 -0
- package/src/core/ai-behavior-tree.spec.ts +116 -0
- package/src/core/ai-behavior-tree.ts +272 -0
- package/src/core/attack-profile.spec.ts +46 -0
- package/src/core/attack-runtime.spec.ts +35 -0
- package/src/core/attack-runtime.ts +32 -0
- package/src/core/context.ts +9 -0
- package/src/core/contracts.ts +146 -1
- package/src/core/defaults.ts +56 -0
- package/src/core/equipment.ts +9 -5
- package/src/core/targets.spec.ts +112 -0
- package/src/core/targets.ts +147 -0
- package/src/enemies/factory.ts +8 -0
- package/src/index.ts +111 -2
- package/src/locomotion.spec.ts +51 -0
- package/src/locomotion.ts +48 -0
- package/src/movement.spec.ts +78 -0
- package/src/movement.ts +46 -0
- package/src/server.ts +242 -66
- package/src/types.ts +105 -35
- package/src/ui.ts +113 -0
- package/src/visual.spec.ts +166 -0
- package/src/visual.ts +285 -0
- package/README.md +0 -1242
package/dist/server/index15.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//#region src/core/equipment.ts
|
|
2
|
+
var resolveItemId = (item) => item?.id?.() ?? item?.id;
|
|
3
|
+
function resolveActionBattleWeapon(entity) {
|
|
4
|
+
const equipments = entity?.equipments?.() || [];
|
|
5
|
+
for (const item of equipments) {
|
|
6
|
+
const itemId = resolveItemId(item);
|
|
7
|
+
const itemData = entity?.databaseById?.(itemId);
|
|
8
|
+
if (itemData?._type === "weapon") return itemData;
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
function resolveActionBattleWeaponAttackProfile(entity) {
|
|
13
|
+
return resolveActionBattleWeapon(entity)?.attackProfile ?? null;
|
|
14
|
+
}
|
|
9
15
|
//#endregion
|
|
10
|
-
export {
|
|
16
|
+
export { resolveActionBattleWeapon, resolveActionBattleWeaponAttackProfile };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/locomotion.ts
|
|
2
|
+
var withActionBattleAnimationUnlocked = (entity, callback) => {
|
|
3
|
+
if (!entity) return callback();
|
|
4
|
+
const previousAnimationFixed = entity.animationFixed;
|
|
5
|
+
entity.animationFixed = false;
|
|
6
|
+
try {
|
|
7
|
+
return callback();
|
|
8
|
+
} finally {
|
|
9
|
+
entity.animationFixed = previousAnimationFixed;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Force a locomotion animation even when an action lock temporarily froze
|
|
14
|
+
* animation changes. This keeps server state and local rendering coherent
|
|
15
|
+
* after attack recovery interrupts movement.
|
|
16
|
+
*/
|
|
17
|
+
var forceActionBattleLocomotionAnimation = (entity, animationName) => {
|
|
18
|
+
if (!entity) return;
|
|
19
|
+
withActionBattleAnimationUnlocked(entity, () => {
|
|
20
|
+
if (typeof entity.resetAnimationState === "function") entity.resetAnimationState();
|
|
21
|
+
if (typeof entity.setGraphicAnimation === "function") entity.setGraphicAnimation(animationName);
|
|
22
|
+
else if (typeof entity.animationName?.set === "function") entity.animationName.set(animationName);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { forceActionBattleLocomotionAnimation, withActionBattleAnimationUnlocked };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/movement.ts
|
|
2
|
+
var UNRESOLVED_ENTITY_MESSAGE = "unable to resolve entity";
|
|
3
|
+
var isActionBattleMovementResolutionError = (error) => {
|
|
4
|
+
return (error instanceof Error ? error.message : String(error ?? "")).includes(UNRESOLVED_ENTITY_MESSAGE);
|
|
5
|
+
};
|
|
6
|
+
var hasActionBattlePhysicsBody = (entity) => {
|
|
7
|
+
if (!entity) return false;
|
|
8
|
+
const map = entity.getCurrentMap?.();
|
|
9
|
+
if (!map) return false;
|
|
10
|
+
if (typeof map.getBody !== "function" || !entity.id) return true;
|
|
11
|
+
return Boolean(map.getBody(entity.id));
|
|
12
|
+
};
|
|
13
|
+
var safeActionBattleDash = (entity, direction, additionalSpeed, duration) => {
|
|
14
|
+
if (!entity || typeof entity.dash !== "function") return false;
|
|
15
|
+
if (!hasActionBattlePhysicsBody(entity)) return false;
|
|
16
|
+
try {
|
|
17
|
+
entity.dash(direction, additionalSpeed, duration);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (isActionBattleMovementResolutionError(error)) return false;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { safeActionBattleDash };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region src/core/ai-behavior-tree.ts
|
|
2
|
+
var isTreeNode = (input) => Boolean(input && typeof input.tick === "function");
|
|
3
|
+
var normalizeTreeResult = (result) => result ?? { status: "failure" };
|
|
4
|
+
var runIntentInput = (input, context) => {
|
|
5
|
+
if (isTreeNode(input)) return input.tick(context);
|
|
6
|
+
return {
|
|
7
|
+
status: "success",
|
|
8
|
+
intent: typeof input === "function" ? input(context) : input
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
var defineAiTree = (input) => {
|
|
12
|
+
if (isTreeNode(input)) return input;
|
|
13
|
+
return { tick(context) {
|
|
14
|
+
return normalizeTreeResult(input(context));
|
|
15
|
+
} };
|
|
16
|
+
};
|
|
17
|
+
var selector = (children) => ({ tick(context) {
|
|
18
|
+
for (const child of children) {
|
|
19
|
+
const result = defineAiTree(child).tick(context);
|
|
20
|
+
if (result.status !== "failure") return result;
|
|
21
|
+
}
|
|
22
|
+
return { status: "failure" };
|
|
23
|
+
} });
|
|
24
|
+
var sequence = (children) => ({ tick(context) {
|
|
25
|
+
let last = { status: "success" };
|
|
26
|
+
for (const child of children) {
|
|
27
|
+
last = defineAiTree(child).tick(context);
|
|
28
|
+
if (last.status !== "success") return last;
|
|
29
|
+
}
|
|
30
|
+
return last;
|
|
31
|
+
} });
|
|
32
|
+
var condition = (predicate) => ({ tick(context) {
|
|
33
|
+
return { status: predicate(context) ? "success" : "failure" };
|
|
34
|
+
} });
|
|
35
|
+
var action = (input, status = "success") => ({ tick(context) {
|
|
36
|
+
return {
|
|
37
|
+
...runIntentInput(input, context),
|
|
38
|
+
status
|
|
39
|
+
};
|
|
40
|
+
} });
|
|
41
|
+
var decision = (resolve) => ({ tick(context) {
|
|
42
|
+
return {
|
|
43
|
+
status: "success",
|
|
44
|
+
decision: typeof resolve === "function" ? resolve(context) : resolve
|
|
45
|
+
};
|
|
46
|
+
} });
|
|
47
|
+
var rule = (predicate, then) => ({
|
|
48
|
+
condition: predicate,
|
|
49
|
+
then
|
|
50
|
+
});
|
|
51
|
+
var defineAiBehavior = (behavior) => {
|
|
52
|
+
const branches = [...(behavior.when ?? []).map((entry) => sequence([condition(entry.condition), action(entry.then)]))];
|
|
53
|
+
if (behavior.otherwise) branches.push(action(behavior.otherwise));
|
|
54
|
+
return selector(branches);
|
|
55
|
+
};
|
|
56
|
+
var hpBelow = (ratio) => {
|
|
57
|
+
return ({ self }) => self.hpPercent !== null && self.hpPercent < ratio;
|
|
58
|
+
};
|
|
59
|
+
var targetVisible = () => {
|
|
60
|
+
return ({ targetInfo }) => Boolean(targetInfo?.visible);
|
|
61
|
+
};
|
|
62
|
+
var targetInRange = (range) => {
|
|
63
|
+
return ({ self, targetInfo }) => {
|
|
64
|
+
if (!targetInfo) return false;
|
|
65
|
+
return targetInfo.distance <= (range ?? self.attackRange);
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var distanceLessThan = (distance) => {
|
|
69
|
+
return ({ targetInfo }) => targetInfo !== null && targetInfo.distance < distance;
|
|
70
|
+
};
|
|
71
|
+
var inState = (state) => {
|
|
72
|
+
return ({ self }) => self.state === state;
|
|
73
|
+
};
|
|
74
|
+
var isEnemyType = (enemyType) => {
|
|
75
|
+
return ({ self }) => self.enemyType === enemyType;
|
|
76
|
+
};
|
|
77
|
+
var idle = () => ({ type: "idle" });
|
|
78
|
+
var patrol = () => ({ type: "patrol" });
|
|
79
|
+
var faceTarget = () => ({ type: "faceTarget" });
|
|
80
|
+
var chase = () => ({ type: "moveToTarget" });
|
|
81
|
+
var moveToTarget = chase;
|
|
82
|
+
var flee = () => ({ type: "fleeFromTarget" });
|
|
83
|
+
var fleeFromTarget = flee;
|
|
84
|
+
var keepDistance = (distance, tolerance) => ({
|
|
85
|
+
type: "keepDistance",
|
|
86
|
+
distance,
|
|
87
|
+
tolerance
|
|
88
|
+
});
|
|
89
|
+
var useAttack = (pattern) => ({
|
|
90
|
+
type: "useAttack",
|
|
91
|
+
pattern
|
|
92
|
+
});
|
|
93
|
+
var useSkill = (skill) => ({
|
|
94
|
+
type: "useSkill",
|
|
95
|
+
skill
|
|
96
|
+
});
|
|
97
|
+
var setMode = (mode) => ({
|
|
98
|
+
type: "setMode",
|
|
99
|
+
mode,
|
|
100
|
+
consume: false
|
|
101
|
+
});
|
|
102
|
+
var ifHpBelow = (ratio, then) => rule(hpBelow(ratio), then);
|
|
103
|
+
var ifTargetVisible = (then) => rule(targetVisible(), then);
|
|
104
|
+
var ifTargetInRange = (then, range) => rule(targetInRange(range), then);
|
|
105
|
+
var ifDistanceLessThan = (distance, then) => rule(distanceLessThan(distance), then);
|
|
106
|
+
//#endregion
|
|
107
|
+
export { action, chase, condition, decision, defineAiBehavior, defineAiTree, distanceLessThan, faceTarget, flee, fleeFromTarget, hpBelow, idle, ifDistanceLessThan, ifHpBelow, ifTargetInRange, ifTargetVisible, inState, isEnemyType, keepDistance, moveToTarget, patrol, rule, selector, sequence, setMode, targetInRange, targetVisible, useAttack, useSkill };
|