refactor: 重构技能系统并移除自动施法模块

- 删除 SACastSystem 及其 meta 文件,移除自动施法逻辑
- 重构 HeroAttrsComp 中的 Buff 处理逻辑,修复百分比计算问题
  - 将治疗和护盾 Buff 的 BType 从 VALUE 改为 RATIO
  - 添加 resolveBuffValue 方法正确计算基于最大生命值的百分比值
  - 修复 applyAttrChange 中 RATIO 类型的叠加逻辑
- 添加 HeroBuffSystem 系统,将 Buff 更新逻辑从 HeroAttrsComp 中分离
- 优化 SkillView 的销毁逻辑,避免直接调用 destroy 方法
  - 禁用碰撞体并设置节点为 inactive 状态
This commit is contained in:
panw
2026-03-13 09:52:16 +08:00
parent d626a6e5c2
commit 6170f47ca6
5 changed files with 47 additions and 686 deletions

View File

@@ -5,6 +5,7 @@ import { Attrs, BType } from "../common/config/HeroAttrs";
import { BuffConf, SkillDisVal, SkillRange } from "../common/config/SkillSet";
import { HeroInfo, HType } from "../common/config/heroSet";
import { mLogger } from "../common/Logger";
import { smc } from "../common/SingletonModuleComp";
import { _decorator } from "cc";
const { property } = _decorator;
@@ -152,39 +153,45 @@ export class HeroAttrsComp extends ecs.Comp {
* @param buffConf buff 配置
*/
addBuff(buffConf: BuffConf) {
// 1. 如果是永久性增益time=0直接修改基础属性
const applyType = buffConf.BType === BType.BOOLEAN ? BType.BOOLEAN : BType.VALUE;
const resolvedValue = applyType === BType.BOOLEAN
? buffConf.value
: this.resolveBuffValue(buffConf.buff, buffConf.value, buffConf.BType);
if (buffConf.time <= 0) {
this.applyAttrChange(buffConf.buff, buffConf.value, buffConf.BType);
this.applyAttrChange(buffConf.buff, resolvedValue, applyType);
return;
}
// 2. 临时性 Buff/Debuff 处理
// 区分存储列表
const targetList = buffConf.isDebuff ? this.DEBUFFS : this.BUFFS;
// 确保列表初始化
// 注意:这里我们用 buffConf.buff (属性名) 作为 key而不是 buffConf.uuid
// 这样同一种属性的 buff 可以叠加或覆盖
const attrKey = buffConf.buff as unknown as number; // 强制转换 key 类型以适配 Record
if (!targetList[attrKey]) {
targetList[attrKey] = [];
}
const currentBuffs = targetList[attrKey];
// 查找是否已有同源的 buff (这里假设 uuid 相同为同源,或者简单点直接追加)
// 策略直接追加update 时统一计算
// 记录添加时的数值,方便后续移除(虽然 update 是重新计算总值的)
currentBuffs.push({
value: buffConf.value,
BType: buffConf.BType,
value: resolvedValue,
BType: applyType,
time: buffConf.time
});
// 立即应用一次属性变更(增量)
this.applyAttrChange(buffConf.buff, buffConf.value, buffConf.BType);
this.applyAttrChange(buffConf.buff, resolvedValue, applyType);
mLogger.log(this.debugMode, 'HeroAttrs', `添加Buff: ${buffConf.name}, 属性:${buffConf.buff}, 值:${buffConf.value}, 时间:${buffConf.time}`);
mLogger.log(this.debugMode, 'HeroAttrs', `添加Buff: ${buffConf.name}, 属性:${buffConf.buff}, 值:${resolvedValue}, 时间:${buffConf.time}`);
}
private resolveBuffValue(attr: Attrs, value: number, type: BType): number {
if (type !== BType.RATIO) return value;
if (attr === Attrs.hp || attr === Attrs.shield) {
return this.hp_max * value / 100;
}
if (attr === Attrs.hp_max || attr === Attrs.shield_max) {
return this[attr] * value / 100;
}
if (typeof this[attr] === "number") {
return (this[attr] as number) * value / 100;
}
return value;
}
/**
@@ -212,43 +219,10 @@ export class HeroAttrsComp extends ecs.Comp {
return;
}
// 处理百分比
// 注意:百分比通常是基于基础值计算,这里简化为直接修改当前值
// 如果需要严格的基础值+百分比,需要维护 baseAttrs 和 bonusAttrs
// 当前架构直接修改属性,百分比暂时按 (当前值 * 百分比) 或 (基础值 * 百分比) 处理
// 鉴于属性系统中 hp/hp_max 等已经是数值,这里百分比暂定为:属性 = 属性 + (属性 * 百分比)
// 但对于 addBuff 这种临时增益,百分比通常是基于"基础值"的。
// 由于没有显式的 base_ap这里简化处理
// VALUE: 直接加减
// RATIO: 简单处理为 value 就是最终加成值(需要配置表里填好的数值),或者基于当前值
// 通常配置表填 10 表示 10%,即 0.1。
// 但这里的 value 已经是 number。假设配置 10 就是 10 点,或者 10%。
// 修正:根据 BType 处理
if (type === BType.RATIO) {
// 假设 value 是百分比整数,如 10 代表 10%
// 必须基于某个基数。这里暂时基于当前值(不严谨,但在没有 base 属性的情况下只能这样,或者基于 100?
// 更合理的做法:如果是 RATIOvalue 应该在配置时就转为实际数值,或者这里基于当前属性计算
// 考虑到 Attrs 定义里有很多非数值属性(如状态),需要特殊处理
// 针对状态类属性IN_FROST 等),通常是 BOOLEAN不走 RATIO
// 针对数值类ap, hpRATIO 应该是 value% * current
// 简化:目前只支持 VALUE 型直接加减。RATIO 型需要更复杂的属性系统支持Base + Add + Mul
// 这里的实现先按 VALUE 处理,如果以后需要 RATIO建议在 addBuff 前计算好 value
// 或者:约定 RATIO 时value 是基于当前值的百分比增量
const ratio = finalValue / 100;
// 注意:这里直接修改 this[attr] 会导致多次叠加问题。
// 临时 Buff 的正确做法是Update 中每一帧重置属性 -> 应用所有 Buff。
// 但当前架构似乎是“增量修改”式的。
// “增量修改”式在移除时很麻烦(尤其是百分比)。
// 妥协方案:只支持 VALUE 加减。配置表里的 RATIO 需要在逻辑层转为 VALUE。
// 但为了兼容 BType.RATIO这里暂时按 (当前值 * ratio) 计算增量
// 这会导致 recursive 问题,所以严谨的项目里属性必须分层。
// 鉴于“少可用原则”,这里仅处理 VALUE 和 BOOLEAN
finalValue = this.resolveBuffValue(attr, finalValue, BType.RATIO);
if (typeof this[attr] === 'number') {
// 警告:直接改写数值可能不准确
this[attr] = (this[attr] as number) * (1 + ratio);
this[attr] = (this[attr] as number) + finalValue;
}
} else if (type === BType.BOOLEAN) {
// 布尔型/状态型value > 0 为 true/计数+1移除时 -1
@@ -475,5 +449,19 @@ export class HeroAttrsComp extends ecs.Comp {
}
@ecs.register('HeroBuffSystem')
export class HeroBuffSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
filter(): ecs.IMatcher {
return ecs.allOf(HeroAttrsComp);
}
update(e: ecs.Entity): void {
if (!smc.mission.play || smc.mission.pause) return;
const attrs = e.get(HeroAttrsComp);
if (!attrs || attrs.is_dead) return;
attrs.updateBuffsDebuffs(this.dt);
}
}