feat(怪物系统): 重构怪物类型与属性计算系统
引入MonType枚举支持普通、精英、BOSS三种怪物类型 新增getMonAttr函数实现基于等级和类型的动态属性计算 更新Mon.ts的load和hero_init方法以支持新参数 扩展heroSet.ts添加多种新怪物类型配置 重构属性初始化流程,移除strengthMultiplier机制 更新相关文档和流程图反映最新设计
This commit is contained in:
@@ -1,29 +1,38 @@
|
||||
# 怪物系统
|
||||
|
||||
<cite>
|
||||
**本文档引用的文件**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts)
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts)
|
||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts)
|
||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts)
|
||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts)
|
||||
**本文档引用的文件**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts) - *在最近的提交中更新*
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts) - *在最近的提交中更新*
|
||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts) - *在最近的提交中更新*
|
||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts) - *新增怪物类型与难度配置*
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts) - *移动行为控制组件*
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts) - *视图与属性管理组件*
|
||||
</cite>
|
||||
|
||||
## 更新摘要
|
||||
**变更内容**
|
||||
- 更新了 `Mon.ts` 中的 `load` 和 `hero_init` 方法以支持 `monType` 参数和等级系统
|
||||
- 引入 `MonType` 枚举(普通、精英、BOSS)实现差异化属性计算
|
||||
- 新增 `getMonAttr` 函数用于根据等级和类型动态计算怪物属性
|
||||
- 扩展 `heroSet.ts` 添加多种新怪物类型(召唤师、治疗者、光环怪等)
|
||||
- 重构属性初始化流程,移除过时的 `strengthMultiplier`,改用基于等级和类型的倍率系统
|
||||
- 更新架构图和流程图以反映最新的 ECS 设计和属性计算逻辑
|
||||
|
||||
## 目录
|
||||
1. [简介](#简介)
|
||||
2. [项目结构](#项目结构)
|
||||
3. [核心组件](#核心组件)
|
||||
4. [架构概览](#架构概览)
|
||||
5. [详细组件分析](#详细组件分析)
|
||||
6. [依赖关系分析](#依赖关系分析)
|
||||
7. [性能考虑](#性能考虑)
|
||||
8. [故障排除指南](#故障排除指南)
|
||||
1. [简介](#简介)
|
||||
2. [项目结构](#项目结构)
|
||||
3. [核心组件](#核心组件)
|
||||
4. [架构概览](#架构概览)
|
||||
5. [详细组件分析](#详细组件分析)
|
||||
6. [依赖关系分析](#依赖关系分析)
|
||||
7. [性能考虑](#性能考虑)
|
||||
8. [故障排除指南](#故障排除指南)
|
||||
9. [结论](#结论)
|
||||
|
||||
## 简介
|
||||
|
||||
Mon.ts文件定义了游戏中的怪物系统,采用ECS(Entity-Component-System)架构模式,通过继承Entity类并注册为`Monster`类型来实现怪物实体的管理和控制。该系统提供了完整的怪物生命周期管理,包括预制体动态加载、属性初始化、难度自适应调整以及移动行为控制等功能。
|
||||
`Mon.ts` 文件定义了游戏中的怪物系统,采用 ECS(Entity-Component-System)架构模式,通过继承 `Entity` 类并注册为 `Monster` 类型来实现怪物实体的管理和控制。该系统提供了完整的怪物生命周期管理,包括预制体动态加载、位置设置、基于等级和类型的属性初始化以及向左移动的行为控制。本次重构引入了 `monType` 参数,支持普通、精英、BOSS 三种类型,并通过 `RogueConfig.ts` 中的 `getMonAttr` 函数实现了基于等级和类型系数的动态属性计算,取代了原有的 `strengthMultiplier` 机制,使难度曲线更加平滑和可配置。
|
||||
|
||||
## 项目结构
|
||||
|
||||
@@ -37,8 +46,9 @@ MonModel[MonModelComp.ts<br/>怪物模型组件]
|
||||
BattleMove[BattleMoveComp.ts<br/>移动组件]
|
||||
end
|
||||
subgraph "配置系统"
|
||||
HeroSet[heroSet.ts<br/>英雄配置]
|
||||
HeroSet[heroSet.ts<br/>英雄与怪物配置]
|
||||
HeroAttrs[HeroAttrs.ts<br/>属性配置]
|
||||
RogueConfig[RogueConfig.ts<br/>肉鸽模式配置]
|
||||
end
|
||||
subgraph "ECS系统"
|
||||
BattleMoveSys[BattleMoveSystem.ts<br/>移动系统]
|
||||
@@ -47,52 +57,60 @@ Mon --> MonModel
|
||||
Mon --> BattleMove
|
||||
Mon --> HeroSet
|
||||
Mon --> HeroAttrs
|
||||
Mon --> RogueConfig
|
||||
BattleMoveSys --> BattleMove
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L109)
|
||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts#L1-L20)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L1-L16)
|
||||
**图表来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L109)
|
||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts#L1-L20)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L1-L16)
|
||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L88)
|
||||
|
||||
**章节来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L109)
|
||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L1-L152)
|
||||
**章节来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L1-L109)
|
||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L1-L152)
|
||||
- [RogueConfig.ts](file://assets/script/game/map/RogueConfig.ts#L31-L88)
|
||||
|
||||
## 核心组件
|
||||
|
||||
### Monster实体类
|
||||
|
||||
Monster类是怪物系统的核心实体类,继承自ECS框架的Entity基类,并注册为`Monster`类型。该类实现了怪物的完整生命周期管理:
|
||||
`Monster` 类是怪物系统的核心实体类,继承自 ECS 框架的 `Entity` 基类,并注册为 `Monster` 类型。该类实现了怪物的完整生命周期管理:
|
||||
|
||||
- **组件管理**:自动添加BattleMoveComp和MonModelComp组件
|
||||
- **生命周期控制**:提供init和destroy方法管理实体状态
|
||||
- **预制体加载**:通过load方法动态加载怪物预制体
|
||||
- **属性初始化**:通过hero_init方法设置怪物基础属性
|
||||
- **组件管理**:在 `init` 方法中自动添加 `BattleMoveComp`、`MonModelComp` 和 `TalComp` 组件
|
||||
- **生命周期控制**:提供 `init` 和 `destroy` 方法管理实体状态,在 `destroy` 中移除关键组件
|
||||
- **预制体加载**:通过 `load` 方法动态加载怪物预制体,并传入 `uuid`、`lv`(等级)、`monType`(怪物类型)等参数
|
||||
- **属性初始化**:通过 `hero_init` 方法设置怪物基础属性,该方法现在依赖 `RogueConfig.getMonAttr` 进行计算
|
||||
|
||||
### BattleMoveComp移动组件
|
||||
|
||||
BattleMoveComp负责控制怪物的移动行为,包含以下关键属性:
|
||||
`BattleMoveComp` 负责控制怪物的移动行为,包含以下关键属性:
|
||||
|
||||
- **direction**:移动方向(1向右,-1向左)
|
||||
- **targetX**:目标X坐标
|
||||
- **moving**:移动状态标识
|
||||
- **direction**:移动方向(1向右,-1向左)
|
||||
- **targetX**:目标X坐标
|
||||
- **moving**:移动状态标识
|
||||
|
||||
在 `Mon.ts` 的 `load` 方法中,该组件被初始化为向左移动(`direction = -1`)至左边界(`targetX = -800`)。
|
||||
|
||||
### 属性系统
|
||||
|
||||
怪物系统采用统一的属性管理机制,支持:
|
||||
|
||||
- **基础属性**:HP、MP、AP、DEF等核心战斗属性
|
||||
- **百分比属性**:暴击率、闪避率等百分比型属性
|
||||
- **特殊属性**:吸血、燃烧概率等特殊效果属性
|
||||
- **基础属性**:HP、MP、AP、DEF 等核心战斗属性
|
||||
- **百分比属性**:暴击率、闪避率等百分比型属性
|
||||
- **特殊属性**:吸血、燃烧概率等特殊效果属性
|
||||
|
||||
**章节来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
属性值存储在 `HeroViewComp` 的 `Attrs` 和 `NeAttrs` 对象中,并通过 `initAttrs` 方法进行初始化和计算。
|
||||
|
||||
**章节来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L72-L778)
|
||||
|
||||
## 架构概览
|
||||
|
||||
怪物系统采用ECS架构模式,实现了高度解耦的设计:
|
||||
怪物系统采用 ECS 架构模式,实现了高度解耦的设计:
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
@@ -102,8 +120,8 @@ class Monster {
|
||||
+BattleMoveComp BattleMove
|
||||
+init() void
|
||||
+destroy() void
|
||||
+load(pos, scale, uuid, is_boss, is_call, strengthMultiplier) void
|
||||
+hero_init(uuid, node, scale, box_group, is_boss, is_call, strengthMultiplier) 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 {
|
||||
+number direction
|
||||
@@ -137,16 +155,17 @@ Monster --> MonModelComp : "包含"
|
||||
Monster --> HeroViewComp : "包含"
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts#L10-L19)
|
||||
**图表来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L17-L40)
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
- [MonModelComp.ts](file://assets/script/game/hero/MonModelComp.ts#L10-L19)
|
||||
- [HeroViewComp.ts](file://assets/script/game/hero/HeroViewComp.ts#L72-L778)
|
||||
|
||||
## 详细组件分析
|
||||
|
||||
### load方法:预制体动态加载流程
|
||||
|
||||
load方法实现了怪物的完整初始化流程:
|
||||
`load` 方法实现了怪物的完整初始化流程,现已支持等级和类型参数:
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
@@ -155,7 +174,7 @@ participant Monster as "Monster实体"
|
||||
participant Resources as "资源系统"
|
||||
participant Scene as "场景节点"
|
||||
participant BattleMove as "BattleMove组件"
|
||||
Client->>Monster : load(pos, scale, uuid, ...)
|
||||
Client->>Monster : load(pos, scale, uuid, lv, monType, ...)
|
||||
Monster->>Resources : 获取预制体路径
|
||||
Resources-->>Monster : 返回Prefab资源
|
||||
Monster->>Scene : 实例化预制体
|
||||
@@ -168,66 +187,71 @@ BattleMove->>BattleMove : targetX = -800
|
||||
Monster->>Client : dispatchEvent("monster_load")
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
**图表来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L35-L58)
|
||||
|
||||
#### 关键步骤解析:
|
||||
|
||||
1. **预制体路径构建**:根据uuid从HeroInfo配置中获取对应的预制体路径
|
||||
2. **实例化处理**:使用oops.res.get获取预制体并实例化
|
||||
3. **场景集成**:将实例化的节点添加到场景的entityLayer中
|
||||
4. **碰撞体管理**:先禁用碰撞体,延迟一帧再启用以避免初始化问题
|
||||
5. **位置设置**:根据传入的pos参数设置怪物初始位置
|
||||
1. **预制体路径构建**:根据 `uuid` 从 `HeroInfo` 配置中获取对应的预制体路径
|
||||
2. **实例化处理**:使用 `oops.res.get` 获取预制体并实例化
|
||||
3. **场景集成**:将实例化的节点添加到场景的 `entityLayer` 中
|
||||
4. **碰撞体管理**:先禁用碰撞体,延迟一帧再启用以避免初始化问题
|
||||
5. **位置设置**:根据传入的 `pos` 参数设置怪物初始位置
|
||||
6. **属性初始化**:调用 `hero_init` 方法,传入 `lv` 和 `monType` 进行属性计算
|
||||
7. **移动初始化**:设置 `BattleMoveComp` 的方向和目标
|
||||
|
||||
**章节来源**
|
||||
**章节来源**
|
||||
- [Mon.ts](file://assets/script/game/hero/Mon.ts#L35-L58)
|
||||
|
||||
### hero_init方法:难度自适应属性系统
|
||||
### hero_init方法:基于等级与类型的属性系统
|
||||
|
||||
hero_init方法实现了基于strengthMultiplier的难度自适应属性调整:
|
||||
`hero_init` 方法实现了基于 `lv`(等级)和 `monType`(怪物类型)的属性调整,取代了旧的 `strengthMultiplier` 机制:
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
Start([开始初始化]) --> GetHeroInfo["获取英雄配置信息"]
|
||||
GetHeroInfo --> SetBasicProps["设置基础属性"]
|
||||
SetBasicProps --> CalcStrength["计算强度倍率"]
|
||||
CalcStrength --> AdjustHP["调整HP = hero.hp × strengthMultiplier"]
|
||||
AdjustHP --> AdjustAP["调整AP = hero.ap × strengthMultiplier"]
|
||||
AdjustAP --> AdjustDEF["调整DEF = hero.def × strengthMultiplier"]
|
||||
AdjustDEF --> LoadSkills["加载技能配置"]
|
||||
GetHeroInfo --> CalcAttr["调用getMonAttr计算属性"]
|
||||
CalcAttr --> SetBasicProps["设置基础属性"]
|
||||
SetBasicProps --> LoadSkills["加载技能配置"]
|
||||
LoadSkills --> InitAttrs["初始化属性系统"]
|
||||
InitAttrs --> Complete([初始化完成])
|
||||
style Start fill:#e1f5fe
|
||||
style Complete fill:#e8f5e8
|
||||
style CalcStrength fill:#fff3e0
|
||||
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)
|
||||
|
||||
#### 属性调整机制:
|
||||
|
||||
1. **基础属性计算**:
|
||||
- HP = hero.hp × strengthMultiplier(向下取整)
|
||||
- AP = hero.ap × strengthMultiplier(向下取整)
|
||||
- DEF = hero.def × strengthMultiplier(向下取整)
|
||||
1. **基础属性计算**:
|
||||
调用 `getMonAttr(lv, uuid, monType)` 函数,该函数根据以下公式计算:
|
||||
```
|
||||
hp = hero.hp * lv * MonAttrSet[monType].HP_MAX
|
||||
ap = hero.ap * lv * MonAttrSet[monType].AP
|
||||
def = hero.def * lv * MonAttrSet[monType].DEF
|
||||
```
|
||||
其中 `MonAttrSet` 定义了不同类型(普通、精英、BOSS)的属性倍率。
|
||||
|
||||
2. **技能系统集成**:
|
||||
- 遍历hero.skills数组
|
||||
- 从SkillSet配置中获取技能详细信息
|
||||
- 创建技能对象并添加到hv.skills数组
|
||||
2. **技能系统集成**:
|
||||
- 遍历 `hero.skills` 数组
|
||||
- 从 `SkillSet` 配置中获取技能详细信息
|
||||
- 创建技能对象并添加到 `hv.skills` 数组
|
||||
|
||||
3. **属性系统初始化**:
|
||||
- 调用getAttrs()获取默认属性值
|
||||
- 调用getNeAttrs()获取负面状态属性
|
||||
- 设置各项属性的基础值和当前值
|
||||
3. **属性系统初始化**:
|
||||
- 调用 `getAttrs()` 获取默认属性值
|
||||
- 调用 `getNeAttrs()` 获取负面状态属性
|
||||
- 将计算出的 `hp`, `ap`, `def` 等值赋给 `Attrs` 对象中的对应属性
|
||||
|
||||
**章节来源**
|
||||
- [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)
|
||||
|
||||
### BattleMoveComp组件:移动行为控制
|
||||
|
||||
BattleMoveComp组件驱动怪物向左移动的行为:
|
||||
`BattleMoveComp` 组件驱动怪物向左移动的行为:
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
@@ -240,26 +264,26 @@ Idle --> [*] : 销毁实体
|
||||
note right of Moving : direction = -1<br/>targetX = -800
|
||||
```
|
||||
|
||||
**图表来源**
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
**图表来源**
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
- [BattleMoveSystem.ts](file://assets/script/game/common/ecs/position/BattleMoveSystem.ts#L10-L271)
|
||||
|
||||
#### 移动参数配置:
|
||||
|
||||
- **direction = -1**:设置向左移动的方向
|
||||
- **targetX = -800**:设定左边界为目标位置
|
||||
- **moving = true**:启用移动状态
|
||||
- **direction = -1**:设置向左移动的方向
|
||||
- **targetX = -800**:设定左边界为目标位置
|
||||
- **moving = true**:启用移动状态
|
||||
|
||||
**章节来源**
|
||||
**章节来源**
|
||||
- [BattleMoveComp.ts](file://assets/script/game/common/ecs/position/BattleMoveComp.ts#L3-L15)
|
||||
|
||||
### 数据复用机制:HeroAttrs与heroSet配置
|
||||
|
||||
怪物系统通过HeroAttrs.ts和heroSet.ts实现英雄配置的数据复用:
|
||||
怪物系统通过 `HeroAttrs.ts` 和 `heroSet.ts` 实现英雄配置的数据复用:
|
||||
|
||||
#### HeroAttrs.ts属性系统
|
||||
|
||||
HeroAttrs.ts定义了完整的属性枚举和类型系统:
|
||||
`HeroAttrs.ts` 定义了完整的属性枚举和类型系统:
|
||||
|
||||
| 属性类别 | 属性名称 | 类型 | 描述 |
|
||||
|---------|---------|------|------|
|
||||
@@ -273,14 +297,15 @@ HeroAttrs.ts定义了完整的属性枚举和类型系统:
|
||||
|
||||
#### heroSet.ts配置系统
|
||||
|
||||
heroSet.ts提供了怪物配置的集中管理:
|
||||
`heroSet.ts` 提供了怪物配置的集中管理:
|
||||
|
||||
- **HeroInfo配置表**:存储所有怪物的基础属性数据
|
||||
- **MonSet位置配置**:定义怪物在战场上的初始位置
|
||||
- **职业类型枚举**:支持warrior、remote、mage、support、assassin五种职业
|
||||
- **HeroInfo配置表**:存储所有怪物的基础属性数据,`fac: FacSet.MON` 标识为怪物
|
||||
- **MonSet位置配置**:定义怪物在战场上的初始位置
|
||||
- **职业类型枚举**:支持 `warrior`、`remote`、`mage`、`support`、`assassin` 五种职业
|
||||
- **新增怪物类型**:包括 `5214` 死灵法师(召唤师)、`5215` 祭司(治疗者)、`5216` 光环幽灵(光环怪)等特殊机制怪物
|
||||
|
||||
**章节来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L25-L105)
|
||||
**章节来源**
|
||||
- [HeroAttrs.ts](file://assets/script/game/common/config/HeroAttrs.ts#L25-L105)
|
||||
- [heroSet.ts](file://assets/script/game/common/config/heroSet.ts#L60-L152)
|
||||
|
||||
## 依赖关系分析
|
||||
@@ -303,6 +328,7 @@ subgraph "配置模块"
|
||||
HeroInfo[HeroInfo配置]
|
||||
HeroAttrs[属性配置]
|
||||
SkillSet[技能配置]
|
||||
RogueConfig[肉鸽配置]
|
||||
end
|
||||
subgraph "系统模块"
|
||||
BattleMoveSys[BattleMoveSystem]
|
||||
@@ -316,45 +342,46 @@ Monster --> HeroView
|
||||
Monster --> HeroInfo
|
||||
Monster --> HeroAttrs
|
||||
Monster --> SkillSet
|
||||
Monster --> RogueConfig
|
||||
BattleMoveSys --> BattleMove
|
||||
BattleMoveSys --> HeroView
|
||||
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)
|
||||
|
||||
### 关键依赖说明:
|
||||
|
||||
1. **ECS框架依赖**:Monster类继承自ecs.Entity,BattleMoveComp继承自ecs.Comp
|
||||
2. **Cocos Creator依赖**:使用Node、Prefab、Vec3等Cocos类型
|
||||
3. **配置依赖**:依赖HeroInfo、HeroAttrs、SkillSet等配置模块
|
||||
4. **系统依赖**:依赖BattleMoveSystem进行移动逻辑处理
|
||||
1. **ECS框架依赖**:`Monster` 类继承自 `ecs.Entity`,`BattleMoveComp` 继承自 `ecs.Comp`
|
||||
2. **Cocos Creator依赖**:使用 `Node`、`Prefab`、`Vec3` 等 Cocos 类型
|
||||
3. **配置依赖**:依赖 `HeroInfo`、`HeroAttrs`、`SkillSet`、`RogueConfig` 等配置模块
|
||||
4. **系统依赖**:依赖 `BattleMoveSystem` 进行移动逻辑处理
|
||||
|
||||
**章节来源**
|
||||
- [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)
|
||||
|
||||
## 性能考虑
|
||||
|
||||
### 内存管理优化
|
||||
|
||||
1. **组件化设计**:通过组件分离职责,避免单个类过于庞大
|
||||
2. **生命周期管理**:destroy方法确保正确清理组件引用
|
||||
3. **资源池化**:预制体实例化采用资源管理系统
|
||||
1. **组件化设计**:通过组件分离职责,避免单个类过于庞大
|
||||
2. **生命周期管理**:`destroy` 方法确保正确清理组件引用
|
||||
3. **资源池化**:预制体实例化采用资源管理系统
|
||||
|
||||
### 性能优化策略
|
||||
|
||||
1. **批量更新**:BattleMoveSystem采用批量处理方式
|
||||
2. **条件检查**:在更新前进行状态检查,避免不必要的计算
|
||||
3. **边界检测**:使用validatePosition方法限制移动范围
|
||||
1. **批量更新**:`BattleMoveSystem` 采用批量处理方式
|
||||
2. **条件检查**:在更新前进行状态检查,避免不必要的计算
|
||||
3. **边界检测**:使用 `validatePosition` 方法限制移动范围
|
||||
|
||||
### 扩展性设计
|
||||
|
||||
1. **配置驱动**:通过配置文件控制怪物属性和行为
|
||||
2. **组件扩展**:支持添加新的组件类型
|
||||
3. **系统扩展**:BattleMoveSystem可添加新的移动逻辑
|
||||
1. **配置驱动**:通过 `heroSet.ts` 和 `RogueConfig.ts` 控制怪物属性和行为
|
||||
2. **组件扩展**:支持添加新的组件类型(如 `BuffComp`、`TalComp`)
|
||||
3. **系统扩展**:`BattleMoveSystem` 可添加新的移动逻辑
|
||||
|
||||
## 故障排除指南
|
||||
|
||||
@@ -362,14 +389,14 @@ SingletonModule --> Monster
|
||||
|
||||
#### 1. 怪物无法正常移动
|
||||
|
||||
**问题现象**:怪物加载后静止不动
|
||||
**问题现象**:怪物加载后静止不动
|
||||
|
||||
**排查步骤**:
|
||||
- 检查BattleMoveComp的moving属性是否为true
|
||||
- 验证targetX设置是否合理
|
||||
- 确认BattleMoveSystem是否正常运行
|
||||
**排查步骤**:
|
||||
- 检查 `BattleMoveComp` 的 `moving` 属性是否为 `true`
|
||||
- 验证 `targetX` 设置是否合理
|
||||
- 确认 `BattleMoveSystem` 是否正常运行
|
||||
|
||||
**解决方案**:
|
||||
**解决方案**:
|
||||
```typescript
|
||||
// 确保移动组件正确初始化
|
||||
const move = this.get(BattleMoveComp);
|
||||
@@ -379,49 +406,50 @@ move.targetX = -800; // 设置合理的边界值
|
||||
|
||||
#### 2. 属性计算错误
|
||||
|
||||
**问题现象**:怪物属性显示异常
|
||||
**问题现象**:怪物属性显示异常
|
||||
|
||||
**排查步骤**:
|
||||
- 检查strengthMultiplier参数是否正确传递
|
||||
- 验证HeroInfo配置中的基础属性值
|
||||
- 确认属性计算逻辑
|
||||
**排查步骤**:
|
||||
- 检查 `lv` 和 `monType` 参数是否正确传递
|
||||
- 验证 `HeroInfo` 配置中的基础属性值
|
||||
- 确认 `getMonAttr` 函数的计算逻辑
|
||||
|
||||
**解决方案**:
|
||||
**解决方案**:
|
||||
```typescript
|
||||
// 确保属性计算正确
|
||||
const baseHp = Math.floor(hero.hp * strengthMultiplier);
|
||||
const baseAp = Math.floor(hero.ap * strengthMultiplier);
|
||||
const baseDef = Math.floor(hero.def * strengthMultiplier);
|
||||
const {hp, ap, def} = getMonAttr(lv, uuid, monType);
|
||||
hv.base_hp = hp;
|
||||
hv.base_ap = ap;
|
||||
hv.base_def = def;
|
||||
```
|
||||
|
||||
#### 3. 预制体加载失败
|
||||
|
||||
**问题现象**:怪物无法显示模型
|
||||
**问题现象**:怪物无法显示模型
|
||||
|
||||
**排查步骤**:
|
||||
- 检查HeroInfo中的path配置是否正确
|
||||
- 验证资源路径是否存在
|
||||
- 确认资源是否已正确打包
|
||||
**排查步骤**:
|
||||
- 检查 `HeroInfo` 中的 `path` 配置是否正确
|
||||
- 验证资源路径是否存在
|
||||
- 确认资源是否已正确打包
|
||||
|
||||
**解决方案**:
|
||||
**解决方案**:
|
||||
```typescript
|
||||
// 确保资源路径正确
|
||||
var path = "game/heros/" + HeroInfo[uuid].path;
|
||||
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)
|
||||
|
||||
## 结论
|
||||
|
||||
Mon.ts文件实现了一个功能完整、架构清晰的怪物系统。通过ECS架构模式,系统实现了高度的模块化和可扩展性。主要特点包括:
|
||||
`Mon.ts` 文件实现了一个功能完整、架构清晰的怪物系统。通过 ECS 架构模式,系统实现了高度的模块化和可扩展性。主要特点包括:
|
||||
|
||||
1. **ECS架构优势**:通过组件化设计实现了职责分离和代码复用
|
||||
2. **难度自适应**:基于strengthMultiplier的属性调整机制提供了灵活的难度控制
|
||||
3. **数据复用**:通过HeroAttrs和heroSet配置系统实现了数据的集中管理
|
||||
4. **性能优化**:采用组件化和批量处理策略确保良好的运行性能
|
||||
5. **扩展性强**:支持添加新怪物类型、配置技能组合和实现召唤单位等扩展需求
|
||||
1. **ECS架构优势**:通过组件化设计实现了职责分离和代码复用
|
||||
2. **难度自适应**:基于 `lv` 和 `monType` 的属性调整机制提供了灵活的难度控制
|
||||
3. **数据复用**:通过 `HeroAttrs` 和 `heroSet` 配置系统实现了数据的集中管理
|
||||
4. **性能优化**:采用组件化和批量处理策略确保良好的运行性能
|
||||
5. **扩展性强**:支持添加新怪物类型、配置技能组合和实现召唤单位等扩展需求
|
||||
|
||||
该系统为游戏开发提供了坚实的基础,能够满足不同类型怪物的开发需求,同时保持了良好的维护性和扩展性。
|
||||
Reference in New Issue
Block a user