hrbattle 0.1.0 → 1.0.0
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.
|
@@ -22,5 +22,11 @@ export interface BattleJsonConfigBundle {
|
|
|
22
22
|
}
|
|
23
23
|
export declare function loadBattleJsonConfigBundle(): BattleJsonConfigBundle;
|
|
24
24
|
export declare function validateBattleJsonConfigBundle(bundle: BattleJsonConfigBundle): void;
|
|
25
|
-
|
|
25
|
+
/** 英雄入参:可以是纯 heroId 字符串,也可以带技能等级覆盖 */
|
|
26
|
+
export type HeroInput = string | {
|
|
27
|
+
heroId: string;
|
|
28
|
+
/** 技能等级覆盖,key 为 skillId,value 为等级数值 */
|
|
29
|
+
skillLevels?: Record<string, number>;
|
|
30
|
+
};
|
|
31
|
+
export declare function buildBattleUnitsFromJsonBundle(bundle: BattleJsonConfigBundle, team1?: HeroInput[], team2?: HeroInput[]): BattleInitUnit[];
|
|
26
32
|
export {};
|
|
@@ -46,13 +46,21 @@ function cloneStats(stats) {
|
|
|
46
46
|
function buildUnitInstanceId(teamId, position, heroId) {
|
|
47
47
|
return `t${teamId}_p${position}_${heroId}`;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
function normalizeHeroInput(input) {
|
|
50
|
+
if (typeof input === "string")
|
|
51
|
+
return { heroId: input };
|
|
52
|
+
return input;
|
|
53
|
+
}
|
|
54
|
+
export function buildBattleUnitsFromJsonBundle(bundle, team1, team2) {
|
|
55
|
+
const team1Inputs = team1 ?? bundle.roster.defaultLineup.team1;
|
|
56
|
+
const team2Inputs = team2 ?? bundle.roster.defaultLineup.team2;
|
|
50
57
|
const heroBookMap = new Map([
|
|
51
58
|
...bundle.heroSkillBooks.map((item) => [item.heroId, item]),
|
|
52
59
|
...bundle.monsterSkillBooks.map((item) => [item.heroId, item]),
|
|
53
60
|
]);
|
|
54
|
-
const buildTeam = (teamId,
|
|
55
|
-
return
|
|
61
|
+
const buildTeam = (teamId, inputs) => {
|
|
62
|
+
return inputs.map((input, index) => {
|
|
63
|
+
const { heroId, skillLevels } = normalizeHeroInput(input);
|
|
56
64
|
const heroBook = heroBookMap.get(heroId);
|
|
57
65
|
if (!heroBook) {
|
|
58
66
|
throw new Error(`missing-hero-skill-book:${heroId}`);
|
|
@@ -69,9 +77,15 @@ export function buildBattleUnitsFromJsonBundle(bundle, team1HeroIds = bundle.ros
|
|
|
69
77
|
position,
|
|
70
78
|
element: heroBook.element,
|
|
71
79
|
stats: cloneStats(stats),
|
|
72
|
-
skills: heroBook.skills.map((skill) =>
|
|
80
|
+
skills: heroBook.skills.map((skill) => {
|
|
81
|
+
const cloned = { ...skill };
|
|
82
|
+
if (skillLevels && skillLevels[skill.id] !== undefined) {
|
|
83
|
+
cloned.level = skillLevels[skill.id];
|
|
84
|
+
}
|
|
85
|
+
return cloned;
|
|
86
|
+
})
|
|
73
87
|
};
|
|
74
88
|
});
|
|
75
89
|
};
|
|
76
|
-
return [...buildTeam(1,
|
|
90
|
+
return [...buildTeam(1, team1Inputs), ...buildTeam(2, team2Inputs)];
|
|
77
91
|
}
|
package/dist/battle/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type TeamId = 1 | 2;
|
|
2
2
|
export type UnitId = string;
|
|
3
3
|
export type ElementType = "fire" | "thunder" | "water" | "rock" | "wind" | "light" | "dark";
|
|
4
|
-
export type SkillType = "basic" | "core" | "ultimate";
|
|
4
|
+
export type SkillType = "basic" | "core" | "ultimate" | "passive";
|
|
5
5
|
export type SkillExecMode = "config" | "script" | "hybrid";
|
|
6
6
|
export type BattleEventName = "OnTurnStart" | "OnTurnEnd" | "OnBeforeCast" | "OnAfterCast" | "OnBeforeDamage" | "OnAfterDamage" | "OnKill" | "OnDeath" | "OnBuffAdd" | "OnBuffRemove" | "OnExtraTurnGranted" | "OnImbalanceBreak" | "OnDamageDealt" | "BeforeDamageTaken";
|
|
7
7
|
export interface UnitStats {
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export { EffectSystem } from "./battle/effectSystem";
|
|
|
7
7
|
export { calcDamage, calcEffectProbability, calcHealOrShield } from "./battle/formula";
|
|
8
8
|
export { ConfigSkillEngine, ScriptSkillEngine, SkillExecutor } from "./battle/skillEngine";
|
|
9
9
|
export { designedScripts } from "./battle/script/designedScripts";
|
|
10
|
+
export { loadBattleJsonConfigBundle, validateBattleJsonConfigBundle, buildBattleUnitsFromJsonBundle } from "./battle/config/jsonConfigLoader";
|
|
11
|
+
export type { BattleJsonConfigBundle, HeroInput } from "./battle/config/jsonConfigLoader";
|
|
10
12
|
export type { BattleScriptApi, BattleConfig, BattleInitUnit, BuffConfig, ISkillScript, SkillDefinition, SkillExecMode, SkillTemplate, UnitModel, UnitStats } from "./battle/types";
|
package/dist/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { EffectSystem } from "./battle/effectSystem";
|
|
|
6
6
|
export { calcDamage, calcEffectProbability, calcHealOrShield } from "./battle/formula";
|
|
7
7
|
export { ConfigSkillEngine, ScriptSkillEngine, SkillExecutor } from "./battle/skillEngine";
|
|
8
8
|
export { designedScripts } from "./battle/script/designedScripts";
|
|
9
|
+
export { loadBattleJsonConfigBundle, validateBattleJsonConfigBundle, buildBattleUnitsFromJsonBundle } from "./battle/config/jsonConfigLoader";
|