From 5a81704379a6ca48d9a0890014cf794809c96d0d Mon Sep 17 00:00:00 2001 From: panw Date: Thu, 20 Nov 2025 14:51:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(hero):=20=E9=87=8D=E6=9E=84=E5=A4=A9?= =?UTF-8?q?=E8=B5=8B=E7=B3=BB=E7=BB=9F=E4=BD=BF=E7=94=A8=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将分散的天赋属性管理改为统一的Talents记录 - 添加addTalent和consumeTalent方法来管理天赋状态 - 修改技能系统使用新的天赋管理接口 --- assets/script/game/hero/HeroAttrsComp.ts | 24 +++++++++++++++++++----- assets/script/game/hero/SACastSystem.ts | 12 ++++-------- assets/script/game/hero/TalComp.ts | 6 ++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index ed00eb42..2ad31dd2 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -3,7 +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"; + interface talTrigger{ value:number @@ -35,9 +35,7 @@ export class HeroAttrsComp extends ecs.Comp { shield: number = 0; // 当前护盾 Attrs: any = []; // 最终属性数组(经过Buff计算后) NeAttrs: any = []; // 负面状态数组 - //=====================天赋触发标签===================== - tal_DSill:talTrigger={value:0,count:0} - tal_WFuny:talTrigger={value:0,count:0} + Talents: Record = {}; BUFFS_TAL: Record = {}; // ==================== 技能距离缓存 ==================== @@ -80,6 +78,7 @@ export class HeroAttrsComp extends ecs.Comp { this.BUFFS = {}; this.BUFFS_TEMP = {}; this.BUFFS_TAL = {}; + this.Talents = {}; // 获取英雄配置 const heroInfo = HeroInfo[this.hero_uuid]; @@ -426,7 +425,19 @@ export class HeroAttrsComp extends ecs.Comp { delete this.BUFFS_TAL[t_uuid]; this.recalculateSingleAttr(attrIndex); } - + + addTalent(eff: number, value: number) { + const t = this.Talents[eff] || { value: 0, count: 0 }; + t.value = value; + t.count += 1; + this.Talents[eff] = t; + } + consumeTalent(eff: number): boolean { + const t = this.Talents[eff]; + if (!t || t.count <= 0) return false; + t.count -= 1; + return true; + } reset() { // 重置为初始状态 @@ -450,6 +461,7 @@ export class HeroAttrsComp extends ecs.Comp { this.BUFFS = {}; this.BUFFS_TEMP = {}; this.BUFFS_TAL = {}; + this.Talents = {}; // 重置技能距离缓存 this.maxSkillDistance = 0; this.minSkillDistance = 0; @@ -470,3 +482,5 @@ export class HeroAttrsComp extends ecs.Comp { } + + diff --git a/assets/script/game/hero/SACastSystem.ts b/assets/script/game/hero/SACastSystem.ts index 6c2ff11b..faf19f9a 100644 --- a/assets/script/game/hero/SACastSystem.ts +++ b/assets/script/game/hero/SACastSystem.ts @@ -134,8 +134,6 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat */ private executeCast(casterEntity: ecs.Entity, s_uuid: number, heroView: HeroViewComp,hset:HSSet): boolean { const heroAttrs=casterEntity.get(HeroAttrsComp) - let isDSill=heroAttrs.tal_DSill.count > 0 - let isWFuny=heroAttrs.tal_WFuny.count > 0 const config = SkillSet[s_uuid]; if (!config) { console.error("[SACastSystem] 技能配置不存在:", s_uuid); @@ -165,14 +163,13 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat }, delay); //风怒wfuny 只针对 普通攻击起效 - if (hset === HSSet.atk&&isWFuny){ + if (hset === HSSet.atk && heroAttrs.consumeTalent(TalEffet.WFUNY)){ heroView.playSkillEffect(s_uuid); //需要再添加 风怒动画 this.createSkill(s_uuid, heroView,targets); - heroAttrs.tal_WFuny.count -- } // 双技能 只针对 技能起效 - if(hset === HSSet.skill&&isDSill){ + if(hset === HSSet.skill && heroAttrs.consumeTalent(TalEffet.D_SKILL)){ targets = this.sTargets(heroView, s_uuid); if (targets.length === 0) { console.warn("[SACastSystem] 没有找到有效目标"); @@ -183,7 +180,6 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat heroView.scheduleOnce(() => { this.createSkill(s_uuid, heroView,targets); }, delay); - heroAttrs.tal_DSill.count -- } @@ -194,7 +190,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat /** * 创建技能实体 */ - private createSkill(s_uuid: number, caster: HeroViewComp,targets:Vec3[]=[],damage:number=0) { + private createSkill(s_uuid: number, caster: HeroViewComp,targets:Vec3[]=[],exr_dmg:number=0) { // 检查节点有效性 if (!caster.node || !caster.node.isValid) { console.warn("[SACastSystem] 施法者节点无效"); @@ -219,7 +215,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat const targetPos = targets[0]; // 使用第一个目标位置 // console.log(`[SACastSystem]: ${s_uuid}, 起始位置: ${startPos}, 目标位置: ${targetPos}`); // 加载技能实体(包括预制体、组件初始化等) - skill.load(startPos, parent, s_uuid, targetPos, caster,damage); + skill.load(startPos, parent, s_uuid, targetPos, caster,exr_dmg); } diff --git a/assets/script/game/hero/TalComp.ts b/assets/script/game/hero/TalComp.ts index a3b02148..4df9796e 100644 --- a/assets/script/game/hero/TalComp.ts +++ b/assets/script/game/hero/TalComp.ts @@ -193,12 +193,10 @@ export class TalComp extends ecs.Comp { const heroAttrs=this.ent.get(HeroAttrsComp); switch(talent.effet){ case TalEffet.WFUNY: - heroAttrs.tal_WFuny.count += 1; - heroAttrs.tal_WFuny.value = talent.value+talent.value_add; + heroAttrs.addTalent(TalEffet.WFUNY, talent.value + talent.value_add); break; case TalEffet.D_SKILL: - heroAttrs.tal_DSill.count += 1; - heroAttrs.tal_DSill.value = talent.value+talent.value_add; + heroAttrs.addTalent(TalEffet.D_SKILL, talent.value + talent.value_add); break; case TalEffet.BUFF: heroAttrs.addTalBuff(talent.uuid, talent.attrs, talent.vType, talent.value + talent.value_add);