feat(天赋系统): 重构天赋系统并添加新天赋效果

- 重构天赋类型和效果枚举,简化触发条件分类
- 添加天赋buff数组支持叠加效果计算
- 实现多种新天赋效果包括风怒、溅射、护盾等
- 修改熟练天赋触发条件从3次改为10次攻击
This commit is contained in:
2025-11-18 16:46:13 +08:00
parent ab8bb01dee
commit 7b067213c0
4 changed files with 140 additions and 50 deletions

View File

@@ -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));
}
}

View File

@@ -1,20 +1,23 @@
import { _decorator } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { BuffConf, SkillSet } from "../common/config/SkillSet";
import { TalAttrs, TalEffet, TalTarget, TriType } from "../common/config/TalSet";
import { HeroInfo } from "../common/config/heroSet";
import { HeroViewComp } from "./HeroViewComp";
const { ccclass } = _decorator;
export interface TalSlot {
uuid: number; // 天赋ID
name: string; // 天赋名称
value: number; // 触发的效果价值
Trigger:boolean //触发值减值
C_Trigger:number //当前值
}
/**
* 天赋系统组件类
* 继承自 CCComp作为 ECS 架构中的组件存在
* 负责管理英雄的天赋系统,包括天赋获取、触发、效果应用等
*/
@ccclass('TalComp')
@ecs.register('TalComp', false)
export class TalComp extends ecs.Comp {
/** 英雄视图组件引用,运行时获取避免循环引用 */
@@ -22,17 +25,15 @@ export class TalComp extends ecs.Comp {
private skillCon:any=null;
/** 英雄唯一标识符,用于从配置中获取英雄信息 */
private heroUuid: number = 0;
start() {
}
/** 天赋数组 */
Tals: Record<number, TalSlot> = {};
/** 天赋槽位数组,默认开启2个最多4个 */
TalSlots:number[]=[1,1,0,0]
reset() {
}
}