refactor(天赋系统): 优化天赋触发逻辑和代码结构

重构 TalComp 类的触发检查方法,将 checkIsTrigger 拆分为 getTriggers 和 checkIsTrigger
简化 SACastSystem 中的天赋触发判断逻辑,使用新的 checkIsTrigger 返回值
This commit is contained in:
2025-11-19 10:34:15 +08:00
parent 9798930879
commit e42bdbb671
2 changed files with 32 additions and 21 deletions

View File

@@ -119,14 +119,11 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
// 2. 更新攻击类型的天赋触发值 // 2. 更新攻击类型的天赋触发值
if(casterEntity.has(TalComp)){ if(casterEntity.has(TalComp)){
const talComp = casterEntity.get(TalComp); const talComp = casterEntity.get(TalComp);
if (hset === HSSet.atk) { if (hset === HSSet.atk) talComp.updateCur(TriType.ATK);
talComp.updateCur(TriType.ATK); if (hset != HSSet.atk) talComp.updateCur(TriType.SKILL);
isWFuny= talComp.checkIsTrigger(TalEffet.WFUNY); isDSill=talComp.checkIsTrigger().isDSill
} isWFuny=talComp.checkIsTrigger().isWFuny
if (hset != HSSet.atk) {
talComp.updateCur(TriType.SKILL);
isDSill= talComp.checkIsTrigger(TalEffet.D_SKILL);
}
} }
@@ -149,6 +146,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
// console.log(`[SACastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`); // console.log(`[SACastSystem] ${heroAttrs?.hero_name ?? '未知'} 施放技能: ${config.name}`);
} }
/** /**
* 创建技能实体 * 创建技能实体
*/ */

View File

@@ -129,22 +129,35 @@ export class TalComp extends ecs.Comp {
// 判断是否有天赋被触发 // 判断是否有天赋被触发
return Triggers; return Triggers;
} }
checkIsTrigger(effet: TalEffet) { getTriggers() {
// 存储所有触发的天赋
let Triggers: Record<string, TalSlot> = {};
// 遍历所有天赋
for (let uuid in this.Tals) { for (let uuid in this.Tals) {
const talent = this.Tals[uuid]; const talent = this.Tals[uuid];
// 匹配天赋类型 if (talent.cur >= (talent.Trigger - talent.Trigger_add)) { // 修复触发条件,累积值达到或超过触发阈值时触发
if (talent.effet == effet) { console.log(`[TalComp]天赋触发,天赋ID:${uuid}`);
// 修复触发条件逻辑:累积值达到或超过触发阈值时触发 // 重置累积值
// 原逻辑中 `talent.Trigger-talent.Trigger` 总是为0导致任何累积值都能触发 talent.cur = 0;
if (talent.cur >= (talent.Trigger - talent.Trigger_add)) { // 修复触发条件,累积值达到或超过触发阈值时触发 // 添加到触发列表
console.log(`[TalComp]天赋触发,天赋ID:${uuid}`); Triggers[uuid] = talent;
// 重置累积值
talent.cur = 0;
// 添加到触发列表
return true;
}
} }
} }
// 判断是否有天赋被触发
return Triggers;
}
checkIsTrigger() {
let res = {
isDSill:false,
isWFuny:false,
}
for(let uuid in this.Tals){
let trigger=this.Tals[uuid]
if(trigger.effet==TalEffet.WFUNY) res.isWFuny=true
if(trigger.effet==TalEffet.D_SKILL) res.isDSill=true
}
return res
} }
/** /**
* 更新天赋的效果数值 * 更新天赋的效果数值