From c98f20ba1d7edb4978613dfb08b2a938786af701 Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 3 Nov 2025 16:07:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(hero):=20=E4=BF=AE=E5=A4=8D=E8=8B=B1?= =?UTF-8?q?=E9=9B=84=E6=AD=BB=E4=BA=A1=E7=8A=B6=E6=80=81=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=92=8C=E6=80=AA=E7=89=A9=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整HeroAnmComp中动画完成时的状态检查,增加dead和stun状态 修改MissionMonComp中怪物生成逻辑,现在只生成第一个怪物 重构HeroViewComp的死亡处理逻辑,添加死亡计时器和复活功能 --- assets/script/game/hero/HeroAnmComp.ts | 2 +- assets/script/game/hero/HeroViewComp.ts | 67 +++++++++++++++--------- assets/script/game/map/MissionMonComp.ts | 3 +- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/assets/script/game/hero/HeroAnmComp.ts b/assets/script/game/hero/HeroAnmComp.ts index 52ad5f9b..85a17671 100644 --- a/assets/script/game/hero/HeroAnmComp.ts +++ b/assets/script/game/hero/HeroAnmComp.ts @@ -21,7 +21,7 @@ export default class HeroAnmComp extends Component{ } onAnimationFinished(type:Animation.EventType, state:AnimationState){ // console.log("[HeroAnmComp]: 动画播放完毕",state.name) - if(state.name!="idle"&&state.name!="move"){ + if(state.name!="idle"&&state.name!="move"&&state.name!="dead"&&state.name!="stun"){ this.anmcon.play(this.default_anim) } } diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index bdd91df4..deb3b598 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -13,6 +13,7 @@ import { HeroAttrsComp } from "./HeroAttrsComp"; import { Tooltip } from "../skill/Tooltip"; import { timedCom } from "../skill/timedCom"; import { HeroInfo, HType } from "../common/config/heroSet"; +import { Timer } from "db://oops-framework/core/common/timer/Timer"; const { ccclass, property } = _decorator; @@ -31,6 +32,7 @@ export class HeroViewComp extends CCComp { box_group:number = BoxSet.HERO; // 碰撞组 usePower:boolean = false; useMp:boolean = false; + deadTime:Timer=new Timer(10) // ==================== UI 节点引用 ==================== private top_node: Node = null!; @@ -102,7 +104,10 @@ export class HeroViewComp extends CCComp { // 添加安全检查,防止在实体销毁过程中访问null的model if (!this.model) return; - if(this.model.is_dead) return; + if(this.model.is_dead){ + if( this.deadTime.update(dt)) this.realDead() + return + } ; // ✅ View 层职责:处理表现相关的逻辑 this.processDamageQueue(); // 伤害数字显示队列 @@ -250,6 +255,7 @@ export class HeroViewComp extends CCComp { /** 状态切换(动画) */ status_change(type:string){ this.status = type; + if(this.model.is_dead) return if(type === "idle"){ this.as.idle(); } else if(type === "move"){ @@ -269,7 +275,15 @@ export class HeroViewComp extends CCComp { } } + alive(){ + this.model.is_dead=false + this.deadTime.reset() + this.as.do_buff(); + this.status_change("idle"); + this.model.hp =this.model.Attrs[Attrs.HP_MAX]*50/100; + this.top_node.active=false + } /** * 死亡视图表现 * 由 HeroAtkSystem 调用,只负责视觉效果和事件通知 @@ -281,29 +295,28 @@ export class HeroViewComp extends CCComp { // 防止重复触发 if(this.model.is_count_dead) return; this.model.is_count_dead = true; // 防止重复触发,必须存在防止重复调用 - + this.top_node.active=false // 播放死亡特效 this.as.dead(); - // 根据阵营触发不同事件 + + } + realDead(){ + // 根据阵营触发不同事件 if(this.model.fac === FacSet.MON){ - // 怪物死亡:延迟触发掉落(暂时不发事件,等待实现) - // this.scheduleOnce(() => { - // oops.message.dispatchEvent(GameEvent.MonsterDead, { - // hero_uuid: this.model.hero_uuid, - // position: this.node.position - // }); - // }, 0.2); - } else if(this.model.fac === FacSet.HERO){ + oops.message.dispatchEvent(GameEvent.MonDead, { + hero_uuid: this.model.hero_uuid, + position: this.node.position + }); + this.ent.destroy(); + } + if(this.model.fac === FacSet.HERO){ // 英雄死亡:延迟触发死亡事件 - this.scheduleOnce(() => { - oops.message.dispatchEvent(GameEvent.HeroDead, { + oops.message.dispatchEvent(GameEvent.HeroDead, { hero_uuid: this.model.hero_uuid - }); - }, 0.2); + }); } } - do_atked(damage:number,isCrit:boolean,s_uuid:number){ if (damage <= 0) return; // 视图层表现 @@ -358,16 +371,7 @@ export class HeroViewComp extends CCComp { // 调试用,生产环境已禁用 } - reset() { - const collider = this.getComponent(Collider2D); - if (collider) { - collider.off(Contact2DType.BEGIN_CONTACT); - } - this.scheduleOnce(() => { - this.node.destroy(); - }, 0.1); - } - + playSkillEffect(skill_id:number) { let skill = SkillSet[skill_id] switch(skill.act){ @@ -421,4 +425,15 @@ export class HeroViewComp extends CCComp { this.hp_tip(TooltipTypes.life, damage.toFixed(0), damage); } } + reset() { + const collider = this.getComponent(Collider2D); + if (collider) { + collider.off(Contact2DType.BEGIN_CONTACT); + } + this.deadTime.reset() + this.scheduleOnce(() => { + this.node.destroy(); + }, 0.1); + } + } diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index 4cfc8b1d..146ae1f6 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -108,7 +108,8 @@ export class MissionMonCompComp extends CCComp { const monsConf = getStageMonConfigs(cStage); // console.log(`[MissionMonComp]:第${cStage}关 - ${stageType}类型,怪物数量: ${monsConf.length}`); - this.generateMonsters(monsConf); + const monsConfFiltered = monsConf.filter((mon: any, index) => index === 0); + this.generateMonsters(monsConfFiltered); }