From 1cce4ce36177a52f2ce36f679ce5739e1927e7a5 Mon Sep 17 00:00:00 2001 From: walkpan Date: Sat, 3 Jan 2026 11:17:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=8B=B1=E9=9B=84=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8B=B1=E9=9B=84=E5=A4=8D=E6=B4=BB=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E5=B9=B6=E6=8E=A7=E5=88=B6=E6=80=AA=E7=89=A9=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现英雄复活功能,当英雄死亡且有复活次数时延迟复活 新增is_reviving状态标记复活中状态 英雄死亡或复活时通过stop_mon_action控制怪物停止刷新和移动 --- assets/script/Main.ts | 10 ++-- .../script/game/common/SingletonModuleComp.ts | 1 + assets/script/game/hero/HeroAtkSystem.ts | 50 ++++++++++++++++++- assets/script/game/hero/HeroAttrsComp.ts | 2 + assets/script/game/hero/HeroAttrsSystem.ts | 2 +- assets/script/game/hero/HeroMove.ts | 3 +- assets/script/game/hero/HeroViewComp.ts | 24 ++++++++- assets/script/game/hero/MonMove.ts | 2 + assets/script/game/hero/SACastSystem.ts | 2 +- assets/script/game/map/MissionComp.ts | 1 + assets/script/game/map/MissionMonComp.ts | 2 + 11 files changed, 88 insertions(+), 11 deletions(-) diff --git a/assets/script/Main.ts b/assets/script/Main.ts index 4cae125c..bb5c2a5b 100644 --- a/assets/script/Main.ts +++ b/assets/script/Main.ts @@ -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); diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 8ba1968e..7adbc08a 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -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 diff --git a/assets/script/game/hero/HeroAtkSystem.ts b/assets/script/game/hero/HeroAtkSystem.ts index 1849cce2..ffd3f25f 100644 --- a/assets/script/game/hero/HeroAtkSystem.ts +++ b/assets/script/game/hero/HeroAtkSystem.ts @@ -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++; diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index f2252c88..8d32caaa 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -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; diff --git a/assets/script/game/hero/HeroAttrsSystem.ts b/assets/script/game/hero/HeroAttrsSystem.ts index e732cf9e..887fdd11 100644 --- a/assets/script/game/hero/HeroAttrsSystem.ts +++ b/assets/script/game/hero/HeroAttrsSystem.ts @@ -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++; diff --git a/assets/script/game/hero/HeroMove.ts b/assets/script/game/hero/HeroMove.ts index 94c5bac4..de2cc5af 100644 --- a/assets/script/game/hero/HeroMove.ts +++ b/assets/script/game/hero/HeroMove.ts @@ -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; } diff --git a/assets/script/game/hero/HeroViewComp.ts b/assets/script/game/hero/HeroViewComp.ts index 75e652ad..e71797ff 100644 --- a/assets/script/game/hero/HeroViewComp.ts +++ b/assets/script/game/hero/HeroViewComp.ts @@ -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 调用,只负责视觉效果和事件通知 diff --git a/assets/script/game/hero/MonMove.ts b/assets/script/game/hero/MonMove.ts index 91fbbd92..24a88afe 100644 --- a/assets/script/game/hero/MonMove.ts +++ b/assets/script/game/hero/MonMove.ts @@ -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); diff --git a/assets/script/game/hero/SACastSystem.ts b/assets/script/game/hero/SACastSystem.ts index 33747793..b0ab02a6 100644 --- a/assets/script/game/hero/SACastSystem.ts +++ b/assets/script/game/hero/SACastSystem.ts @@ -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; diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index f14bb619..fb1880a9 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -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 diff --git a/assets/script/game/map/MissionMonComp.ts b/assets/script/game/map/MissionMonComp.ts index dd2a98ac..05249dd9 100644 --- a/assets/script/game/map/MissionMonComp.ts +++ b/assets/script/game/map/MissionMonComp.ts @@ -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;