fix(hero): 修复英雄死亡状态处理和怪物生成逻辑
调整HeroAnmComp中动画完成时的状态检查,增加dead和stun状态 修改MissionMonComp中怪物生成逻辑,现在只生成第一个怪物 重构HeroViewComp的死亡处理逻辑,添加死亡计时器和复活功能
This commit is contained in:
@@ -21,7 +21,7 @@ export default class HeroAnmComp extends Component{
|
|||||||
}
|
}
|
||||||
onAnimationFinished(type:Animation.EventType, state:AnimationState){
|
onAnimationFinished(type:Animation.EventType, state:AnimationState){
|
||||||
// console.log("[HeroAnmComp]: 动画播放完毕",state.name)
|
// 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)
|
this.anmcon.play(this.default_anim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { HeroAttrsComp } from "./HeroAttrsComp";
|
|||||||
import { Tooltip } from "../skill/Tooltip";
|
import { Tooltip } from "../skill/Tooltip";
|
||||||
import { timedCom } from "../skill/timedCom";
|
import { timedCom } from "../skill/timedCom";
|
||||||
import { HeroInfo, HType } from "../common/config/heroSet";
|
import { HeroInfo, HType } from "../common/config/heroSet";
|
||||||
|
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -31,6 +32,7 @@ export class HeroViewComp extends CCComp {
|
|||||||
box_group:number = BoxSet.HERO; // 碰撞组
|
box_group:number = BoxSet.HERO; // 碰撞组
|
||||||
usePower:boolean = false;
|
usePower:boolean = false;
|
||||||
useMp:boolean = false;
|
useMp:boolean = false;
|
||||||
|
deadTime:Timer=new Timer(10)
|
||||||
// ==================== UI 节点引用 ====================
|
// ==================== UI 节点引用 ====================
|
||||||
private top_node: Node = null!;
|
private top_node: Node = null!;
|
||||||
|
|
||||||
@@ -102,7 +104,10 @@ export class HeroViewComp extends CCComp {
|
|||||||
|
|
||||||
// 添加安全检查,防止在实体销毁过程中访问null的model
|
// 添加安全检查,防止在实体销毁过程中访问null的model
|
||||||
if (!this.model) return;
|
if (!this.model) return;
|
||||||
if(this.model.is_dead) return;
|
if(this.model.is_dead){
|
||||||
|
if( this.deadTime.update(dt)) this.realDead()
|
||||||
|
return
|
||||||
|
} ;
|
||||||
// ✅ View 层职责:处理表现相关的逻辑
|
// ✅ View 层职责:处理表现相关的逻辑
|
||||||
this.processDamageQueue(); // 伤害数字显示队列
|
this.processDamageQueue(); // 伤害数字显示队列
|
||||||
|
|
||||||
@@ -250,6 +255,7 @@ export class HeroViewComp extends CCComp {
|
|||||||
/** 状态切换(动画) */
|
/** 状态切换(动画) */
|
||||||
status_change(type:string){
|
status_change(type:string){
|
||||||
this.status = type;
|
this.status = type;
|
||||||
|
if(this.model.is_dead) return
|
||||||
if(type === "idle"){
|
if(type === "idle"){
|
||||||
this.as.idle();
|
this.as.idle();
|
||||||
} else if(type === "move"){
|
} 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 调用,只负责视觉效果和事件通知
|
* 由 HeroAtkSystem 调用,只负责视觉效果和事件通知
|
||||||
@@ -281,29 +295,28 @@ export class HeroViewComp extends CCComp {
|
|||||||
// 防止重复触发
|
// 防止重复触发
|
||||||
if(this.model.is_count_dead) return;
|
if(this.model.is_count_dead) return;
|
||||||
this.model.is_count_dead = true; // 防止重复触发,必须存在防止重复调用
|
this.model.is_count_dead = true; // 防止重复触发,必须存在防止重复调用
|
||||||
|
this.top_node.active=false
|
||||||
// 播放死亡特效
|
// 播放死亡特效
|
||||||
this.as.dead();
|
this.as.dead();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
realDead(){
|
||||||
// 根据阵营触发不同事件
|
// 根据阵营触发不同事件
|
||||||
if(this.model.fac === FacSet.MON){
|
if(this.model.fac === FacSet.MON){
|
||||||
// 怪物死亡:延迟触发掉落(暂时不发事件,等待实现)
|
oops.message.dispatchEvent(GameEvent.MonDead, {
|
||||||
// this.scheduleOnce(() => {
|
hero_uuid: this.model.hero_uuid,
|
||||||
// oops.message.dispatchEvent(GameEvent.MonsterDead, {
|
position: this.node.position
|
||||||
// hero_uuid: this.model.hero_uuid,
|
});
|
||||||
// position: this.node.position
|
this.ent.destroy();
|
||||||
// });
|
}
|
||||||
// }, 0.2);
|
if(this.model.fac === FacSet.HERO){
|
||||||
} else if(this.model.fac === FacSet.HERO){
|
|
||||||
// 英雄死亡:延迟触发死亡事件
|
// 英雄死亡:延迟触发死亡事件
|
||||||
this.scheduleOnce(() => {
|
|
||||||
oops.message.dispatchEvent(GameEvent.HeroDead, {
|
oops.message.dispatchEvent(GameEvent.HeroDead, {
|
||||||
hero_uuid: this.model.hero_uuid
|
hero_uuid: this.model.hero_uuid
|
||||||
});
|
});
|
||||||
}, 0.2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
do_atked(damage:number,isCrit:boolean,s_uuid:number){
|
do_atked(damage:number,isCrit:boolean,s_uuid:number){
|
||||||
if (damage <= 0) return;
|
if (damage <= 0) return;
|
||||||
// 视图层表现
|
// 视图层表现
|
||||||
@@ -358,15 +371,6 @@ 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) {
|
playSkillEffect(skill_id:number) {
|
||||||
let skill = SkillSet[skill_id]
|
let skill = SkillSet[skill_id]
|
||||||
@@ -421,4 +425,15 @@ export class HeroViewComp extends CCComp {
|
|||||||
this.hp_tip(TooltipTypes.life, damage.toFixed(0), damage);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,8 @@ export class MissionMonCompComp extends CCComp {
|
|||||||
|
|
||||||
const monsConf = getStageMonConfigs(cStage);
|
const monsConf = getStageMonConfigs(cStage);
|
||||||
// console.log(`[MissionMonComp]:第${cStage}关 - ${stageType}类型,怪物数量: ${monsConf.length}`);
|
// console.log(`[MissionMonComp]:第${cStage}关 - ${stageType}类型,怪物数量: ${monsConf.length}`);
|
||||||
this.generateMonsters(monsConf);
|
const monsConfFiltered = monsConf.filter((mon: any, index) => index === 0);
|
||||||
|
this.generateMonsters(monsConfFiltered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user