From 3b21ee4048ec6c16bd99e6b08a50cb96ca1b56a4 Mon Sep 17 00:00:00 2001 From: panw Date: Fri, 31 Oct 2025 11:05:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8A=80=E8=83=BD=E7=B3=BB=E7=BB=9F):?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84=E6=8A=80=E8=83=BD=E6=96=BD=E6=94=BE?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将SkillCastSystem重命名为SCastSystem和SACastSystem以区分不同功能 - 优化SMoveComp中位置属性的初始化,改为null避免不必要的对象创建 - 统一日志前缀使用系统名称提高可读性 - 在SACastSystem中添加目标位置检查逻辑 - 修复代码格式问题,统一缩进和注释风格 --- assets/script/game/hero/SACastSystem.ts | 29 +++++++++++++++++++------ assets/script/game/hero/SCastSystem.ts | 16 +++++++------- assets/script/game/skill/SMoveComp.ts | 4 ++-- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/assets/script/game/hero/SACastSystem.ts b/assets/script/game/hero/SACastSystem.ts index 7851c3b3..fcf4251a 100644 --- a/assets/script/game/hero/SACastSystem.ts +++ b/assets/script/game/hero/SACastSystem.ts @@ -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); + // 获取施法者位置作为起始位置 + 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); + } /** diff --git a/assets/script/game/hero/SCastSystem.ts b/assets/script/game/hero/SCastSystem.ts index fedaf567..5e4d0a10 100644 --- a/assets/script/game/hero/SCastSystem.ts +++ b/assets/script/game/hero/SCastSystem.ts @@ -24,8 +24,8 @@ import { CSRequestComp } from "../skill/STagComps"; * - 施法检查与执行分离 * - 自动处理资源消耗和CD重置 */ -// @ecs.register('SkillCastSystem') -export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem { +// @ecs.register('SCastSystem') +export class SCastSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem { /** * 过滤器:拥有技能数据 + 施法请求的实体 @@ -45,7 +45,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn // 1. 验证数据完整性 if (!skillsComp || !heroAttrs || !request || !heroView) { - console.warn("[SkillCastSystem] 数据不完整,取消施法"); + console.warn("[SCastSystem] 数据不完整,取消施法"); e.remove(CSRequestComp); return; } @@ -53,7 +53,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn // 2. 获取技能数据 const skill = skillsComp.getSkill(request.s_uuid); if (!skill) { - console.warn(`[SkillCastSystem] 技能索引无效: ${request.s_uuid }`); + console.warn(`[SCastSystem] 技能索引无效: ${request.s_uuid }`); e.remove(CSRequestComp); return; } @@ -103,7 +103,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn private executeCast(casterEntity: ecs.Entity, skill: any, targets: Vec3[], heroView: HeroViewComp) { const config = SkillSet[skill.uuid]; if (!config) { - console.error("[SkillCastSystem] 技能配置不存在:", skill.uuid); + console.error("[SCastSystem] 技能配置不存在:", skill.uuid); return; } @@ -117,7 +117,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn }, delay); const heroAttrs = casterEntity.get(HeroAttrsComp); - console.log(`[SkillCastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`); + console.log(`[SCastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`); } /** @@ -126,14 +126,14 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn private createSkill(skillId: number, caster: HeroViewComp, targets: Vec3[]) { // 检查节点有效性 if (!caster.node || !caster.node.isValid) { - console.warn("[SkillCastSystem] 施法者节点无效"); + console.warn("[SCastSystem] 施法者节点无效"); return; } // 获取场景节点 const parent = caster.node.parent; if (!parent) { - console.warn("[SkillCastSystem] 场景节点无效"); + console.warn("[SCastSystem] 场景节点无效"); return; } diff --git a/assets/script/game/skill/SMoveComp.ts b/assets/script/game/skill/SMoveComp.ts index ed9e91e1..40f4ebf0 100644 --- a/assets/script/game/skill/SMoveComp.ts +++ b/assets/script/game/skill/SMoveComp.ts @@ -10,9 +10,9 @@ import { BoxSet } from "../common/config/BoxSet"; @ecs.register('SMoveData') export class SMoveDataComp extends ecs.Comp { /** 起始位置 */ - startPos: Vec3 = v3(); + startPos: Vec3 = null; /** 目标位置 */ - targetPos: Vec3 = v3(); + targetPos: Vec3 = null; /** 移动速度 */ speed: number = 500; /** 移动持续时间 */