fix(英雄属性): 修复回血时未正确触发视图层特效的问题
调整 HeroAttrsSystem 中 HP 自然回复的逻辑,当回血值大于零时,通过 HeroViewComp 触发对应的视图层特效。同时,在 HeroAttrsComp 的注释中补充了触发视图层的条件说明,以保持数据层与视图层的分离。
This commit is contained in:
@@ -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);
|
||||
// }
|
||||
|
||||
|
||||
@@ -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. 限制属性值在合理范围内
|
||||
|
||||
Reference in New Issue
Block a user