wiki更新

This commit is contained in:
panw
2025-10-30 16:49:19 +08:00
parent 40e0086be3
commit 93ceaa70e4
18 changed files with 746 additions and 1100 deletions

View File

@@ -10,8 +10,19 @@
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts)
- [ecs.md](file://doc/ecs/ecs.md)
- [Main.ts](file://assets/script/Main.ts)
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts) - *在最近的提交中更新*
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts) - *在最近的提交中更新*
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts) - *在最近的提交中添加*
</cite>
## 更新摘要
**已做更改**
- 更新了组件注册机制部分以反映在多个系统中添加ECS注册装饰器的更改
- 添加了关于技能系统的新部分包括CastSkillRequestComp、SkillCastSystem、SkillCDSystem和SkillAutocastSystem
- 更新了实际案例分析,以包含新的技能系统实现
- 在扩展开发指南中添加了新的系统接口示例
- 更新了文档来源以包含新分析的文件
## 目录
1. [简介](#简介)
2. [ECS架构概述](#ecs架构概述)
@@ -66,7 +77,7 @@ end
### 组件注册机制
组件通过装饰器`@ecs.register`进行注册,框架自动管理组件的生命周期和内存回收。
组件通过装饰器`@ecs.register`进行注册,框架自动管理组件的生命周期和内存回收。最近的代码重构为多个英雄系统添加了ECS注册装饰器使架构更符合标准。
```mermaid
classDiagram
@@ -336,6 +347,123 @@ HeroViewComp实现了复杂的BUFF/DEBUFF管理系统
**章节来源**
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L780)
### 技能系统架构分析
最近的代码重构为技能系统添加了ECS注册装饰器创建了一套完整的技能处理系统。
#### 技能系统组件
```mermaid
classDiagram
class CastSkillRequestComp {
+number skillIndex
+Vec3[] targetPositions
+reset() void
}
class HeroSkillsComp {
+Skill[] skills
+canCast(index, mp) boolean
+getReadySkills(mp) number[]
+resetCD(index) void
+updateCDs(dt) void
}
class SkillEnt {
+load(startPos, parent, skillId, targets, caster, extraDamage) void
}
```
**章节来源**
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L17-L29)
- [HeroSkills.ts](file://assets/script/game/hero/HeroSkills.ts#L1-L200)
#### 技能系统层次结构
```mermaid
classDiagram
class System {
<<abstract>>
+execute(dt) void
}
class ComblockSystem {
+filter() IMatcher
+update(entity) void
+entityEnter(entity) void
+entityRemove(entity) void
}
class SkillCastSystem {
+filter() IMatcher
+entityEnter(e) void
+checkCastConditions(skillsData, heroModel, skillIndex) boolean
+executeCast(casterEntity, skill, targetPositions, heroView) void
+createSkillEntity(skillId, caster, targetPositions) void
}
class SkillCDSystem {
+filter() IMatcher
+update(e) void
}
class SkillAutocastSystem {
+filter() IMatcher
+update(e) void
+selectTargets(caster) Vec3[]
}
System <|-- ComblockSystem
ComblockSystem <|-- SkillCastSystem
ComblockSystem <|-- SkillCDSystem
ComblockSystem <|-- SkillAutocastSystem
```
**章节来源**
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L47-L271)
#### 技能施法流程
```mermaid
sequenceDiagram
participant Auto as SkillAutocastSystem
participant Cast as SkillCastSystem
participant Entity as Entity
participant Skill as SkillEnt
Auto->>Entity : update()
Auto->>Entity : add(CastSkillRequestComp)
Cast->>Entity : entityEnter()
Cast->>Entity : checkCastConditions()
Cast->>Entity : executeCast()
Cast->>Entity : playSkillEffect()
Cast->>Cast : createSkillEntity()
Cast->>Skill : load()
Cast->>Entity : remove(CastSkillRequestComp)
```
**图表来源**
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L47-L171)
#### 技能系统功能分析
新的技能系统架构体现了ECS设计的几个关键优势
1. **职责分离**
- `SkillAutocastSystem`:负责决策"何时施法"
- `SkillCastSystem`:负责处理"如何施法"
- `SkillCDSystem`:负责管理"技能冷却"
2. **标记驱动设计**
- 使用`CastSkillRequestComp`作为标记组件
- 避免了直接调用系统方法的耦合
- 符合ECS的声明式编程理念
3. **可扩展性**
- 可以轻松添加新的施法策略系统
- 可以复用相同的施法执行逻辑
- 支持玩家输入和AI系统共享同一套施法机制
4. **调试友好**
- 每个系统都有详细的日志输出
- 可以独立启用/禁用调试模式
- 明确的执行流程便于问题排查
**章节来源**
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L271)
## 性能优化与最佳实践
### 内存管理策略
@@ -432,6 +560,11 @@ export class NewSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
| `IEntityEnterSystem` | 实体首次进入 | 初始化实体状态 |
| `IEntityRemoveSystem` | 实体移除处理 | 清理资源和状态 |
| `ISystemFirstUpdate` | 系统首次更新 | 系统初始化逻辑 |
| `ISystemDebug` | 调试模式 | 开发阶段的调试信息输出 |
**章节来源**
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L47-L271)
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts#L18-L247)
### 扩展示例