refactor(技能系统): 移除未使用属性并优化目标选择逻辑
- 移除 Skill.ts 中未使用的 wfuny 属性赋值 - 将 SCastSystem 中的目标选择逻辑重构为统一方法 - 在施放技能前增加目标有效性检查,避免无效操作 - 移除 HeroAtkSystem 中未使用的导入和接口字段 - 调整 SkillSet 中技能 6008 的 ready 参数值
This commit is contained in:
@@ -25,6 +25,7 @@ import { GameConst } from "../common/config/GameConst";
|
||||
@ecs.register('SCastSystem')
|
||||
export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
debugMode: boolean = false; // 是否启用调试模式
|
||||
private readonly emptyCastPlan = { skillId: 0, targets: [] as HeroViewComp[] };
|
||||
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(HeroAttrsComp, HeroViewComp);
|
||||
@@ -39,12 +40,12 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
if (heroAttrs.is_dead || heroAttrs.is_reviving || heroAttrs.isStun() || heroAttrs.isFrost()) return;
|
||||
heroAttrs.updateCD(this.dt);
|
||||
if (!heroAttrs.is_atking) return;
|
||||
const castSkillId = this.pickCastSkill(heroAttrs, heroView);
|
||||
if (castSkillId === 0) return;
|
||||
this.castSkill(e, castSkillId, heroAttrs, heroView);
|
||||
const castPlan = this.pickCastSkill(heroAttrs, heroView);
|
||||
if (castPlan.skillId === 0 || castPlan.targets.length === 0) return;
|
||||
this.castSkill(e, castPlan, heroAttrs, heroView);
|
||||
}
|
||||
|
||||
private pickCastSkill(heroAttrs: HeroAttrsComp, heroView: HeroViewComp): number {
|
||||
private pickCastSkill(heroAttrs: HeroAttrsComp, heroView: HeroViewComp): { skillId: number; targets: HeroViewComp[] } {
|
||||
const skillCandidates = [heroAttrs.skill_id, heroAttrs.atk_id];
|
||||
for (const s_uuid of skillCandidates) {
|
||||
if (!s_uuid) continue;
|
||||
@@ -55,16 +56,15 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
if (!isMainSkill && !heroAttrs.can_atk) continue;
|
||||
const targets = this.findTargets(heroView, heroAttrs, config);
|
||||
if (targets.length === 0) continue;
|
||||
return s_uuid;
|
||||
return { skillId: s_uuid, targets };
|
||||
}
|
||||
return 0;
|
||||
return this.emptyCastPlan;
|
||||
}
|
||||
|
||||
private castSkill(entity: ecs.Entity, s_uuid: number, heroAttrs: HeroAttrsComp, heroView: HeroViewComp) {
|
||||
private castSkill(entity: ecs.Entity, castPlan: { skillId: number; targets: HeroViewComp[] }, heroAttrs: HeroAttrsComp, heroView: HeroViewComp) {
|
||||
const s_uuid = castPlan.skillId;
|
||||
const config = SkillSet[s_uuid];
|
||||
if (!config) return;
|
||||
const targets = this.findTargets(heroView, heroAttrs, config);
|
||||
if (targets.length === 0) return;
|
||||
heroView.playSkillEffect(s_uuid);
|
||||
const isMainSkill = s_uuid === heroAttrs.skill_id;
|
||||
|
||||
@@ -75,8 +75,10 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
|
||||
heroView.scheduleOnce(() => {
|
||||
if (!heroView.node || !heroView.node.isValid || heroAttrs.is_dead) return;
|
||||
this.applyPrimaryEffect(entity, s_uuid, config, heroView, targets);
|
||||
this.applyExtraEffects(config, targets);
|
||||
const validTargets = this.filterValidTargets(castPlan.targets);
|
||||
if (validTargets.length === 0) return;
|
||||
this.applyPrimaryEffect(entity, s_uuid, config, heroView, validTargets);
|
||||
this.applyExtraEffects(config, validTargets);
|
||||
}, delay);
|
||||
if (isMainSkill) {
|
||||
heroAttrs.triggerSkillCD();
|
||||
@@ -138,6 +140,16 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
}
|
||||
}
|
||||
|
||||
private filterValidTargets(targets: HeroViewComp[]): HeroViewComp[] {
|
||||
return targets.filter(target => {
|
||||
if (!target || !target.node || !target.node.isValid) return false;
|
||||
if (!target.ent) return false;
|
||||
const model = target.ent.get(HeroAttrsComp);
|
||||
if (!model || model.is_dead || model.is_reviving) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private findTargets(caster: HeroViewComp, casterAttrs: HeroAttrsComp, config: SkillConfig): HeroViewComp[] {
|
||||
const range = casterAttrs.getCachedMaxSkillDistance() || GameConst.Battle.DEFAULT_SEARCH_RANGE;
|
||||
const isEnemy = config.TGroup === TGroup.Enemy;
|
||||
|
||||
Reference in New Issue
Block a user