refactor(技能系统): 重构技能施放系统并优化位置初始化

- 将SkillCastSystem重命名为SCastSystem和SACastSystem以区分不同功能
- 优化SMoveComp中位置属性的初始化,改为null避免不必要的对象创建
- 统一日志前缀使用系统名称提高可读性
- 在SACastSystem中添加目标位置检查逻辑
- 修复代码格式问题,统一缩进和注释风格
This commit is contained in:
2025-10-31 11:05:44 +08:00
parent 2b3b80b308
commit 3b21ee4048
3 changed files with 32 additions and 17 deletions

View File

@@ -74,7 +74,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
skills.resetCD(skill.s_uuid);
}
/**
/**
* 检查施法条件
*/
private checkCastConditions(skills: HeroSkillsComp, heroAttrs: HeroAttrsComp, s_uuid: number): boolean {
@@ -102,7 +102,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
private executeCast(casterEntity: ecs.Entity, s_uuid: number, heroView: HeroViewComp) {
const config = SkillSet[s_uuid];
if (!config) {
console.error("[SkillCastSystem] 技能配置不存在:", s_uuid);
console.error("[SACastSystem] 技能配置不存在:", s_uuid);
return;
}
// 1. 播放施法动画
@@ -115,7 +115,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
}, delay);
const heroAttrs = casterEntity.get(HeroAttrsComp);
console.log(`[SkillCastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`);
console.log(`[SACastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`);
}
/**
@@ -124,20 +124,35 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
private createSkill(s_uuid: number, caster: HeroViewComp) {
// 检查节点有效性
if (!caster.node || !caster.node.isValid) {
console.warn("[SkillCastSystem] 施法者节点无效");
console.warn("[SACastSystem] 施法者节点无效");
return;
}
// 获取场景节点
const parent = caster.node.parent;
if (!parent) {
console.warn("[SkillCastSystem] 场景节点无效");
console.warn("[SACastSystem] 场景节点无效");
return;
}
const targets=this.sTargets(caster);
// ✅ 使用Skill 创建技能
// 获取目标位置
const targets = this.sTargets(caster);
if (targets.length === 0) {
console.warn("[SACastSystem] 没有找到有效目标");
return;
}
// 创建技能实体
const skill = ecs.getEntity<Skill>(Skill);
// 获取施法者位置作为起始位置
const startPos = caster.node.position.clone();
const targetPos = targets[0]; // 使用第一个目标位置
console.log(`[SACastSystem]: ${s_uuid}, 起始位置: ${startPos}, 目标位置: ${targetPos}`);
// 加载技能实体(包括预制体、组件初始化等)
skill.load(startPos, parent, s_uuid, targetPos, caster);
}
/**