From 76772a1102519ebd8e8879aee12792c18d81dc68 Mon Sep 17 00:00:00 2001 From: panw Date: Thu, 23 Apr 2026 10:07:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(hero):=20=E4=BF=AE=E5=A4=8D=E5=A4=8D?= =?UTF-8?q?=E6=B4=BB=E5=90=8E=E7=A2=B0=E6=92=9E=E4=BD=93=E5=92=8CUI?= =?UTF-8?q?=E6=9C=AA=E6=81=A2=E5=A4=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 HeroViewComp.alive() 中恢复碰撞体启用状态和顶部UI节点 - 在 HeroAtkSystem 中先触发死亡技能再检查复活,确保亡语效果正确触发 - 重构死亡处理逻辑,将死亡技能触发分离到独立方法 --- assets/script/game/hero/HeroAtkSystem.ts | 44 +++++++++++++++--------- assets/script/game/hero/HeroViewComp.ts | 16 ++++++--- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/assets/script/game/hero/HeroAtkSystem.ts b/assets/script/game/hero/HeroAtkSystem.ts index 3f903351..0ec481eb 100644 --- a/assets/script/game/hero/HeroAtkSystem.ts +++ b/assets/script/game/hero/HeroAtkSystem.ts @@ -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; - - TAttrsComp.is_dead = true; + if (!TAttrsComp) return; - // 触发死亡技能 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); diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 1fcf04c1..066992e1 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -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"); }