refactor(skill): 重构技能组件目录结构并重命名施法请求组件

将技能相关组件从hero目录移动到skill目录
将CastSkillRequestComp重命名为CSRequestComp
更新相关引用和文档说明
This commit is contained in:
2025-10-31 09:22:50 +08:00
parent a1c605238d
commit b38e63e200
14 changed files with 47 additions and 129 deletions

View File

@@ -1,10 +1,10 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Vec3, v3 } from "cc";
import { CastSkillRequestComp } from "./STagComps";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroViewComp } from "./HeroViewComp";
import { SkillSet, SType } from "../common/config/SkillSet";
import { HeroSkillsComp } from "./HeroSkills";
import { CSRequestComp } from "../skill/STagComps";
/**
* ==================== 自动施法系统 ====================
@@ -17,7 +17,7 @@ import { HeroSkillsComp } from "./HeroSkills";
*
* 设计理念:
* - 负责"何时施法"的决策
* - 通过添加 CastSkillRequestComp 触发施法
* - 通过添加 CSRequestComp 触发施法
* - 可被玩家输入系统或AI系统复用
* - 支持多种AI策略
*/
@@ -53,7 +53,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
if (!config || config.SType !== SType.damage) continue;
// ✅ 添加施法请求标记组件
const request = e.add(CastSkillRequestComp) as CastSkillRequestComp;
const request = e.add(CSRequestComp) as CSRequestComp;
request.skillIndex = skillIndex;
request.targets = this.sTargets(heroView);

View File

@@ -2,7 +2,7 @@
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "37d898a0-b376-4f18-8559-2acf6f4e7db7",
"uuid": "e76866cc-7379-436f-91ff-e71e790580a9",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -1,18 +1,18 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Vec3, v3 } from "cc";
import { CastSkillRequestComp } from "./STagComps";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroViewComp } from "./HeroViewComp";
import { SkillSet, SType } from "../common/config/SkillSet";
import { SkillEnt } from "../skill/SkillEnt";
import { HeroSkillsComp } from "./HeroSkills";
import { Skill } from "../skill/Skill";
import { CSRequestComp } from "../skill/STagComps";
/**
* ==================== 技能施法系统 手动施法====================
*
* 职责:
* 1. 监听 CastSkillRequestComp 标记组件
* 1. 监听 CSRequestComp 标记组件
* 2. 检查施法条件CD、MP、状态
* 3. 扣除资源MP
* 4. 创建技能实体
@@ -31,7 +31,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
* 过滤器:拥有技能数据 + 施法请求的实体
*/
filter(): ecs.IMatcher {
return ecs.allOf(HeroSkillsComp, HeroAttrsComp, CastSkillRequestComp);
return ecs.allOf(HeroSkillsComp, HeroAttrsComp, CSRequestComp);
}
/**
@@ -40,13 +40,13 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
entityEnter(e: ecs.Entity): void {
const skills = e.get(HeroSkillsComp);
const heroModel = e.get(HeroAttrsComp);
const request = e.get(CastSkillRequestComp);
const request = e.get(CSRequestComp);
const heroView = e.get(HeroViewComp);
// 1. 验证数据完整性
if (!skills || !heroModel || !request || !heroView) {
console.warn("[SkillCastSystem] 数据不完整,取消施法");
e.remove(CastSkillRequestComp);
e.remove(CSRequestComp);
return;
}
@@ -54,13 +54,13 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
const skill = skills.getSkill(request.skillIndex);
if (!skill) {
console.warn(`[SkillCastSystem] 技能索引无效: ${request.skillIndex}`);
e.remove(CastSkillRequestComp);
e.remove(CSRequestComp);
return;
}
// 3. 检查施法条件
if (!this.checkCastConditions(skills, heroModel, request.skillIndex)) {
e.remove(CastSkillRequestComp);
e.remove(CSRequestComp);
return;
}
@@ -72,7 +72,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
skills.resetCD(request.skillIndex);
// 6. 移除请求标记
e.remove(CastSkillRequestComp);
e.remove(CSRequestComp);
}
/**

View File

@@ -1,106 +0,0 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Vec3 } from "cc";
/**
* ==================== 技能数据组件 ====================
*
* 用途:
* - 存储单个技能的完整数据
* - 包含技能配置、状态、目标等信息
* - 可被技能系统读取和修改
*/
@ecs.register('SkillData')
export class SkillDataComp extends ecs.Comp {
/** 技能唯一ID */
skillId: number = 0;
/** 技能名称 */
name: string = "";
/** 技能等级 */
level: number = 1;
/** 技能类型 */
type: number = 0;
/** 消耗MP */
cost: number = 0;
/** 冷却时间 */
cooldown: number = 0;
/** 当前冷却剩余时间 */
currentCooldown: number = 0;
/** 伤害值 */
damage: number = 0;
/** 技能范围 */
range: number = 0;
/** 施法时间 */
castTime: number = 0;
/** 技能描述 */
description: string = "";
/** 是否已解锁 */
unlocked: boolean = false;
/** 技能图标路径 */
iconPath: string = "";
/** 额外属性数据 */
extraData: any = null;
reset() {
this.skillId = 0;
this.name = "";
this.level = 1;
this.type = 0;
this.cost = 0;
this.cooldown = 0;
this.currentCooldown = 0;
this.damage = 0;
this.range = 0;
this.castTime = 0;
this.description = "";
this.unlocked = false;
this.iconPath = "";
this.extraData = null;
}
/**
* 检查技能是否可以施放
*/
canCast(currentMP: number): boolean {
return this.unlocked &&
this.currentCooldown <= 0 &&
currentMP >= this.cost;
}
/**
* 更新冷却时间
*/
updateCooldown(deltaTime: number): void {
if (this.currentCooldown > 0) {
this.currentCooldown = Math.max(0, this.currentCooldown - deltaTime);
}
}
/**
* 重置冷却时间
*/
resetCooldown(): void {
this.currentCooldown = this.cooldown;
}
/**
* 获取冷却进度 (0-1)
*/
getCooldownProgress(): number {
if (this.cooldown <= 0) return 1;
return Math.max(0, 1 - (this.currentCooldown / this.cooldown));
}
}

View File

@@ -1,47 +0,0 @@
import { Vec3, v3 } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { BezierMove } from "../BezierMove/BezierMove";
import { RType, SkillSet } from "../common/config/SkillSet";
/**
* 技能移动数据组件
* 存储技能实体的移动相关数据
*/
@ecs.register('SMoveData')
export class SMoveDataComp extends ecs.Comp {
/** 起始位置 */
startPos: Vec3 = v3();
/** 目标位置 */
targetPos: Vec3 = v3();
/** 移动速度 */
speed: number = 500;
/** 移动持续时间 */
duration: number = 0;
/** 移动方向 */
direction: Vec3 = v3();
/** 是否自动销毁(到达目标后) */
autoDestroy: boolean = true;
s_uuid:number=0;
reset() {
this.startPos.set(0, 0, 0);
this.targetPos.set(0, 0, 0);
this.speed = 500;
this.duration = 0;
this.direction.set(0, 0, 0);
this.autoDestroy = true;
}
}
// /** 业务层业务逻辑处理对象 */
// export class SMoveSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
// filter(): ecs.IMatcher {
// return ecs.allOf(SMoveDataComp);
// }
// entityEnter(e: ecs.Entity): void {
// // 注:自定义业务逻辑
// let s_uuid=e.get(SMoveDataComp).s_uuid
// let SConf=SkillSet[s_uuid]
// e.remove(SMoveDataComp);
// }
// }

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d0c2d505-f2c3-4cf3-82f7-490f9d14e096",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,53 +0,0 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Vec3 } from "cc";
/**
* ==================== 施法请求标记组件 ====================
*
* 用途:
* - 标记角色想要施放某个技能
* - 由外部如AI系统、玩家输入添加
* - 施法系统处理后自动移除
*/
@ecs.register('CastSkillRequest')
export class CastSkillRequestComp extends ecs.Comp {
/** 技能索引(在 HeroSkillsComp.skills 中的位置) */
skillIndex: number = 0;
/** 目标位置数组(由请求者提供) */
targets: Vec3[] = [];
reset() {
this.skillIndex = 0;
this.targets = [];
}
}
/**
* ==================== 技能命中标记组件 ====================
*
* 用途:
* - 标记技能已命中目标
* - 记录命中信息
* - 伤害系统处理后移除
*/
@ecs.register('SkillHit')
export class SkillHitComp extends ecs.Comp {
/** 技能ID */
s_uuid: number = 0;
/** 命中位置 */
hitPosition: Vec3 = new Vec3();
/** 伤害值 */
damage: number = 0;
/** 施法者实体ID */
casterId: number = 0;
reset() {
this.s_uuid = 0;
this.hitPosition.set(0, 0, 0);
this.damage = 0;
this.casterId = 0;
}
}