fix(hero): 修复英雄死亡状态处理和怪物生成逻辑
调整HeroAnmComp中动画完成时的状态检查,增加dead和stun状态 修改MissionMonComp中怪物生成逻辑,现在只生成第一个怪物 重构HeroViewComp的死亡处理逻辑,添加死亡计时器和复活功能
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user