From 576c3ebbd5af6b1d427b2ac75cd5267ab1fa85ee Mon Sep 17 00:00:00 2001 From: panw Date: Wed, 4 Feb 2026 15:11:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=8B=B1=E9=9B=84=E5=B1=9E=E6=80=A7):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=9E=E8=A1=80=E6=97=B6=E6=9C=AA=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E8=A7=A6=E5=8F=91=E8=A7=86=E5=9B=BE=E5=B1=82=E7=89=B9?= =?UTF-8?q?=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整 HeroAttrsSystem 中 HP 自然回复的逻辑,当回血值大于零时,通过 HeroViewComp 触发对应的视图层特效。同时,在 HeroAttrsComp 的注释中补充了触发视图层的条件说明,以保持数据层与视图层的分离。 --- assets/script/game/hero/HeroAttrsComp.ts | 2 +- assets/script/game/hero/HeroAttrsSystem.ts | 25 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index 3ca96266..c71e9266 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -249,7 +249,7 @@ export class HeroAttrsComp extends ecs.Comp { // ✅ 数据层只负责数据修改,不调用视图层 // let heroView = this.ent.get(HeroViewComp); - // if(heroView){ + // if(heroView && addValue > 0){ // heroView.health(addValue); // } diff --git a/assets/script/game/hero/HeroAttrsSystem.ts b/assets/script/game/hero/HeroAttrsSystem.ts index b09dca48..a51d52d5 100644 --- a/assets/script/game/hero/HeroAttrsSystem.ts +++ b/assets/script/game/hero/HeroAttrsSystem.ts @@ -5,6 +5,7 @@ import { Attrs } from "../common/config/HeroAttrs"; import { HeroUpSet } from "../common/config/heroSet"; import { HeroSkillsComp } from "./HeroSkills"; import { HeroAttrsComp } from "./HeroAttrsComp"; +import { HeroViewComp } from "./HeroViewComp"; import { mLogger } from "../common/Logger"; /** * ==================== 英雄属性更新系统 ==================== @@ -84,8 +85,28 @@ export class HeroAttrSystem extends ecs.ComblockSystem if(this.timer.update(this.dt)){ // 2. HP/MP 自然回复(业务规则) - model.mp += HeroUpSet.MP - model.hp += HeroUpSet.HP + // 加上回血/回蓝属性的影响 + const hpRegen = model.Attrs[Attrs.HP_REGEN] || 0; + const mpRegen = model.Attrs[Attrs.MP_REGEN] || 0; + + model.mp += HeroUpSet.MP + mpRegen; + // model.hp += HeroUpSet.HP + hpRegen; + // model.add_hp(HeroUpSet.HP + hpRegen, true); + + // 回血逻辑 + 视图表现 + const totalHpRegen = HeroUpSet.HP + hpRegen; + if (totalHpRegen > 0) { + model.add_hp(totalHpRegen, true); + // 触发视图层回血特效 + const view = e.get(HeroViewComp); + if (view) { + view.health(totalHpRegen); + } + } else if (totalHpRegen < 0) { + // 如果是扣血(虽然叫 regen),走正常的扣血逻辑? + // 暂时按原样处理,只处理正向回血的特效 + model.add_hp(totalHpRegen, true); + } } // 3. 限制属性值在合理范围内