refactor(hero): 重构技能系统变量命名和自动施法系统

将技能相关变量名从skillId改为s_uuid以提高一致性
重命名自动施法系统文件并优化目标选择方法命名
删除旧版自动施法系统文件,新增重构后的实现
This commit is contained in:
2025-10-31 09:00:37 +08:00
parent 2f19433a0a
commit a1c605238d
4 changed files with 39 additions and 44 deletions

View File

@@ -6,9 +6,10 @@ 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";
/**
* ==================== 技能施法系统 ====================
* ==================== 技能施法系统 手动施法====================
*
* 职责:
* 1. 监听 CastSkillRequestComp 标记组件
@@ -37,20 +38,20 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
* 实体进入时触发(即请求施法时)
*/
entityEnter(e: ecs.Entity): void {
const skillsData = e.get(HeroSkillsComp);
const skills = e.get(HeroSkillsComp);
const heroModel = e.get(HeroAttrsComp);
const request = e.get(CastSkillRequestComp);
const heroView = e.get(HeroViewComp);
// 1. 验证数据完整性
if (!skillsData || !heroModel || !request || !heroView) {
if (!skills || !heroModel || !request || !heroView) {
console.warn("[SkillCastSystem] 数据不完整,取消施法");
e.remove(CastSkillRequestComp);
return;
}
// 2. 获取技能数据
const skill = skillsData.getSkill(request.skillIndex);
const skill = skills.getSkill(request.skillIndex);
if (!skill) {
console.warn(`[SkillCastSystem] 技能索引无效: ${request.skillIndex}`);
e.remove(CastSkillRequestComp);
@@ -58,17 +59,17 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
}
// 3. 检查施法条件
if (!this.checkCastConditions(skillsData, heroModel, request.skillIndex)) {
if (!this.checkCastConditions(skills, heroModel, request.skillIndex)) {
e.remove(CastSkillRequestComp);
return;
}
// 4. 执行施法
this.executeCast(e, skill, request.targetPositions, heroView);
this.executeCast(e, skill, request.targets, heroView);
// 5. 扣除资源和重置CD
heroModel.mp -= skill.cost;
skillsData.resetCD(request.skillIndex);
skills.resetCD(request.skillIndex);
// 6. 移除请求标记
e.remove(CastSkillRequestComp);
@@ -77,7 +78,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
/**
* 检查施法条件
*/
private checkCastConditions(skillsData: HeroSkillsComp, heroModel: HeroAttrsComp, skillIndex: number): boolean {
private checkCastConditions(skills: HeroSkillsComp, heroModel: HeroAttrsComp, skillIndex: number): boolean {
// 检查角色状态
if (heroModel.is_dead) {
return false;
@@ -89,7 +90,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
}
// 检查CD和MP
if (!skillsData.canCast(skillIndex, heroModel.mp)) {
if (!skills.canCast(skillIndex, heroModel.mp)) {
return false;
}
@@ -99,7 +100,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
/**
* 执行施法
*/
private executeCast(casterEntity: ecs.Entity, skill: any, targetPositions: Vec3[], heroView: HeroViewComp) {
private executeCast(casterEntity: ecs.Entity, skill: any, targets: Vec3[], heroView: HeroViewComp) {
const config = SkillSet[skill.uuid];
if (!config) {
console.error("[SkillCastSystem] 技能配置不存在:", skill.uuid);
@@ -112,7 +113,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
// 2. 延迟创建技能实体(等待动画)
const delay = config.with ?? 0.3; // 施法前摇时间
heroView.scheduleOnce(() => {
this.createSkillEntity(skill.uuid, heroView, targetPositions);
this.createSkill(skill.uuid, heroView, targets);
}, delay);
const heroModel = casterEntity.get(HeroAttrsComp);
@@ -122,7 +123,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
/**
* 创建技能实体
*/
private createSkillEntity(skillId: number, caster: HeroViewComp, targetPositions: Vec3[]) {
private createSkill(skillId: number, caster: HeroViewComp, targets: Vec3[]) {
// 检查节点有效性
if (!caster.node || !caster.node.isValid) {
console.warn("[SkillCastSystem] 施法者节点无效");
@@ -137,13 +138,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
}
// ✅ 使用现有的 SkillEnt 创建技能
const skillEnt = ecs.getEntity<SkillEnt>(SkillEnt);
skillEnt.load(
caster.node.position, // 起始位置
parent, // 父节点
skillId, // 技能ID
targetPositions, // 目标位置数组
caster, // 施法者
);
// const skill = ecs.getEntity<Skill>(Skill);
}
}