fix(cast&skill): 修复技能预制体加载问题,重构代码并添加调试日志
为SCastSystem添加多处调试日志,便于排查技能施法相关问题 重构Skill类的load方法,将同步预制体获取改为异步加载逻辑 封装重复的技能节点初始化逻辑为内部函数,提升代码可读性 修复预制体未预加载时无法创建技能实体的问题
This commit is contained in:
@@ -128,9 +128,13 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
targetPos = this.resolveEnemyCastTargetPos(config, mockAttrs, mockView, target, maxRange);
|
targetPos = this.resolveEnemyCastTargetPos(config, mockAttrs, mockView, target, maxRange);
|
||||||
}
|
}
|
||||||
// 如果全屏都没找到敌人,直接放弃释放伤害技能
|
// 如果全屏都没找到敌人,直接放弃释放伤害技能
|
||||||
if (!targetPos) return;
|
if (!targetPos) {
|
||||||
|
console.log("[SCastSystem] forceCastCardSkill: no enemy found for skill", s_uuid);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("[SCastSystem] forceCastCardSkill: casting skill", s_uuid, "castTimes", castTimes, "targetPos", targetPos);
|
||||||
for (let i = 0; i < castTimes; i++) {
|
for (let i = 0; i < castTimes; i++) {
|
||||||
if (isFriendly) {
|
if (isFriendly) {
|
||||||
const friendlyTargets = this.resolveFriendlyTargets(targetEids, FacSet.HERO);
|
const friendlyTargets = this.resolveFriendlyTargets(targetEids, FacSet.HERO);
|
||||||
@@ -147,7 +151,10 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
private createSkillEntityForCard(s_uuid: number, skillLv: number, mockAttrs: HeroAttrsComp, startPos: Vec3, targetPos: Vec3 | null, castIndex: number = 0, overrides?: SkillOverrides) {
|
private createSkillEntityForCard(s_uuid: number, skillLv: number, mockAttrs: HeroAttrsComp, startPos: Vec3, targetPos: Vec3 | null, castIndex: number = 0, overrides?: SkillOverrides) {
|
||||||
const scene = smc.map.MapView.scene;
|
const scene = smc.map.MapView.scene;
|
||||||
const parent = scene.entityLayer?.node?.getChildByName("SKILL");
|
const parent = scene.entityLayer?.node?.getChildByName("SKILL");
|
||||||
if (!parent || !targetPos) return;
|
if (!parent || !targetPos) {
|
||||||
|
console.log("[SCastSystem] createSkillEntityForCard failed: parent or targetPos missing", !!parent, !!targetPos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const skill = ecs.getEntity<Skill>(Skill);
|
const skill = ecs.getEntity<Skill>(Skill);
|
||||||
const actualStartPos = this.resolveRepeatCastStartPos(startPos, castIndex);
|
const actualStartPos = this.resolveRepeatCastStartPos(startPos, castIndex);
|
||||||
@@ -160,6 +167,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
skill.load(actualStartPos, parent, s_uuid, targetPos.clone(), mockView, mockAttrs, skillLv, 0, overrides);
|
skill.load(actualStartPos, parent, s_uuid, targetPos.clone(), mockView, mockAttrs, skillLv, 0, overrides);
|
||||||
|
console.log("[SCastSystem] createSkillEntityForCard success for skill", s_uuid);
|
||||||
}
|
}
|
||||||
/** 空施法计划:用于“当前无可施法技能”时的统一返回 */
|
/** 空施法计划:用于“当前无可施法技能”时的统一返回 */
|
||||||
private readonly emptyCastPlan = { skillId: 0, skillLv: 1, isFriendly: false, targetPos: null as Vec3 | null, targetEids: [] as number[], overrides: undefined as SkillOverrides | undefined };
|
private readonly emptyCastPlan = { skillId: 0, skillLv: 1, isFriendly: false, targetPos: null as Vec3 | null, targetEids: [] as number[], overrides: undefined as SkillOverrides | undefined };
|
||||||
|
|||||||
@@ -109,13 +109,8 @@ export class Skill extends ecs.Entity {
|
|||||||
}
|
}
|
||||||
config = mergeSkillParams(config, overrides);
|
config = mergeSkillParams(config, overrides);
|
||||||
|
|
||||||
// 加载预制体
|
|
||||||
const path = `game/skill/atk/${config.sp_name}`;
|
const path = `game/skill/atk/${config.sp_name}`;
|
||||||
const prefab:Prefab = oops.res.get(path, Prefab);
|
const initSkillNode = (prefab: Prefab) => {
|
||||||
if (!prefab) {
|
|
||||||
mLogger.error(this.debugMode, 'Skill', "[Skill] 预制体加载失败:", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const node: Node = Skill.getFromPool(path) || instantiate(prefab);
|
const node: Node = Skill.getFromPool(path) || instantiate(prefab);
|
||||||
if (!node || !node.isValid) {
|
if (!node || !node.isValid) {
|
||||||
mLogger.error(this.debugMode, 'Skill', "[Skill] 节点无效:", path);
|
mLogger.error(this.debugMode, 'Skill', "[Skill] 节点无效:", path);
|
||||||
@@ -227,6 +222,22 @@ export class Skill extends ecs.Entity {
|
|||||||
sDataCom.hit_count = 0
|
sDataCom.hit_count = 0
|
||||||
sDataCom.max_hit_count = Math.max(1,sHit)
|
sDataCom.max_hit_count = Math.max(1,sHit)
|
||||||
SView.init();
|
SView.init();
|
||||||
|
};
|
||||||
|
|
||||||
|
let prefab: Prefab = oops.res.get(path, Prefab);
|
||||||
|
if (prefab) {
|
||||||
|
initSkillNode(prefab);
|
||||||
|
} else {
|
||||||
|
oops.res.loadAsync(path, Prefab).then((res: Prefab) => {
|
||||||
|
if (res) {
|
||||||
|
initSkillNode(res);
|
||||||
|
} else {
|
||||||
|
mLogger.error(this.debugMode, 'Skill', "[Skill] 预制体加载失败:", path);
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
mLogger.error(this.debugMode, 'Skill', "[Skill] 预制体加载异常:", path, err);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 模块资源释放 */
|
/** 模块资源释放 */
|
||||||
|
|||||||
Reference in New Issue
Block a user