wiki更新
This commit is contained in:
@@ -2,15 +2,21 @@
|
||||
|
||||
<cite>
|
||||
**本文档中引用的文件**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts)
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts)
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts)
|
||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts)
|
||||
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts)
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts) - *更新了属性类型和职业成长配置*
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts) - *更新了英雄实体初始化逻辑*
|
||||
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts) - *重构了属性组件,包含攻击状态管理*
|
||||
- [HeroViewComp.ts](file://assets\game\hero\HeroViewComp.ts) - *更新了视图组件,移除了攻击状态管理*
|
||||
- [heroSet.ts](file://assets\script\game\common\config\heroSet.ts) - *包含了英雄配置数据*
|
||||
- [GameEvent.ts](file://assets\script\game\common\config\GameEvent.ts) - *定义了游戏事件系统*
|
||||
</cite>
|
||||
|
||||
## 更新摘要
|
||||
**主要变更**
|
||||
- **架构重构**:将`is_atking`攻击状态从`HeroViewComp`视图层迁移至`HeroAttrsComp`数据层,实现状态管理集中化
|
||||
- **ECS架构优化**:为`HeroAttrSystem`等系统添加ECS注册装饰器,使架构更符合标准
|
||||
- **职责分离**:`HeroViewComp`不再管理攻击状态,仅负责UI表现和动画控制
|
||||
- **代码维护性提升**:通过将状态管理集中在数据层,提高了代码的可维护性和测试性
|
||||
|
||||
## 目录
|
||||
1. [简介](#简介)
|
||||
2. [项目结构](#项目结构)
|
||||
@@ -24,10 +30,12 @@
|
||||
|
||||
## 简介
|
||||
|
||||
英雄属性系统是游戏《heroes》的核心战斗机制之一,负责管理英雄的基础属性、成长属性、动态计算以及战斗中的实时更新。该系统采用模块化设计,通过HeroAttrs.ts定义属性枚举和配置,Hero.ts实现英雄实体管理,HeroViewComp.ts处理属性计算和UI更新,形成了完整的属性管理体系。
|
||||
英雄属性系统是游戏《heroes》的核心战斗机制之一,负责管理英雄的基础属性、成长属性、动态计算以及战斗中的实时更新。该系统采用模块化设计,通过HeroAttrs.ts定义属性枚举和配置,Hero.ts实现英雄实体管理,HeroAttrsComp.ts处理属性计算和状态管理,形成了完整的属性管理体系。
|
||||
|
||||
系统支持多种属性类型,包括基础生存属性、攻击属性、防御属性、特殊效果属性等,每种属性都有明确的数值型或百分比型分类。通过Buff系统实现属性的动态叠加和计算,确保战斗中的属性变化能够实时反映在UI界面中。
|
||||
|
||||
**更新说明**:根据最新代码重构,攻击状态`is_atking`已从视图层`HeroViewComp`迁移至数据层`HeroAttrsComp`,实现了状态管理的集中化。这一变更遵循了ECS架构的最佳实践,将数据状态与表现逻辑分离,提高了系统的可维护性和扩展性。
|
||||
|
||||
## 项目结构
|
||||
|
||||
英雄属性系统的核心文件分布在以下目录结构中:
|
||||
@@ -41,12 +49,12 @@ C[GameEvent.ts<br/>事件系统]
|
||||
end
|
||||
subgraph "实体管理层"
|
||||
D[Hero.ts<br/>英雄实体]
|
||||
E[HeroViewComp.ts<br/>视图组件]
|
||||
F[BuffComp.ts<br/>缓冲组件]
|
||||
E[HeroAttrsComp.ts<br/>属性组件]
|
||||
F[HeroViewComp.ts<br/>视图组件]
|
||||
end
|
||||
subgraph "战斗系统"
|
||||
G[Mon.ts<br/>怪物系统]
|
||||
H[BuffComp.ts<br/>UI组件]
|
||||
H[BuffComp.ts<br/>缓冲组件]
|
||||
end
|
||||
A --> D
|
||||
B --> D
|
||||
@@ -58,13 +66,13 @@ H --> F
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L1-L50)
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L30)
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L50)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L1-L50)
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L1-L30)
|
||||
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts#L1-L50)
|
||||
|
||||
**章节来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L1-L546)
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L100)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L1-L546)
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L1-L100)
|
||||
|
||||
## 核心组件
|
||||
|
||||
@@ -88,7 +96,7 @@ H --> F
|
||||
- **百分比型属性(RATIO)**:按百分比计算的相对数值,如暴击率、闪避率
|
||||
|
||||
**章节来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L142-L226)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L142-L226)
|
||||
|
||||
## 架构概览
|
||||
|
||||
@@ -98,28 +106,30 @@ H --> F
|
||||
sequenceDiagram
|
||||
participant Player as 玩家操作
|
||||
participant Hero as Hero实体
|
||||
participant Attrs as HeroAttrsComp
|
||||
participant View as HeroViewComp
|
||||
participant Buff as Buff系统
|
||||
participant UI as UI组件
|
||||
Player->>Hero : 创建英雄
|
||||
Hero->>View : hero_init()
|
||||
View->>View : 初始化基础属性
|
||||
View->>View : 初始化属性配置
|
||||
View->>Buff : initAttrs()
|
||||
Hero->>Attrs : hero_init()
|
||||
Attrs->>Attrs : 初始化基础属性
|
||||
Attrs->>Attrs : 初始化属性配置
|
||||
Attrs->>Buff : initAttrs()
|
||||
Note over Player,UI : 属性计算流程
|
||||
Player->>Buff : 添加Buff
|
||||
Buff->>View : recalculateSingleAttr()
|
||||
View->>View : 计算属性值
|
||||
View->>UI : 更新UI显示
|
||||
Buff->>Attrs : recalculateSingleAttr()
|
||||
Attrs->>Attrs : 计算属性值
|
||||
Attrs->>UI : 更新UI显示
|
||||
Note over Player,UI : 属性更新流程
|
||||
Player->>Buff : 属性变更
|
||||
Buff->>View : 触发重新计算
|
||||
View->>UI : 实时更新显示
|
||||
Player->>Attrs : 攻击状态变更
|
||||
Attrs->>Attrs : is_atking=true
|
||||
Attrs->>View : 触发攻击动画
|
||||
View->>UI : 播放攻击动画
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L65-L99)
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L165-L250)
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L65-L99)
|
||||
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts#L165-L250)
|
||||
|
||||
## 详细组件分析
|
||||
|
||||
@@ -166,8 +176,8 @@ Attrs --> NeAttrs : "负面状态"
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L10-L105)
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L8-L10)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L10-L105)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L8-L10)
|
||||
|
||||
#### 属性类型配置
|
||||
|
||||
@@ -203,11 +213,11 @@ style I fill:#c8e6c9
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L266-L439)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L266-L439)
|
||||
|
||||
**章节来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L106-L226)
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L266-L439)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L106-L226)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L266-L439)
|
||||
|
||||
### Hero.ts - 英雄实体管理
|
||||
|
||||
@@ -219,22 +229,22 @@ Hero.ts负责英雄实体的创建和基础属性初始化:
|
||||
sequenceDiagram
|
||||
participant Client as 客户端
|
||||
participant Hero as Hero实体
|
||||
participant Model as HeroModelComp
|
||||
participant Model as HeroAttrsComp
|
||||
participant View as HeroViewComp
|
||||
Client->>Hero : load(pos, scale, uuid)
|
||||
Hero->>Hero : 查找空闲槽位
|
||||
Hero->>Hero : 加载英雄预制体
|
||||
Hero->>Hero : 设置位置和缩放
|
||||
Hero->>Hero : hero_init(uuid, node)
|
||||
Hero->>View : 初始化属性配置
|
||||
Hero->>View : 设置基础属性值
|
||||
Hero->>View : 初始化属性系统
|
||||
Hero->>Model : 初始化属性配置
|
||||
Hero->>Model : 设置基础属性值
|
||||
Hero->>Model : 初始化属性系统
|
||||
Hero->>Model : 添加模型组件
|
||||
Hero-->>Client : 英雄加载完成
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L40-L99)
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L40-L99)
|
||||
|
||||
#### 基础属性设置
|
||||
|
||||
@@ -248,11 +258,11 @@ hero_init方法完成了英雄基础属性的初始化:
|
||||
| 技能列表 | 循环遍历 | 技能配置表 |
|
||||
|
||||
**章节来源**
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L65-L99)
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L65-L99)
|
||||
|
||||
### HeroViewComp.ts - 属性计算与UI更新
|
||||
### HeroAttrsComp.ts - 属性计算与状态管理
|
||||
|
||||
HeroViewComp.ts是属性系统的核心计算引擎,负责属性的动态计算和UI更新:
|
||||
HeroAttrsComp.ts是属性系统的核心计算引擎,负责属性的动态计算和状态管理:
|
||||
|
||||
#### 属性计算算法
|
||||
|
||||
@@ -279,39 +289,30 @@ style M fill:#e8f5e8
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L254-L354)
|
||||
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts#L254-L354)
|
||||
|
||||
#### Buff系统设计
|
||||
#### 状态管理重构
|
||||
|
||||
Buff系统支持持久和临时两种类型的Buff叠加:
|
||||
根据最新代码重构,`is_atking`攻击状态已从视图层迁移至数据层:
|
||||
|
||||
| Buff类型 | 存储位置 | 生命周期 | 计算方式 |
|
||||
|---------|---------|---------|---------|
|
||||
| 持久Buff | BUFFS | 手动清除 | 直接累加 |
|
||||
| 临时Buff | BUFFS_TEMP | 时间到期自动清除 | 时间递减计算 |
|
||||
| 增益Buff | 正数值 | - | 属性提升 |
|
||||
| 减益Buff | 负数值 | - | 属性削弱 |
|
||||
|
||||
#### 属性计算公式
|
||||
|
||||
系统根据不同属性类型采用不同的计算公式:
|
||||
|
||||
**百分比型属性公式**:
|
||||
```
|
||||
最终值 = 基础值 + 所有数值型Buff之和 + 所有百分比Buff之和
|
||||
```typescript
|
||||
// HeroAttrsComp.ts - 数据层状态管理
|
||||
export class HeroAttrsComp extends ecs.Comp {
|
||||
// ... 其他属性
|
||||
is_atking: boolean = false; // 是否正在攻击
|
||||
is_stop: boolean = false; // 是否正在停止
|
||||
// ... 其他状态
|
||||
}
|
||||
```
|
||||
|
||||
**数值型属性公式**:
|
||||
```
|
||||
最终值 = (基础值 + 所有数值型Buff之和) × (1 + 所有百分比Buff之和/100)
|
||||
```
|
||||
这一变更实现了状态管理的集中化,符合ECS架构的最佳实践。
|
||||
|
||||
**章节来源**
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L165-L354)
|
||||
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts#L7-L380)
|
||||
|
||||
### BuffComp.ts - UI组件集成
|
||||
### HeroViewComp.ts - UI更新与动画控制
|
||||
|
||||
BuffComp.ts负责将属性变化实时反映到UI界面上:
|
||||
HeroViewComp.ts现在仅负责UI表现和动画控制,不再管理攻击状态:
|
||||
|
||||
#### UI更新机制
|
||||
|
||||
@@ -335,11 +336,11 @@ Note over Attr,UI : 护盾更新流程
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts#L44-L80)
|
||||
- [HeroViewComp.ts](file://assets\script\game\hero\HeroViewComp.ts#L44-L80)
|
||||
|
||||
#### UI组件类型
|
||||
|
||||
BuffComp管理多种UI组件:
|
||||
HeroViewComp管理多种UI组件:
|
||||
|
||||
| UI组件 | 功能 | 更新触发 |
|
||||
|-------|------|---------|
|
||||
@@ -350,7 +351,7 @@ BuffComp管理多种UI组件:
|
||||
| 状态图标 | 显示负面状态 | 状态切换 |
|
||||
|
||||
**章节来源**
|
||||
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts#L1-L80)
|
||||
- [HeroViewComp.ts](file://assets\script\game\hero\HeroViewComp.ts#L1-L80)
|
||||
|
||||
### Mon.ts - 怪物属性系统
|
||||
|
||||
@@ -366,7 +367,7 @@ Mon.ts继承了英雄的属性系统,但针对怪物进行了优化:
|
||||
| UI更新 | 实时同步 | 基础显示 |
|
||||
|
||||
**章节来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L87-L108)
|
||||
- [Mon.ts](file://assets\script\game\hero\Mon.ts#L87-L108)
|
||||
|
||||
## 依赖关系分析
|
||||
|
||||
@@ -381,8 +382,8 @@ C[GameEvent.ts]
|
||||
end
|
||||
subgraph "实体层"
|
||||
D[Hero.ts]
|
||||
E[HeroViewComp.ts]
|
||||
F[BuffComp.ts]
|
||||
E[HeroAttrsComp.ts]
|
||||
F[HeroViewComp.ts]
|
||||
end
|
||||
subgraph "战斗层"
|
||||
G[Mon.ts]
|
||||
@@ -402,8 +403,8 @@ style E fill:#e8f5e8
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L1-L20)
|
||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L20)
|
||||
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L1-L20)
|
||||
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L1-L20)
|
||||
|
||||
### 模块间通信
|
||||
|
||||
@@ -417,7 +418,7 @@ style E fill:#e8f5e8
|
||||
| 数据绑定 | 状态管理 | MVVM模式 |
|
||||
|
||||
**章节来源**
|
||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts#L1-L70)
|
||||
- [GameEvent.ts](file://assets\script\game\common\config\GameEvent.ts#L1-L70)
|
||||
|
||||
## 性能考虑
|
||||
|
||||
@@ -486,7 +487,7 @@ style E fill:#e8f5e8
|
||||
3. 检查内存使用情况
|
||||
|
||||
**章节来源**
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L385-L425)
|
||||
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts#L385-L425)
|
||||
|
||||
## 结论
|
||||
|
||||
@@ -498,4 +499,6 @@ style E fill:#e8f5e8
|
||||
4. **实时UI同步**:确保属性变化能够即时反映在用户界面上
|
||||
5. **性能优化**:通过多种优化策略保证系统的流畅运行
|
||||
|
||||
**架构演进**:最新的代码重构将`is_atking`攻击状态从视图层迁移至数据层,实现了状态管理的集中化。这一变更遵循了ECS架构的最佳实践,提高了代码的可维护性和测试性。通过将数据状态与表现逻辑分离,系统变得更加健壮和可扩展。
|
||||
|
||||
该系统为游戏提供了坚实的战斗基础,支持丰富的角色定制和战斗策略,是整个游戏体验的重要组成部分。随着游戏的发展,这套属性系统已经证明了其良好的扩展性和稳定性,能够适应未来更多的功能需求。
|
||||
Reference in New Issue
Block a user