fix(战斗): 修正英雄复活与战斗结束时的生命值恢复逻辑
移除英雄复活时直接设置固定生命值的硬编码,改为在战斗结束阶段统一恢复所有英雄(包括墓地英雄)70%最大生命值。这确保了生命值恢复机制的一致性和可维护性,并避免了状态同步问题。
This commit is contained in:
@@ -395,7 +395,6 @@ export class HeroViewComp extends CCComp {
|
||||
this.deadCD = 0;
|
||||
this.as.do_buff();
|
||||
this.status_change("idle");
|
||||
this.model.hp =this.model.hp_max*50/100;
|
||||
this.top_node.active=true
|
||||
this.setTopBarOpacity(false);
|
||||
this.lastBarUpdateTime=0
|
||||
|
||||
@@ -372,6 +372,9 @@ export class MissionComp extends CCComp {
|
||||
smc.mission.stop_spawn_mon = true;
|
||||
// 触发战斗结束技能(fend)
|
||||
this.triggerHeroBattleSkills(false);
|
||||
|
||||
// 战斗结束阶段,给予所有英雄恢复70%血量的技能效果
|
||||
this.healAllHeroes();
|
||||
break;
|
||||
|
||||
case MissionPhase.Settle:
|
||||
@@ -481,6 +484,27 @@ export class MissionComp extends CCComp {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗结束阶段治疗所有英雄(包括墓地英雄),恢复70%最大生命值
|
||||
*/
|
||||
private healAllHeroes() {
|
||||
ecs.query(this.heroAttrsMatcher).forEach(entity => {
|
||||
const attrs = entity.get(HeroAttrsComp);
|
||||
const view = entity.get(HeroViewComp);
|
||||
if (!attrs || !view || attrs.fac !== FacSet.HERO) return;
|
||||
|
||||
// 计算恢复量:70% 的最大生命值
|
||||
const healAmount = Math.floor(attrs.hp_max * 0.7);
|
||||
|
||||
// 应用恢复量,不超过最大生命值
|
||||
attrs.hp = Math.min(attrs.hp_max, attrs.hp + healAmount);
|
||||
attrs.dirty_hp = true;
|
||||
|
||||
// 触发治疗动画,即使在墓地的英雄也触发(会在其当前位置播放)
|
||||
view.health(healAmount);
|
||||
});
|
||||
}
|
||||
|
||||
/** 开始战斗按钮点击回调 */
|
||||
private onStartFightBtnClick() {
|
||||
if (!smc.mission.play) return;
|
||||
|
||||
@@ -133,7 +133,6 @@ export class MissionHeroCompComp extends CCComp {
|
||||
view.node.setPosition(spawnPos);
|
||||
hero.playDropAnim(spawnPos, landingPos.y);
|
||||
}
|
||||
model.hp = model.hp_max;
|
||||
model.dirty_hp = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user