wiki更新
This commit is contained in:
@@ -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)
|
||||
|
||||
### 扩展示例
|
||||
|
||||
|
||||
@@ -2,20 +2,27 @@
|
||||
|
||||
<cite>
|
||||
**本文档中引用的文件**
|
||||
- [Main.ts](file://assets/script/Main.ts)
|
||||
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts)
|
||||
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts)
|
||||
- [EcsPositionSystem.ts](file://assets/script/game/common/ecs/position/EcsPositionSystem.ts)
|
||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts)
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
||||
- [HeroModelComp.ts](file://assets/script/game/hero/HeroModelComp.ts)
|
||||
- [Main.ts](file://assets/script/Main.ts) - *更新了ECS系统注册*
|
||||
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts#L1-L207)
|
||||
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts#L1-L195)
|
||||
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L272) - *新增ECS系统注册装饰器*
|
||||
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts#L1-L248) - *新增ECS系统注册装饰器*
|
||||
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L1-L380) - *新增ECS组件注册装饰器*
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L780)
|
||||
- [MapModelComp.ts](file://assets/script/game/map/model/MapModelComp.ts)
|
||||
- [MapViewComp.ts](file://assets/script/game/map/view/MapViewComp.ts)
|
||||
- [ecs.md](file://doc/ecs/ecs.md)
|
||||
- [MvvmInfo.md](file://doc/mvvm/MvvmInfo.md)
|
||||
</cite>
|
||||
|
||||
## 更新摘要
|
||||
**变更内容**
|
||||
- 在HSkillSystem.ts、HeroAtk.ts和HeroAttrsComp.ts中添加了ECS注册装饰器
|
||||
- Main.ts的初始化流程更新,反映架构入口点调整
|
||||
- 移除了过时的SkillConComp组件,更新技能系统架构说明
|
||||
- 新增了英雄属性更新系统(HeroAttrSystem)和生命周期系统(HeroLifecycleSystem)的文档
|
||||
- 更新了ECS架构支柱章节,反映最新的系统注册模式
|
||||
|
||||
## 目录
|
||||
1. [引言](#引言)
|
||||
2. [项目架构概览](#项目架构概览)
|
||||
@@ -89,10 +96,15 @@ class ecs_Comp {
|
||||
+canRecycle boolean
|
||||
+ent Entity
|
||||
}
|
||||
class BattleMoveComp {
|
||||
+direction number
|
||||
+targetX number
|
||||
+moving boolean
|
||||
class HeroAttrsComp {
|
||||
+hero_uuid number
|
||||
+lv number
|
||||
+base_ap number
|
||||
+base_hp number
|
||||
+hp number
|
||||
+mp number
|
||||
+Attrs any
|
||||
+BUFFS any
|
||||
+reset() void
|
||||
}
|
||||
class HeroViewComp {
|
||||
@@ -104,44 +116,48 @@ class HeroViewComp {
|
||||
+BUFFS any
|
||||
+update(dt) void
|
||||
}
|
||||
class HeroModelComp {
|
||||
+reset() void
|
||||
class HeroSkillsComp {
|
||||
+skills SkillSlot[]
|
||||
+initSkills(skillIds) void
|
||||
+canCast(index, mp) boolean
|
||||
+resetCD(index) void
|
||||
+updateCDs(dt) void
|
||||
}
|
||||
ecs_Comp <|-- BattleMoveComp
|
||||
ecs_Comp <|-- HeroAttrsComp
|
||||
ecs_Comp <|-- HeroViewComp
|
||||
ecs_Comp <|-- HeroModelComp
|
||||
ecs_Comp <|-- HeroSkillsComp
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L1-L16)
|
||||
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L7-L380) - *新增ECS组件注册*
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L780)
|
||||
- [HeroModelComp.ts](file://assets/script/game/hero/HeroModelComp.ts#L1-L13)
|
||||
- [HeroSkills.ts](file://assets/script/game/hero/HeroSkills.ts#L1-L150)
|
||||
|
||||
### 系统协作机制
|
||||
|
||||
系统通过过滤器机制实现高效的实体管理:
|
||||
系统通过过滤器机制实现高效的实体管理,并使用ECS注册装饰器进行系统注册:
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant RS as RootSystem
|
||||
participant BS as BattleMoveSystem
|
||||
participant HSS as HeroAttrSystem
|
||||
participant ECS as ECS引擎
|
||||
participant Entity as 实体
|
||||
participant Comp as 组件
|
||||
RS->>ECS : 执行系统
|
||||
ECS->>BS : filter()匹配实体
|
||||
BS->>Entity : 获取BattleMoveComp
|
||||
BS->>Entity : 获取HeroViewComp
|
||||
BS->>Entity : update()处理逻辑
|
||||
ECS->>HSS : filter()匹配实体
|
||||
HSS->>Entity : 获取HeroAttrsComp
|
||||
HSS->>Entity : update()处理逻辑
|
||||
Entity->>Comp : 更新状态
|
||||
Comp-->>Entity : 返回结果
|
||||
Entity-->>BS : 完成处理
|
||||
BS-->>RS : 系统执行完毕
|
||||
Entity-->>HSS : 完成处理
|
||||
HSS-->>RS : 系统执行完毕
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L1-L272)
|
||||
- [EcsPositionSystem.ts](file://assets/script/game/common/ecs/position/EcsPositionSystem.ts#L1-L9)
|
||||
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L272) - *新增ECS系统注册装饰器*
|
||||
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts#L1-L248) - *新增ECS系统注册装饰器*
|
||||
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L397-L437) - *新增HeroAttrSystem*
|
||||
|
||||
### ECS解耦优势
|
||||
|
||||
@@ -154,7 +170,7 @@ ECS架构在游戏逻辑中实现了以下解耦效果:
|
||||
|
||||
**章节来源**
|
||||
- [ecs.md](file://doc/ecs/ecs.md#L1-L357)
|
||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L1-L272)
|
||||
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L272) - *新增ECS系统注册装饰器*
|
||||
|
||||
## MVVM架构支柱
|
||||
|
||||
@@ -314,7 +330,7 @@ LoadConfig --> SetupGUI[设置GUI框架]
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [Main.ts](file://assets/script/Main.ts#L15-L41)
|
||||
- [Main.ts](file://assets/script/Main.ts#L15-L41) - *更新了ECS系统注册*
|
||||
|
||||
### 初始化流程详解
|
||||
|
||||
|
||||
Reference in New Issue
Block a user