feat(英雄系统): 添加英雄复活机制并控制怪物行为
实现英雄复活功能,当英雄死亡且有复活次数时延迟复活 新增is_reviving状态标记复活中状态 英雄死亡或复活时通过stop_mon_action控制怪物停止刷新和移动
This commit is contained in:
@@ -12,11 +12,11 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('Main')
|
||||
export class Main extends Root {
|
||||
start() {
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb
|
||||
|EPhysics2DDrawFlags.Pair
|
||||
|EPhysics2DDrawFlags.CenterOfMass
|
||||
|EPhysics2DDrawFlags.Joint
|
||||
|EPhysics2DDrawFlags.Shape;
|
||||
// PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Aabb
|
||||
// |EPhysics2DDrawFlags.Pair
|
||||
// |EPhysics2DDrawFlags.CenterOfMass
|
||||
// |EPhysics2DDrawFlags.Joint
|
||||
// |EPhysics2DDrawFlags.Shape;
|
||||
}
|
||||
protected async run() {
|
||||
smc.initialize = ecs.getEntity<Initialize>(Initialize);
|
||||
|
||||
@@ -37,6 +37,7 @@ export class SingletonModuleComp extends ecs.Comp {
|
||||
pause:false,
|
||||
in_select:false,
|
||||
in_fight:false,
|
||||
stop_mon_action:false,
|
||||
};
|
||||
guides:any=[0,0,0,0,0]
|
||||
current_guide:number=0
|
||||
|
||||
@@ -125,7 +125,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
isCrit:false,
|
||||
isDodge:false,
|
||||
}
|
||||
if (!TAttrsComp || TAttrsComp.is_dead) return reDate;
|
||||
if (!TAttrsComp || TAttrsComp.is_dead || TAttrsComp.is_reviving) return reDate;
|
||||
|
||||
const caster = damageEvent.caster;
|
||||
const CAttrsComp = caster?.ent?.get(HeroAttrsComp);
|
||||
@@ -197,8 +197,34 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
|
||||
// 检查死亡
|
||||
if (TAttrsComp.hp <= 0) {
|
||||
// 复活机制:如果玩家属性内的复活属性值>=1 则执行复活,原地50%血量复活
|
||||
if (TAttrsComp.fac === FacSet.HERO && TAttrsComp.Attrs[Attrs.REVIVE_COUNT] >= 1) {
|
||||
TAttrsComp.Attrs[Attrs.REVIVE_COUNT]--;
|
||||
TAttrsComp.is_reviving = true; // 标记为正在复活
|
||||
|
||||
// 停止怪物行动
|
||||
smc.mission.stop_mon_action = true;
|
||||
|
||||
// 触发死亡动画(假死)
|
||||
if (targetView) {
|
||||
targetView.do_dead();
|
||||
// 延迟1秒复活
|
||||
targetView.scheduleRevive(1.0);
|
||||
}
|
||||
|
||||
console.log(`[HeroAtkSystem] Hero waiting to revive! Lives left: ${TAttrsComp.Attrs[Attrs.REVIVE_COUNT]}`);
|
||||
return reDate;
|
||||
}
|
||||
|
||||
// 增加被击杀计数
|
||||
if (caster) CAttrsComp.Attrs.killed_count++;
|
||||
|
||||
// 玩家英雄死亡后,怪物停止刷新和移动
|
||||
if (TAttrsComp.fac === FacSet.HERO) {
|
||||
smc.mission.stop_mon_action = true;
|
||||
console.log("[HeroAtkSystem] Hero died, stopping monster action (spawn/move)");
|
||||
}
|
||||
|
||||
this.doDead(target);
|
||||
// ✅ 触发死亡视图表现
|
||||
if (targetView) {
|
||||
@@ -228,6 +254,28 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
if (CView) CView.do_atked(thornsDmg, false, SkillSet[5000].uuid, false);
|
||||
// 检查死亡
|
||||
if (CAttrs.hp <= 0) {
|
||||
// 复活机制
|
||||
if (CAttrs.fac === FacSet.HERO && CAttrs.Attrs[Attrs.REVIVE_COUNT] >= 1) {
|
||||
CAttrs.Attrs[Attrs.REVIVE_COUNT]--;
|
||||
CAttrs.is_reviving = true;
|
||||
|
||||
smc.mission.stop_mon_action = true;
|
||||
|
||||
if (CView) {
|
||||
CView.do_dead();
|
||||
CView.scheduleRevive(1.0);
|
||||
}
|
||||
|
||||
console.log(`[HeroAtkSystem] Hero waiting to revive from Thorns! Lives left: ${CAttrs.Attrs[Attrs.REVIVE_COUNT]}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 玩家英雄死亡后,怪物停止刷新和移动
|
||||
if (CAttrs.fac === FacSet.HERO) {
|
||||
smc.mission.stop_mon_action = true;
|
||||
console.log("[HeroAtkSystem] Hero died from thorns, stopping monster action (spawn/move)");
|
||||
}
|
||||
|
||||
this.doDead(caster);
|
||||
// 增加击杀计数
|
||||
if (caster) TAttrsComp.Attrs.killed_count++;
|
||||
|
||||
@@ -66,6 +66,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
is_master: boolean = false;
|
||||
is_friend: boolean = false;
|
||||
is_kalami: boolean = false;
|
||||
is_reviving: boolean = false; // 是否正在复活中
|
||||
// ==================== 计数统计 ====================
|
||||
atk_count: number = 0; // 攻击次数
|
||||
atked_count: number = 0; // 被攻击次数
|
||||
@@ -583,6 +584,7 @@ export class HeroAttrsComp extends ecs.Comp {
|
||||
this.is_master = false;
|
||||
this.is_friend = false;
|
||||
this.is_kalami = false;
|
||||
this.is_reviving = false;
|
||||
this.atk_count = 0;
|
||||
this.atked_count = 0;
|
||||
this.killed_count =0;
|
||||
|
||||
@@ -66,7 +66,7 @@ export class HeroAttrSystem extends ecs.ComblockSystem
|
||||
update(e: ecs.Entity): void {
|
||||
if(!smc.mission.play || smc.mission.pause) return;
|
||||
const model = e.get(HeroAttrsComp);
|
||||
if (!model || model.is_dead) return;
|
||||
if (!model || model.is_dead || model.is_reviving) return;
|
||||
|
||||
// 统计:记录本帧处理的实体数
|
||||
this.entityCount++;
|
||||
|
||||
@@ -51,7 +51,8 @@ export class HeroMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
this.updateRenderOrder(e);
|
||||
|
||||
if (!shouldStop) {
|
||||
if (model.is_stop || model.is_dead || model.isStun() || model.isFrost()) {
|
||||
if (model.is_stop || model.is_dead || model.is_reviving || model.isStun() || model.isFrost()) {
|
||||
if (model.is_reviving) return;
|
||||
view.status_change("idle");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ export class HeroViewComp extends CCComp {
|
||||
/** 状态切换(动画) */
|
||||
status_change(type:string){
|
||||
this.status = type;
|
||||
if(this.model.is_dead) return
|
||||
if(this.model.is_dead || this.model.is_reviving) return
|
||||
if(type === "idle"){
|
||||
this.as.idle();
|
||||
} else if(type === "move"){
|
||||
@@ -351,14 +351,34 @@ export class HeroViewComp extends CCComp {
|
||||
}
|
||||
|
||||
alive(){
|
||||
// 重置复活标记 - 必须最先重置,否则status_change会被拦截
|
||||
this.model.is_reviving = false;
|
||||
|
||||
this.model.is_dead=false
|
||||
this.model.is_count_dead=false
|
||||
this.as.do_buff();
|
||||
this.status_change("idle");
|
||||
this.model.hp =this.model.Attrs[Attrs.HP_MAX]*50/100;
|
||||
this.top_node.active=false
|
||||
this.lastBarUpdateTime=0
|
||||
|
||||
|
||||
// 恢复怪物行动
|
||||
if (this.model.fac === FacSet.HERO) {
|
||||
smc.mission.stop_mon_action = false;
|
||||
console.log("[HeroViewComp] Hero revived, resuming monster action");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调度复活逻辑
|
||||
* @param delay 延迟时间(秒)
|
||||
*/
|
||||
scheduleRevive(delay: number) {
|
||||
this.scheduleOnce(() => {
|
||||
this.alive();
|
||||
}, delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* 死亡视图表现
|
||||
* 由 HeroAtkSystem 调用,只负责视觉效果和事件通知
|
||||
|
||||
@@ -41,6 +41,8 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
if (!smc.mission.play || smc.mission.pause) return;
|
||||
// 如果英雄死亡(停止怪物行动标志为true),则停止怪物移动
|
||||
if (smc.mission.stop_mon_action) return;
|
||||
|
||||
const move = e.get(MonMoveComp);
|
||||
const model = e.get(HeroAttrsComp);
|
||||
|
||||
@@ -49,7 +49,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
|
||||
if (!heroAttrs || !heroView) return;
|
||||
|
||||
// 检查基本条件
|
||||
if (heroAttrs.is_dead || heroAttrs.isStun() || heroAttrs.isFrost()) return;
|
||||
if (heroAttrs.is_dead || heroAttrs.is_reviving || heroAttrs.isStun() || heroAttrs.isFrost()) return;
|
||||
|
||||
// 检查是否正在攻击(只有攻击时才释放技能)
|
||||
if (!heroAttrs.is_atking) return;
|
||||
|
||||
@@ -182,6 +182,7 @@ export class MissionComp extends CCComp {
|
||||
data_init(){
|
||||
//局内数据初始化 smc 数据初始化
|
||||
smc.mission.play = true;
|
||||
smc.mission.stop_mon_action = false;
|
||||
smc.vmdata.mission_data.in_fight=false
|
||||
smc.vmdata.mission_data.fight_time=0
|
||||
smc.vmdata.mission_data.level=0
|
||||
|
||||
@@ -61,6 +61,8 @@ export class MissionMonCompComp extends CCComp {
|
||||
|
||||
protected update(dt: number): void {
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
// 如果英雄死亡(停止怪物行动标志为true),则停止刷怪逻辑
|
||||
if(smc.mission.stop_mon_action) return;
|
||||
|
||||
// 累加游戏时间
|
||||
this.gameTime += dt;
|
||||
|
||||
Reference in New Issue
Block a user