From 4ed531e1000a2002e9d1a16558620e715da61f7d Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 24 Nov 2025 10:27:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(hero):=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E5=A4=A9=E8=B5=8B=E7=9B=B8=E5=85=B3=E6=96=B9=E6=B3=95=E4=BB=A5?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E8=AE=A1=E6=95=B0=E5=9E=8B=E5=92=8C=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将计数型天赋操作方法从addTalent/consumeTalent重命名为addCountTal/useCountTal 将数值型天赋操作方法从addTalBuff/clearTalBuff重命名为addValueTal/useValueTalByUuid 更新相关文档和调用代码以保持一致性 --- assets/script/game/hero/HeroAtkSystem.ts | 4 +- assets/script/game/hero/HeroAttrsComp.ts | 38 ++++++++++--------- assets/script/game/hero/SACastSystem.ts | 4 +- assets/script/game/hero/TalComp.ts | 16 +++++--- .../script/game/wx_clound_client_api/USAGE.md | 4 +- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/assets/script/game/hero/HeroAtkSystem.ts b/assets/script/game/hero/HeroAtkSystem.ts index 155a37a4..27c6af1f 100644 --- a/assets/script/game/hero/HeroAtkSystem.ts +++ b/assets/script/game/hero/HeroAtkSystem.ts @@ -156,7 +156,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd // 暴击判定 // 使用施法者的暴击率属性(damageEvent.Attrs 快照) const isCrit = this.checkChance(damageEvent.Attrs[Attrs.CRITICAL]); - if (isCrit) attackerModel?.clearTalBuffByAttr(Attrs.CRITICAL); + if (isCrit) attackerModel?.useValueTalByAttr(Attrs.CRITICAL); // 清除施法者的暴击buff // 计算伤害 let damage = this.dmgCount(damageEvent.Attrs,targetAttrs.Attrs,damageEvent.s_uuid); if (isCrit) { @@ -179,7 +179,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd // 使用施法者的击退概率属性(damageEvent.Attrs 快照) // 击退成功后需要清理施法者的相关天赋buff const isBack = this.checkChance(damageEvent.Attrs[Attrs.BACK_CHANCE] || 0); - if (isBack) attackerModel?.clearTalBuffByAttr(Attrs.BACK_CHANCE); + if (isBack) attackerModel?.useValueTalByAttr(Attrs.BACK_CHANCE); // ✅ 触发视图层表现(伤害数字、受击动画、后退) diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index 04b539c9..ffc01f2a 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -35,7 +35,9 @@ export class HeroAttrsComp extends ecs.Comp { shield: number = 0; // 当前护盾 Attrs: any = []; // 最终属性数组(经过Buff计算后) NeAttrs: any = []; // 负面状态数组 - Talents: Record = {}; + //计数型天赋buff + Talents: Record = {}; + //数值型天赋buff BUFFS_TAL: Record = {}; // ==================== 技能距离缓存 ==================== @@ -407,7 +409,7 @@ export class HeroAttrsComp extends ecs.Comp { } - addTalBuff(t_uuid: number, attrIndex?: number, bType?: BType, value: number = 0) { + addValueTal(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) { @@ -418,14 +420,27 @@ export class HeroAttrsComp extends ecs.Comp { } this.recalculateSingleAttr(attrIndex); } - clearTalBuff(t_uuid: number) { + addCountTal(eff: number, value: number) { + const t = this.Talents[eff] || { value: 0, count: 0 }; + t.value = value; + t.count += 1; + this.Talents[eff] = t; + } + + useCountTal(eff: number): boolean { + const t = this.Talents[eff]; + if (!t || t.count <= 0) return false; + t.count -= 1; + return true; + } + useValueTalByUuid(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); } - clearTalBuffByAttr(attrIndex: number) { + useValueTalByAttr(attrIndex: number) { let changed = false; for (const key in this.BUFFS_TAL) { const b = this.BUFFS_TAL[Number(key)]; @@ -436,20 +451,7 @@ export class HeroAttrsComp extends ecs.Comp { } if (changed) 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() { // 重置为初始状态 this.hero_uuid = 1001; diff --git a/assets/script/game/hero/SACastSystem.ts b/assets/script/game/hero/SACastSystem.ts index 3066009f..491d15d8 100644 --- a/assets/script/game/hero/SACastSystem.ts +++ b/assets/script/game/hero/SACastSystem.ts @@ -163,13 +163,13 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat }, delay); //风怒wfuny 只针对 普通攻击起效 - if (hset === HSSet.atk && heroAttrs.consumeTalent(TalEffet.WFUNY)){ + if (hset === HSSet.atk && heroAttrs.useCountTal(TalEffet.WFUNY)){ heroView.playSkillEffect(s_uuid); //需要再添加 风怒动画 this.createSkill(s_uuid, heroView,targets); } // 双技能 只针对 技能起效 - if(hset === HSSet.skill && heroAttrs.consumeTalent(TalEffet.D_SKILL)){ + if(hset === HSSet.skill && heroAttrs.useCountTal(TalEffet.D_SKILL)){ targets = this.sTargets(heroView, s_uuid); if (targets.length === 0) { console.warn("[SACastSystem] 没有找到有效目标"); diff --git a/assets/script/game/hero/TalComp.ts b/assets/script/game/hero/TalComp.ts index a690fbde..fd7cacf5 100644 --- a/assets/script/game/hero/TalComp.ts +++ b/assets/script/game/hero/TalComp.ts @@ -189,6 +189,10 @@ export class TalComp extends ecs.Comp { } } //执行天赋触发效果 + // 功能: + // - 根据天赋类型执行相应的效果 + // - 支持计数型和数值型天赋 + // --heroAttrs.addTalent 是计数型天赋buff heroAttrs.addTalBuff 是数值型天赋buff doTriggerTal(uuid: number) { // 检查天赋是否存在 if (!this.Tals[uuid]) { @@ -199,22 +203,22 @@ export class TalComp extends ecs.Comp { const heroAttrs=this.ent.get(HeroAttrsComp); switch(talent.effet){ case TalEffet.WFUNY: - heroAttrs.addTalent(TalEffet.WFUNY, talent.value + talent.value_add); + heroAttrs.addCountTal(TalEffet.WFUNY, talent.value + talent.value_add); break; case TalEffet.D_SKILL: - heroAttrs.addTalent(TalEffet.D_SKILL, talent.value + talent.value_add); + heroAttrs.addCountTal(TalEffet.D_SKILL, talent.value + talent.value_add); break; case TalEffet.C_ATK: - heroAttrs.addTalent(TalEffet.C_ATK, talent.value + talent.value_add); + heroAttrs.addCountTal(TalEffet.C_ATK, talent.value + talent.value_add); break; case TalEffet.C_SKILL: - heroAttrs.addTalent(TalEffet.C_SKILL, talent.value + talent.value_add); + heroAttrs.addCountTal(TalEffet.C_SKILL, talent.value + talent.value_add); break; case TalEffet.C_MSKILL: - heroAttrs.addTalent(TalEffet.C_MSKILL, talent.value + talent.value_add); + heroAttrs.addCountTal(TalEffet.C_MSKILL, talent.value + talent.value_add); break; case TalEffet.BUFF: - heroAttrs.addTalBuff(talent.uuid, talent.attrs, talent.vType, talent.value + talent.value_add); + heroAttrs.addValueTal(talent.uuid, talent.attrs, talent.vType, talent.value + talent.value_add); break; } } diff --git a/assets/script/game/wx_clound_client_api/USAGE.md b/assets/script/game/wx_clound_client_api/USAGE.md index 621c547f..c09da119 100644 --- a/assets/script/game/wx_clound_client_api/USAGE.md +++ b/assets/script/game/wx_clound_client_api/USAGE.md @@ -201,10 +201,10 @@ console.log("道具1001数量:", itemInfo.result.data.count); const talents = await WxCloudApi.getTalents(); // 添加天赋点 -const result = await WxCloudApi.addTalent(1001, 1); +const result = await WxCloudApi.addCountTal(1001, 1); // 消耗天赋点 -const result = await WxCloudApi.consumeTalent(1001, 1); +const result = await WxCloudApi.useCountTal(1001, 1); ``` ### 装备操作