Compare commits
3 Commits
acd8d108e9
...
c0243fc159
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0243fc159 | ||
|
|
24b27877b0 | ||
|
|
beff0d624a |
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
|
||||
/** 任务(关卡)生命周期阶段 */
|
||||
@@ -99,6 +100,18 @@ export class MissionComp extends CCComp {
|
||||
@property(Node)
|
||||
time_node:Node = null!
|
||||
|
||||
/** 阶段名称映射表(用于 UI 显示) */
|
||||
private static readonly PhaseNameMap: Record<MissionPhase, string> = {
|
||||
[MissionPhase.None]: "未开始",
|
||||
[MissionPhase.PrepareStart]: "准备开始",
|
||||
[MissionPhase.Prepare]: "准备阶段",
|
||||
[MissionPhase.PrepareEnd]: "准备结束",
|
||||
[MissionPhase.BattleStart]: "战斗开始",
|
||||
[MissionPhase.Battle]: "战斗中",
|
||||
[MissionPhase.BattleEnd]: "战斗结束",
|
||||
[MissionPhase.Settle]: "结算阶段"
|
||||
};
|
||||
|
||||
// ======================== 运行时状态 ========================
|
||||
|
||||
/** 战斗倒计时(秒) */
|
||||
@@ -113,7 +126,8 @@ export class MissionComp extends CCComp {
|
||||
gold:0,
|
||||
diamond:0
|
||||
}
|
||||
|
||||
/**秒计时 */
|
||||
PhaseTime:Timer= new Timer(0.5)
|
||||
/** 上一次显示的时间字符串(避免重复设置) */
|
||||
private lastTimeStr: string = "";
|
||||
/** 上一次显示的秒数(避免重复计算) */
|
||||
@@ -181,6 +195,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 +291,19 @@ export class MissionComp extends CCComp {
|
||||
const oldPhase = this.currentPhase;
|
||||
this.currentPhase = targetPhase;
|
||||
|
||||
// 取消状态机内部产生的定时流转任务,防止状态错乱
|
||||
this.unschedule(this.autoNextPhase);
|
||||
// 更新阶段显示 UI
|
||||
if (this.time_node && this.time_node.isValid) {
|
||||
const phaseNode = this.time_node.getChildByPath("Phase/Label");
|
||||
if (phaseNode) {
|
||||
const label = phaseNode.getComponent(Label);
|
||||
if (label) {
|
||||
label.string = MissionComp.PhaseNameMap[targetPhase] || "未知";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 重置状态机的计时器
|
||||
this.PhaseTime.reset();
|
||||
|
||||
switch (targetPhase) {
|
||||
case MissionPhase.PrepareStart:
|
||||
@@ -275,7 +311,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 +319,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 +369,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 +458,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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user