refactor(map): 使用Timer统一管理状态机阶段计时
替换scheduleOnce为Timer实例,统一管理任务阶段过渡计时 将open_Victory和fight_end的延迟逻辑移至autoNextPhase处理
This commit is contained in:
@@ -44,6 +44,7 @@ import { Monster } from "../hero/Mon";
|
|||||||
import { Skill } from "../skill/Skill";
|
import { Skill } from "../skill/Skill";
|
||||||
import { Tooltip } from "../skill/Tooltip";
|
import { Tooltip } from "../skill/Tooltip";
|
||||||
import { CardInitCoins } from "../common/config/CardSet";
|
import { CardInitCoins } from "../common/config/CardSet";
|
||||||
|
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
/** 任务(关卡)生命周期阶段 */
|
/** 任务(关卡)生命周期阶段 */
|
||||||
@@ -113,7 +114,8 @@ export class MissionComp extends CCComp {
|
|||||||
gold:0,
|
gold:0,
|
||||||
diamond:0
|
diamond:0
|
||||||
}
|
}
|
||||||
|
/**2秒计时 */
|
||||||
|
PhaseTime:Timer= new Timer(2)
|
||||||
/** 上一次显示的时间字符串(避免重复设置) */
|
/** 上一次显示的时间字符串(避免重复设置) */
|
||||||
private lastTimeStr: string = "";
|
private lastTimeStr: string = "";
|
||||||
/** 上一次显示的秒数(避免重复计算) */
|
/** 上一次显示的秒数(避免重复计算) */
|
||||||
@@ -181,6 +183,17 @@ export class MissionComp extends CCComp {
|
|||||||
protected update(dt: number): void {
|
protected update(dt: number): void {
|
||||||
if(!smc.mission.play) return
|
if(!smc.mission.play) return
|
||||||
if(smc.mission.pause) 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){
|
if(this.currentPhase === MissionPhase.Battle){
|
||||||
this.syncMonsterSpawnState(dt)
|
this.syncMonsterSpawnState(dt)
|
||||||
if(smc.mission.stop_mon_action) return
|
if(smc.mission.stop_mon_action) return
|
||||||
@@ -266,8 +279,8 @@ export class MissionComp extends CCComp {
|
|||||||
const oldPhase = this.currentPhase;
|
const oldPhase = this.currentPhase;
|
||||||
this.currentPhase = targetPhase;
|
this.currentPhase = targetPhase;
|
||||||
|
|
||||||
// 取消状态机内部产生的定时流转任务,防止状态错乱
|
// 重置状态机的计时器
|
||||||
this.unschedule(this.autoNextPhase);
|
this.PhaseTime.reset();
|
||||||
|
|
||||||
switch (targetPhase) {
|
switch (targetPhase) {
|
||||||
case MissionPhase.PrepareStart:
|
case MissionPhase.PrepareStart:
|
||||||
@@ -275,7 +288,6 @@ export class MissionComp extends CCComp {
|
|||||||
smc.vmdata.mission_data.in_fight = false;
|
smc.vmdata.mission_data.in_fight = false;
|
||||||
smc.mission.stop_spawn_mon = true;
|
smc.mission.stop_spawn_mon = true;
|
||||||
if (this.start_btn && this.start_btn.isValid) this.start_btn.active = false;
|
if (this.start_btn && this.start_btn.isValid) this.start_btn.active = false;
|
||||||
this.scheduleOnce(this.autoNextPhase, 2);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MissionPhase.Prepare:
|
case MissionPhase.Prepare:
|
||||||
@@ -284,13 +296,11 @@ export class MissionComp extends CCComp {
|
|||||||
|
|
||||||
case MissionPhase.PrepareEnd:
|
case MissionPhase.PrepareEnd:
|
||||||
if (this.start_btn && this.start_btn.isValid) this.start_btn.active = false;
|
if (this.start_btn && this.start_btn.isValid) this.start_btn.active = false;
|
||||||
this.scheduleOnce(this.autoNextPhase, 2);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MissionPhase.BattleStart:
|
case MissionPhase.BattleStart:
|
||||||
// 触发战斗开始技能(fstart)
|
// 触发战斗开始技能(fstart)
|
||||||
this.triggerHeroBattleSkills(true);
|
this.triggerHeroBattleSkills(true);
|
||||||
this.scheduleOnce(this.autoNextPhase, 2);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MissionPhase.Battle:
|
case MissionPhase.Battle:
|
||||||
@@ -336,6 +346,28 @@ export class MissionComp extends CCComp {
|
|||||||
case MissionPhase.BattleStart:
|
case MissionPhase.BattleStart:
|
||||||
this.changePhase(MissionPhase.Battle);
|
this.changePhase(MissionPhase.Battle);
|
||||||
break;
|
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 是否因英雄全灭触发
|
* @param is_hero_dead 是否因英雄全灭触发
|
||||||
*/
|
*/
|
||||||
open_Victory(e:any,is_hero_dead: boolean = false){
|
open_Victory(e:any,is_hero_dead: boolean = false){
|
||||||
|
// 直接切入 BattleEnd,触发 fend 表现
|
||||||
|
// 倒计时逻辑已在 update 中由 PhaseTime 接管,2s 后将触发 autoNextPhase 弹窗结算
|
||||||
this.changePhase(MissionPhase.BattleEnd);
|
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(){
|
fight_end(){
|
||||||
|
// 这里只是强制清理关卡,为了防止重复弹窗,标记 play = false
|
||||||
|
smc.mission.play=false
|
||||||
this.changePhase(MissionPhase.BattleEnd);
|
this.changePhase(MissionPhase.BattleEnd);
|
||||||
|
|
||||||
this.scheduleOnce(() => {
|
|
||||||
this.changePhase(MissionPhase.Settle);
|
|
||||||
smc.mission.play=false
|
|
||||||
this.cleanComponents()
|
|
||||||
this.clearBattlePools()
|
|
||||||
}, 2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user