feat(天赋系统): 重构天赋buff处理逻辑并添加vType支持

- 在TalSlot接口和talConf配置中添加vType字段区分数值型和百分比型buff
- 重构HeroAttrsComp中BUFFS_TAL数据结构,改为以天赋uuid为key的映射
- 实现新的addTalBuff和clearTalBuff方法处理天赋buff
- 在TalComp中添加BUFF类型天赋的触发处理
This commit is contained in:
2025-11-20 14:35:29 +08:00
parent 94d5aa8920
commit f2ec48bd2b
3 changed files with 53 additions and 74 deletions

View File

@@ -38,8 +38,7 @@ export class HeroAttrsComp extends ecs.Comp {
//=====================天赋触发标签=====================
tal_DSill:talTrigger={value:0,count:0}
tal_WFuny:talTrigger={value:0,count:0}
/** 天赋buff数组 - 触发过期,数量可叠加 */
BUFFS_TAL: Record<number, Array<{tal:number,value: number, BType: BType,count:number}>> = {};
BUFFS_TAL: Record<number, {count:number,BType:BType,attrIndex:number,value: number}> = {};
// ==================== 技能距离缓存 ====================
maxSkillDistance: number = 0; // 最远技能攻击距离缓存受MP影响
@@ -188,12 +187,10 @@ export class HeroAttrsComp extends ecs.Comp {
}
}
}
// 遍历天赋buff数组数值型叠加 value*count
if (this.BUFFS_TAL[attrIndex] && this.BUFFS_TAL[attrIndex].length > 0) {
for (const buff of this.BUFFS_TAL[attrIndex]) {
if (buff.BType === BType.VALUE) {
totalValue += buff.value * buff.count;
}
for (const key in this.BUFFS_TAL) {
const buff = this.BUFFS_TAL[Number(key)];
if (buff.attrIndex === attrIndex && buff.BType === BType.VALUE) {
totalValue += buff.value;
}
}
@@ -216,12 +213,10 @@ export class HeroAttrsComp extends ecs.Comp {
}
}
}
// 遍历天赋buff数组百分比型叠加 value*count
if (this.BUFFS_TAL[attrIndex] && this.BUFFS_TAL[attrIndex].length > 0) {
for (const buff of this.BUFFS_TAL[attrIndex]) {
if (buff.BType === BType.RATIO) {
totalRatio += buff.value * buff.count;
}
for (const key in this.BUFFS_TAL) {
const buff = this.BUFFS_TAL[Number(key)];
if (buff.attrIndex === attrIndex && buff.BType === BType.RATIO) {
totalRatio += buff.value;
}
}
@@ -413,6 +408,25 @@ export class HeroAttrsComp extends ecs.Comp {
}
addTalBuff(t_uuid: number, attrIndex?: number, bType?: BType, value: number = 0) {
if (attrIndex === undefined || bType === undefined) return;
const buff = this.BUFFS_TAL[t_uuid];
if (!buff) {
this.BUFFS_TAL[t_uuid] = { count: 1, BType: bType, attrIndex, value };
} else {
buff.count += 1;
buff.value += value;
}
this.recalculateSingleAttr(attrIndex);
}
clearTalBuff(t_uuid: number) {
const buff = this.BUFFS_TAL[t_uuid];
if (!buff) return;
const attrIndex = buff.attrIndex;
delete this.BUFFS_TAL[t_uuid];
this.recalculateSingleAttr(attrIndex);
}
reset() {
// 重置为初始状态
@@ -451,45 +465,8 @@ export class HeroAttrsComp extends ecs.Comp {
this.atk_count = 0;
this.atked_count = 0;
}
private getTalAttr(tal: number) {
const conf = talConf[tal];
if (!conf) return null;
const attrIndex = conf.attrs ?? TalAttrs.NON;
if (attrIndex === TalAttrs.NON) return null;
const bType = AttrsType[attrIndex as unknown as number];
const value = conf.value;
return { attrIndex: attrIndex as unknown as number, bType, value };
}
addTalBuff(tal: number, count: number = 1) {
const info = this.getTalAttr(tal);
if (!info) return;
const { attrIndex, bType, value } = info;
if (!this.BUFFS_TAL[attrIndex]) this.BUFFS_TAL[attrIndex] = [];
const list = this.BUFFS_TAL[attrIndex];
const exist = list.find(i => i.tal === tal && i.BType === bType);
if (exist) {
exist.count += count;
} else {
list.push({ tal, value, BType: bType, count });
}
this.recalculateSingleAttr(attrIndex);
}
clearTalBuff(tal: number) {
const affected = new Set<number>();
for (const key in this.BUFFS_TAL) {
const idx = parseInt(key);
const list = this.BUFFS_TAL[idx];
if (!list || list.length === 0) continue;
const newList = list.filter(i => i.tal !== tal);
if (newList.length !== list.length) {
this.BUFFS_TAL[idx] = newList;
affected.add(idx);
if (newList.length === 0) delete this.BUFFS_TAL[idx];
}
}
affected.forEach(i => this.recalculateSingleAttr(i));
}
}