wiki更新
This commit is contained in:
@@ -15,14 +15,16 @@
|
|||||||
- [MapLayer.ts](file://assets/script/game/map/view/map/layer/MapLayer.ts)
|
- [MapLayer.ts](file://assets/script/game/map/view/map/layer/MapLayer.ts)
|
||||||
- [EntityLayer.ts](file://assets/script/game/map/view/map/layer/EntityLayer.ts)
|
- [EntityLayer.ts](file://assets/script/game/map/view/map/layer/EntityLayer.ts)
|
||||||
- [SkillLayer.ts](file://assets/script/game/map/view/map/layer/SkillLayer.ts)
|
- [SkillLayer.ts](file://assets/script/game/map/view/map/layer/SkillLayer.ts)
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts) - *在最近提交中更新*
|
||||||
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts) - *在最近提交中更新*
|
||||||
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts) - *在最近提交中更新*
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
## 更新摘要
|
## 更新摘要
|
||||||
**已更新内容**
|
**已更新内容**
|
||||||
- 更新了“随机关卡生成逻辑分析”章节,反映使用 `MonType` 枚举重构的怪物生成系统
|
- 更新了“怪物实体设计模式分析”章节,反映使用 `HeroAttrsComp` 和 `MonMoveComp` 的重构
|
||||||
- 更新了“怪物实体设计模式分析”章节,以包含新的 `monType` 和 `buffs` 参数
|
- 更新了“依赖分析”图表,反映 `Mon.ts` 和 `MissionMonComp.ts` 的变更
|
||||||
- 更新了“依赖分析”图表,反映 `RogueConfig.ts` 和 `MissionMonComp.ts` 的变更
|
- 新增了“怪物属性与移动系统重构”章节,详细说明 `HeroAttrsComp` 和 `MonMoveComp` 的使用
|
||||||
- 新增了“怪物类型与属性计算”章节,详细说明 `MonType` 枚举和 `getMonAttr` 函数
|
|
||||||
- 所有受影响的代码示例和序列图均已更新
|
- 所有受影响的代码示例和序列图均已更新
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
@@ -73,7 +75,9 @@ end
|
|||||||
end
|
end
|
||||||
subgraph "hero"
|
subgraph "hero"
|
||||||
Mon_ts["Mon.ts"]
|
Mon_ts["Mon.ts"]
|
||||||
MonModelComp_ts["MonModelComp.ts"]
|
MonMove_ts["MonMove.ts"]
|
||||||
|
HeroAttrsComp_ts["HeroAttrsComp.ts"]
|
||||||
|
HeroViewComp_ts["HeroViewComp.ts"]
|
||||||
end
|
end
|
||||||
subgraph "common"
|
subgraph "common"
|
||||||
subgraph "config"
|
subgraph "config"
|
||||||
@@ -225,6 +229,52 @@ GameMap --> MapModelComp : "包含"
|
|||||||
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L1-L35)
|
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L1-L35)
|
||||||
- [MapModelComp.ts](file://assets/script/game/map/model/MapModelComp.ts#L1-L42)
|
- [MapModelComp.ts](file://assets/script/game/map/model/MapModelComp.ts#L1-L42)
|
||||||
|
|
||||||
|
### 怪物属性与移动系统重构
|
||||||
|
|
||||||
|
根据最近的代码重构,怪物系统已进行重大更新。`Mon.ts`不再使用专用的`MonAttrsComp`和`MonViewComp`,而是统一使用英雄系统的`HeroAttrsComp`和`HeroViewComp`,实现了代码复用和逻辑一致性。同时,为怪物创建了专属的`MonMoveComp`移动组件,与英雄系统分离。
|
||||||
|
|
||||||
|
#### 重构后组件关系
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class Monster {
|
||||||
|
+HeroModel : HeroAttrsComp
|
||||||
|
+HeroView : HeroViewComp
|
||||||
|
+HeroSkills : HeroSkillsComp
|
||||||
|
+MonMove : MonMoveComp
|
||||||
|
}
|
||||||
|
class HeroAttrsComp {
|
||||||
|
+hero_uuid : number
|
||||||
|
+lv : number
|
||||||
|
+hp : number
|
||||||
|
+mp : number
|
||||||
|
+Attrs : Array
|
||||||
|
}
|
||||||
|
class HeroViewComp {
|
||||||
|
+scale : number
|
||||||
|
+box_group : number
|
||||||
|
}
|
||||||
|
class MonMoveComp {
|
||||||
|
+direction : number
|
||||||
|
+targetX : number
|
||||||
|
+moving : boolean
|
||||||
|
}
|
||||||
|
Monster --> HeroAttrsComp : "使用"
|
||||||
|
Monster --> HeroViewComp : "使用"
|
||||||
|
Monster --> MonMoveComp : "使用"
|
||||||
|
```
|
||||||
|
|
||||||
|
**图示来源**
|
||||||
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L131)
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L7-L380)
|
||||||
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L24-L404)
|
||||||
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L8-L22)
|
||||||
|
|
||||||
|
**本节来源**
|
||||||
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L131)
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L7-L380)
|
||||||
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L24-L404)
|
||||||
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L8-L22)
|
||||||
|
|
||||||
### 怪物类型与属性计算
|
### 怪物类型与属性计算
|
||||||
|
|
||||||
`RogueConfig.ts`文件引入了`MonType`枚举来定义怪物类型,取代了原有的布尔标记。`MonType`包含`NORMAL`(普通)、`ELITE`(精英)和`BOSS`(首领)三种类型。系统通过`MonAttrSet`配置表为不同类型的怪物设置属性倍率。`getMonAttr`函数根据怪物等级、UUID和类型计算最终属性值,确保精英和Boss怪物具有更高的生命值、攻击力和防御力。
|
`RogueConfig.ts`文件引入了`MonType`枚举来定义怪物类型,取代了原有的布尔标记。`MonType`包含`NORMAL`(普通)、`ELITE`(精英)和`BOSS`(首领)三种类型。系统通过`MonAttrSet`配置表为不同类型的怪物设置属性倍率。`getMonAttr`函数根据怪物等级、UUID和类型计算最终属性值,确保精英和Boss怪物具有更高的生命值、攻击力和防御力。
|
||||||
@@ -282,7 +332,7 @@ end
|
|||||||
|
|
||||||
### 怪物实体设计模式分析
|
### 怪物实体设计模式分析
|
||||||
|
|
||||||
`Mon.ts`文件定义了`Monster`类,代表游戏中的怪物实体。该类基于ECS架构,包含`HeroModel`(模型组件)、`HeroView`(视图组件)和`BattleMove`(战斗移动组件)。`load`方法的签名已更新,增加了`monType`和`buffs`参数。该方法调用`getMonAttr`函数根据关卡等级和怪物类型计算属性,并将这些属性传递给`hero_init`方法进行初始化。怪物的技能、属性和状态均在此方法中初始化。
|
`Mon.ts`文件定义了`Monster`类,代表游戏中的怪物实体。该类基于ECS架构,包含`HeroModel`(模型组件)、`HeroView`(视图组件)和`MonMove`(专属移动组件)。`load`方法的签名已更新,增加了`monType`和`buffs`参数。该方法调用`getMonAttr`函数根据关卡等级和怪物类型计算属性,并将这些属性传递给`hero_init`方法进行初始化。怪物的技能、属性和状态均在此方法中初始化。
|
||||||
|
|
||||||
#### 复杂逻辑组件
|
#### 复杂逻辑组件
|
||||||
```mermaid
|
```mermaid
|
||||||
@@ -297,7 +347,7 @@ GetHeroInfo --> CalculateAttrs["调用getMonAttr计算最终属性"]
|
|||||||
CalculateAttrs --> ApplyBuffs["应用buffs数组"]
|
CalculateAttrs --> ApplyBuffs["应用buffs数组"]
|
||||||
ApplyBuffs --> InitSkills["初始化技能数组"]
|
ApplyBuffs --> InitSkills["初始化技能数组"]
|
||||||
InitSkills --> AddComponent["将HeroViewComp添加到实体"]
|
InitSkills --> AddComponent["将HeroViewComp添加到实体"]
|
||||||
AddComponent --> SetMove["设置BattleMove参数"]
|
AddComponent --> SetMove["设置MonMove参数"]
|
||||||
SetMove --> Dispatch["派发monster_load事件"]
|
SetMove --> Dispatch["派发monster_load事件"]
|
||||||
Dispatch --> End([怪物加载完成])
|
Dispatch --> End([怪物加载完成])
|
||||||
```
|
```
|
||||||
@@ -388,7 +438,9 @@ MapViewScene_ts --> EntityLayer_ts
|
|||||||
MapViewScene_ts --> SkillLayer_ts
|
MapViewScene_ts --> SkillLayer_ts
|
||||||
MissionMonComp_ts --> RogueConfig_ts
|
MissionMonComp_ts --> RogueConfig_ts
|
||||||
MissionMonComp_ts --> Mon_ts
|
MissionMonComp_ts --> Mon_ts
|
||||||
Mon_ts --> heroSet_ts
|
Mon_ts --> HeroAttrsComp_ts
|
||||||
|
Mon_ts --> HeroViewComp_ts
|
||||||
|
Mon_ts --> MonMove_ts
|
||||||
RogueConfig_ts --> heroSet_ts
|
RogueConfig_ts --> heroSet_ts
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -402,7 +454,10 @@ RogueConfig_ts --> heroSet_ts
|
|||||||
- [SkillLayer.ts](file://assets/script/game/map/view/map/layer/SkillLayer.ts#L1-L47)
|
- [SkillLayer.ts](file://assets/script/game/map/view/map/layer/SkillLayer.ts#L1-L47)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L239)
|
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L239)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L1-L310)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L1-L310)
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L108)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L131)
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L7-L380)
|
||||||
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L24-L404)
|
||||||
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L8-L22)
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L1-L151)
|
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L1-L151)
|
||||||
|
|
||||||
**本节来源**
|
**本节来源**
|
||||||
@@ -415,7 +470,10 @@ RogueConfig_ts --> heroSet_ts
|
|||||||
- [SkillLayer.ts](file://assets/script/game/map/view/map/layer/SkillLayer.ts#L1-L47)
|
- [SkillLayer.ts](file://assets/script/game/map/view/map/layer/SkillLayer.ts#L1-L47)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L239)
|
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L239)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L1-L310)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L1-L310)
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L108)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L131)
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L7-L380)
|
||||||
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L24-L404)
|
||||||
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L8-L22)
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L1-L151)
|
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L1-L151)
|
||||||
|
|
||||||
## 性能考虑
|
## 性能考虑
|
||||||
@@ -430,7 +488,7 @@ RogueConfig_ts --> heroSet_ts
|
|||||||
**本节来源**
|
**本节来源**
|
||||||
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L1-L35)
|
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L1-L35)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L239)
|
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L239)
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L108)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L131)
|
||||||
- [map_delivery.json](file://assets/resources/config/map/map_delivery.json#L1-L29)
|
- [map_delivery.json](file://assets/resources/config/map/map_delivery.json#L1-L29)
|
||||||
|
|
||||||
## 结论
|
## 结论
|
||||||
|
|||||||
@@ -3,16 +3,17 @@
|
|||||||
<cite>
|
<cite>
|
||||||
**本文档引用的文件**
|
**本文档引用的文件**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts) - *在最近的提交中更新*
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts) - *在最近的提交中更新*
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts) - *新增并替代旧的属性组件*
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts) - *在最近的提交中更新*
|
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts) - *在最近的提交中更新*
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts) - *在最近的提交中更新*
|
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts) - *在最近的提交中更新*
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *新增怪物类型与难度配置*
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *新增怪物类型与难度配置*
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts) - *移动行为控制组件*
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts) - *移动行为控制组件*
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts) - *视图与属性管理组件*
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts) - *视图与属性管理组件*
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
## 更新摘要
|
## 更新摘要
|
||||||
**变更内容**
|
**变更内容**
|
||||||
- 更新了 `Mon.ts` 中的 `load` 和 `hero_init` 方法以支持 `monType` 参数和等级系统
|
- 重构 `Mon.ts` 中的组件依赖,移除 `MonAttrsComp` 和 `MonViewComp`,统一使用 `HeroAttrsComp` 和 `HeroViewComp`
|
||||||
- 引入 `MonType` 枚举(普通、精英、BOSS)实现差异化属性计算
|
- 引入 `MonType` 枚举(普通、精英、BOSS)实现差异化属性计算
|
||||||
- 新增 `getMonAttr` 函数用于根据等级和类型动态计算怪物属性
|
- 新增 `getMonAttr` 函数用于根据等级和类型动态计算怪物属性
|
||||||
- 扩展 `heroSet.ts` 添加多种新怪物类型(召唤师、治疗者、光环怪等)
|
- 扩展 `heroSet.ts` 添加多种新怪物类型(召唤师、治疗者、光环怪等)
|
||||||
@@ -32,7 +33,7 @@
|
|||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
`Mon.ts` 文件定义了游戏中的怪物系统,采用 ECS(Entity-Component-System)架构模式,通过继承 `Entity` 类并注册为 `Monster` 类型来实现怪物实体的管理和控制。该系统提供了完整的怪物生命周期管理,包括预制体动态加载、位置设置、基于等级和类型的属性初始化以及向左移动的行为控制。本次重构引入了 `monType` 参数,支持普通、精英、BOSS 三种类型,并通过 `RogueConfig.ts` 中的 `getMonAttr` 函数实现了基于等级和类型系数的动态属性计算,取代了原有的 `strengthMultiplier` 机制,使难度曲线更加平滑和可配置。
|
`Mon.ts` 文件定义了游戏中的怪物系统,采用 ECS(实体-组件-系统)架构模式,通过继承 `Entity` 类并注册为 `Monster` 类型来实现怪物实体的管理和控制。该系统提供了完整的怪物生命周期管理,包括预制体动态加载、位置设置、基于等级和类型的属性初始化以及向左移动的行为控制。本次重构引入了 `monType` 参数,支持普通、精英、BOSS 三种类型,并通过 `RogueConfig.ts` 中的 `getMonAttr` 函数实现了基于等级和类型系数的动态属性计算,取代了原有的 `strengthMultiplier` 机制,使难度曲线更加平滑和可配置。同时,系统已统一使用英雄的 `HeroAttrsComp` 组件,实现了英雄与怪物之间的数据与逻辑复用,提升了代码一致性与可维护性。
|
||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
@@ -42,8 +43,8 @@
|
|||||||
graph TB
|
graph TB
|
||||||
subgraph "怪物系统模块"
|
subgraph "怪物系统模块"
|
||||||
Mon[Mon.ts<br/>怪物实体类]
|
Mon[Mon.ts<br/>怪物实体类]
|
||||||
MonModel[MonModelComp.ts<br/>怪物模型组件]
|
MonModel[HeroAttrsComp.ts<br/>属性与模型组件]
|
||||||
BattleMove[BattleMoveComp.ts<br/>移动组件]
|
BattleMove[MonMove.ts<br/>移动组件]
|
||||||
end
|
end
|
||||||
subgraph "配置系统"
|
subgraph "配置系统"
|
||||||
HeroSet[heroSet.ts<br/>英雄与怪物配置]
|
HeroSet[heroSet.ts<br/>英雄与怪物配置]
|
||||||
@@ -51,7 +52,7 @@ HeroAttrs[HeroAttrs.ts<br/>属性配置]
|
|||||||
RogueConfig[RogueConfig.ts<br/>肉鸽模式配置]
|
RogueConfig[RogueConfig.ts<br/>肉鸽模式配置]
|
||||||
end
|
end
|
||||||
subgraph "ECS系统"
|
subgraph "ECS系统"
|
||||||
BattleMoveSys[BattleMoveSystem.ts<br/>移动系统]
|
BattleMoveSys[MonMoveSystem.ts<br/>移动系统]
|
||||||
end
|
end
|
||||||
Mon --> MonModel
|
Mon --> MonModel
|
||||||
Mon --> BattleMove
|
Mon --> BattleMove
|
||||||
@@ -63,8 +64,8 @@ BattleMoveSys --> BattleMove
|
|||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L109)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L109)
|
||||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts#L1-L20)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L1-L20)
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L1-L16)
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L1-L16)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L88)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L88)
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
@@ -78,14 +79,14 @@ BattleMoveSys --> BattleMove
|
|||||||
|
|
||||||
`Monster` 类是怪物系统的核心实体类,继承自 ECS 框架的 `Entity` 基类,并注册为 `Monster` 类型。该类实现了怪物的完整生命周期管理:
|
`Monster` 类是怪物系统的核心实体类,继承自 ECS 框架的 `Entity` 基类,并注册为 `Monster` 类型。该类实现了怪物的完整生命周期管理:
|
||||||
|
|
||||||
- **组件管理**:在 `init` 方法中自动添加 `BattleMoveComp`、`MonModelComp` 和 `TalComp` 组件
|
- **组件管理**:在 `init` 方法中自动添加 `MonMoveComp`、`HeroAttrsComp` 和 `HeroSkillsComp` 组件
|
||||||
- **生命周期控制**:提供 `init` 和 `destroy` 方法管理实体状态,在 `destroy` 中移除关键组件
|
- **生命周期控制**:提供 `init` 和 `destroy` 方法管理实体状态,在 `destroy` 中移除关键组件
|
||||||
- **预制体加载**:通过 `load` 方法动态加载怪物预制体,并传入 `uuid`、`lv`(等级)、`monType`(怪物类型)等参数
|
- **预制体加载**:通过 `load` 方法动态加载怪物预制体,并传入 `uuid`、`lv`(等级)、`monType`(怪物类型)等参数
|
||||||
- **属性初始化**:通过 `hero_init` 方法设置怪物基础属性,该方法现在依赖 `RogueConfig.getMonAttr` 进行计算
|
- **属性初始化**:通过 `load` 方法中的逻辑设置怪物基础属性,该方法现在依赖 `RogueConfig.getMonAttr` 进行计算,并直接使用 `HeroAttrsComp` 统一管理属性
|
||||||
|
|
||||||
### BattleMoveComp移动组件
|
### MonMoveComp移动组件
|
||||||
|
|
||||||
`BattleMoveComp` 负责控制怪物的移动行为,包含以下关键属性:
|
`MonMoveComp` 负责控制怪物的移动行为,包含以下关键属性:
|
||||||
|
|
||||||
- **direction**:移动方向(1向右,-1向左)
|
- **direction**:移动方向(1向右,-1向左)
|
||||||
- **targetX**:目标X坐标
|
- **targetX**:目标X坐标
|
||||||
@@ -101,12 +102,12 @@ BattleMoveSys --> BattleMove
|
|||||||
- **百分比属性**:暴击率、闪避率等百分比型属性
|
- **百分比属性**:暴击率、闪避率等百分比型属性
|
||||||
- **特殊属性**:吸血、燃烧概率等特殊效果属性
|
- **特殊属性**:吸血、燃烧概率等特殊效果属性
|
||||||
|
|
||||||
属性值存储在 `HeroViewComp` 的 `Attrs` 和 `NeAttrs` 对象中,并通过 `initAttrs` 方法进行初始化和计算。
|
属性值存储在 `HeroAttrsComp` 的 `Attrs` 和 `NeAttrs` 对象中,并通过 `initAttrs` 方法进行初始化和计算。此设计实现了英雄与怪物共用同一套属性组件,极大提升了代码复用率。
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L3-L15)
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L72-L778)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L72-L778)
|
||||||
|
|
||||||
## 架构概览
|
## 架构概览
|
||||||
|
|
||||||
@@ -115,50 +116,45 @@ BattleMoveSys --> BattleMove
|
|||||||
```mermaid
|
```mermaid
|
||||||
classDiagram
|
classDiagram
|
||||||
class Monster {
|
class Monster {
|
||||||
+MonModelComp HeroModel
|
+HeroAttrsComp HeroModel
|
||||||
+HeroViewComp HeroView
|
+HeroViewComp HeroView
|
||||||
+BattleMoveComp BattleMove
|
+MonMoveComp MonMove
|
||||||
+init() void
|
+init() void
|
||||||
+destroy() void
|
+destroy() void
|
||||||
+load(pos, scale, uuid, lv, monType, buffs, is_call) void
|
+load(pos, scale, uuid, lv, monType, buffs, is_call) void
|
||||||
+hero_init(uuid, node, scale, box_group, lv, monType, buffs, is_call) void
|
|
||||||
}
|
}
|
||||||
class BattleMoveComp {
|
class MonMoveComp {
|
||||||
+number direction
|
+number direction
|
||||||
+number targetX
|
+number targetX
|
||||||
+boolean moving
|
+boolean moving
|
||||||
+reset() void
|
+reset() void
|
||||||
}
|
}
|
||||||
class MonModelComp {
|
class HeroAttrsComp {
|
||||||
+reset() void
|
|
||||||
}
|
|
||||||
class HeroViewComp {
|
|
||||||
+number scale
|
|
||||||
+FacSet fac
|
|
||||||
+HType type
|
|
||||||
+boolean is_boss
|
|
||||||
+number box_group
|
|
||||||
+number hero_uuid
|
+number hero_uuid
|
||||||
+string hero_name
|
+string hero_name
|
||||||
+number base_hp
|
+number lv
|
||||||
+number base_mp
|
+number type
|
||||||
+number base_ap
|
+number fac
|
||||||
+number base_def
|
|
||||||
+number hp
|
+number hp
|
||||||
+number mp
|
+number mp
|
||||||
+object Attrs
|
+object Attrs
|
||||||
+object skills
|
+object NeAttrs
|
||||||
+initAttrs() void
|
+initAttrs() void
|
||||||
}
|
}
|
||||||
Monster --> BattleMoveComp : "包含"
|
class HeroViewComp {
|
||||||
Monster --> MonModelComp : "包含"
|
+number scale
|
||||||
|
+number box_group
|
||||||
|
+init() void
|
||||||
|
}
|
||||||
|
Monster --> MonMoveComp : "包含"
|
||||||
|
Monster --> HeroAttrsComp : "包含"
|
||||||
Monster --> HeroViewComp : "包含"
|
Monster --> HeroViewComp : "包含"
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L3-L15)
|
||||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts#L10-L19)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L72-L778)
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L72-L778)
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L72-L778)
|
||||||
|
|
||||||
## 详细组件分析
|
## 详细组件分析
|
||||||
@@ -173,17 +169,17 @@ participant Client as "调用方"
|
|||||||
participant Monster as "Monster实体"
|
participant Monster as "Monster实体"
|
||||||
participant Resources as "资源系统"
|
participant Resources as "资源系统"
|
||||||
participant Scene as "场景节点"
|
participant Scene as "场景节点"
|
||||||
participant BattleMove as "BattleMove组件"
|
participant MonMove as "MonMove组件"
|
||||||
Client->>Monster : load(pos, scale, uuid, lv, monType, ...)
|
Client->>Monster : load(pos, scale, uuid, lv, monType, ...)
|
||||||
Monster->>Resources : 获取预制体路径
|
Monster->>Resources : 获取预制体路径
|
||||||
Resources-->>Monster : 返回Prefab资源
|
Resources-->>Monster : 返回Prefab资源
|
||||||
Monster->>Scene : 实例化预制体
|
Monster->>Scene : 实例化预制体
|
||||||
Scene-->>Monster : 返回Node节点
|
Scene-->>Monster : 返回Node节点
|
||||||
Monster->>Monster : 设置位置和缩放
|
Monster->>Monster : 设置位置和缩放
|
||||||
Monster->>Monster : hero_init初始化属性
|
Monster->>Monster : 初始化属性
|
||||||
Monster->>BattleMove : 设置移动参数
|
Monster->>MonMove : 设置移动参数
|
||||||
BattleMove->>BattleMove : direction = -1
|
MonMove->>MonMove : direction = -1
|
||||||
BattleMove->>BattleMove : targetX = -800
|
MonMove->>MonMove : targetX = -800
|
||||||
Monster->>Client : dispatchEvent("monster_load")
|
Monster->>Client : dispatchEvent("monster_load")
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -197,15 +193,16 @@ Monster->>Client : dispatchEvent("monster_load")
|
|||||||
3. **场景集成**:将实例化的节点添加到场景的 `entityLayer` 中
|
3. **场景集成**:将实例化的节点添加到场景的 `entityLayer` 中
|
||||||
4. **碰撞体管理**:先禁用碰撞体,延迟一帧再启用以避免初始化问题
|
4. **碰撞体管理**:先禁用碰撞体,延迟一帧再启用以避免初始化问题
|
||||||
5. **位置设置**:根据传入的 `pos` 参数设置怪物初始位置
|
5. **位置设置**:根据传入的 `pos` 参数设置怪物初始位置
|
||||||
6. **属性初始化**:调用 `hero_init` 方法,传入 `lv` 和 `monType` 进行属性计算
|
6. **属性初始化**:调用 `getMonAttr` 计算属性,并赋值给 `HeroAttrsComp`
|
||||||
7. **移动初始化**:设置 `BattleMoveComp` 的方向和目标
|
7. **技能初始化**:通过 `HeroSkillsComp.initSkills` 加载技能配置
|
||||||
|
8. **移动初始化**:设置 `MonMoveComp` 的方向和目标
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L35-L58)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L35-L58)
|
||||||
|
|
||||||
### hero_init方法:基于等级与类型的属性系统
|
### 属性初始化:基于等级与类型的属性系统
|
||||||
|
|
||||||
`hero_init` 方法实现了基于 `lv`(等级)和 `monType`(怪物类型)的属性调整,取代了旧的 `strengthMultiplier` 机制:
|
`load` 方法中实现了基于 `lv`(等级)和 `monType`(怪物类型)的属性调整,取代了旧的 `strengthMultiplier` 机制:
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart TD
|
flowchart TD
|
||||||
@@ -238,7 +235,7 @@ style CalcAttr fill:#fff3e0
|
|||||||
2. **技能系统集成**:
|
2. **技能系统集成**:
|
||||||
- 遍历 `hero.skills` 数组
|
- 遍历 `hero.skills` 数组
|
||||||
- 从 `SkillSet` 配置中获取技能详细信息
|
- 从 `SkillSet` 配置中获取技能详细信息
|
||||||
- 创建技能对象并添加到 `hv.skills` 数组
|
- 创建技能对象并添加到 `HeroSkillsComp` 中
|
||||||
|
|
||||||
3. **属性系统初始化**:
|
3. **属性系统初始化**:
|
||||||
- 调用 `getAttrs()` 获取默认属性值
|
- 调用 `getAttrs()` 获取默认属性值
|
||||||
@@ -249,9 +246,9 @@ style CalcAttr fill:#fff3e0
|
|||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L60-L91)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L60-L91)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L79-L88)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L79-L88)
|
||||||
|
|
||||||
### BattleMoveComp组件:移动行为控制
|
### MonMoveComp组件:移动行为控制
|
||||||
|
|
||||||
`BattleMoveComp` 组件驱动怪物向左移动的行为:
|
`MonMoveComp` 组件驱动怪物向左移动的行为:
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
@@ -265,8 +262,8 @@ note right of Moving : direction = -1<br/>targetX = -800
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L3-L15)
|
||||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L10-L271)
|
- [MonMoveSystem.ts](file://assets/script/game/hero/MonMove.ts#L10-L271)
|
||||||
|
|
||||||
#### 移动参数配置:
|
#### 移动参数配置:
|
||||||
|
|
||||||
@@ -275,7 +272,7 @@ note right of Moving : direction = -1<br/>targetX = -800
|
|||||||
- **moving = true**:启用移动状态
|
- **moving = true**:启用移动状态
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
- [MonMove.ts](file://assets/script/game/hero/MonMove.ts#L3-L15)
|
||||||
|
|
||||||
### 数据复用机制:HeroAttrs与heroSet配置
|
### 数据复用机制:HeroAttrs与heroSet配置
|
||||||
|
|
||||||
@@ -321,8 +318,9 @@ Oops[Oops插件框架]
|
|||||||
end
|
end
|
||||||
subgraph "核心模块"
|
subgraph "核心模块"
|
||||||
Monster[Monster实体]
|
Monster[Monster实体]
|
||||||
BattleMove[BattleMove组件]
|
MonMove[MonMove组件]
|
||||||
HeroView[HeroView组件]
|
HeroView[HeroView组件]
|
||||||
|
HeroAttrs[HeroAttrs组件]
|
||||||
end
|
end
|
||||||
subgraph "配置模块"
|
subgraph "配置模块"
|
||||||
HeroInfo[HeroInfo配置]
|
HeroInfo[HeroInfo配置]
|
||||||
@@ -331,37 +329,38 @@ SkillSet[技能配置]
|
|||||||
RogueConfig[肉鸽配置]
|
RogueConfig[肉鸽配置]
|
||||||
end
|
end
|
||||||
subgraph "系统模块"
|
subgraph "系统模块"
|
||||||
BattleMoveSys[BattleMoveSystem]
|
MonMoveSystem[MonMoveSystem]
|
||||||
SingletonModule[单例模块]
|
SingletonModule[单例模块]
|
||||||
end
|
end
|
||||||
Monster --> ECS
|
Monster --> ECS
|
||||||
Monster --> CC
|
Monster --> CC
|
||||||
Monster --> Oops
|
Monster --> Oops
|
||||||
Monster --> BattleMove
|
Monster --> MonMove
|
||||||
|
Monster --> HeroAttrs
|
||||||
Monster --> HeroView
|
Monster --> HeroView
|
||||||
Monster --> HeroInfo
|
Monster --> HeroInfo
|
||||||
Monster --> HeroAttrs
|
Monster --> HeroAttrs
|
||||||
Monster --> SkillSet
|
Monster --> SkillSet
|
||||||
Monster --> RogueConfig
|
Monster --> RogueConfig
|
||||||
BattleMoveSys --> BattleMove
|
MonMoveSystem --> MonMove
|
||||||
BattleMoveSys --> HeroView
|
MonMoveSystem --> HeroAttrs
|
||||||
SingletonModule --> Monster
|
SingletonModule --> Monster
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L15)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L15)
|
||||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L1-L10)
|
- [MonMoveSystem.ts](file://assets/script/game/hero/MonMove.ts#L1-L10)
|
||||||
|
|
||||||
### 关键依赖说明:
|
### 关键依赖说明:
|
||||||
|
|
||||||
1. **ECS框架依赖**:`Monster` 类继承自 `ecs.Entity`,`BattleMoveComp` 继承自 `ecs.Comp`
|
1. **ECS框架依赖**:`Monster` 类继承自 `ecs.Entity`,`MonMoveComp` 继承自 `ecs.Comp`
|
||||||
2. **Cocos Creator依赖**:使用 `Node`、`Prefab`、`Vec3` 等 Cocos 类型
|
2. **Cocos Creator依赖**:使用 `Node`、`Prefab`、`Vec3` 等 Cocos 类型
|
||||||
3. **配置依赖**:依赖 `HeroInfo`、`HeroAttrs`、`SkillSet`、`RogueConfig` 等配置模块
|
3. **配置依赖**:依赖 `HeroInfo`、`HeroAttrs`、`SkillSet`、`RogueConfig` 等配置模块
|
||||||
4. **系统依赖**:依赖 `BattleMoveSystem` 进行移动逻辑处理
|
4. **系统依赖**:依赖 `MonMoveSystem` 进行移动逻辑处理
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L15)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L15)
|
||||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L1-L10)
|
- [MonMoveSystem.ts](file://assets/script/game/hero/MonMove.ts#L1-L10)
|
||||||
|
|
||||||
## 性能考虑
|
## 性能考虑
|
||||||
|
|
||||||
@@ -373,7 +372,7 @@ SingletonModule --> Monster
|
|||||||
|
|
||||||
### 性能优化策略
|
### 性能优化策略
|
||||||
|
|
||||||
1. **批量更新**:`BattleMoveSystem` 采用批量处理方式
|
1. **批量更新**:`MonMoveSystem` 采用批量处理方式
|
||||||
2. **条件检查**:在更新前进行状态检查,避免不必要的计算
|
2. **条件检查**:在更新前进行状态检查,避免不必要的计算
|
||||||
3. **边界检测**:使用 `validatePosition` 方法限制移动范围
|
3. **边界检测**:使用 `validatePosition` 方法限制移动范围
|
||||||
|
|
||||||
@@ -381,7 +380,7 @@ SingletonModule --> Monster
|
|||||||
|
|
||||||
1. **配置驱动**:通过 `heroSet.ts` 和 `RogueConfig.ts` 控制怪物属性和行为
|
1. **配置驱动**:通过 `heroSet.ts` 和 `RogueConfig.ts` 控制怪物属性和行为
|
||||||
2. **组件扩展**:支持添加新的组件类型(如 `BuffComp`、`TalComp`)
|
2. **组件扩展**:支持添加新的组件类型(如 `BuffComp`、`TalComp`)
|
||||||
3. **系统扩展**:`BattleMoveSystem` 可添加新的移动逻辑
|
3. **系统扩展**:`MonMoveSystem` 可添加新的移动逻辑
|
||||||
|
|
||||||
## 故障排除指南
|
## 故障排除指南
|
||||||
|
|
||||||
@@ -392,14 +391,14 @@ SingletonModule --> Monster
|
|||||||
**问题现象**:怪物加载后静止不动
|
**问题现象**:怪物加载后静止不动
|
||||||
|
|
||||||
**排查步骤**:
|
**排查步骤**:
|
||||||
- 检查 `BattleMoveComp` 的 `moving` 属性是否为 `true`
|
- 检查 `MonMoveComp` 的 `moving` 属性是否为 `true`
|
||||||
- 验证 `targetX` 设置是否合理
|
- 验证 `targetX` 设置是否合理
|
||||||
- 确认 `BattleMoveSystem` 是否正常运行
|
- 确认 `MonMoveSystem` 是否正常运行
|
||||||
|
|
||||||
**解决方案**:
|
**解决方案**:
|
||||||
```typescript
|
```typescript
|
||||||
// 确保移动组件正确初始化
|
// 确保移动组件正确初始化
|
||||||
const move = this.get(BattleMoveComp);
|
const move = this.get(MonMoveComp);
|
||||||
move.moving = true;
|
move.moving = true;
|
||||||
move.targetX = -800; // 设置合理的边界值
|
move.targetX = -800; // 设置合理的边界值
|
||||||
```
|
```
|
||||||
@@ -440,7 +439,7 @@ var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L35-L58)
|
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L35-L58)
|
||||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L10-L50)
|
- [MonMoveSystem.ts](file://assets/script/game/hero/MonMove.ts#L10-L50)
|
||||||
|
|
||||||
## 结论
|
## 结论
|
||||||
|
|
||||||
@@ -448,7 +447,7 @@ var prefab: Prefab = oops.res.get(path, Prefab)!;
|
|||||||
|
|
||||||
1. **ECS架构优势**:通过组件化设计实现了职责分离和代码复用
|
1. **ECS架构优势**:通过组件化设计实现了职责分离和代码复用
|
||||||
2. **难度自适应**:基于 `lv` 和 `monType` 的属性调整机制提供了灵活的难度控制
|
2. **难度自适应**:基于 `lv` 和 `monType` 的属性调整机制提供了灵活的难度控制
|
||||||
3. **数据复用**:通过 `HeroAttrs` 和 `heroSet` 配置系统实现了数据的集中管理
|
3. **数据复用**:通过 `HeroAttrsComp` 统一管理英雄与怪物属性,实现逻辑一致性
|
||||||
4. **性能优化**:采用组件化和批量处理策略确保良好的运行性能
|
4. **性能优化**:采用组件化和批量处理策略确保良好的运行性能
|
||||||
5. **扩展性强**:支持添加新怪物类型、配置技能组合和实现召唤单位等扩展需求
|
5. **扩展性强**:支持添加新怪物类型、配置技能组合和实现召唤单位等扩展需求
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,17 @@
|
|||||||
|
|
||||||
<cite>
|
<cite>
|
||||||
**本文档引用的文件**
|
**本文档引用的文件**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *在最近提交中更新*
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts) - *在最近提交中更新*
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts) - *在最近提交中更新*
|
- [GameMap.ts](file://assets\script\game\map\GameMap.ts) - *在最近提交中更新*
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts) - *在最近提交中更新*
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts)
|
|
||||||
- [GameMap.ts](file://assets/script/game/map/GameMap.ts)
|
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
## 更新摘要
|
## 更新摘要
|
||||||
**已做更改**
|
**已做更改**
|
||||||
- 全面重构关卡生成逻辑,采用新的 `MonType` 枚举替代旧的布尔标记
|
- 全面重构怪物类型与属性计算系统,引入 `MonType` 枚举和动态属性计算机制
|
||||||
- 更新关卡类型判断机制,基于 `EliteStage` 和 `BossStage` 数组配置
|
- 更新关卡类型判断逻辑,基于 `EliteStage` 和 `BossStage` 数组进行判定
|
||||||
- 重写怪物属性计算系统,引入 `MonAttrSet` 属性倍率配置
|
- 重写怪物属性计算函数 `getMonAttr`,实现基于等级、类型和基础属性的动态计算
|
||||||
- 更新随机事件系统,使用数字枚举值替代字符串
|
- 优化关卡生成流程 `getStageMonConfigs`,增强代码可读性和维护性
|
||||||
- 同步更新调用流程和配置结构
|
- 同步更新文档以准确反映最新代码实现
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [系统概述](#系统概述)
|
1. [系统概述](#系统概述)
|
||||||
@@ -46,8 +43,8 @@
|
|||||||
**更新** 重构了怪物生成逻辑,使用 `MonType` 枚举和数组配置替代原有实现
|
**更新** 重构了怪物生成逻辑,使用 `MonType` 枚举和数组配置替代原有实现
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L1-L50)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L1-L50)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L40)
|
- [GameMap.ts](file://assets\script\game\map\GameMap.ts#L1-L35)
|
||||||
|
|
||||||
## 核心架构
|
## 核心架构
|
||||||
|
|
||||||
@@ -67,19 +64,16 @@ F --> J[Boss怪物添加]
|
|||||||
F --> K[额外怪物生成]
|
F --> K[额外怪物生成]
|
||||||
end
|
end
|
||||||
subgraph "应用层"
|
subgraph "应用层"
|
||||||
L[MissionMonComp.ts] --> M[GameMap.ts]
|
L[GameMap.ts] --> M[MapModelComp]
|
||||||
L --> N[Mon.ts]
|
L --> N[MapViewComp]
|
||||||
L --> O[MapModelComp.ts]
|
|
||||||
end
|
end
|
||||||
A --> F
|
A --> F
|
||||||
F --> L
|
F --> L
|
||||||
M --> O
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L1-L173)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L1-L173)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L1-L200)
|
- [GameMap.ts](file://assets\script\game\map\GameMap.ts#L1-L35)
|
||||||
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L1-L35)
|
|
||||||
|
|
||||||
## 关卡类型系统
|
## 关卡类型系统
|
||||||
|
|
||||||
@@ -111,7 +105,7 @@ IMonsConfig --> StageConfig : "生成"
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L31)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L31-L31)
|
||||||
|
|
||||||
### 关卡类型特征对比
|
### 关卡类型特征对比
|
||||||
|
|
||||||
@@ -122,8 +116,8 @@ IMonsConfig --> StageConfig : "生成"
|
|||||||
| Boss关卡 | 关卡号在BossStage数组中 | Boss+精英+普通怪物 | 高难度,包含Boss |
|
| Boss关卡 | 关卡号在BossStage数组中 | Boss+精英+普通怪物 | 高难度,包含Boss |
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L18-L20)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L18-L20)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L31)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L31-L31)
|
||||||
|
|
||||||
## 怪物类型体系
|
## 怪物类型体系
|
||||||
|
|
||||||
@@ -156,8 +150,8 @@ MonsterPool --> MonsterConfig : "包含"
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L31)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L31-L31)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L18-L20)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L18-L20)
|
||||||
|
|
||||||
### 怪物池配置
|
### 怪物池配置
|
||||||
|
|
||||||
@@ -168,8 +162,8 @@ MonsterPool --> MonsterConfig : "包含"
|
|||||||
- **Boss怪物池**:固定配置的Boss怪物列表 `BossMons`
|
- **Boss怪物池**:固定配置的Boss怪物列表 `BossMons`
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L18-L20)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L18-L20)
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L20-L215)
|
- [RogueConfig.ts](file://assets\script\game\common\config\heroSet.ts#L20-L215)
|
||||||
|
|
||||||
## 关卡配置规则
|
## 关卡配置规则
|
||||||
|
|
||||||
@@ -192,7 +186,7 @@ H --> I[返回怪物配置]
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L95-L173)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L95-L173)
|
||||||
|
|
||||||
### 怪物数量计算算法
|
### 怪物数量计算算法
|
||||||
|
|
||||||
@@ -214,7 +208,7 @@ if (isEliteStage) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L95-L173)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L95-L173)
|
||||||
|
|
||||||
## 随机事件系统
|
## 随机事件系统
|
||||||
|
|
||||||
@@ -239,7 +233,7 @@ EventType --> StageRule : "配置概率"
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L35-L40)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L35-L40)
|
||||||
|
|
||||||
### 事件触发机制
|
### 事件触发机制
|
||||||
|
|
||||||
@@ -263,7 +257,7 @@ if (Math.random() < StageRule.specialAttributeRate) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L45-L56)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L45-L56)
|
||||||
|
|
||||||
## 动态难度计算
|
## 动态难度计算
|
||||||
|
|
||||||
@@ -287,7 +281,7 @@ G --> H
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L69-L73)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L69-L73)
|
||||||
|
|
||||||
### 难度曲线特征
|
### 难度曲线特征
|
||||||
|
|
||||||
@@ -298,7 +292,7 @@ G --> H
|
|||||||
| Boss怪物 | 5.0x | 2.0x | 2.0x | 2.0x | 2.0x | 终极挑战 |
|
| Boss怪物 | 5.0x | 2.0x | 2.0x | 2.0x | 2.0x | 终极挑战 |
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L69-L73)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L69-L73)
|
||||||
|
|
||||||
## 关卡生成流程
|
## 关卡生成流程
|
||||||
|
|
||||||
@@ -308,29 +302,23 @@ G --> H
|
|||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant MC as MissionComp
|
|
||||||
participant RM as MissionMonComp
|
|
||||||
participant RC as RogueConfig
|
participant RC as RogueConfig
|
||||||
|
participant GM as GameMap
|
||||||
participant MM as MapModel
|
participant MM as MapModel
|
||||||
participant M as Monster
|
participant MV as MapView
|
||||||
MC->>RM : do_mon_wave()
|
RC->>RC : getStageMonConfigs(stageNumber)
|
||||||
RM->>RC : getStageMonConfigs(stageNumber)
|
RC-->>GM : 怪物配置数组
|
||||||
RC-->>RM : 怪物配置数组
|
GM->>GM : load()
|
||||||
RM->>RM : generateMonsters()
|
GM->>MM : 初始化模型组件
|
||||||
|
GM->>MV : 加载地图显示资源
|
||||||
loop 每个怪物配置
|
loop 每个怪物配置
|
||||||
RM->>RM : addToStageSpawnQueue()
|
MM->>MM : 添加怪物实体
|
||||||
end
|
|
||||||
loop 怪物生成队列
|
|
||||||
RM->>M : addMonster()
|
|
||||||
M->>MM : 加载怪物资源
|
|
||||||
MM-->>M : 怪物实例
|
|
||||||
M-->>RM : 怪物实体
|
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L102-L136)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L95-L173)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L95-L173)
|
- [GameMap.ts](file://assets\script\game\map\GameMap.ts#L20-L35)
|
||||||
|
|
||||||
### 怪物生成队列管理
|
### 怪物生成队列管理
|
||||||
|
|
||||||
@@ -351,7 +339,7 @@ stateDiagram-v2
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L45-L85)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L95-L173)
|
||||||
|
|
||||||
## 实际调用机制
|
## 实际调用机制
|
||||||
|
|
||||||
@@ -362,44 +350,33 @@ stateDiagram-v2
|
|||||||
```mermaid
|
```mermaid
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant GM as GameMap
|
participant GM as GameMap
|
||||||
participant MC as MissionComp
|
|
||||||
participant MMon as MissionMonComp
|
|
||||||
participant RC as RogueConfig
|
participant RC as RogueConfig
|
||||||
GM->>MC : 初始化游戏
|
GM->>GM : 初始化游戏
|
||||||
MC->>MC : data_init()
|
GM->>RC : getStageMonConfigs(currentStage)
|
||||||
MC->>MC : mission_start()
|
RC-->>GM : 怪物配置数据
|
||||||
MC->>MC : to_fight()
|
GM->>GM : load()
|
||||||
MC->>MMon : fight_ready()
|
|
||||||
MMon->>MMon : do_mon_wave()
|
|
||||||
Note over MMon : 开始关卡生成流程
|
|
||||||
MMon->>RC : getStageMonConfigs(currentStage)
|
|
||||||
RC-->>MMon : 怪物配置数据
|
|
||||||
MMon->>MMon : generateMonsters()
|
|
||||||
MMon->>MMon : addToStageSpawnQueue()
|
|
||||||
loop 怪物生成循环
|
loop 怪物生成循环
|
||||||
MMon->>MMon : spawnNextMonster()
|
GM->>GM : instantiate怪物
|
||||||
MMon->>GM : addMonster()
|
GM->>GM : 添加到地图
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L25-L35)
|
- [GameMap.ts](file://assets\script\game\map\GameMap.ts#L25-L35)
|
||||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L75-L95)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L95-L173)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L40-L50)
|
|
||||||
|
|
||||||
### 数据流传递
|
### 数据流传递
|
||||||
|
|
||||||
关卡配置数据通过以下路径传递:
|
关卡配置数据通过以下路径传递:
|
||||||
|
|
||||||
1. **配置层**:RogueConfig.ts 提供基础配置
|
1. **配置层**:RogueConfig.ts 提供基础配置
|
||||||
2. **逻辑层**:MissionMonComp.ts 处理游戏逻辑
|
2. **逻辑层**:GameMap.ts 处理游戏逻辑
|
||||||
3. **渲染层**:Mon.ts 负责怪物渲染和行为
|
3. **渲染层**:MapViewComp.ts 负责地图渲染
|
||||||
4. **状态层**:smc.vmdata.mission_data 管理游戏状态
|
4. **状态层**:MapModelComp.ts 管理游戏状态
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [GameMap.ts](file://assets/script/game/map/GameMap.ts#L25-L35)
|
- [GameMap.ts](file://assets\script\game\map\GameMap.ts#L25-L35)
|
||||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L75-L95)
|
- [RogueConfig.ts](file://assets\script\game\map\RogueConfig.ts#L95-L173)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts#L40-L50)
|
|
||||||
|
|
||||||
## 扩展指南
|
## 扩展指南
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,22 @@
|
|||||||
|
|
||||||
<cite>
|
<cite>
|
||||||
**本文档引用文件**
|
**本文档引用文件**
|
||||||
- [Mission.ts](file://assets/script/game/common/config/Mission.ts)
|
- [Mission.ts](file://assets/script/game/common/config/Mission.ts) - *奖励常量配置*
|
||||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts)
|
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts) - *奖励数据管理与实体销毁逻辑*
|
||||||
- [VictoryComp.ts](file://assets/script/game/map/VictoryComp.ts)
|
- [VictoryComp.ts](file://assets/script/game/map/VictoryComp.ts) - *奖励界面展示*
|
||||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts)
|
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts) - *事件定义*
|
||||||
- [GameUIConfig.ts](file://assets/script/game/common/config/GameUIConfig.ts)
|
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts) - *怪物生成与事件处理*
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *肉鸽关卡配置*
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts)
|
- [Design.md](file://assets/script/Design.md) - *系统设计概述*
|
||||||
- [Design.md](file://assets/script/Design.md)
|
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
|
## 更新摘要
|
||||||
|
**变更内容**
|
||||||
|
- 更新了`MissionComp`中实体销毁逻辑,修复空引用问题
|
||||||
|
- 修正奖励发放流程中组件清理的实现方式
|
||||||
|
- 更新相关章节以反映最新的代码实现
|
||||||
|
- 增强源码追踪信息,标注关键修改点
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [奖励系统概述](#奖励系统概述)
|
1. [奖励系统概述](#奖励系统概述)
|
||||||
2. [三选一奖励机制](#三选一奖励机制)
|
2. [三选一奖励机制](#三选一奖励机制)
|
||||||
@@ -232,6 +238,31 @@ VictoryComp --> GameEvent : "触发"
|
|||||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts#L43)
|
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts#L43)
|
||||||
- [GameUIConfig.ts](file://assets/script/game/common/config/GameUIConfig.ts#L30)
|
- [GameUIConfig.ts](file://assets/script/game/common/config/GameUIConfig.ts#L30)
|
||||||
|
|
||||||
|
### 实体销毁逻辑优化
|
||||||
|
|
||||||
|
根据最新代码变更,`MissionComp`中的`cleanComponents`方法已优化,修复了实体销毁时可能出现的空引用问题。新的实现直接销毁实体,让ECS系统自动处理组件清理,避免在组件`reset`方法中访问已被销毁的实体引用。
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
private cleanComponents() {
|
||||||
|
// 优化销毁顺序:直接销毁实体,让ECS系统自动处理组件清理
|
||||||
|
// 这样可以避免在组件reset方法中访问已经被销毁的实体引用
|
||||||
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
|
});
|
||||||
|
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
|
});
|
||||||
|
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
此变更确保了在战斗结束后的清理过程中,不会因组件访问已被销毁的实体而导致运行时错误,提高了系统的稳定性。
|
||||||
|
|
||||||
|
**Section sources**
|
||||||
|
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L137-L149) - *修复实体销毁空引用问题*
|
||||||
|
|
||||||
## 扩展新奖励类型
|
## 扩展新奖励类型
|
||||||
|
|
||||||
### 配置修改步骤
|
### 配置修改步骤
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
**本文档引用的文件**
|
**本文档引用的文件**
|
||||||
- [Mission.ts](file://assets/script/game/common/config/Mission.ts)
|
- [Mission.ts](file://assets/script/game/common/config/Mission.ts)
|
||||||
- [Tasks.ts](file://assets/script/game/common/config/Tasks.ts)
|
- [Tasks.ts](file://assets/script/game/common/config/Tasks.ts)
|
||||||
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts)
|
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts) - *最近提交中已更新*
|
||||||
- [MissionHeroComp.ts](file://assets/script/game/map/MissionHeroComp.ts)
|
- [MissionHeroComp.ts](file://assets/script/game/map/MissionHeroComp.ts)
|
||||||
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts)
|
- [MissionMonComp.ts](file://assets/script/game/map/MissionMonComp.ts)
|
||||||
- [MissionHomeComp.ts](file://assets/script/game/map/MissionHomeComp.ts)
|
- [MissionHomeComp.ts](file://assets/script/game/map/MissionHomeComp.ts)
|
||||||
@@ -17,6 +17,13 @@
|
|||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts)
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
|
## 更新摘要
|
||||||
|
**已做更改**
|
||||||
|
- 更新了“核心组件分析”中关于MissionComp的实体销毁逻辑说明
|
||||||
|
- 修正了“性能优化考虑”中关于组件清理的描述
|
||||||
|
- 移除了过时的故障排除建议,增加了针对空引用问题的解决方案
|
||||||
|
- 所有文件引用和标题均已转换为中文
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [简介](#简介)
|
1. [简介](#简介)
|
||||||
2. [系统架构概览](#系统架构概览)
|
2. [系统架构概览](#系统架构概览)
|
||||||
@@ -524,6 +531,31 @@ do_reward() {
|
|||||||
2. **随机数优化**:使用高效的随机数生成算法
|
2. **随机数优化**:使用高效的随机数生成算法
|
||||||
3. **数据结构优化**:使用合适的数据结构提高查找效率
|
3. **数据结构优化**:使用合适的数据结构提高查找效率
|
||||||
|
|
||||||
|
### 实体销毁优化
|
||||||
|
|
||||||
|
根据最近的代码提交,MissionComp中的实体销毁逻辑已优化:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
private cleanComponents() {
|
||||||
|
// 优化销毁顺序:直接销毁实体,让ECS系统自动处理组件清理
|
||||||
|
// 这样可以避免在组件reset方法中访问已经被销毁的实体引用
|
||||||
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
|
});
|
||||||
|
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
|
});
|
||||||
|
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
此更改修复了实体销毁时可能出现的空引用问题,确保在清理过程中不会访问已被销毁的实体。
|
||||||
|
|
||||||
|
**节来源**
|
||||||
|
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L137-L149) - *最近提交中已更新*
|
||||||
|
|
||||||
## 故障排除指南
|
## 故障排除指南
|
||||||
|
|
||||||
### 常见问题及解决方案
|
### 常见问题及解决方案
|
||||||
@@ -580,35 +612,36 @@ validateRewardWeights() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 性能问题
|
#### 实体销毁空引用问题
|
||||||
|
|
||||||
**症状**:奖励生成过程卡顿
|
**症状**:在组件清理过程中出现空引用错误
|
||||||
|
|
||||||
**原因分析**:
|
**原因分析**:
|
||||||
1. 奖励算法复杂度过高
|
1. 组件清理顺序不当
|
||||||
2. 数据库查询频繁
|
2. 在reset方法中访问已被销毁的实体
|
||||||
3. UI渲染过于复杂
|
|
||||||
|
|
||||||
**解决方案**:
|
**解决方案**:
|
||||||
```typescript
|
```typescript
|
||||||
// 优化奖励生成算法
|
// 优化后的实体销毁方法
|
||||||
async generateRewardsOptimized() {
|
private cleanComponents() {
|
||||||
// 使用Web Worker异步处理
|
// 直接销毁实体,让ECS系统自动处理组件清理
|
||||||
const worker = new Worker('reward_worker.js');
|
ecs.query(ecs.allOf(HeroViewComp)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
worker.postMessage({
|
});
|
||||||
monsters: this.monsters,
|
ecs.query(ecs.allOf(AtkConCom)).forEach(entity => {
|
||||||
heroes: this.heroes,
|
entity.destroy();
|
||||||
difficulty: this.difficulty
|
});
|
||||||
|
ecs.query(ecs.allOf(SkillViewCom)).forEach(entity => {
|
||||||
|
entity.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
worker.onmessage = (e) => {
|
|
||||||
this.rewards = e.data;
|
|
||||||
this.displayRewards();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
此解决方案通过直接销毁实体而非逐个清理组件,避免了在组件reset方法中访问已被销毁实体的问题。
|
||||||
|
|
||||||
|
**节来源**
|
||||||
|
- [MissionComp.ts](file://assets/script/game/map/MissionComp.ts#L137-L149) - *最近提交中已更新*
|
||||||
|
|
||||||
## 总结
|
## 总结
|
||||||
|
|
||||||
奖励系统是本游戏的核心机制,通过精心设计的三选一奖励选择模式,为玩家提供了丰富的策略选择空间。系统采用模块化架构,各组件职责明确,通过事件驱动的方式实现松耦合设计。
|
奖励系统是本游戏的核心机制,通过精心设计的三选一奖励选择模式,为玩家提供了丰富的策略选择空间。系统采用模块化架构,各组件职责明确,通过事件驱动的方式实现松耦合设计。
|
||||||
|
|||||||
@@ -10,8 +10,19 @@
|
|||||||
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts)
|
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts)
|
||||||
- [ecs.md](file://doc/ecs/ecs.md)
|
- [ecs.md](file://doc/ecs/ecs.md)
|
||||||
- [Main.ts](file://assets/script/Main.ts)
|
- [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>
|
</cite>
|
||||||
|
|
||||||
|
## 更新摘要
|
||||||
|
**已做更改**
|
||||||
|
- 更新了组件注册机制部分,以反映在多个系统中添加ECS注册装饰器的更改
|
||||||
|
- 添加了关于技能系统的新部分,包括CastSkillRequestComp、SkillCastSystem、SkillCDSystem和SkillAutocastSystem
|
||||||
|
- 更新了实际案例分析,以包含新的技能系统实现
|
||||||
|
- 在扩展开发指南中添加了新的系统接口示例
|
||||||
|
- 更新了文档来源以包含新分析的文件
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [简介](#简介)
|
1. [简介](#简介)
|
||||||
2. [ECS架构概述](#ecs架构概述)
|
2. [ECS架构概述](#ecs架构概述)
|
||||||
@@ -66,7 +77,7 @@ end
|
|||||||
|
|
||||||
### 组件注册机制
|
### 组件注册机制
|
||||||
|
|
||||||
组件通过装饰器`@ecs.register`进行注册,框架自动管理组件的生命周期和内存回收。
|
组件通过装饰器`@ecs.register`进行注册,框架自动管理组件的生命周期和内存回收。最近的代码重构为多个英雄系统添加了ECS注册装饰器,使架构更符合标准。
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
classDiagram
|
classDiagram
|
||||||
@@ -336,6 +347,123 @@ HeroViewComp实现了复杂的BUFF/DEBUFF管理系统:
|
|||||||
**章节来源**
|
**章节来源**
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L780)
|
- [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` | 实体首次进入 | 初始化实体状态 |
|
| `IEntityEnterSystem` | 实体首次进入 | 初始化实体状态 |
|
||||||
| `IEntityRemoveSystem` | 实体移除处理 | 清理资源和状态 |
|
| `IEntityRemoveSystem` | 实体移除处理 | 清理资源和状态 |
|
||||||
| `ISystemFirstUpdate` | 系统首次更新 | 系统初始化逻辑 |
|
| `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>
|
<cite>
|
||||||
**本文档中引用的文件**
|
**本文档中引用的文件**
|
||||||
- [Main.ts](file://assets/script/Main.ts)
|
- [Main.ts](file://assets/script/Main.ts) - *更新了ECS系统注册*
|
||||||
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts)
|
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts#L1-L207)
|
||||||
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts)
|
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts#L1-L195)
|
||||||
- [EcsPositionSystem.ts](file://assets/script/game/common/ecs/position/EcsPositionSystem.ts)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L272) - *新增ECS系统注册装饰器*
|
||||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts)
|
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts#L1-L248) - *新增ECS系统注册装饰器*
|
||||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L1-L380) - *新增ECS组件注册装饰器*
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L780)
|
||||||
- [HeroModelComp.ts](file://assets/script/game/hero/HeroModelComp.ts)
|
|
||||||
- [MapModelComp.ts](file://assets/script/game/map/model/MapModelComp.ts)
|
- [MapModelComp.ts](file://assets/script/game/map/model/MapModelComp.ts)
|
||||||
- [MapViewComp.ts](file://assets/script/game/map/view/MapViewComp.ts)
|
- [MapViewComp.ts](file://assets/script/game/map/view/MapViewComp.ts)
|
||||||
- [ecs.md](file://doc/ecs/ecs.md)
|
- [ecs.md](file://doc/ecs/ecs.md)
|
||||||
- [MvvmInfo.md](file://doc/mvvm/MvvmInfo.md)
|
- [MvvmInfo.md](file://doc/mvvm/MvvmInfo.md)
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
|
## 更新摘要
|
||||||
|
**变更内容**
|
||||||
|
- 在HSkillSystem.ts、HeroAtk.ts和HeroAttrsComp.ts中添加了ECS注册装饰器
|
||||||
|
- Main.ts的初始化流程更新,反映架构入口点调整
|
||||||
|
- 移除了过时的SkillConComp组件,更新技能系统架构说明
|
||||||
|
- 新增了英雄属性更新系统(HeroAttrSystem)和生命周期系统(HeroLifecycleSystem)的文档
|
||||||
|
- 更新了ECS架构支柱章节,反映最新的系统注册模式
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [引言](#引言)
|
1. [引言](#引言)
|
||||||
2. [项目架构概览](#项目架构概览)
|
2. [项目架构概览](#项目架构概览)
|
||||||
@@ -89,10 +96,15 @@ class ecs_Comp {
|
|||||||
+canRecycle boolean
|
+canRecycle boolean
|
||||||
+ent Entity
|
+ent Entity
|
||||||
}
|
}
|
||||||
class BattleMoveComp {
|
class HeroAttrsComp {
|
||||||
+direction number
|
+hero_uuid number
|
||||||
+targetX number
|
+lv number
|
||||||
+moving boolean
|
+base_ap number
|
||||||
|
+base_hp number
|
||||||
|
+hp number
|
||||||
|
+mp number
|
||||||
|
+Attrs any
|
||||||
|
+BUFFS any
|
||||||
+reset() void
|
+reset() void
|
||||||
}
|
}
|
||||||
class HeroViewComp {
|
class HeroViewComp {
|
||||||
@@ -104,44 +116,48 @@ class HeroViewComp {
|
|||||||
+BUFFS any
|
+BUFFS any
|
||||||
+update(dt) void
|
+update(dt) void
|
||||||
}
|
}
|
||||||
class HeroModelComp {
|
class HeroSkillsComp {
|
||||||
+reset() void
|
+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 <|-- 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)
|
- [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
|
```mermaid
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant RS as RootSystem
|
participant RS as RootSystem
|
||||||
participant BS as BattleMoveSystem
|
participant HSS as HeroAttrSystem
|
||||||
participant ECS as ECS引擎
|
participant ECS as ECS引擎
|
||||||
participant Entity as 实体
|
participant Entity as 实体
|
||||||
participant Comp as 组件
|
participant Comp as 组件
|
||||||
RS->>ECS : 执行系统
|
RS->>ECS : 执行系统
|
||||||
ECS->>BS : filter()匹配实体
|
ECS->>HSS : filter()匹配实体
|
||||||
BS->>Entity : 获取BattleMoveComp
|
HSS->>Entity : 获取HeroAttrsComp
|
||||||
BS->>Entity : 获取HeroViewComp
|
HSS->>Entity : update()处理逻辑
|
||||||
BS->>Entity : update()处理逻辑
|
|
||||||
Entity->>Comp : 更新状态
|
Entity->>Comp : 更新状态
|
||||||
Comp-->>Entity : 返回结果
|
Comp-->>Entity : 返回结果
|
||||||
Entity-->>BS : 完成处理
|
Entity-->>HSS : 完成处理
|
||||||
BS-->>RS : 系统执行完毕
|
HSS-->>RS : 系统执行完毕
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [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系统注册装饰器*
|
||||||
- [EcsPositionSystem.ts](file://assets/script/game/common/ecs/position/EcsPositionSystem.ts#L1-L9)
|
- [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解耦优势
|
### ECS解耦优势
|
||||||
|
|
||||||
@@ -154,7 +170,7 @@ ECS架构在游戏逻辑中实现了以下解耦效果:
|
|||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [ecs.md](file://doc/ecs/ecs.md#L1-L357)
|
- [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架构支柱
|
## 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系统注册*
|
||||||
|
|
||||||
### 初始化流程详解
|
### 初始化流程详解
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
- [storage.md](file://doc/core/common/storage.md)
|
- [storage.md](file://doc/core/common/storage.md)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *新增怪物类型配置与属性倍率*
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *新增怪物类型配置与属性倍率*
|
||||||
- [MissionMonComp.ts](file://assets/script/game/hero/Mon.ts) - *更新怪物生成逻辑*
|
- [MissionMonComp.ts](file://assets/script/game/hero/Mon.ts) - *更新怪物生成逻辑*
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts) - *新增事件总线组件,基于ECS框架重构*
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
## 更新摘要
|
## 更新摘要
|
||||||
@@ -21,6 +22,7 @@
|
|||||||
- 新增怪物类型系统,支持普通/精英/Boss三种类型
|
- 新增怪物类型系统,支持普通/精英/Boss三种类型
|
||||||
- 添加怪物属性倍率配置,不同类型的怪物具有差异化属性
|
- 添加怪物属性倍率配置,不同类型的怪物具有差异化属性
|
||||||
- 更新关卡生成逻辑,支持程序化生成不同类型的怪物组合
|
- 更新关卡生成逻辑,支持程序化生成不同类型的怪物组合
|
||||||
|
- 新增基于ECS框架的事件总线组件(EBusComp),重构角色视图数据逻辑
|
||||||
- 增强资源引用追踪,添加新修改文件的来源标注
|
- 增强资源引用追踪,添加新修改文件的来源标注
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
@@ -38,7 +40,7 @@
|
|||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
本游戏采用基于Oops Framework的模块化架构,核心运行系统包含初始化流程、事件系统、资源加载与本地存储四大核心模块。系统通过异步队列管理初始化顺序,使用事件总线实现模块间解耦,采用分层资源管理模式,并提供安全可靠的本地存储机制。新增的怪物生成系统支持多种怪物类型和差异化属性配置。
|
本游戏采用基于Oops Framework的模块化架构,核心运行系统包含初始化流程、事件系统、资源加载与本地存储四大核心模块。系统通过异步队列管理初始化顺序,使用事件总线实现模块间解耦,采用分层资源管理模式,并提供安全可靠的本地存储机制。新增的怪物生成系统支持多种怪物类型和差异化属性配置。基于ECS框架重构了角色视图的数据逻辑,引入了EBusComp事件总线组件,提升了系统的可维护性和扩展性。
|
||||||
|
|
||||||
## 项目架构概览
|
## 项目架构概览
|
||||||
|
|
||||||
@@ -67,6 +69,10 @@ Map[GameMap]
|
|||||||
Monster[怪物生成系统]
|
Monster[怪物生成系统]
|
||||||
Scene[场景管理]
|
Scene[场景管理]
|
||||||
end
|
end
|
||||||
|
subgraph "ECS框架"
|
||||||
|
EBus[EBusComp]
|
||||||
|
Hero[Hero组件系统]
|
||||||
|
end
|
||||||
Main --> Init
|
Main --> Init
|
||||||
Init --> Loading
|
Init --> Loading
|
||||||
Init --> SMC
|
Init --> SMC
|
||||||
@@ -76,12 +82,14 @@ SMC --> Storage
|
|||||||
Init --> ResMgr
|
Init --> ResMgr
|
||||||
ResMgr --> Loader
|
ResMgr --> Loader
|
||||||
Map --> Monster
|
Map --> Monster
|
||||||
|
Hero --> EBus
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [Main.ts](file://assets/script/Main.ts#L1-L41)
|
- [Main.ts](file://assets/script/Main.ts#L1-L41)
|
||||||
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts#L1-L207)
|
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts#L1-L207)
|
||||||
- [LoadingViewComp.ts](file://assets/script/game/initialize/view/LoadingViewComp.ts#L1-L91)
|
- [LoadingViewComp.ts](file://assets/script/game/initialize/view/LoadingViewComp.ts#L1-L91)
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts#L6-L89)
|
||||||
|
|
||||||
## 初始化系统
|
## 初始化系统
|
||||||
|
|
||||||
@@ -199,14 +207,75 @@ G --> H[移除监听器]
|
|||||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts#L1-L70)
|
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts#L1-L70)
|
||||||
- [event.md](file://doc/core/common/event.md#L1-L44)
|
- [event.md](file://doc/core/common/event.md#L1-L44)
|
||||||
|
|
||||||
|
### EBusComp - 基于ECS的事件总线组件
|
||||||
|
|
||||||
|
#### EBusComp架构设计
|
||||||
|
|
||||||
|
EBusComp是基于ECS框架重构的事件总线组件,为角色视图和数据逻辑提供高效的通信机制。
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class EBusComp {
|
||||||
|
-_eventTarget : EventTarget
|
||||||
|
+emit(event : string, data? : any) : void
|
||||||
|
+on(event : string, listener : Function, object? : any) : void
|
||||||
|
+off(event? : string, callback? : Function, target? : any) : void
|
||||||
|
+once(event : string, callback : Function, target? : any) : void
|
||||||
|
+targetOff(target : any) : void
|
||||||
|
+reset() : void
|
||||||
|
}
|
||||||
|
class EventTarget {
|
||||||
|
+emit(event : string, data? : any) : void
|
||||||
|
+on(event : string, callback : Function, target? : any) : void
|
||||||
|
+off(event : string, callback : Function, target? : any) : void
|
||||||
|
+once(event : string, callback : Function, target? : any) : void
|
||||||
|
+targetOff(target : any) : void
|
||||||
|
}
|
||||||
|
EBusComp --> EventTarget : 使用
|
||||||
|
```
|
||||||
|
|
||||||
|
**图表来源**
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts#L6-L89)
|
||||||
|
|
||||||
|
#### 核心功能特性
|
||||||
|
|
||||||
|
1. **发布订阅模式**:提供标准的事件发布(emit)和订阅(on/once)接口
|
||||||
|
2. **灵活的取消订阅**:支持多种取消订阅方式
|
||||||
|
- 无参调用:清理本节点所有监听
|
||||||
|
- 仅提供事件名:清理该事件名下所有回调
|
||||||
|
- 完整参数:精确移除指定回调
|
||||||
|
3. **内存管理**:在reset方法中自动清理所有事件监听,防止内存泄漏
|
||||||
|
4. **ECS集成**:通过@ecs.register装饰器注册为ECS组件,实现框架级集成
|
||||||
|
|
||||||
|
#### 使用示例
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 发布事件
|
||||||
|
this.entity.get(EBusComp).emit(GameEvent.HeroLvUp, { level: 5 });
|
||||||
|
|
||||||
|
// 订阅事件
|
||||||
|
this.entity.get(EBusComp).on(GameEvent.HeroLvUp, this.onHeroLevelUp, this);
|
||||||
|
|
||||||
|
// 订阅一次性事件
|
||||||
|
this.entity.get(EBusComp).once(GameEvent.MissionComplete, this.onMissionComplete, this);
|
||||||
|
|
||||||
|
// 取消订阅
|
||||||
|
this.entity.get(EBusComp).off(GameEvent.HeroLvUp, this.onHeroLevelUp, this);
|
||||||
|
```
|
||||||
|
|
||||||
|
**章节来源**
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts#L6-L89)
|
||||||
|
|
||||||
### 事件系统最佳实践
|
### 事件系统最佳实践
|
||||||
|
|
||||||
1. **持续监听**:适用于长期关注的事件
|
1. **持续监听**:适用于长期关注的事件
|
||||||
2. **一次性监听**:适用于仅需响应一次的事件
|
2. **一次性监听**:适用于仅需响应一次的事件
|
||||||
3. **内存管理**:及时取消不再需要的事件监听
|
3. **内存管理**:及时取消不再需要的事件监听
|
||||||
|
4. **ECS组件化**:利用EBusComp实现组件间的松耦合通信
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [event.md](file://doc/core/common/event.md#L1-L44)
|
- [event.md](file://doc/core/common/event.md#L1-L44)
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts#L6-L89)
|
||||||
|
|
||||||
## 资源加载系统
|
## 资源加载系统
|
||||||
|
|
||||||
@@ -503,6 +572,8 @@ S --> T[资源释放]
|
|||||||
U[怪物系统] --> V[RogueConfig配置]
|
U[怪物系统] --> V[RogueConfig配置]
|
||||||
V --> W[MissionMonComp生成]
|
V --> W[MissionMonComp生成]
|
||||||
W --> X[属性计算]
|
W --> X[属性计算]
|
||||||
|
Y[ECS框架] --> Z[EBusComp事件总线]
|
||||||
|
Z --> AA[组件间通信]
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
@@ -510,6 +581,7 @@ W --> X[属性计算]
|
|||||||
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts#L1-L207)
|
- [Initialize.ts](file://assets/script/game/initialize/Initialize.ts#L1-L207)
|
||||||
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts#L1-L194)
|
- [SingletonModuleComp.ts](file://assets/script/game/common/SingletonModuleComp.ts#L1-L194)
|
||||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L0-L178)
|
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L0-L178)
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts#L6-L89)
|
||||||
|
|
||||||
### 数据流管理
|
### 数据流管理
|
||||||
|
|
||||||
@@ -533,6 +605,7 @@ W --> X[属性计算]
|
|||||||
2. **监听管理**:及时移除不需要的事件监听器
|
2. **监听管理**:及时移除不需要的事件监听器
|
||||||
3. **参数传递**:合理设计事件参数结构
|
3. **参数传递**:合理设计事件参数结构
|
||||||
4. **性能考虑**:避免在高频事件中执行复杂操作
|
4. **性能考虑**:避免在高频事件中执行复杂操作
|
||||||
|
5. **ECS集成**:充分利用EBusComp组件实现高效的组件间通信
|
||||||
|
|
||||||
### 资源管理最佳实践
|
### 资源管理最佳实践
|
||||||
|
|
||||||
@@ -559,4 +632,8 @@ W --> X[属性计算]
|
|||||||
|
|
||||||
本游戏的核心运行系统通过模块化设计实现了高度的可维护性和扩展性。初始化系统确保游戏启动的稳定性和效率,事件系统提供了灵活的模块间通信机制,资源管理系统支持复杂的资源加载和管理需求,本地存储系统保障了数据的安全性和持久性。
|
本游戏的核心运行系统通过模块化设计实现了高度的可维护性和扩展性。初始化系统确保游戏启动的稳定性和效率,事件系统提供了灵活的模块间通信机制,资源管理系统支持复杂的资源加载和管理需求,本地存储系统保障了数据的安全性和持久性。
|
||||||
|
|
||||||
新增的怪物生成系统通过RogueConfig.ts和MissionMonComp.ts实现了程序化的怪物生成逻辑,支持普通、精英、BOSS三种怪物类型,并通过属性倍率配置实现了差异化的设计。系统采用的异步队列模式、事件驱动架构和单例管理模式,为游戏开发提供了坚实的基础框架。通过合理的配置和优化,这套系统能够支持大型游戏项目的开发需求,同时保持良好的性能表现和用户体验。
|
新增的怪物生成系统通过RogueConfig.ts和MissionMonComp.ts实现了程序化的怪物生成逻辑,支持普通、精英、BOSS三种怪物类型,并通过属性倍率配置实现了差异化的设计。系统采用的异步队列模式、事件驱动架构和单例管理模式,为游戏开发提供了坚实的基础框架。
|
||||||
|
|
||||||
|
特别值得注意的是,基于ECS框架重构了角色视图的数据逻辑,引入了EBusComp事件总线组件。这一改进不仅提升了系统的可维护性和扩展性,还实现了组件间的松耦合通信。EBusComp组件提供了标准的发布订阅接口,支持灵活的事件管理和内存清理机制,为游戏的长期发展奠定了良好的基础。
|
||||||
|
|
||||||
|
通过合理的配置和优化,这套系统能够支持大型游戏项目的开发需求,同时保持良好的性能表现和用户体验。
|
||||||
@@ -1,769 +0,0 @@
|
|||||||
# 技能系统
|
|
||||||
|
|
||||||
<cite>
|
|
||||||
**本文档中引用的文件**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts)
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts)
|
|
||||||
- [SkillViewCom.ts](file://assets/script/game/skill/SkillViewCom.ts)
|
|
||||||
- [AtkConCom.ts](file://assets/script/game/skill/AtkConCom.ts)
|
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
|
||||||
- [Tooltip.ts](file://assets/script/game/skill/Tooltip.ts)
|
|
||||||
</cite>
|
|
||||||
|
|
||||||
## 目录
|
|
||||||
1. [简介](#简介)
|
|
||||||
2. [项目结构](#项目结构)
|
|
||||||
3. [核心组件](#核心组件)
|
|
||||||
4. [架构概览](#架构概览)
|
|
||||||
5. [详细组件分析](#详细组件分析)
|
|
||||||
6. [技能配置系统](#技能配置系统)
|
|
||||||
7. [技能控制机制](#技能控制机制)
|
|
||||||
8. [技能释放流程](#技能释放流程)
|
|
||||||
9. [异常处理与最佳实践](#异常处理与最佳实践)
|
|
||||||
10. [性能考虑](#性能考虑)
|
|
||||||
11. [故障排除指南](#故障排除指南)
|
|
||||||
12. [总结](#总结)
|
|
||||||
|
|
||||||
## 简介
|
|
||||||
|
|
||||||
技能系统是游戏战斗的核心机制,负责管理角色的技能释放、冷却时间、目标选择、特效播放等关键功能。本系统采用ECS架构设计,通过模块化的方式实现了技能的完整生命周期管理,包括技能配置、控制、执行和特效展示。
|
|
||||||
|
|
||||||
## 项目结构
|
|
||||||
|
|
||||||
技能系统的文件组织遵循模块化原则,主要分为以下几个部分:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TB
|
|
||||||
subgraph "配置层"
|
|
||||||
A[SkillSet.ts<br/>技能配置表]
|
|
||||||
end
|
|
||||||
subgraph "控制层"
|
|
||||||
B[SkillConComp.ts<br/>技能控制组件]
|
|
||||||
end
|
|
||||||
subgraph "执行层"
|
|
||||||
C[SkillEnt.ts<br/>技能实体]
|
|
||||||
D[SkillViewCom.ts<br/>技能视图组件]
|
|
||||||
E[AtkConCom.ts<br/>攻击控制组件]
|
|
||||||
end
|
|
||||||
subgraph "支持层"
|
|
||||||
F[HeroViewComp.ts<br/>英雄视图组件]
|
|
||||||
G[Tooltip.ts<br/>提示系统]
|
|
||||||
end
|
|
||||||
A --> B
|
|
||||||
B --> C
|
|
||||||
C --> D
|
|
||||||
D --> E
|
|
||||||
B --> F
|
|
||||||
E --> G
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L1-L148)
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L177)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L1-L78)
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L1-L148)
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L177)
|
|
||||||
|
|
||||||
## 核心组件
|
|
||||||
|
|
||||||
技能系统由以下核心组件构成:
|
|
||||||
|
|
||||||
### 技能配置表 (SkillSet)
|
|
||||||
负责定义技能的所有属性和行为规则,包括技能类型、目标群体、伤害类型、冷却时间等关键字段。
|
|
||||||
|
|
||||||
### 技能控制组件 (SkillConComp)
|
|
||||||
管理技能的触发逻辑、冷却时间计算、目标选择和定时器资源管理。
|
|
||||||
|
|
||||||
### 技能实体 (SkillEnt)
|
|
||||||
负责技能的实例化、特效加载和生命周期管理。
|
|
||||||
|
|
||||||
### 技能视图组件 (SkillViewCom)
|
|
||||||
处理技能的视觉表现、动画播放和位置计算。
|
|
||||||
|
|
||||||
### 攻击控制组件 (AtkConCom)
|
|
||||||
实现具体的攻击逻辑、碰撞检测和伤害计算。
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L1-L148)
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L177)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L1-L78)
|
|
||||||
|
|
||||||
## 架构概览
|
|
||||||
|
|
||||||
技能系统采用分层架构设计,确保各组件职责清晰、耦合度低:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TD
|
|
||||||
subgraph "表现层"
|
|
||||||
A[技能视图组件<br/>SkillViewCom]
|
|
||||||
B[特效播放<br/>Animation/Particle]
|
|
||||||
end
|
|
||||||
subgraph "控制层"
|
|
||||||
C[技能控制组件<br/>SkillConComp]
|
|
||||||
D[攻击控制组件<br/>AtkConCom]
|
|
||||||
end
|
|
||||||
subgraph "数据层"
|
|
||||||
E[技能实体<br/>SkillEnt]
|
|
||||||
F[技能配置<br/>SkillSet]
|
|
||||||
end
|
|
||||||
subgraph "业务层"
|
|
||||||
G[英雄视图组件<br/>HeroViewComp]
|
|
||||||
H[目标选择<br/>selectTargets]
|
|
||||||
end
|
|
||||||
A --> C
|
|
||||||
C --> E
|
|
||||||
E --> F
|
|
||||||
C --> G
|
|
||||||
D --> A
|
|
||||||
G --> H
|
|
||||||
B --> D
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillViewCom.ts](file://assets/script/game/skill/SkillViewCom.ts#L1-L156)
|
|
||||||
- [AtkConCom.ts](file://assets/script/game/skill/AtkConCom.ts#L1-L236)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L1-L78)
|
|
||||||
|
|
||||||
## 详细组件分析
|
|
||||||
|
|
||||||
### 技能配置系统 (SkillSet)
|
|
||||||
|
|
||||||
技能配置系统是整个技能体系的基础,定义了技能的所有属性和行为规则。
|
|
||||||
|
|
||||||
#### 技能类型枚举 (SType)
|
|
||||||
|
|
||||||
| 类型 | 值 | 描述 | 用途 |
|
|
||||||
|------|----|----- |----- |
|
|
||||||
| damage | 0 | 伤害技能 | 对目标造成物理/魔法伤害 |
|
|
||||||
| heal | 1 | 治疗技能 | 恢复目标生命值 |
|
|
||||||
| shield | 2 | 护盾技能 | 为目标添加护盾 |
|
|
||||||
| atk_speed | 3 | 攻击速度提升 | 提升攻击速度 |
|
|
||||||
| power_up | 4 | 力量提升 | 提升攻击力 |
|
|
||||||
| ap_up | 5 | 法术强度提升 | 提升法术伤害 |
|
|
||||||
| dod_up | 6 | 闪避提升 | 提升闪避率 |
|
|
||||||
| crit_up | 7 | 暴击率提升 | 提升暴击率 |
|
|
||||||
| crit_dmg_up | 8 | 暴击伤害提升 | 提升暴击伤害 |
|
|
||||||
| wfuny_up | 9 | 连击率提升 | 提升连击触发概率 |
|
|
||||||
| zhaohuan | 10 | 召唤技能 | 召唤生物协助战斗 |
|
|
||||||
| buff | 11 | 增益技能 | 为目标添加增益效果 |
|
|
||||||
|
|
||||||
#### 目标群体枚举 (TGroup)
|
|
||||||
|
|
||||||
| 群体 | 值 | 描述 | 适用场景 |
|
|
||||||
|------|----|----- |---------|
|
|
||||||
| Self | 0 | 自身 | 自身增益、治疗技能 |
|
|
||||||
| Ally | 1 | 所有敌人 | 团队治疗、辅助技能 |
|
|
||||||
| Team | 2 | 所有友方 | 团队增益、保护技能 |
|
|
||||||
| Enemy | 3 | 敌方单位 | 输出技能、控制技能 |
|
|
||||||
| All | 4 | 所有单位 | 全局效果、范围伤害 |
|
|
||||||
|
|
||||||
#### 伤害类型枚举 (DTType)
|
|
||||||
|
|
||||||
| 类型 | 值 | 描述 | 特点 |
|
|
||||||
|------|----|----- |------|
|
|
||||||
| single | 0 | 单体伤害 | 针对单一目标 |
|
|
||||||
| range | 1 | 范围伤害 | 对多个目标造成伤害 |
|
|
||||||
|
|
||||||
#### 关键字段说明
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
classDiagram
|
|
||||||
class SkillConfig {
|
|
||||||
+number uuid
|
|
||||||
+string name
|
|
||||||
+string sp_name
|
|
||||||
+AtkedName AtkedName
|
|
||||||
+string path
|
|
||||||
+TGroup TGroup
|
|
||||||
+SType SType
|
|
||||||
+string act
|
|
||||||
+DTType DTType
|
|
||||||
+DType DType
|
|
||||||
+number ap
|
|
||||||
+number cd
|
|
||||||
+number t_num
|
|
||||||
+number hit_num
|
|
||||||
+number hit
|
|
||||||
+number hitcd
|
|
||||||
+number speed
|
|
||||||
+number cost
|
|
||||||
+number with
|
|
||||||
+BuffConf[] buffs
|
|
||||||
+NeAttrsConf[] neAttrs
|
|
||||||
+string info
|
|
||||||
+number hero
|
|
||||||
}
|
|
||||||
class BuffConf {
|
|
||||||
+Attrs buff
|
|
||||||
+BType BType
|
|
||||||
+number value
|
|
||||||
+number time
|
|
||||||
+number chance
|
|
||||||
}
|
|
||||||
class NeAttrsConf {
|
|
||||||
+NeAttrs neAttrs
|
|
||||||
+number value
|
|
||||||
+number time
|
|
||||||
}
|
|
||||||
SkillConfig --> BuffConf : "包含"
|
|
||||||
SkillConfig --> NeAttrsConf : "包含"
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L118-L148)
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L1-L148)
|
|
||||||
|
|
||||||
### 技能控制组件 (SkillConComp)
|
|
||||||
|
|
||||||
技能控制组件负责技能的整体管理和触发逻辑,是技能系统的核心控制器。
|
|
||||||
|
|
||||||
#### 主要功能
|
|
||||||
|
|
||||||
1. **冷却时间管理**
|
|
||||||
- 监控技能冷却进度
|
|
||||||
- 自动重置冷却时间
|
|
||||||
- 处理技能消耗检查
|
|
||||||
|
|
||||||
2. **自动施法条件判断**
|
|
||||||
- 检查角色状态(眩晕、冰冻等)
|
|
||||||
- 验证魔法值充足
|
|
||||||
- 判断攻击状态冲突
|
|
||||||
|
|
||||||
3. **多段技能连发机制**
|
|
||||||
- 实现wfuny连击系统
|
|
||||||
- 控制技能释放间隔
|
|
||||||
- 管理连击计数器
|
|
||||||
|
|
||||||
4. **目标选择策略**
|
|
||||||
- 基于阵营的目标查询
|
|
||||||
- 前排/后排目标优先级
|
|
||||||
- 随机目标选择算法
|
|
||||||
|
|
||||||
#### 核心方法分析
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
participant Player as 玩家输入
|
|
||||||
participant SkillCon as 技能控制组件
|
|
||||||
participant HeroView as 英雄视图
|
|
||||||
participant SkillEnt as 技能实体
|
|
||||||
participant AtkCon as 攻击控制
|
|
||||||
Player->>SkillCon : 更新技能冷却
|
|
||||||
SkillCon->>SkillCon : 检查冷却时间
|
|
||||||
SkillCon->>HeroView : 检查角色状态
|
|
||||||
HeroView-->>SkillCon : 状态验证结果
|
|
||||||
SkillCon->>SkillCon : 选择目标
|
|
||||||
SkillCon->>HeroView : 播放技能特效
|
|
||||||
SkillCon->>SkillEnt : 创建技能实体
|
|
||||||
SkillEnt->>AtkCon : 初始化攻击组件
|
|
||||||
AtkCon->>AtkCon : 执行攻击逻辑
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L35-L177)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L15-L78)
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L177)
|
|
||||||
|
|
||||||
### 技能实体 (SkillEnt)
|
|
||||||
|
|
||||||
技能实体负责技能的实例化和生命周期管理,确保技能能够正确地在游戏中表现。
|
|
||||||
|
|
||||||
#### 实体创建流程
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart TD
|
|
||||||
A[技能触发] --> B[加载技能配置]
|
|
||||||
B --> C{配置是否存在?}
|
|
||||||
C --> |否| D[输出错误日志]
|
|
||||||
C --> |是| E[检查施法者]
|
|
||||||
E --> F{施法者是否存在?}
|
|
||||||
F --> |否| D
|
|
||||||
F --> |是| G[加载特效预制体]
|
|
||||||
G --> H{预制体加载成功?}
|
|
||||||
H --> |否| D
|
|
||||||
H --> |是| I[实例化特效节点]
|
|
||||||
I --> J[设置节点属性]
|
|
||||||
J --> K[添加技能组件]
|
|
||||||
K --> L[技能实体就绪]
|
|
||||||
D --> M[结束]
|
|
||||||
L --> N[等待执行时机]
|
|
||||||
N --> O[执行技能逻辑]
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L15-L78)
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L1-L78)
|
|
||||||
|
|
||||||
### 技能视图组件 (SkillViewCom)
|
|
||||||
|
|
||||||
技能视图组件处理技能的视觉表现和动画播放,是技能外观效果的主要控制者。
|
|
||||||
|
|
||||||
#### 动画类型支持
|
|
||||||
|
|
||||||
| 类型 | 值 | 描述 | 实现方式 |
|
|
||||||
|------|----|----- |---------|
|
|
||||||
| linear | 0 | 直线运动 | 线性插值移动 |
|
|
||||||
| bezier | 1 | 贝塞尔曲线 | 贝塞尔曲线轨迹 |
|
|
||||||
| fixed | 2 | 固定起点 | 起点固定,终点动态 |
|
|
||||||
| fixedEnd | 3 | 固定终点 | 终点固定,起点动态 |
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillViewCom.ts](file://assets/script/game/skill/SkillViewCom.ts#L1-L156)
|
|
||||||
|
|
||||||
### 攻击控制组件 (AtkConCom)
|
|
||||||
|
|
||||||
攻击控制组件实现具体的攻击逻辑,包括碰撞检测、伤害计算和效果应用。
|
|
||||||
|
|
||||||
#### 碰撞检测机制
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart TD
|
|
||||||
A[技能移动] --> B[检测碰撞]
|
|
||||||
B --> C{是否接触敌方}
|
|
||||||
C --> |否| D[继续移动]
|
|
||||||
C --> |是| E[检查穿透次数]
|
|
||||||
E --> F{达到最大穿透?}
|
|
||||||
F --> |是| G[销毁技能]
|
|
||||||
F --> |否| H[计算伤害]
|
|
||||||
H --> I[应用伤害效果]
|
|
||||||
I --> J[增加穿透计数]
|
|
||||||
J --> K{范围伤害?}
|
|
||||||
K --> |是| L[对范围内所有目标]
|
|
||||||
K --> |否| M[仅对当前目标]
|
|
||||||
L --> N[继续移动]
|
|
||||||
M --> N
|
|
||||||
D --> N
|
|
||||||
G --> O[结束]
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [AtkConCom.ts](file://assets/script/game/skill/AtkConCom.ts#L120-L180)
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [AtkConCom.ts](file://assets/script/game/skill/AtkConCom.ts#L1-L236)
|
|
||||||
|
|
||||||
## 技能配置系统
|
|
||||||
|
|
||||||
技能配置系统是技能系统的基础,通过SkillSet.ts定义了所有技能的属性和行为规则。
|
|
||||||
|
|
||||||
### 配置表结构
|
|
||||||
|
|
||||||
技能配置表采用Record结构,以技能UUID作为键,SkillConfig接口作为值:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const SkillSet: Record<number, SkillConfig> = {
|
|
||||||
6001: {
|
|
||||||
uuid: 6001,
|
|
||||||
name: "挥击",
|
|
||||||
sp_name: "atk_s1",
|
|
||||||
AtkedName: AtkedName.atked,
|
|
||||||
path: "3036",
|
|
||||||
TGroup: TGroup.Enemy,
|
|
||||||
SType: SType.damage,
|
|
||||||
act: "atk",
|
|
||||||
DTType: DTType.single,
|
|
||||||
DType: DType.ATK,
|
|
||||||
ap: 100,
|
|
||||||
cd: 1,
|
|
||||||
t_num: 1,
|
|
||||||
hit_num: 1,
|
|
||||||
hit: 1,
|
|
||||||
hitcd: 0.2,
|
|
||||||
speed: 720,
|
|
||||||
cost: 0,
|
|
||||||
with: 0,
|
|
||||||
buffs: [],
|
|
||||||
neAttrs: [],
|
|
||||||
info: "向最前方敌人扔出石斧,造成100%攻击的伤害"
|
|
||||||
},
|
|
||||||
// 更多技能配置...
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 关键配置字段详解
|
|
||||||
|
|
||||||
| 字段 | 类型 | 描述 | 默认值 | 说明 |
|
|
||||||
|------|------|------|--------|------|
|
|
||||||
| uuid | number | 技能唯一标识符 | - | 必需,用于技能识别 |
|
|
||||||
| name | string | 技能名称 | - | 显示用名称 |
|
|
||||||
| sp_name | string | 特效名称 | - | 对应特效资源文件名 |
|
|
||||||
| TGroup | TGroup | 目标群体 | - | 技能作用目标类型 |
|
|
||||||
| SType | SType | 技能类型 | - | 技能效果类型 |
|
|
||||||
| cd | number | 冷却时间 | - | 技能冷却秒数 |
|
|
||||||
| cost | number | 消耗值 | - | 魔法值或能量消耗 |
|
|
||||||
| ap | number | 伤害倍率 | - | 伤害相对于攻击力的百分比 |
|
|
||||||
| hit | number | 穿透次数 | 0 | 攻击可穿透的目标数量 |
|
|
||||||
| hitcd | number | 持续伤害间隔 | 0 | 持续伤害的触发间隔 |
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L118-L148)
|
|
||||||
|
|
||||||
## 技能控制机制
|
|
||||||
|
|
||||||
技能控制机制是技能系统的核心,负责技能的触发、冷却管理和执行逻辑。
|
|
||||||
|
|
||||||
### 冷却时间管理系统
|
|
||||||
|
|
||||||
冷却时间管理采用增量式计算,每帧更新技能的冷却进度:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart TD
|
|
||||||
A[技能冷却开始] --> B[dt累积]
|
|
||||||
B --> C[检查冷却时间]
|
|
||||||
C --> D{是否达到冷却?}
|
|
||||||
D --> |否| E[继续累积]
|
|
||||||
D --> |是| F[检查魔法值]
|
|
||||||
F --> G{魔法值充足?}
|
|
||||||
G --> |否| H[等待补充]
|
|
||||||
G --> |是| I[触发技能]
|
|
||||||
E --> B
|
|
||||||
H --> F
|
|
||||||
I --> J[重置冷却时间]
|
|
||||||
J --> K[扣除魔法值]
|
|
||||||
K --> L[技能准备就绪]
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L35-L50)
|
|
||||||
|
|
||||||
### 自动施法条件判断
|
|
||||||
|
|
||||||
系统在每次更新时检查多个条件:
|
|
||||||
|
|
||||||
1. **战斗状态检查**
|
|
||||||
- 检查mission.play状态
|
|
||||||
- 验证mission.pause状态
|
|
||||||
|
|
||||||
2. **角色状态检查**
|
|
||||||
- 检查眩晕状态 (isStun())
|
|
||||||
- 检查冰冻状态 (isFrost())
|
|
||||||
|
|
||||||
3. **技能状态检查**
|
|
||||||
- 验证冷却时间是否完成
|
|
||||||
- 检查魔法值是否足够
|
|
||||||
- 确认攻击状态不冲突
|
|
||||||
|
|
||||||
### 多段技能连发机制
|
|
||||||
|
|
||||||
系统支持wfuny连击机制,通过check_wfuny方法判断是否触发连击:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
participant SkillCon as 技能控制
|
|
||||||
participant HeroView as 英雄视图
|
|
||||||
participant Timer as 定时器系统
|
|
||||||
SkillCon->>HeroView : 检查wfuny属性
|
|
||||||
HeroView-->>SkillCon : 返回连击概率
|
|
||||||
SkillCon->>SkillCon : 随机数生成
|
|
||||||
alt 触发连击
|
|
||||||
SkillCon->>Timer : 设置延迟执行
|
|
||||||
Timer->>SkillCon : 延迟后再次执行
|
|
||||||
SkillCon->>SkillCon : 递归调用doSkill
|
|
||||||
else 未触发连击
|
|
||||||
SkillCon->>SkillCon : 正常结束
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L85-L105)
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L35-L177)
|
|
||||||
|
|
||||||
## 技能释放流程
|
|
||||||
|
|
||||||
技能释放是一个复杂的多阶段过程,涉及预判、特效播放、实体生成等多个环节。
|
|
||||||
|
|
||||||
### 技能释放全过程
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
participant Player as 玩家操作
|
|
||||||
participant SkillCon as 技能控制
|
|
||||||
participant HeroView as 英雄视图
|
|
||||||
participant SkillEnt as 技能实体
|
|
||||||
participant AtkCon as 攻击控制
|
|
||||||
participant Target as 目标对象
|
|
||||||
Player->>SkillCon : 发起技能请求
|
|
||||||
SkillCon->>SkillCon : 验证技能可用性
|
|
||||||
SkillCon->>HeroView : 播放技能动画
|
|
||||||
HeroView-->>SkillCon : 动画播放完成
|
|
||||||
SkillCon->>SkillCon : 创建技能实体
|
|
||||||
SkillCon->>SkillEnt : 加载技能配置
|
|
||||||
SkillEnt->>SkillEnt : 实例化特效节点
|
|
||||||
SkillEnt->>AtkCon : 添加攻击组件
|
|
||||||
AtkCon->>AtkCon : 初始化技能参数
|
|
||||||
AtkCon->>Target : 开始攻击逻辑
|
|
||||||
Target-->>AtkCon : 碰撞检测结果
|
|
||||||
AtkCon->>AtkCon : 计算伤害效果
|
|
||||||
AtkCon->>Target : 应用伤害效果
|
|
||||||
AtkCon->>AtkCon : 检查技能结束条件
|
|
||||||
alt 技能需要多段
|
|
||||||
AtkCon->>AtkCon : 继续下一段攻击
|
|
||||||
else 技能结束
|
|
||||||
AtkCon->>AtkCon : 销毁技能实体
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L60-L105)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L15-L78)
|
|
||||||
- [AtkConCom.ts](file://assets/script/game/skill/AtkConCom.ts#L120-L180)
|
|
||||||
|
|
||||||
### 目标选择策略
|
|
||||||
|
|
||||||
目标选择是技能系统的重要组成部分,采用智能算法确定技能目标:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart TD
|
|
||||||
A[开始目标选择] --> B[查询目标实体]
|
|
||||||
B --> C{是否有目标?}
|
|
||||||
C --> |否| D[返回默认位置]
|
|
||||||
C --> |是| E[确定前排目标]
|
|
||||||
E --> F[添加前排目标到列表]
|
|
||||||
F --> G{还需要更多目标?}
|
|
||||||
G --> |否| H[返回目标列表]
|
|
||||||
G --> |是| I[随机选择剩余目标]
|
|
||||||
I --> J[添加到目标列表]
|
|
||||||
J --> K{达到目标数量?}
|
|
||||||
K --> |否| G
|
|
||||||
K --> |是| H
|
|
||||||
D --> L[填充默认位置]
|
|
||||||
L --> H
|
|
||||||
```
|
|
||||||
|
|
||||||
**图表来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L120-L175)
|
|
||||||
|
|
||||||
### 定时器资源管理
|
|
||||||
|
|
||||||
系统使用定时器管理技能的延迟执行,确保技能释放的精确控制:
|
|
||||||
|
|
||||||
| 定时器类型 | 用途 | 生命周期 | 清理方式 |
|
|
||||||
|------------|------|----------|----------|
|
|
||||||
| 技能延迟定时器 | 技能特效延迟播放 | 技能生命周期内 | 技能结束后清理 |
|
|
||||||
| 连击延迟定时器 | 多段技能间隔 | 连击期间 | 连击结束时清理 |
|
|
||||||
| 冷却定时器 | 技能冷却倒计时 | 技能冷却期间 | 冷却完成时清理 |
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L60-L177)
|
|
||||||
|
|
||||||
## 异常处理与最佳实践
|
|
||||||
|
|
||||||
技能系统在设计时充分考虑了各种异常情况,提供了完善的错误处理机制。
|
|
||||||
|
|
||||||
### 节点有效性检查
|
|
||||||
|
|
||||||
系统在关键操作前进行节点有效性检查,防止因节点被销毁导致的异常:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
private doSkill(config: typeof SkillSet[keyof typeof SkillSet], is_wfuny: boolean = false, dmg: number = 0) {
|
|
||||||
// 添加节点有效性检查
|
|
||||||
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 技能执行逻辑
|
|
||||||
|
|
||||||
// 再次检查节点有效性
|
|
||||||
if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 异常处理策略
|
|
||||||
|
|
||||||
1. **技能配置缺失处理**
|
|
||||||
```typescript
|
|
||||||
load(startPos: Vec3, parent: Node, uuid: number, targetPos: any[], caster: HeroViewComp = null, dmg: number = 0) {
|
|
||||||
const config = SkillSet[uuid];
|
|
||||||
if (!config) {
|
|
||||||
console.error("[Skill] 技能配置不存在:", uuid);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **资源加载失败处理**
|
|
||||||
```typescript
|
|
||||||
const prefab: Prefab = oops.res.get(path, Prefab);
|
|
||||||
if (!prefab) {
|
|
||||||
console.error("[Skill] 预制体加载失败:", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **战斗状态异常处理**
|
|
||||||
```typescript
|
|
||||||
update(dt: number) {
|
|
||||||
if (!smc.mission.play || smc.mission.pause) return;
|
|
||||||
// 技能逻辑执行
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 最佳实践建议
|
|
||||||
|
|
||||||
1. **资源管理**
|
|
||||||
- 及时清理定时器资源
|
|
||||||
- 正确释放技能实体
|
|
||||||
- 避免内存泄漏
|
|
||||||
|
|
||||||
2. **性能优化**
|
|
||||||
- 使用对象池管理技能实体
|
|
||||||
- 减少不必要的对象创建
|
|
||||||
- 优化碰撞检测频率
|
|
||||||
|
|
||||||
3. **错误恢复**
|
|
||||||
- 提供默认行为处理异常
|
|
||||||
- 记录详细的错误日志
|
|
||||||
- 实现优雅降级机制
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L66-L105)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L15-L40)
|
|
||||||
|
|
||||||
## 性能考虑
|
|
||||||
|
|
||||||
技能系统在设计时充分考虑了性能优化,采用了多种策略确保流畅的游戏体验。
|
|
||||||
|
|
||||||
### 对象池管理
|
|
||||||
|
|
||||||
技能实体采用对象池模式,避免频繁的对象创建和销毁:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 在SkillConComp中维护定时器映射
|
|
||||||
private _timers: { [key: string]: any } = {};
|
|
||||||
|
|
||||||
// 定时器资源管理
|
|
||||||
public clear_timer() {
|
|
||||||
Object.values(this._timers).forEach(clearTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
onDestroy() {
|
|
||||||
// 清理所有定时器
|
|
||||||
Object.values(this._timers).forEach(clearTimeout);
|
|
||||||
this._timers = {};
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 内存优化策略
|
|
||||||
|
|
||||||
1. **延迟加载**
|
|
||||||
- 技能特效按需加载
|
|
||||||
- 避免一次性加载所有技能资源
|
|
||||||
|
|
||||||
2. **引用管理**
|
|
||||||
- 使用浅拷贝传递技能属性
|
|
||||||
- 避免深层复制造成的性能开销
|
|
||||||
|
|
||||||
3. **生命周期管理**
|
|
||||||
- 及时销毁不需要的技能实体
|
|
||||||
- 清理事件监听器和定时器
|
|
||||||
|
|
||||||
### 碰撞检测优化
|
|
||||||
|
|
||||||
攻击控制组件采用高效的碰撞检测算法:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 范围伤害优化
|
|
||||||
public atk(args: any) {
|
|
||||||
let targetsInRange: HeroViewComp[] = [];
|
|
||||||
|
|
||||||
// 使用ECS查询优化目标查找
|
|
||||||
ecs.query(ecs.allOf(HeroViewComp)).some(e => {
|
|
||||||
const view = e.get(HeroViewComp);
|
|
||||||
if (view.fac != this.fac) {
|
|
||||||
const distance = Math.abs(this.node.position.x - view.node.position.x);
|
|
||||||
if (distance <= dis) {
|
|
||||||
targetsInRange.push(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 故障排除指南
|
|
||||||
|
|
||||||
### 常见问题及解决方案
|
|
||||||
|
|
||||||
#### 技能无法触发
|
|
||||||
|
|
||||||
**症状**: 技能按下后没有反应
|
|
||||||
**可能原因**:
|
|
||||||
1. 冷却时间未完成
|
|
||||||
2. 魔法值不足
|
|
||||||
3. 角色处于异常状态
|
|
||||||
4. 技能配置缺失
|
|
||||||
|
|
||||||
**解决步骤**:
|
|
||||||
1. 检查技能冷却时间
|
|
||||||
2. 验证角色魔法值
|
|
||||||
3. 确认角色状态正常
|
|
||||||
4. 检查SkillSet配置
|
|
||||||
|
|
||||||
#### 特效播放异常
|
|
||||||
|
|
||||||
**症状**: 技能释放但没有特效
|
|
||||||
**可能原因**:
|
|
||||||
1. 特效资源加载失败
|
|
||||||
2. 节点被提前销毁
|
|
||||||
3. 动画组件配置错误
|
|
||||||
|
|
||||||
**解决步骤**:
|
|
||||||
1. 检查资源路径和文件名
|
|
||||||
2. 验证节点有效性
|
|
||||||
3. 确认动画组件正确绑定
|
|
||||||
|
|
||||||
#### 目标选择错误
|
|
||||||
|
|
||||||
**症状**: 技能攻击了错误的目标
|
|
||||||
**可能原因**:
|
|
||||||
1. 目标查询逻辑错误
|
|
||||||
2. 阵营判断失误
|
|
||||||
3. 前排/后排判定错误
|
|
||||||
|
|
||||||
**解决步骤**:
|
|
||||||
1. 检查阵营判断逻辑
|
|
||||||
2. 验证目标位置计算
|
|
||||||
3. 确认优先级设置
|
|
||||||
|
|
||||||
**章节来源**
|
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L170-L177)
|
|
||||||
- [SkillEnt.ts](file://assets/script/game/skill/SkillEnt.ts#L25-L40)
|
|
||||||
|
|
||||||
## 总结
|
|
||||||
|
|
||||||
技能系统是一个复杂而精密的战斗机制,通过合理的架构设计和完善的异常处理,实现了高效、稳定的技能管理功能。
|
|
||||||
|
|
||||||
### 系统优势
|
|
||||||
|
|
||||||
1. **模块化设计**: 各组件职责清晰,易于维护和扩展
|
|
||||||
2. **性能优化**: 采用对象池和延迟加载策略,确保流畅运行
|
|
||||||
3. **异常处理**: 完善的错误检查和恢复机制
|
|
||||||
4. **灵活性**: 支持多种技能类型和效果组合
|
|
||||||
|
|
||||||
### 技术特点
|
|
||||||
|
|
||||||
1. **ECS架构**: 基于组件式设计,提高代码复用性
|
|
||||||
2. **事件驱动**: 通过事件系统实现组件间的松耦合通信
|
|
||||||
3. **配置驱动**: 技能行为完全由配置文件控制
|
|
||||||
4. **资源管理**: 完善的资源加载和释放机制
|
|
||||||
|
|
||||||
### 扩展建议
|
|
||||||
|
|
||||||
1. **技能树系统**: 可以在此基础上扩展技能升级和解锁机制
|
|
||||||
2. **连携技能**: 支持多个角色协同释放的组合技能
|
|
||||||
3. **动态平衡**: 根据玩家表现动态调整技能效果
|
|
||||||
4. **AI适配**: 为AI敌人提供专门的技能释放策略
|
|
||||||
|
|
||||||
技能系统作为游戏战斗的核心,其设计理念和实现方式为类似项目的开发提供了宝贵的参考价值。
|
|
||||||
@@ -2,15 +2,21 @@
|
|||||||
|
|
||||||
<cite>
|
<cite>
|
||||||
**本文档中引用的文件**
|
**本文档中引用的文件**
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts)
|
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts) - *更新了属性类型和职业成长配置*
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts)
|
- [Hero.ts](file://assets\script\game\hero\Hero.ts) - *更新了英雄实体初始化逻辑*
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts) - *重构了属性组件,包含攻击状态管理*
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts)
|
- [HeroViewComp.ts](file://assets\game\hero\HeroViewComp.ts) - *更新了视图组件,移除了攻击状态管理*
|
||||||
- [GameEvent.ts](file://assets/script/game/common/config/GameEvent.ts)
|
- [heroSet.ts](file://assets\script\game\common\config\heroSet.ts) - *包含了英雄配置数据*
|
||||||
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts)
|
- [GameEvent.ts](file://assets\script\game\common\config\GameEvent.ts) - *定义了游戏事件系统*
|
||||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts)
|
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
|
## 更新摘要
|
||||||
|
**主要变更**
|
||||||
|
- **架构重构**:将`is_atking`攻击状态从`HeroViewComp`视图层迁移至`HeroAttrsComp`数据层,实现状态管理集中化
|
||||||
|
- **ECS架构优化**:为`HeroAttrSystem`等系统添加ECS注册装饰器,使架构更符合标准
|
||||||
|
- **职责分离**:`HeroViewComp`不再管理攻击状态,仅负责UI表现和动画控制
|
||||||
|
- **代码维护性提升**:通过将状态管理集中在数据层,提高了代码的可维护性和测试性
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [简介](#简介)
|
1. [简介](#简介)
|
||||||
2. [项目结构](#项目结构)
|
2. [项目结构](#项目结构)
|
||||||
@@ -24,10 +30,12 @@
|
|||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
英雄属性系统是游戏《heroes》的核心战斗机制之一,负责管理英雄的基础属性、成长属性、动态计算以及战斗中的实时更新。该系统采用模块化设计,通过HeroAttrs.ts定义属性枚举和配置,Hero.ts实现英雄实体管理,HeroViewComp.ts处理属性计算和UI更新,形成了完整的属性管理体系。
|
英雄属性系统是游戏《heroes》的核心战斗机制之一,负责管理英雄的基础属性、成长属性、动态计算以及战斗中的实时更新。该系统采用模块化设计,通过HeroAttrs.ts定义属性枚举和配置,Hero.ts实现英雄实体管理,HeroAttrsComp.ts处理属性计算和状态管理,形成了完整的属性管理体系。
|
||||||
|
|
||||||
系统支持多种属性类型,包括基础生存属性、攻击属性、防御属性、特殊效果属性等,每种属性都有明确的数值型或百分比型分类。通过Buff系统实现属性的动态叠加和计算,确保战斗中的属性变化能够实时反映在UI界面中。
|
系统支持多种属性类型,包括基础生存属性、攻击属性、防御属性、特殊效果属性等,每种属性都有明确的数值型或百分比型分类。通过Buff系统实现属性的动态叠加和计算,确保战斗中的属性变化能够实时反映在UI界面中。
|
||||||
|
|
||||||
|
**更新说明**:根据最新代码重构,攻击状态`is_atking`已从视图层`HeroViewComp`迁移至数据层`HeroAttrsComp`,实现了状态管理的集中化。这一变更遵循了ECS架构的最佳实践,将数据状态与表现逻辑分离,提高了系统的可维护性和扩展性。
|
||||||
|
|
||||||
## 项目结构
|
## 项目结构
|
||||||
|
|
||||||
英雄属性系统的核心文件分布在以下目录结构中:
|
英雄属性系统的核心文件分布在以下目录结构中:
|
||||||
@@ -41,12 +49,12 @@ C[GameEvent.ts<br/>事件系统]
|
|||||||
end
|
end
|
||||||
subgraph "实体管理层"
|
subgraph "实体管理层"
|
||||||
D[Hero.ts<br/>英雄实体]
|
D[Hero.ts<br/>英雄实体]
|
||||||
E[HeroViewComp.ts<br/>视图组件]
|
E[HeroAttrsComp.ts<br/>属性组件]
|
||||||
F[BuffComp.ts<br/>缓冲组件]
|
F[HeroViewComp.ts<br/>视图组件]
|
||||||
end
|
end
|
||||||
subgraph "战斗系统"
|
subgraph "战斗系统"
|
||||||
G[Mon.ts<br/>怪物系统]
|
G[Mon.ts<br/>怪物系统]
|
||||||
H[BuffComp.ts<br/>UI组件]
|
H[BuffComp.ts<br/>缓冲组件]
|
||||||
end
|
end
|
||||||
A --> D
|
A --> D
|
||||||
B --> D
|
B --> D
|
||||||
@@ -58,13 +66,13 @@ H --> F
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.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)
|
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L1-L30)
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L50)
|
- [HeroAttrsComp.ts](file://assets\script\game\hero\HeroAttrsComp.ts#L1-L50)
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L1-L546)
|
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L1-L546)
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L100)
|
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L1-L100)
|
||||||
|
|
||||||
## 核心组件
|
## 核心组件
|
||||||
|
|
||||||
@@ -88,7 +96,7 @@ H --> F
|
|||||||
- **百分比型属性(RATIO)**:按百分比计算的相对数值,如暴击率、闪避率
|
- **百分比型属性(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
|
sequenceDiagram
|
||||||
participant Player as 玩家操作
|
participant Player as 玩家操作
|
||||||
participant Hero as Hero实体
|
participant Hero as Hero实体
|
||||||
|
participant Attrs as HeroAttrsComp
|
||||||
participant View as HeroViewComp
|
participant View as HeroViewComp
|
||||||
participant Buff as Buff系统
|
participant Buff as Buff系统
|
||||||
participant UI as UI组件
|
participant UI as UI组件
|
||||||
Player->>Hero : 创建英雄
|
Player->>Hero : 创建英雄
|
||||||
Hero->>View : hero_init()
|
Hero->>Attrs : hero_init()
|
||||||
View->>View : 初始化基础属性
|
Attrs->>Attrs : 初始化基础属性
|
||||||
View->>View : 初始化属性配置
|
Attrs->>Attrs : 初始化属性配置
|
||||||
View->>Buff : initAttrs()
|
Attrs->>Buff : initAttrs()
|
||||||
Note over Player,UI : 属性计算流程
|
Note over Player,UI : 属性计算流程
|
||||||
Player->>Buff : 添加Buff
|
Player->>Buff : 添加Buff
|
||||||
Buff->>View : recalculateSingleAttr()
|
Buff->>Attrs : recalculateSingleAttr()
|
||||||
View->>View : 计算属性值
|
Attrs->>Attrs : 计算属性值
|
||||||
View->>UI : 更新UI显示
|
Attrs->>UI : 更新UI显示
|
||||||
Note over Player,UI : 属性更新流程
|
Note over Player,UI : 属性更新流程
|
||||||
Player->>Buff : 属性变更
|
Player->>Attrs : 攻击状态变更
|
||||||
Buff->>View : 触发重新计算
|
Attrs->>Attrs : is_atking=true
|
||||||
View->>UI : 实时更新显示
|
Attrs->>View : 触发攻击动画
|
||||||
|
View->>UI : 播放攻击动画
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L65-L99)
|
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L65-L99)
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L165-L250)
|
- [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#L10-L105)
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L8-L10)
|
- [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#L106-L226)
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L266-L439)
|
- [HeroAttrs.ts](file://assets\script\game\common\config\HeroAttrs.ts#L266-L439)
|
||||||
|
|
||||||
### Hero.ts - 英雄实体管理
|
### Hero.ts - 英雄实体管理
|
||||||
|
|
||||||
@@ -219,22 +229,22 @@ Hero.ts负责英雄实体的创建和基础属性初始化:
|
|||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant Client as 客户端
|
participant Client as 客户端
|
||||||
participant Hero as Hero实体
|
participant Hero as Hero实体
|
||||||
participant Model as HeroModelComp
|
participant Model as HeroAttrsComp
|
||||||
participant View as HeroViewComp
|
participant View as HeroViewComp
|
||||||
Client->>Hero : load(pos, scale, uuid)
|
Client->>Hero : load(pos, scale, uuid)
|
||||||
Hero->>Hero : 查找空闲槽位
|
Hero->>Hero : 查找空闲槽位
|
||||||
Hero->>Hero : 加载英雄预制体
|
Hero->>Hero : 加载英雄预制体
|
||||||
Hero->>Hero : 设置位置和缩放
|
Hero->>Hero : 设置位置和缩放
|
||||||
Hero->>Hero : hero_init(uuid, node)
|
Hero->>Hero : hero_init(uuid, node)
|
||||||
Hero->>View : 初始化属性配置
|
Hero->>Model : 初始化属性配置
|
||||||
Hero->>View : 设置基础属性值
|
Hero->>Model : 设置基础属性值
|
||||||
Hero->>View : 初始化属性系统
|
Hero->>Model : 初始化属性系统
|
||||||
Hero->>Model : 添加模型组件
|
Hero->>Model : 添加模型组件
|
||||||
Hero-->>Client : 英雄加载完成
|
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类型 | 存储位置 | 生命周期 | 计算方式 |
|
```typescript
|
||||||
|---------|---------|---------|---------|
|
// HeroAttrsComp.ts - 数据层状态管理
|
||||||
| 持久Buff | BUFFS | 手动清除 | 直接累加 |
|
export class HeroAttrsComp extends ecs.Comp {
|
||||||
| 临时Buff | BUFFS_TEMP | 时间到期自动清除 | 时间递减计算 |
|
// ... 其他属性
|
||||||
| 增益Buff | 正数值 | - | 属性提升 |
|
is_atking: boolean = false; // 是否正在攻击
|
||||||
| 减益Buff | 负数值 | - | 属性削弱 |
|
is_stop: boolean = false; // 是否正在停止
|
||||||
|
// ... 其他状态
|
||||||
#### 属性计算公式
|
}
|
||||||
|
|
||||||
系统根据不同属性类型采用不同的计算公式:
|
|
||||||
|
|
||||||
**百分比型属性公式**:
|
|
||||||
```
|
|
||||||
最终值 = 基础值 + 所有数值型Buff之和 + 所有百分比Buff之和
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**数值型属性公式**:
|
这一变更实现了状态管理的集中化,符合ECS架构的最佳实践。
|
||||||
```
|
|
||||||
最终值 = (基础值 + 所有数值型Buff之和) × (1 + 所有百分比Buff之和/100)
|
|
||||||
```
|
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [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更新机制
|
#### 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组件类型
|
#### UI组件类型
|
||||||
|
|
||||||
BuffComp管理多种UI组件:
|
HeroViewComp管理多种UI组件:
|
||||||
|
|
||||||
| 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 - 怪物属性系统
|
### Mon.ts - 怪物属性系统
|
||||||
|
|
||||||
@@ -366,7 +367,7 @@ Mon.ts继承了英雄的属性系统,但针对怪物进行了优化:
|
|||||||
| UI更新 | 实时同步 | 基础显示 |
|
| 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
|
end
|
||||||
subgraph "实体层"
|
subgraph "实体层"
|
||||||
D[Hero.ts]
|
D[Hero.ts]
|
||||||
E[HeroViewComp.ts]
|
E[HeroAttrsComp.ts]
|
||||||
F[BuffComp.ts]
|
F[HeroViewComp.ts]
|
||||||
end
|
end
|
||||||
subgraph "战斗层"
|
subgraph "战斗层"
|
||||||
G[Mon.ts]
|
G[Mon.ts]
|
||||||
@@ -402,8 +403,8 @@ style E fill:#e8f5e8
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.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)
|
- [Hero.ts](file://assets\script\game\hero\Hero.ts#L1-L20)
|
||||||
|
|
||||||
### 模块间通信
|
### 模块间通信
|
||||||
|
|
||||||
@@ -417,7 +418,7 @@ style E fill:#e8f5e8
|
|||||||
| 数据绑定 | 状态管理 | MVVM模式 |
|
| 数据绑定 | 状态管理 | 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. 检查内存使用情况
|
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同步**:确保属性变化能够即时反映在用户界面上
|
4. **实时UI同步**:确保属性变化能够即时反映在用户界面上
|
||||||
5. **性能优化**:通过多种优化策略保证系统的流畅运行
|
5. **性能优化**:通过多种优化策略保证系统的流畅运行
|
||||||
|
|
||||||
|
**架构演进**:最新的代码重构将`is_atking`攻击状态从视图层迁移至数据层,实现了状态管理的集中化。这一变更遵循了ECS架构的最佳实践,提高了代码的可维护性和测试性。通过将数据状态与表现逻辑分离,系统变得更加健壮和可扩展。
|
||||||
|
|
||||||
该系统为游戏提供了坚实的战斗基础,支持丰富的角色定制和战斗策略,是整个游戏体验的重要组成部分。随着游戏的发展,这套属性系统已经证明了其良好的扩展性和稳定性,能够适应未来更多的功能需求。
|
该系统为游戏提供了坚实的战斗基础,支持丰富的角色定制和战斗策略,是整个游戏体验的重要组成部分。随着游戏的发展,这套属性系统已经证明了其良好的扩展性和稳定性,能够适应未来更多的功能需求。
|
||||||
@@ -7,12 +7,35 @@
|
|||||||
- [TalSet.ts](file://assets/script/game/common/config/TalSet.ts)
|
- [TalSet.ts](file://assets/script/game/common/config/TalSet.ts)
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts)
|
- [Hero.ts](file://assets/script/game/hero/Hero.ts)
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts)
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts)
|
||||||
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts)
|
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts)
|
||||||
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts)
|
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts)
|
||||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts)
|
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts)
|
||||||
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts)
|
||||||
|
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts)
|
||||||
|
- [EBusComp.ts](file://assets/script/game/hero/EBusComp.ts)
|
||||||
</cite>
|
</cite>
|
||||||
|
|
||||||
|
## 更新摘要
|
||||||
|
**变更内容**
|
||||||
|
- 移除了 `SkillConComp` 组件,重构为基于ECS系统的技能控制机制
|
||||||
|
- 将 `is_atking` 攻击状态从视图层 `HeroViewComp` 迁移到数据层 `HeroAttrsComp`
|
||||||
|
- 拆分通用移动组件为专属的英雄和怪物移动系统
|
||||||
|
- 在攻击和死亡事件中集成视觉反馈
|
||||||
|
- 根据ECS框架重构角色视图和数据逻辑,新增事件总线组件 `EBusComp`
|
||||||
|
|
||||||
|
**新增章节**
|
||||||
|
- ECS架构下的技能系统
|
||||||
|
- 攻击与死亡事件的视觉反馈
|
||||||
|
|
||||||
|
**已移除章节**
|
||||||
|
- 原有的 `SkillConComp` 技能控制组件相关内容
|
||||||
|
|
||||||
|
**来源追踪系统更新**
|
||||||
|
- 更新了受影响文件的引用链接和行号范围
|
||||||
|
- 添加了新组件和系统的文件引用
|
||||||
|
- 标记了已移除组件的废弃状态
|
||||||
|
|
||||||
## 目录
|
## 目录
|
||||||
1. [简介](#简介)
|
1. [简介](#简介)
|
||||||
2. [系统架构概览](#系统架构概览)
|
2. [系统架构概览](#系统架构概览)
|
||||||
@@ -27,7 +50,7 @@
|
|||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|
||||||
英雄系统是游戏的核心战斗机制,负责管理英雄的属性、技能、天赋和状态。本系统采用模块化设计,通过ECS架构实现组件间的松耦合通信,支持复杂的战斗逻辑和动态效果管理。
|
英雄系统是游戏的核心战斗机制,负责管理英雄的属性、技能、天赋和状态。本系统采用模块化设计,通过ECS架构实现组件间的松耦合通信,支持复杂的战斗逻辑和动态效果管理。近期重构移除了 `SkillConComp` 组件,将技能控制逻辑迁移至基于ECS系统的 `HSkillSystem`,同时将攻击状态从视图层迁移至数据层,实现了更合理的数据与表现分离。
|
||||||
|
|
||||||
## 系统架构概览
|
## 系统架构概览
|
||||||
|
|
||||||
@@ -41,25 +64,26 @@ BC[BuffComp<br/>状态显示组件]
|
|||||||
end
|
end
|
||||||
subgraph "控制层"
|
subgraph "控制层"
|
||||||
HC[Hero<br/>英雄实体]
|
HC[Hero<br/>英雄实体]
|
||||||
SC[SkillConComp<br/>技能控制组件]
|
SS[HSkillSystem<br/>技能系统]
|
||||||
TC[TalComp<br/>天赋控制组件]
|
TC[TalComp<br/>天赋控制组件]
|
||||||
end
|
end
|
||||||
subgraph "配置层"
|
subgraph "配置层"
|
||||||
HA[HeroAttrs<br/>属性配置]
|
HA[HeroAttrs<br/>属性配置]
|
||||||
SS[SkillSet<br/>技能配置]
|
SSC[SkillSet<br/>技能配置]
|
||||||
TS[TalSet<br/>天赋配置]
|
TS[TalSet<br/>天赋配置]
|
||||||
end
|
end
|
||||||
subgraph "数据层"
|
subgraph "数据层"
|
||||||
|
HAC[HeroAttrsComp<br/>属性数据组件]
|
||||||
HM[HeroModelComp<br/>模型数据]
|
HM[HeroModelComp<br/>模型数据]
|
||||||
MM[MonModelComp<br/>怪物数据]
|
MM[MonModelComp<br/>怪物数据]
|
||||||
end
|
end
|
||||||
HC --> HV
|
HC --> HV
|
||||||
HC --> HM
|
HC --> HAC
|
||||||
SC --> HV
|
SS --> HV
|
||||||
TC --> HV
|
TC --> HV
|
||||||
HV --> BC
|
HV --> BC
|
||||||
HV --> HA
|
HV --> HA
|
||||||
SC --> SS
|
SS --> SSC
|
||||||
TC --> TS
|
TC --> TS
|
||||||
HV --> MM
|
HV --> MM
|
||||||
```
|
```
|
||||||
@@ -67,7 +91,7 @@ HV --> MM
|
|||||||
**图表来源**
|
**图表来源**
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L100)
|
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L100)
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L100)
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L100)
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L50)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L50)
|
||||||
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L1-L50)
|
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L1-L50)
|
||||||
|
|
||||||
## 英雄属性系统
|
## 英雄属性系统
|
||||||
@@ -209,18 +233,54 @@ SkillConfig --> BuffConf
|
|||||||
**图表来源**
|
**图表来源**
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L80-L148)
|
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L80-L148)
|
||||||
|
|
||||||
### 技能控制逻辑
|
### ECS架构下的技能系统
|
||||||
|
|
||||||
技能释放遵循严格的时序控制:
|
技能系统已重构为基于ECS的系统架构,主要包含以下组件:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
classDiagram
|
||||||
|
class CastSkillRequestComp {
|
||||||
|
+skillIndex : number
|
||||||
|
+targetPositions : Vec3[]
|
||||||
|
+reset() void
|
||||||
|
}
|
||||||
|
class SkillCastSystem {
|
||||||
|
+filter() IMatcher
|
||||||
|
+entityEnter(e : Entity) void
|
||||||
|
+checkCastConditions() boolean
|
||||||
|
+executeCast() void
|
||||||
|
+createSkillEntity() void
|
||||||
|
}
|
||||||
|
class SkillCDSystem {
|
||||||
|
+filter() IMatcher
|
||||||
|
+update(e : Entity) void
|
||||||
|
+updateCDs(dt : number) void
|
||||||
|
}
|
||||||
|
class SkillAutocastSystem {
|
||||||
|
+filter() IMatcher
|
||||||
|
+update(e : Entity) void
|
||||||
|
+selectTargets() Vec3[]
|
||||||
|
}
|
||||||
|
CastSkillRequestComp --> SkillCastSystem
|
||||||
|
SkillCastSystem --> SkillCDSystem
|
||||||
|
SkillAutocastSystem --> CastSkillRequestComp
|
||||||
|
```
|
||||||
|
|
||||||
|
**章节来源**
|
||||||
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L271)
|
||||||
|
|
||||||
|
### 技能施法流程
|
||||||
|
|
||||||
|
技能施法遵循ECS标记组件驱动的时序控制:
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant Player as 玩家输入
|
participant Player as 玩家输入
|
||||||
participant SC as SkillConComp
|
participant SC as SkillAutocastSystem
|
||||||
participant HV as HeroViewComp
|
participant HV as HeroViewComp
|
||||||
participant SE as SkillEnt
|
participant SE as SkillEnt
|
||||||
participant Target as 目标实体
|
participant Target as 目标实体
|
||||||
Player->>SC : 技能冷却完成
|
Player->>SC : 添加CastSkillRequest
|
||||||
SC->>SC : 检查英雄状态
|
SC->>SC : 检查英雄状态
|
||||||
SC->>HV : 选择目标
|
SC->>HV : 选择目标
|
||||||
HV-->>SC : 返回目标坐标
|
HV-->>SC : 返回目标坐标
|
||||||
@@ -232,7 +292,7 @@ SE-->>HV : 更新状态
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L50-L120)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L100-L150)
|
||||||
|
|
||||||
### 目标选择算法
|
### 目标选择算法
|
||||||
|
|
||||||
@@ -252,11 +312,11 @@ H --> I
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L130-L170)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L200-L250)
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L1-L148)
|
- [SkillSet.ts](file://assets/script/game/common/config/SkillSet.ts#L1-L148)
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L177)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L271)
|
||||||
|
|
||||||
## 天赋系统
|
## 天赋系统
|
||||||
|
|
||||||
@@ -355,7 +415,7 @@ P --> S[技能列表更新]
|
|||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
classDiagram
|
classDiagram
|
||||||
class HeroViewComp {
|
class HeroAttrsComp {
|
||||||
+BUFFS : Record~number, Array~
|
+BUFFS : Record~number, Array~
|
||||||
+BUFFS_TEMP : Record~number, Array~
|
+BUFFS_TEMP : Record~number, Array~
|
||||||
+NeAttrs : Record~number, Object~
|
+NeAttrs : Record~number, Object~
|
||||||
@@ -376,12 +436,12 @@ class NeAttrs {
|
|||||||
+IN_BURN : 2
|
+IN_BURN : 2
|
||||||
+IN_POISON : 3
|
+IN_POISON : 3
|
||||||
}
|
}
|
||||||
HeroViewComp --> BuffInfo
|
HeroAttrsComp --> BuffInfo
|
||||||
HeroViewComp --> NeAttrs
|
HeroAttrsComp --> NeAttrs
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L80-L120)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L80-L120)
|
||||||
|
|
||||||
### 属性计算公式
|
### 属性计算公式
|
||||||
|
|
||||||
@@ -397,25 +457,25 @@ HeroViewComp --> NeAttrs
|
|||||||
```mermaid
|
```mermaid
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
participant Game as 游戏循环
|
participant Game as 游戏循环
|
||||||
participant HV as HeroViewComp
|
participant HAC as HeroAttrsComp
|
||||||
participant Buff as Buff系统
|
participant Buff as Buff系统
|
||||||
participant Attr as 属性计算
|
participant Attr as 属性计算
|
||||||
Game->>HV : update(dt)
|
Game->>HAC : update(dt)
|
||||||
HV->>Buff : updateTemporaryBuffsDebuffs(dt)
|
HAC->>Buff : updateTemporaryBuffsDebuffs(dt)
|
||||||
Buff->>Buff : 减少剩余时间
|
Buff->>Buff : 减少剩余时间
|
||||||
Buff->>Buff : 移除过期buff
|
Buff->>Buff : 移除过期buff
|
||||||
Buff->>Attr : recalculateSingleAttr()
|
Buff->>Attr : recalculateSingleAttr()
|
||||||
Attr->>Attr : 重新计算属性值
|
Attr->>Attr : 重新计算属性值
|
||||||
Attr-->>HV : 更新后的属性
|
Attr-->>HAC : 更新后的属性
|
||||||
HV->>HV : clampSingleAttr()
|
HAC->>HAC : clampSingleAttr()
|
||||||
HV-->>Game : 状态更新完成
|
HAC-->>Game : 状态更新完成
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L400-L500)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L400-L500)
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L1-L780)
|
- [HeroAttrsComp.ts](file://assets/script/game/hero/HeroAttrsComp.ts#L1-L489)
|
||||||
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts#L1-L213)
|
- [BuffComp.ts](file://assets/script/game/hero/BuffComp.ts#L1-L213)
|
||||||
|
|
||||||
## 组件间通信机制
|
## 组件间通信机制
|
||||||
@@ -427,11 +487,11 @@ graph LR
|
|||||||
subgraph "英雄实体"
|
subgraph "英雄实体"
|
||||||
E[Hero实体]
|
E[Hero实体]
|
||||||
HV[HeroViewComp]
|
HV[HeroViewComp]
|
||||||
HC[HeroConComp]
|
HAC[HeroAttrsComp]
|
||||||
BM[BattleMoveComp]
|
BM[HeroMoveComp]
|
||||||
end
|
end
|
||||||
subgraph "技能系统"
|
subgraph "技能系统"
|
||||||
SC[SkillConComp]
|
SS[HSkillSystem]
|
||||||
SE[SkillEnt]
|
SE[SkillEnt]
|
||||||
end
|
end
|
||||||
subgraph "状态系统"
|
subgraph "状态系统"
|
||||||
@@ -439,19 +499,19 @@ BC[BuffComp]
|
|||||||
TC[TalComp]
|
TC[TalComp]
|
||||||
end
|
end
|
||||||
E --> HV
|
E --> HV
|
||||||
E --> HC
|
E --> HAC
|
||||||
E --> BM
|
E --> BM
|
||||||
HC --> SC
|
HAC --> SS
|
||||||
SC --> SE
|
SS --> SE
|
||||||
HV --> BC
|
HV --> BC
|
||||||
HV --> TC
|
HV --> TC
|
||||||
TC --> HV
|
TC --> HV
|
||||||
SC --> HV
|
SS --> HV
|
||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L15-L35)
|
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L15-L35)
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L15-L30)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L15-L30)
|
||||||
|
|
||||||
### 事件驱动通信
|
### 事件驱动通信
|
||||||
|
|
||||||
@@ -460,13 +520,13 @@ SC --> HV
|
|||||||
| 事件类型 | 发送者 | 接收者 | 用途 |
|
| 事件类型 | 发送者 | 接收者 | 用途 |
|
||||||
|---------|-------|-------|------|
|
|---------|-------|-------|------|
|
||||||
| GameEvent.MasterCalled | Hero | Talent系统 | 英雄召唤事件 |
|
| GameEvent.MasterCalled | Hero | Talent系统 | 英雄召唤事件 |
|
||||||
| GameEvent.CastHeroSkill | SkillCon | 其他组件 | 技能释放通知 |
|
| GameEvent.CastHeroSkill | HSkillSystem | 其他组件 | 技能释放通知 |
|
||||||
| GameEvent.FightEnd | Battle | 所有组件 | 战斗结束事件 |
|
| GameEvent.FightEnd | Battle | 所有组件 | 战斗结束事件 |
|
||||||
| GameEvent.HeroDead | HeroView | Talent系统 | 英雄死亡事件 |
|
| GameEvent.HeroDead | HeroView | Talent系统 | 英雄死亡事件 |
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L100)
|
- [Hero.ts](file://assets/script/game/hero/Hero.ts#L1-L100)
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L1-L50)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L1-L50)
|
||||||
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L1-L50)
|
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L1-L50)
|
||||||
|
|
||||||
## 关键功能实现
|
## 关键功能实现
|
||||||
@@ -477,7 +537,7 @@ SC --> HV
|
|||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart TD
|
flowchart TD
|
||||||
A[玩家输入技能] --> B[SkillConComp接收]
|
A[玩家输入技能] --> B[HSkillSystem接收]
|
||||||
B --> C{英雄状态检查}
|
B --> C{英雄状态检查}
|
||||||
C --> |眩晕/冰冻| D[阻止技能释放]
|
C --> |眩晕/冰冻| D[阻止技能释放]
|
||||||
C --> |正常状态| E[检查冷却时间]
|
C --> |正常状态| E[检查冷却时间]
|
||||||
@@ -495,7 +555,7 @@ M --> O[技能释放成功]
|
|||||||
```
|
```
|
||||||
|
|
||||||
**图表来源**
|
**图表来源**
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L50-L100)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L50-L100)
|
||||||
|
|
||||||
### 属性升级系统
|
### 属性升级系统
|
||||||
|
|
||||||
@@ -557,10 +617,38 @@ P --> C
|
|||||||
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L100-L170)
|
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L100-L170)
|
||||||
|
|
||||||
**章节来源**
|
**章节来源**
|
||||||
- [SkillConComp.ts](file://assets/script/game/hero/SkillConComp.ts#L50-L177)
|
- [HSkillSystem.ts](file://assets/script/game/hero/HSkillSystem.ts#L50-L271)
|
||||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L500-L546)
|
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L500-L546)
|
||||||
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L100-L171)
|
- [TalComp.ts](file://assets/script/game/hero/TalComp.ts#L100-L171)
|
||||||
|
|
||||||
|
### 攻击与死亡事件的视觉反馈
|
||||||
|
|
||||||
|
攻击和死亡事件现在集成视觉反馈,增强游戏表现力:
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant Attack as 攻击事件
|
||||||
|
participant HAC as HeroAttrsComp
|
||||||
|
participant HV as HeroViewComp
|
||||||
|
participant AtkSys as HeroAtkSystem
|
||||||
|
Attack->>HAC : 发起攻击
|
||||||
|
HAC->>AtkSys : doAttack()
|
||||||
|
AtkSys->>HV : do_atked()
|
||||||
|
HV->>HV : 显示伤害数字
|
||||||
|
HV->>HV : 播放受击动画
|
||||||
|
HV->>HV : 角色后退
|
||||||
|
Attack->>HAC : 造成伤害
|
||||||
|
HAC->>HAC : 更新血量
|
||||||
|
HAC->>HV : 检查死亡
|
||||||
|
HV->>HV : do_dead()
|
||||||
|
HV->>HV : 播放死亡特效
|
||||||
|
HV->>HV : 触发死亡事件
|
||||||
|
```
|
||||||
|
|
||||||
|
**章节来源**
|
||||||
|
- [HeroAtk.ts](file://assets/script/game/hero/HeroAtk.ts#L1-L247)
|
||||||
|
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L200-L300)
|
||||||
|
|
||||||
## 性能优化考虑
|
## 性能优化考虑
|
||||||
|
|
||||||
### 内存管理优化
|
### 内存管理优化
|
||||||
@@ -591,4 +679,4 @@ P --> C
|
|||||||
4. **高效状态管理**: 实现了完整的Buff/Debuff生命周期管理
|
4. **高效状态管理**: 实现了完整的Buff/Debuff生命周期管理
|
||||||
5. **松耦合架构**: 通过ECS和事件机制实现组件间的解耦通信
|
5. **松耦合架构**: 通过ECS和事件机制实现组件间的解耦通信
|
||||||
|
|
||||||
该系统为游戏提供了坚实的战斗基础,支持复杂的游戏玩法和深度的角色养成体验。通过合理的架构设计和性能优化,确保了系统的稳定性和可扩展性。
|
近期重构将技能控制逻辑迁移至ECS系统,移除了 `SkillConComp` 组件,同时将攻击状态从视图层迁移至数据层,实现了更合理的数据与表现分离。该系统为游戏提供了坚实的战斗基础,支持复杂的游戏玩法和深度的角色养成体验。通过合理的架构设计和性能优化,确保了系统的稳定性和可扩展性。
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user