refactor(skill): 将buff/debuff应用逻辑从SkillView移到SCastSystem

重构技能效果应用逻辑,将buff/debuff处理从SkillView的碰撞检测中移除,统一在SCastSystem中根据技能配置决定是否创建技能实体或直接应用支持效果。这样可以更清晰地分离伤害技能和支持技能的处理逻辑,避免在碰撞时重复应用效果。
This commit is contained in:
panw
2026-03-12 22:02:42 +08:00
parent fac8d571c3
commit 5d83bd1516
3 changed files with 41 additions and 33 deletions

View File

@@ -316,7 +316,7 @@ export const BuffsList: Record<number, BuffConf> = {
// 治疗 (基于攻击力百分比)
10301: { uuid: 10301, name: "治疗", icon: "1292", buff: Attrs.hp, BType: BType.VALUE, value: 30, time: 0, chance: 1, info: "回复30%生命值" },
// 护盾 (基于攻击力百分比)
10302: { uuid: 10302, name: "护盾", icon: "1255", buff: Attrs.shield, BType: BType.VALUE, value: 30, time: 60, chance: 1, info: "获得30%护盾" },
10302: { uuid: 10302, name: "护盾", icon: "1255", buff: Attrs.shield, BType: BType.VALUE, value: 30, time: 0, chance: 1, info: "获得30%护盾" },
// ========== 减益类 Buff (属性降低) ========== 10200 - 10299
// 减速 (移动速度降低)

View File

@@ -72,8 +72,14 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const delay = GameConst.Battle.SKILL_CAST_DELAY;
heroView.scheduleOnce(() => {
if (!heroView.node || !heroView.node.isValid || heroAttrs.is_dead) return;
// 始终创建技能实体所有效果伤害、Buff、Debuff均在 SkillView 中处理
this.createSkillEntity(s_uuid, heroView, targets[0].node.position);
// 优先判断是否有ap伤害物理/魔法伤害)
if (config.ap > 0) {
this.createSkillEntity(s_uuid, heroView, targets[0].node.position);
}
// 接着应用buff效果包括治疗、护盾等已转换为buff的逻辑
if ((config.buffs && config.buffs.length > 0) || (config.debuffs && config.debuffs.length > 0)) {
this.applySupportSkill(entity, config, targets);
}
}, delay);
if (isMainSkill) {
heroAttrs.triggerSkillCD();
@@ -90,6 +96,38 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
skill.load(caster.node.position.clone(), parent, s_uuid, targetPos.clone(), caster, 0);
}
private applySupportSkill(casterEntity: ecs.Entity, config: SkillConfig, targets: HeroViewComp[]) {
const casterAttrs = casterEntity.get(HeroAttrsComp);
if (!casterAttrs) return;
for (const target of targets) {
if (!target.ent) continue;
const model = target.ent.get(HeroAttrsComp);
if (!model || model.is_dead) continue;
// 统一通过 Buff 系统应用效果
if (config.buffs) {
for (const buffId of config.buffs) {
const buffConf = BuffsList[buffId];
if (buffConf) {
model.addBuff(buffConf);
}
}
}
// 应用 Debuff 效果
if (config.debuffs) {
for (const buffId of config.debuffs) {
const buffConf = BuffsList[buffId];
if (buffConf) {
model.addBuff(buffConf);
}
}
}
}
mLogger.log(this.debugMode, "SCastSystem", `[SCastSystem] ${casterAttrs.hero_name} 施放 ${config.name}`);
}
private findTargets(caster: HeroViewComp, casterAttrs: HeroAttrsComp, config: SkillConfig): HeroViewComp[] {
const range = casterAttrs.getCachedMaxSkillDistance() || GameConst.Battle.DEFAULT_SEARCH_RANGE;
const isEnemy = config.TGroup === TGroup.Enemy;

View File

@@ -140,36 +140,6 @@ export class SkillView extends CCComp {
this.sData.dmg_ratio,
);
// 1. 应用 Buff 效果 (对目标,虽然通常 Buff 是给自己,但这里 target 是碰撞对象)
// 注意:如果是增益 Buff (如治疗),通常目标应该是自己或队友。
// 但 SkillView 的碰撞逻辑通常是针对"命中目标"。
// 如果是治疗技能target 应该是队友。如果是攻击技能target 是敌人。
// 这里的逻辑假设 SkillView 命中的就是正确的目标。
if (this.SConf.buffs && this.SConf.buffs.length > 0) {
const targetModel = target.ent.get(HeroAttrsComp);
if (targetModel) {
for (const buffId of this.SConf.buffs) {
const buffConf = BuffsList[buffId];
if (buffConf) {
targetModel.addBuff(buffConf);
}
}
}
}
// 2. 应用 Debuff 效果
if (this.SConf.debuffs && this.SConf.debuffs.length > 0) {
const targetModel = target.ent.get(HeroAttrsComp);
if (targetModel) {
for (const buffId of this.SConf.debuffs) {
const buffConf = BuffsList[buffId];
if (buffConf) {
targetModel.addBuff(buffConf);
}
}
}
}
// 更新技能命中次数
this.sData.hit_count++
if (