refactor(技能系统): 重构技能施放系统并优化位置初始化
- 将SkillCastSystem重命名为SCastSystem和SACastSystem以区分不同功能 - 优化SMoveComp中位置属性的初始化,改为null避免不必要的对象创建 - 统一日志前缀使用系统名称提高可读性 - 在SACastSystem中添加目标位置检查逻辑 - 修复代码格式问题,统一缩进和注释风格
This commit is contained in:
@@ -74,7 +74,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
|
|||||||
skills.resetCD(skill.s_uuid);
|
skills.resetCD(skill.s_uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 检查施法条件
|
* 检查施法条件
|
||||||
*/
|
*/
|
||||||
private checkCastConditions(skills: HeroSkillsComp, heroAttrs: HeroAttrsComp, s_uuid: number): boolean {
|
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) {
|
private executeCast(casterEntity: ecs.Entity, s_uuid: number, heroView: HeroViewComp) {
|
||||||
const config = SkillSet[s_uuid];
|
const config = SkillSet[s_uuid];
|
||||||
if (!config) {
|
if (!config) {
|
||||||
console.error("[SkillCastSystem] 技能配置不存在:", s_uuid);
|
console.error("[SACastSystem] 技能配置不存在:", s_uuid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 1. 播放施法动画
|
// 1. 播放施法动画
|
||||||
@@ -115,7 +115,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
|
|||||||
}, delay);
|
}, delay);
|
||||||
|
|
||||||
const heroAttrs = casterEntity.get(HeroAttrsComp);
|
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) {
|
private createSkill(s_uuid: number, caster: HeroViewComp) {
|
||||||
// 检查节点有效性
|
// 检查节点有效性
|
||||||
if (!caster.node || !caster.node.isValid) {
|
if (!caster.node || !caster.node.isValid) {
|
||||||
console.warn("[SkillCastSystem] 施法者节点无效");
|
console.warn("[SACastSystem] 施法者节点无效");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取场景节点
|
// 获取场景节点
|
||||||
const parent = caster.node.parent;
|
const parent = caster.node.parent;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
console.warn("[SkillCastSystem] 场景节点无效");
|
console.warn("[SACastSystem] 场景节点无效");
|
||||||
return;
|
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 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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ import { CSRequestComp } from "../skill/STagComps";
|
|||||||
* - 施法检查与执行分离
|
* - 施法检查与执行分离
|
||||||
* - 自动处理资源消耗和CD重置
|
* - 自动处理资源消耗和CD重置
|
||||||
*/
|
*/
|
||||||
// @ecs.register('SkillCastSystem')
|
// @ecs.register('SCastSystem')
|
||||||
export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
|
export class SCastSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤器:拥有技能数据 + 施法请求的实体
|
* 过滤器:拥有技能数据 + 施法请求的实体
|
||||||
@@ -45,7 +45,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
|||||||
|
|
||||||
// 1. 验证数据完整性
|
// 1. 验证数据完整性
|
||||||
if (!skillsComp || !heroAttrs || !request || !heroView) {
|
if (!skillsComp || !heroAttrs || !request || !heroView) {
|
||||||
console.warn("[SkillCastSystem] 数据不完整,取消施法");
|
console.warn("[SCastSystem] 数据不完整,取消施法");
|
||||||
e.remove(CSRequestComp);
|
e.remove(CSRequestComp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
|||||||
// 2. 获取技能数据
|
// 2. 获取技能数据
|
||||||
const skill = skillsComp.getSkill(request.s_uuid);
|
const skill = skillsComp.getSkill(request.s_uuid);
|
||||||
if (!skill) {
|
if (!skill) {
|
||||||
console.warn(`[SkillCastSystem] 技能索引无效: ${request.s_uuid }`);
|
console.warn(`[SCastSystem] 技能索引无效: ${request.s_uuid }`);
|
||||||
e.remove(CSRequestComp);
|
e.remove(CSRequestComp);
|
||||||
return;
|
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) {
|
private executeCast(casterEntity: ecs.Entity, skill: any, targets: Vec3[], heroView: HeroViewComp) {
|
||||||
const config = SkillSet[skill.uuid];
|
const config = SkillSet[skill.uuid];
|
||||||
if (!config) {
|
if (!config) {
|
||||||
console.error("[SkillCastSystem] 技能配置不存在:", skill.uuid);
|
console.error("[SCastSystem] 技能配置不存在:", skill.uuid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ export class SkillCastSystem extends ecs.ComblockSystem implements ecs.IEntityEn
|
|||||||
}, delay);
|
}, delay);
|
||||||
|
|
||||||
const heroAttrs = casterEntity.get(HeroAttrsComp);
|
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[]) {
|
private createSkill(skillId: number, caster: HeroViewComp, targets: Vec3[]) {
|
||||||
// 检查节点有效性
|
// 检查节点有效性
|
||||||
if (!caster.node || !caster.node.isValid) {
|
if (!caster.node || !caster.node.isValid) {
|
||||||
console.warn("[SkillCastSystem] 施法者节点无效");
|
console.warn("[SCastSystem] 施法者节点无效");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取场景节点
|
// 获取场景节点
|
||||||
const parent = caster.node.parent;
|
const parent = caster.node.parent;
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
console.warn("[SkillCastSystem] 场景节点无效");
|
console.warn("[SCastSystem] 场景节点无效");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import { BoxSet } from "../common/config/BoxSet";
|
|||||||
@ecs.register('SMoveData')
|
@ecs.register('SMoveData')
|
||||||
export class SMoveDataComp extends ecs.Comp {
|
export class SMoveDataComp extends ecs.Comp {
|
||||||
/** 起始位置 */
|
/** 起始位置 */
|
||||||
startPos: Vec3 = v3();
|
startPos: Vec3 = null;
|
||||||
/** 目标位置 */
|
/** 目标位置 */
|
||||||
targetPos: Vec3 = v3();
|
targetPos: Vec3 = null;
|
||||||
/** 移动速度 */
|
/** 移动速度 */
|
||||||
speed: number = 500;
|
speed: number = 500;
|
||||||
/** 移动持续时间 */
|
/** 移动持续时间 */
|
||||||
|
|||||||
Reference in New Issue
Block a user