feat(天赋系统): 重构天赋buff处理逻辑并添加vType支持
- 在TalSlot接口和talConf配置中添加vType字段区分数值型和百分比型buff - 重构HeroAttrsComp中BUFFS_TAL数据结构,改为以天赋uuid为key的映射 - 实现新的addTalBuff和clearTalBuff方法处理天赋buff - 在TalComp中添加BUFF类型天赋的触发处理
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BType } from "../common/config/HeroAttrs";
|
||||
import { TalAttrs, talConf, TalEffet, TalTarget, TriType} from "../common/config/TalSet";
|
||||
import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
@@ -14,6 +15,7 @@ export interface TalSlot {
|
||||
target: TalTarget;
|
||||
effet: TalEffet;
|
||||
attrs?:TalAttrs //触发的attrs效果的对应attrs value: number; // 触发的效果数值
|
||||
vType:BType; // 数值型还是百分比型
|
||||
value: number; // 触发的效果数值
|
||||
value_add: number; // 触发的效果数值增量
|
||||
Trigger: number; // 天赋触发阈值
|
||||
@@ -86,6 +88,7 @@ export class TalComp extends ecs.Comp {
|
||||
target: tConf.target,
|
||||
effet: tConf.effet,
|
||||
attrs: tConf.attrs,
|
||||
vType: tConf.vType,
|
||||
value: tConf.value, // 效果数值初始为配置值
|
||||
value_add: 0, // 效果数值增量初始为0
|
||||
Trigger: tConf.Trigger, // 触发阈值(后续可从配置中读取)
|
||||
@@ -179,6 +182,7 @@ export class TalComp extends ecs.Comp {
|
||||
|
||||
}
|
||||
}
|
||||
//执行天赋触发效果
|
||||
doTriggerTal(uuid: number) {
|
||||
// 检查天赋是否存在
|
||||
if (!this.Tals[uuid]) {
|
||||
@@ -196,16 +200,13 @@ export class TalComp extends ecs.Comp {
|
||||
heroAttrs.tal_DSill.count += 1;
|
||||
heroAttrs.tal_DSill.value = talent.value+talent.value_add;
|
||||
break;
|
||||
case TalEffet.BUFF:
|
||||
heroAttrs.addTalBuff(talent.uuid, talent.attrs, talent.vType, talent.value + talent.value_add);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 重置组件状态
|
||||
*
|
||||
* 功能:
|
||||
* - 清空所有天赋数据
|
||||
* - 重置英雄ID
|
||||
* - 清除英雄视图引用
|
||||
* - 为组件的复用做准备
|
||||
*/
|
||||
reset() {
|
||||
this.Tals = {};
|
||||
|
||||
Reference in New Issue
Block a user