From beff0d624a89ac86011b05584df1b27e5e4cbf91 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 14 Apr 2026 10:40:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor(map):=20=E4=BD=BF=E7=94=A8Timer?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86=E7=8A=B6=E6=80=81=E6=9C=BA?= =?UTF-8?q?=E9=98=B6=E6=AE=B5=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 替换scheduleOnce为Timer实例,统一管理任务阶段过渡计时 将open_Victory和fight_end的延迟逻辑移至autoNextPhase处理 --- assets/script/game/map/MissionComp.ts | 68 +++++++++++++++++---------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index 151c7d50..a27912fc 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -44,6 +44,7 @@ import { Monster } from "../hero/Mon"; import { Skill } from "../skill/Skill"; import { Tooltip } from "../skill/Tooltip"; import { CardInitCoins } from "../common/config/CardSet"; +import { Timer } from "db://oops-framework/core/common/timer/Timer"; const { ccclass, property } = _decorator; /** 任务(关卡)生命周期阶段 */ @@ -113,7 +114,8 @@ export class MissionComp extends CCComp { gold:0, diamond:0 } - + /**2秒计时 */ + PhaseTime:Timer= new Timer(2) /** 上一次显示的时间字符串(避免重复设置) */ private lastTimeStr: string = ""; /** 上一次显示的秒数(避免重复计算) */ @@ -181,6 +183,17 @@ export class MissionComp extends CCComp { protected update(dt: number): void { if(!smc.mission.play) return if(smc.mission.pause) return + + // 处理过渡阶段的计时 + if (this.currentPhase === MissionPhase.PrepareStart || + this.currentPhase === MissionPhase.PrepareEnd || + this.currentPhase === MissionPhase.BattleStart || + this.currentPhase === MissionPhase.BattleEnd) { + if (this.PhaseTime.update(dt)) { + this.autoNextPhase(); + } + } + if(this.currentPhase === MissionPhase.Battle){ this.syncMonsterSpawnState(dt) if(smc.mission.stop_mon_action) return @@ -266,8 +279,8 @@ export class MissionComp extends CCComp { const oldPhase = this.currentPhase; this.currentPhase = targetPhase; - // 取消状态机内部产生的定时流转任务,防止状态错乱 - this.unschedule(this.autoNextPhase); + // 重置状态机的计时器 + this.PhaseTime.reset(); switch (targetPhase) { case MissionPhase.PrepareStart: @@ -275,7 +288,6 @@ export class MissionComp extends CCComp { smc.vmdata.mission_data.in_fight = false; smc.mission.stop_spawn_mon = true; if (this.start_btn && this.start_btn.isValid) this.start_btn.active = false; - this.scheduleOnce(this.autoNextPhase, 2); break; case MissionPhase.Prepare: @@ -284,13 +296,11 @@ export class MissionComp extends CCComp { case MissionPhase.PrepareEnd: if (this.start_btn && this.start_btn.isValid) this.start_btn.active = false; - this.scheduleOnce(this.autoNextPhase, 2); break; case MissionPhase.BattleStart: // 触发战斗开始技能(fstart) this.triggerHeroBattleSkills(true); - this.scheduleOnce(this.autoNextPhase, 2); break; case MissionPhase.Battle: @@ -336,6 +346,28 @@ export class MissionComp extends CCComp { case MissionPhase.BattleStart: this.changePhase(MissionPhase.Battle); break; + case MissionPhase.BattleEnd: + // BattleEnd 计时结束后,如果是因为全灭或手动调用的 fight_end,进入 Settle + // 需要注意的是,open_Victory / fight_end 现在只需切换到 BattleEnd 即可,Settle 由这里自动接管 + this.changePhase(MissionPhase.Settle); + + // 此时已经经过了 2s,可以真正执行结算弹窗或清理逻辑 + if (smc.mission.play) { + // 如果游戏还在运行中,说明是通过 open_Victory 进来的 + smc.mission.pause = true; + mLogger.log(this.debugMode, 'MissionComp', " autoNextPhase -> open_Victory logic", this.revive_times); + oops.gui.open(UIID.Victory, { + victory: false, + rewards: this.rewards, + game_data: this.game_data, + can_revive: this.revive_times > 0 + }); + } else { + // 如果 play 已经是 false,说明是通过 fight_end 进来的 + this.cleanComponents(); + this.clearBattlePools(); + } + break; } } @@ -403,33 +435,17 @@ export class MissionComp extends CCComp { * @param is_hero_dead 是否因英雄全灭触发 */ open_Victory(e:any,is_hero_dead: boolean = false){ + // 直接切入 BattleEnd,触发 fend 表现 + // 倒计时逻辑已在 update 中由 PhaseTime 接管,2s 后将触发 autoNextPhase 弹窗结算 this.changePhase(MissionPhase.BattleEnd); - - // 延迟 2s 后进入结算,让 BattleEnd 阶段的表现能够播完 - this.scheduleOnce(() => { - this.changePhase(MissionPhase.Settle); - smc.mission.pause = true; - mLogger.log(this.debugMode, 'MissionComp', " open_Victory",is_hero_dead,this.revive_times) - oops.gui.open(UIID.Victory,{ - victory:false, - rewards:this.rewards, - game_data:this.game_data, - can_revive: is_hero_dead && this.revive_times > 0 - }) - }, 2); } /** 战斗结束:延迟清理组件和对象池 */ fight_end(){ + // 这里只是强制清理关卡,为了防止重复弹窗,标记 play = false + smc.mission.play=false this.changePhase(MissionPhase.BattleEnd); - - this.scheduleOnce(() => { - this.changePhase(MissionPhase.Settle); - smc.mission.play=false - this.cleanComponents() - this.clearBattlePools() - }, 2) } /**