- Added BattleState class to manage battle flow, including turn management and event handling. - Introduced BuffInstance class to represent buffs applied to combatants. - Created CardInstance class to handle card definitions and cost calculations. - Developed CombatantState class to manage combatant attributes and actions. - Implemented EffectRegistry to apply effects based on event specifications. - Added various handlers (BlockHandler, DamageHandler, DrawHandler, etc.) to process specific events. - Created IntentPlanner and IntentState classes to manage enemy actions and intents. - Established a queue system for handling battle events with BattleEventQueue and BattleEventTask. - Introduced triggers for applying effects based on game events (e.g., OnCardDrawnGainBlockTrigger). - Added necessary UID files for new scripts to ensure proper resource management.
2.9 KiB
2.9 KiB
战斗系统统一事件内核重构交接文档
1. 背景
当前项目规模较小,团队决定采用激进重构:
- 一次性切换到统一事件队列执行模型。
- 不再保留旧执行路径作为长期主线。
- 先保证架构正确,再扩展玩法细节。
2. 最终目标
- 卡牌效果和 Buff 效果统一为事件生产者。
- 所有战斗效果统一经 BattleEventQueue 执行。
- 出牌器和抽牌器可在单点位置切换。
- 新增普通卡仅需一个 CardDef 资源文件。
3. 强制约束
- 命令层禁止直改 hp/block/strength/weak。
- 二次触发事件必须追加队尾。
- 触发顺序固定:速度/权重 -> acquire_index。
- 策略返回空动作时不自动结束回合。
4. 重构阶段
Phase 1 文档先行
- 更新架构文档术语与流程。
- 交付本交接文档给团队统一口径。
Phase 2 事件内核
- 新建 BattleEventType/BattleEventPayload/BattleEventTask/BattleEventQueue。
- 建立队列执行循环和防循环机制。
Phase 3 处理器
- 落地 Damage/Block/Weak/Draw/Discard 处理器。
- BattleState 收敛为状态容器与原子操作。
Phase 4 Buff触发器
- Buff 改为 TriggerSubscriber + BuffInstance。
- 增加常见触发器模板:抽牌、伤害、出牌、弃牌、回合。
Phase 5 命令事件化
- PlayCardCommand 只发 CARD_PLAY_REQUESTED。
- EndTurnCommand 只发 TURN_END_REQUESTED 和敌方行动请求。
Phase 6 策略化与单点切换
- 引入 BattleRuleProvider 作为唯一规则入口。
- 引入 AutoPlayPolicy 和 DrawPolicy。
- 预置四种出牌策略和一种标准抽牌策略。
Phase 7 内容模型
- CardDef 补齐卡面、稀有度、描述、目标和效果。
- EffectSpec 改为事件模板。
- ConditionSpec 变可执行过滤器。
Phase 8 测试与验收
- 建立队列顺序、防循环、触发器、策略切换测试。
- 建立单卡单文件新增可用性测试。
5. 代码落点
- Game/Presentation/Battle/Scripts/BattleController.gd
- Game/Application/Commands/PlayCardCommand.gd
- Game/Application/Commands/EndTurnCommand.gd
- Game/Runtime/BattleState.gd
- Game/Runtime/CombatantState.gd
- Game/Infrastructure/BattleEventBus.gd
- Game/Content/Cards/CardDef.gd
- Game/Content/Cards/EffectSpec.gd
- Game/Content/Cards/ConditionSpec.gd
新增目录建议:
- Game/Runtime/Queue
- Game/Runtime/Handlers
- Game/Runtime/Triggers
- Game/Runtime/Buffs
- Game/Runtime/AutoPlay
- Game/Runtime/Draw
- Game/Runtime/Rules
6. 验收清单
- 命令层不存在直改战斗属性。
- 所有效果执行都经过 BattleEventQueue。
- 触发顺序规则稳定并可复现。
- 仅改 BattleRuleProvider 可切换策略。
- 新增普通卡只需一个 CardDef 文件。
7. 团队协作建议
- 事件内核、处理器、策略层分工并行。
- 每个 Phase 独立验收后再合并。
- 禁止跨 Phase 混改,防止回归定位困难。