feat(天赋系统): 重构天赋系统并添加新天赋效果
- 重构天赋类型和效果枚举,简化触发条件分类 - 添加天赋buff数组支持叠加效果计算 - 实现多种新天赋效果包括风怒、溅射、护盾等 - 修改熟练天赋触发条件从3次改为10次攻击
This commit is contained in:
@@ -3,6 +3,7 @@ import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
|
||||
import { BuffConf } from "../common/config/SkillSet";
|
||||
import { HeroInfo, AttrSet } from "../common/config/heroSet";
|
||||
import { HeroSkillsComp } from "./HeroSkills";
|
||||
import { talConf, TalAttrs } from "../common/config/TalSet";
|
||||
|
||||
|
||||
@ecs.register('HeroAttrs')
|
||||
@@ -42,7 +43,9 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
|
||||
/** 临时型buff数组 - 按时间自动过期 */
|
||||
BUFFS_TEMP: Record<number, Array<{value: number, BType: BType, remainTime: number}>> = {};
|
||||
|
||||
/** 天赋buff数组 - 触发过期,数量可叠加 */
|
||||
BUFFS_TAL: Record<number, Array<{tal:number,value: number, BType: BType,count:number}>> = {};
|
||||
|
||||
// ==================== 标记状态 ====================
|
||||
is_dead: boolean = false;
|
||||
is_count_dead: boolean = false;
|
||||
@@ -70,6 +73,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
// 清空现有 buff/debuff
|
||||
this.BUFFS = {};
|
||||
this.BUFFS_TEMP = {};
|
||||
this.BUFFS_TAL = {};
|
||||
|
||||
// 获取英雄配置
|
||||
const heroInfo = HeroInfo[this.hero_uuid];
|
||||
@@ -177,6 +181,14 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 收集所有百分比型 buff/debuff
|
||||
let totalRatio = 0;
|
||||
@@ -197,6 +209,14 @@ 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 根据属性类型计算最终值
|
||||
const attrType = AttrsType[attrIndex];
|
||||
@@ -408,6 +428,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.NeAttrs = [];
|
||||
this.BUFFS = {};
|
||||
this.BUFFS_TEMP = {};
|
||||
this.BUFFS_TAL = {};
|
||||
// 重置技能距离缓存
|
||||
this.maxSkillDistance = 0;
|
||||
this.minSkillDistance = 0;
|
||||
@@ -423,5 +444,45 @@ 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));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user