hrbattle 1.0.1 → 1.0.2
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.
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { BattleResult } from "../battle/battleCore";
|
|
2
|
+
import { type BattleJsonConfigBundle, type HeroInput } from "../battle/config/jsonConfigLoader";
|
|
3
|
+
import type { BattleConfig, BattleInitUnit, ISkillScript } from "../battle/types";
|
|
4
|
+
export interface ReusableBattleFacadeOptions {
|
|
5
|
+
bundle?: BattleJsonConfigBundle;
|
|
6
|
+
scripts?: Record<string, ISkillScript>;
|
|
7
|
+
defaultConfig?: BattleConfig;
|
|
8
|
+
validateBundle?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class ReusableBattleFacade {
|
|
11
|
+
private readonly facade;
|
|
12
|
+
private readonly bundle;
|
|
13
|
+
private readonly scripts;
|
|
14
|
+
private defaultConfig?;
|
|
15
|
+
constructor(options?: ReusableBattleFacadeOptions);
|
|
16
|
+
getBundle(): BattleJsonConfigBundle;
|
|
17
|
+
setDefaultConfig(config: BattleConfig): void;
|
|
18
|
+
buildUnits(team1?: HeroInput[], team2?: HeroInput[]): BattleInitUnit[];
|
|
19
|
+
startWithUnits(units: BattleInitUnit[], config?: Partial<BattleConfig>): BattleResult;
|
|
20
|
+
startWithLineup(team1?: HeroInput[], team2?: HeroInput[], config?: Partial<BattleConfig>): BattleResult;
|
|
21
|
+
stop(): void;
|
|
22
|
+
private resolveConfig;
|
|
23
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { buildBattleUnitsFromJsonBundle, loadBattleJsonConfigBundle, validateBattleJsonConfigBundle } from "../battle/config/jsonConfigLoader";
|
|
2
|
+
import { designedScripts } from "../battle/script/designedScripts";
|
|
3
|
+
import { BattleFacade } from "./BattleFacade";
|
|
4
|
+
export class ReusableBattleFacade {
|
|
5
|
+
facade = new BattleFacade();
|
|
6
|
+
bundle;
|
|
7
|
+
scripts;
|
|
8
|
+
defaultConfig;
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.bundle = options.bundle ?? loadBattleJsonConfigBundle();
|
|
11
|
+
this.scripts = options.scripts ?? designedScripts;
|
|
12
|
+
this.defaultConfig = options.defaultConfig;
|
|
13
|
+
if (options.validateBundle !== false) {
|
|
14
|
+
validateBattleJsonConfigBundle(this.bundle);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
getBundle() {
|
|
18
|
+
return this.bundle;
|
|
19
|
+
}
|
|
20
|
+
setDefaultConfig(config) {
|
|
21
|
+
this.defaultConfig = { ...config };
|
|
22
|
+
}
|
|
23
|
+
buildUnits(team1, team2) {
|
|
24
|
+
return buildBattleUnitsFromJsonBundle(this.bundle, team1, team2);
|
|
25
|
+
}
|
|
26
|
+
startWithUnits(units, config) {
|
|
27
|
+
return this.facade.start(units, this.resolveConfig(config), (core) => {
|
|
28
|
+
core.getEffectSystem().registerBuffConfigs(this.bundle.buffs);
|
|
29
|
+
core.getConfigSkillEngine().registerTemplates(this.bundle.skillTemplates);
|
|
30
|
+
for (const [scriptId, script] of Object.entries(this.scripts)) {
|
|
31
|
+
core.registerSkillScript(scriptId, script);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
startWithLineup(team1, team2, config) {
|
|
36
|
+
return this.startWithUnits(this.buildUnits(team1, team2), config);
|
|
37
|
+
}
|
|
38
|
+
stop() {
|
|
39
|
+
this.facade.stop();
|
|
40
|
+
}
|
|
41
|
+
resolveConfig(config) {
|
|
42
|
+
const resolved = {
|
|
43
|
+
...this.defaultConfig,
|
|
44
|
+
...config
|
|
45
|
+
};
|
|
46
|
+
if (typeof resolved.seed !== "number" || typeof resolved.maxTurns !== "number") {
|
|
47
|
+
throw new Error("missing-battle-config:seed|maxTurns");
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
seed: resolved.seed,
|
|
51
|
+
maxTurns: resolved.maxTurns
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BattleCore } from "./battle/battleCore";
|
|
2
2
|
export { BattleFacade } from "./cocos-adapter/BattleFacade";
|
|
3
|
+
export { ReusableBattleFacade } from "./cocos-adapter/ReusableBattleFacade";
|
|
3
4
|
export { buildClientBattleResult } from "./cocos-adapter/clientBattleResult";
|
|
4
5
|
export type { BuildClientBattleResultInput, ClientAction, ClientActionStateRef, ClientBattleResult, ClientImbalanceChange, ClientPanelBuffDelta, ClientPositionChange, ClientStateSettlementDelta, ClientStatChange, ClientTurnSettlement } from "./cocos-adapter/clientBattleResult";
|
|
5
6
|
export { BattleEventBus } from "./battle/eventBus";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BattleCore } from "./battle/battleCore";
|
|
2
2
|
export { BattleFacade } from "./cocos-adapter/BattleFacade";
|
|
3
|
+
export { ReusableBattleFacade } from "./cocos-adapter/ReusableBattleFacade";
|
|
3
4
|
export { buildClientBattleResult } from "./cocos-adapter/clientBattleResult";
|
|
4
5
|
export { BattleEventBus } from "./battle/eventBus";
|
|
5
6
|
export { EffectSystem } from "./battle/effectSystem";
|