fix(hero): 修复复活后碰撞体和UI未恢复的问题
- 在 HeroViewComp.alive() 中恢复碰撞体启用状态和顶部UI节点 - 在 HeroAtkSystem 中先触发死亡技能再检查复活,确保亡语效果正确触发 - 重构死亡处理逻辑,将死亡技能触发分离到独立方法
This commit is contained in:
@@ -187,6 +187,9 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
|
||||
// 检查死亡
|
||||
if (TAttrsComp.hp <= 0) {
|
||||
// 先触发死亡技能(如亡语),不管后续是否复活都应触发
|
||||
this.triggerDeadSkills(target);
|
||||
|
||||
// 复活机制:如果玩家属性内的复活属性值>=1 则执行复活,原地50%血量复活
|
||||
let canRevive = false;
|
||||
let maxReviveCount = 0;
|
||||
@@ -214,6 +217,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
// 触发复活动画
|
||||
if (targetView) {
|
||||
targetView.playReady(skillConf.readyAnm);
|
||||
targetView.alive()
|
||||
}
|
||||
mLogger.log(this.debugMode, 'HeroAtkSystem', ` Hero waiting to revive! Lives revived: ${TAttrsComp.revived_count}/${maxReviveCount}, Hp restored: ${reviveHpPercent}%`);
|
||||
return reDate;
|
||||
@@ -273,25 +277,13 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
|
||||
|
||||
/**
|
||||
* 处理角色死亡
|
||||
*
|
||||
* 死亡处理流程:
|
||||
* 1. 标记死亡状态(is_dead = true)
|
||||
* 2. 触发死亡事件(onDeath)
|
||||
* 3. 记录调试信息(如启用调试模式)
|
||||
*
|
||||
* @param entity 死亡的实体
|
||||
*
|
||||
* @important 死亡状态一旦设置,该实体将不再处理新的伤害事件
|
||||
* 这确保了死亡逻辑的单一性和一致性
|
||||
* 触发死亡技能(如亡语)
|
||||
* 不管是否复活,只要血量归零都触发
|
||||
*/
|
||||
private doDead(entity: ecs.Entity): void {
|
||||
private triggerDeadSkills(entity: ecs.Entity): void {
|
||||
const TAttrsComp = entity.get(HeroAttrsComp);
|
||||
if (!TAttrsComp || TAttrsComp.is_dead) return;
|
||||
if (!TAttrsComp) return;
|
||||
|
||||
TAttrsComp.is_dead = true;
|
||||
|
||||
// 触发死亡技能
|
||||
if (TAttrsComp.dead && TAttrsComp.dead.length > 0) {
|
||||
const view = entity.get(HeroViewComp);
|
||||
if (view) {
|
||||
@@ -310,6 +302,26 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理角色死亡
|
||||
*
|
||||
* 死亡处理流程:
|
||||
* 1. 标记死亡状态(is_dead = true)
|
||||
* 2. 触发死亡事件(onDeath)
|
||||
* 3. 记录调试信息(如启用调试模式)
|
||||
*
|
||||
* @param entity 死亡的实体
|
||||
*
|
||||
* @important 死亡状态一旦设置,该实体将不再处理新的伤害事件
|
||||
* 这确保了死亡逻辑的单一性和一致性
|
||||
*/
|
||||
private doDead(entity: ecs.Entity): void {
|
||||
const TAttrsComp = entity.get(HeroAttrsComp);
|
||||
if (!TAttrsComp || TAttrsComp.is_dead) return;
|
||||
|
||||
TAttrsComp.is_dead = true;
|
||||
|
||||
// 触发死亡事件
|
||||
this.onDeath(entity);
|
||||
|
||||
@@ -392,11 +392,17 @@ export class HeroViewComp extends CCComp {
|
||||
this.model.is_dead=false
|
||||
this.model.is_count_dead=false
|
||||
this.deadCD = 0;
|
||||
// this.status_change("idle");
|
||||
// this.top_node.active=true
|
||||
// this.setTopBarOpacity(false);
|
||||
// this.lastBarUpdateTime=0
|
||||
|
||||
// 恢复碰撞体
|
||||
const collider = this.node.getComponent(Collider2D);
|
||||
if (collider) {
|
||||
collider.enabled = true;
|
||||
}
|
||||
|
||||
// 恢复UI
|
||||
this.top_node.active = true;
|
||||
|
||||
this.status_change("idle");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user