hrbattle 0.1.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.
- package/README.md +103 -0
- package/dist/battle/battleCore.d.ts +83 -0
- package/dist/battle/battleCore.js +779 -0
- package/dist/battle/config/json/designed-buffs.json +608 -0
- package/dist/battle/config/json/designed-hero-skill-books.json +146 -0
- package/dist/battle/config/json/designed-monster-skill-books.json +308 -0
- package/dist/battle/config/json/designed-roster.json +438 -0
- package/dist/battle/config/json/designed-skill-templates.json +81 -0
- package/dist/battle/config/jsonConfigLoader.d.ts +26 -0
- package/dist/battle/config/jsonConfigLoader.js +77 -0
- package/dist/battle/effectSystem.d.ts +26 -0
- package/dist/battle/effectSystem.js +175 -0
- package/dist/battle/eventBus.d.ts +8 -0
- package/dist/battle/eventBus.js +20 -0
- package/dist/battle/formula.d.ts +19 -0
- package/dist/battle/formula.js +92 -0
- package/dist/battle/logger.d.ts +28 -0
- package/dist/battle/logger.js +66 -0
- package/dist/battle/random.d.ts +6 -0
- package/dist/battle/random.js +16 -0
- package/dist/battle/script/designedScripts.d.ts +2 -0
- package/dist/battle/script/designedScripts.js +1013 -0
- package/dist/battle/script/monsterScripts.d.ts +2 -0
- package/dist/battle/script/monsterScripts.js +277 -0
- package/dist/battle/script/monsterScripts18xx.d.ts +2 -0
- package/dist/battle/script/monsterScripts18xx.js +330 -0
- package/dist/battle/script/monsterScripts19xx.d.ts +2 -0
- package/dist/battle/script/monsterScripts19xx.js +271 -0
- package/dist/battle/script/monsterScripts19xxPart2.d.ts +2 -0
- package/dist/battle/script/monsterScripts19xxPart2.js +400 -0
- package/dist/battle/skillEngine.d.ts +36 -0
- package/dist/battle/skillEngine.js +246 -0
- package/dist/battle/targeting.d.ts +3 -0
- package/dist/battle/targeting.js +38 -0
- package/dist/battle/turnbar.d.ts +8 -0
- package/dist/battle/turnbar.js +40 -0
- package/dist/battle/types.d.ts +302 -0
- package/dist/battle/types.js +1 -0
- package/dist/cocos-adapter/BattleFacade.d.ts +8 -0
- package/dist/cocos-adapter/BattleFacade.js +22 -0
- package/dist/cocos-adapter/clientBattleResult.d.ts +127 -0
- package/dist/cocos-adapter/clientBattleResult.js +413 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/package.json +32 -0
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# 勇者再就业战斗系统(hrbattle)
|
|
2
|
+
|
|
3
|
+
## 项目简介
|
|
4
|
+
这是《勇者再就业》的核心战斗系统项目。
|
|
5
|
+
战斗采用回合制框架,并结合“走条”机制驱动行动顺序,整体体验参考阴阳师式速度条战斗:
|
|
6
|
+
- 角色并非严格按固定回合轮流出手
|
|
7
|
+
- 行动顺序由速度与行动条推进共同决定
|
|
8
|
+
- 战斗节奏可通过技能、增益、减益进行动态干预
|
|
9
|
+
|
|
10
|
+
## 战斗机制概览
|
|
11
|
+
### 1) 走条与行动顺序
|
|
12
|
+
- 每个单位拥有独立行动条进度
|
|
13
|
+
- 行动条随时间推进,推进速度与单位速度属性相关
|
|
14
|
+
- 当行动条达到阈值后,单位获得行动权
|
|
15
|
+
- 行动结束后清空或回退行动条,并重新进入推进循环
|
|
16
|
+
|
|
17
|
+
### 2) 回合与单位行动
|
|
18
|
+
- 系统层面以“单位行动”为最小回合单位
|
|
19
|
+
- 单位行动通常包含:选择技能 → 目标判定 → 结算伤害/治疗/状态 → 触发被动
|
|
20
|
+
- 支持普通攻击、主动技能、被动技能、连击、反击等战斗行为扩展
|
|
21
|
+
|
|
22
|
+
### 3) 状态与效果系统
|
|
23
|
+
- 支持增益、减益、控制、护盾、持续伤害、持续治疗等常见效果
|
|
24
|
+
- 支持按时机触发:行动前、受击时、行动后、回合结束时
|
|
25
|
+
- 支持持续回合数与叠层管理
|
|
26
|
+
|
|
27
|
+
### 4) 胜负判定
|
|
28
|
+
- 一方全灭判负
|
|
29
|
+
- 支持拓展特殊条件:回合上限、守护目标存活、指定单位击杀等
|
|
30
|
+
|
|
31
|
+
## 设计目标
|
|
32
|
+
- 高可扩展:便于新增角色、技能、效果类型
|
|
33
|
+
- 高可配置:尽量通过配置驱动战斗内容,而非硬编码
|
|
34
|
+
- 易调试:关键流程可追踪、可回放、可复现
|
|
35
|
+
- 易平衡:参数结构清晰,方便数值迭代
|
|
36
|
+
|
|
37
|
+
## 推荐模块划分
|
|
38
|
+
- `BattleCore`:战斗主循环与状态机
|
|
39
|
+
- `TurnBarSystem`:行动条推进与行动权分配
|
|
40
|
+
- `TurnBarSystem`:行动条推进与行动权分配
|
|
41
|
+
- `SkillSystem`:技能释放流程与目标选择
|
|
42
|
+
- `EffectSystem`:Buff/Debuff 生命周期与触发
|
|
43
|
+
- `DamageSystem`:伤害、治疗、护盾等数值结算
|
|
44
|
+
- `VictorySystem`:胜负条件判定与战斗结束流程
|
|
45
|
+
- `BattleLogger`:战斗日志、事件流、回放数据输出
|
|
46
|
+
|
|
47
|
+
## 开发建议
|
|
48
|
+
### 配置驱动
|
|
49
|
+
- 角色基础属性、技能参数、效果模板建议数据化
|
|
50
|
+
- 战斗逻辑与表现层解耦,便于前后端或客户端模块协作
|
|
51
|
+
|
|
52
|
+
### 测试与验证
|
|
53
|
+
- 为关键流程建立最小可复现战斗样例
|
|
54
|
+
- 覆盖关键场景:先手争夺、控制链、反击链、DOT 结算、死亡触发
|
|
55
|
+
- 用固定随机种子验证战斗可复现性
|
|
56
|
+
|
|
57
|
+
## 快速开始
|
|
58
|
+
当前仓库为战斗系统项目骨架,后续可按以下步骤完善:
|
|
59
|
+
1. 定义角色属性与战斗单位数据结构
|
|
60
|
+
2. 实现行动条推进与行动权分配
|
|
61
|
+
3. 接入技能与效果结算流程
|
|
62
|
+
4. 完成胜负判定与战斗日志输出
|
|
63
|
+
5. 建立自动化测试与关键战斗样例
|
|
64
|
+
|
|
65
|
+
## 技能模板逐级数值配置
|
|
66
|
+
- 支持在模板 step 上按等级配置独立数值:
|
|
67
|
+
- `ratioByLevel: number[]`
|
|
68
|
+
- `flatByLevel: number[]`
|
|
69
|
+
- `fixedProbByLevel: number[]`
|
|
70
|
+
- 优先级:`*ByLevel` 高于单值字段(`ratio`、`flat`、`fixedProb`)。
|
|
71
|
+
- 等级越界策略:当技能等级超过数组长度时,使用最后一个数组值。
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"id": "example.skill",
|
|
76
|
+
"steps": [
|
|
77
|
+
{
|
|
78
|
+
"kind": "damage",
|
|
79
|
+
"ratio": 0.5,
|
|
80
|
+
"ratioByLevel": [0.5, 0.62, 0.74, 0.86, 0.98],
|
|
81
|
+
"scaleStat": "Att"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"kind": "buff",
|
|
85
|
+
"ratio": 0,
|
|
86
|
+
"buffId": "slow",
|
|
87
|
+
"fixedProb": 6000,
|
|
88
|
+
"fixedProbByLevel": [6000, 7000, 8000, 9000, 10000]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 贡献指南
|
|
95
|
+
1. Fork 本仓库
|
|
96
|
+
2. 新建分支(例如 `feature/turn-bar`)
|
|
97
|
+
3. 提交改动并补充必要说明
|
|
98
|
+
4. 发起 Pull Request
|
|
99
|
+
|
|
100
|
+
## 版本规划建议
|
|
101
|
+
- `v0.1`:最小可运行战斗闭环(走条 + 普攻 + 胜负判定)
|
|
102
|
+
- `v0.2`:技能系统与常规状态效果
|
|
103
|
+
- `v0.3`:复杂触发链、日志回放与测试体系完善
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { BattleEventBus } from "./eventBus";
|
|
2
|
+
import { EffectSystem } from "./effectSystem";
|
|
3
|
+
import { BattleLogger } from "./logger";
|
|
4
|
+
import { ConfigSkillEngine, ScriptSkillEngine } from "./skillEngine";
|
|
5
|
+
import type { BattleConfig, BattleInitUnit, ISkillScript, SkillDefinition, TriggerContext, UnitId, UnitModel } from "./types";
|
|
6
|
+
export interface BattleResult {
|
|
7
|
+
winner: 1 | 2 | 0;
|
|
8
|
+
totalTurns: number;
|
|
9
|
+
logs: BattleLogger;
|
|
10
|
+
}
|
|
11
|
+
type ChasePredicate = (ctx: TriggerContext, actor: UnitModel) => boolean;
|
|
12
|
+
type ChaseSkillResolver = (actor: UnitModel) => SkillDefinition | undefined;
|
|
13
|
+
export declare class BattleCore {
|
|
14
|
+
private readonly initUnits;
|
|
15
|
+
private readonly config;
|
|
16
|
+
private readonly units;
|
|
17
|
+
private readonly rng;
|
|
18
|
+
private readonly eventBus;
|
|
19
|
+
private readonly turnBar;
|
|
20
|
+
private readonly logger;
|
|
21
|
+
private readonly effectSystem;
|
|
22
|
+
private readonly configSkillEngine;
|
|
23
|
+
private readonly scriptSkillEngine;
|
|
24
|
+
private readonly skillExecutor;
|
|
25
|
+
private readonly skillSlots;
|
|
26
|
+
private readonly chasePredicates;
|
|
27
|
+
private readonly chaseSkillResolvers;
|
|
28
|
+
private readonly pendingImbalanceClear;
|
|
29
|
+
private readonly pendingReactiveCounters;
|
|
30
|
+
private scriptPassivesInitialized;
|
|
31
|
+
private activeSkillContext;
|
|
32
|
+
private turn;
|
|
33
|
+
private actionCount;
|
|
34
|
+
constructor(initUnits: BattleInitUnit[], config: BattleConfig);
|
|
35
|
+
getEventBus(): BattleEventBus;
|
|
36
|
+
getLogger(): BattleLogger;
|
|
37
|
+
getEffectSystem(): EffectSystem;
|
|
38
|
+
getConfigSkillEngine(): ConfigSkillEngine;
|
|
39
|
+
getScriptSkillEngine(): ScriptSkillEngine;
|
|
40
|
+
getUnitById(unitId: UnitId): UnitModel | undefined;
|
|
41
|
+
addBuffToUnit(sourceId: UnitId, targetId: UnitId, buffId: string): void;
|
|
42
|
+
/** 动态召唤一个新单位加入战斗 */
|
|
43
|
+
spawnUnit(initUnit: BattleInitUnit): UnitModel | null;
|
|
44
|
+
/** 延长目标单位所有主动技能的冷却回合数 */
|
|
45
|
+
extendCooldown(unitId: UnitId, delta: number): void;
|
|
46
|
+
/** 击杀指定单位 */
|
|
47
|
+
killUnit(unitId: UnitId): void;
|
|
48
|
+
grantActionProgress(unitId: UnitId, ratio: number): void;
|
|
49
|
+
registerSkillScript(scriptId: string, script: ISkillScript): void;
|
|
50
|
+
registerChase(predicate: ChasePredicate, resolver: ChaseSkillResolver): void;
|
|
51
|
+
private registerReactiveCounterRules;
|
|
52
|
+
private processPendingReactiveCounters;
|
|
53
|
+
private consumeBuffStack;
|
|
54
|
+
private registerConfiguredChaseRules;
|
|
55
|
+
run(): BattleResult;
|
|
56
|
+
private initializeScriptPassives;
|
|
57
|
+
private performAction;
|
|
58
|
+
private canCast;
|
|
59
|
+
private executeSkill;
|
|
60
|
+
private tryChaseAndAssist;
|
|
61
|
+
private applyDamage;
|
|
62
|
+
private applyHeal;
|
|
63
|
+
private applyShield;
|
|
64
|
+
private applyImbalanceDelta;
|
|
65
|
+
private computeImbalanceMax;
|
|
66
|
+
private accumulateStagger;
|
|
67
|
+
private onImbalanceBreak;
|
|
68
|
+
private applyBuff;
|
|
69
|
+
private applyTurnStart;
|
|
70
|
+
private applyTurnEnd;
|
|
71
|
+
private gainEnergy;
|
|
72
|
+
private gainEnergyToUnit;
|
|
73
|
+
private decrementAllCooldowns;
|
|
74
|
+
private getSlots;
|
|
75
|
+
private rearrangePositions;
|
|
76
|
+
private winner;
|
|
77
|
+
private resolveWinnerByRule;
|
|
78
|
+
private hpRatio;
|
|
79
|
+
private mustUnit;
|
|
80
|
+
private maxUltimateCost;
|
|
81
|
+
private snapshotBuffs;
|
|
82
|
+
}
|
|
83
|
+
export {};
|