refactor: 重构关卡经济与战斗流程
1. 移除战斗阶段限制,允许玩家在战斗中操作卡牌 2. 新增波次间5秒自动倒计时机制 3. 将固定波次金币奖励改为怪物死亡掉落 4. 重构卡牌面板逻辑,统一抽卡按钮状态判断 5. 清理冗余的战斗阶段状态变量与相关代码
This commit is contained in:
@@ -49,7 +49,6 @@ import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
||||
import { FieldSkillType } from "../common/config/SkillSet";
|
||||
import { FieldSkillHelper } from "../hero/FieldSkillHelper";
|
||||
import { spawningEngine } from "./RogueConfig";
|
||||
import { MissionEconomy } from "./MissionEconomy";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 任务(关卡)生命周期阶段 */
|
||||
@@ -129,6 +128,10 @@ export class MissionComp extends CCComp {
|
||||
}
|
||||
/**秒计时 */
|
||||
PhaseTime: Timer = new Timer(1)
|
||||
/** 波次间倒计时(秒) */
|
||||
private waveCountdown: number = 0;
|
||||
/** 波次间倒计时总时长(秒) */
|
||||
private readonly WAVE_COUNTDOWN_DURATION: number = 5;
|
||||
/** 上一次显示的时间字符串(避免重复设置) */
|
||||
private lastTimeStr: string = "";
|
||||
/** 上一次显示的秒数(避免重复计算) */
|
||||
@@ -159,10 +162,10 @@ export class MissionComp extends CCComp {
|
||||
private currentWave: number = 0;
|
||||
/** 是否为Boss波次 */
|
||||
private isBossWave: boolean = false;
|
||||
/** 上一次发放金币奖励的波数(防止重复发放) */
|
||||
private lastPrepareCoinWave: number = 0;
|
||||
/** 当前任务阶段 */
|
||||
public currentPhase: MissionPhase = MissionPhase.None;
|
||||
/** 是否处于波次间倒计时状态 */
|
||||
private isWaveCountdown: boolean = false;
|
||||
|
||||
// ======================== ECS 查询匹配器(预缓存) ========================
|
||||
|
||||
@@ -219,9 +222,18 @@ export class MissionComp extends CCComp {
|
||||
// 如果是暂停状态,且不在 BattleEnd 阶段(全灭时需要播放完 fend 技能动画并自动流转),才真正停止 update 逻辑
|
||||
if (smc.mission.pause && this.currentPhase !== MissionPhase.BattleEnd) return
|
||||
|
||||
// 波次间倒计时:PrepareStart 复用为倒计时阶段,5 秒后自动进入下一波
|
||||
if (this.currentPhase === MissionPhase.PrepareStart) {
|
||||
this.waveCountdown -= dt;
|
||||
this.updateCountdownUI();
|
||||
if (this.waveCountdown <= 0) {
|
||||
this.autoNextPhase();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理过渡阶段的计时
|
||||
if (this.currentPhase === MissionPhase.PrepareStart ||
|
||||
this.currentPhase === MissionPhase.PrepareEnd ||
|
||||
if (this.currentPhase === MissionPhase.PrepareEnd ||
|
||||
this.currentPhase === MissionPhase.BattleStart ||
|
||||
this.currentPhase === MissionPhase.BattleEnd) {
|
||||
if (this.PhaseTime.update(dt)) {
|
||||
@@ -260,6 +272,39 @@ export class MissionComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 波次倒计时 ========================
|
||||
|
||||
/** 进入波次间倒计时:重置倒计时并显示提示 */
|
||||
private startWaveCountdown() {
|
||||
this.waveCountdown = this.WAVE_COUNTDOWN_DURATION;
|
||||
this.isWaveCountdown = true;
|
||||
this.updateCountdownUI(true);
|
||||
}
|
||||
|
||||
/** 更新倒计时 UI(显示剩余秒数) */
|
||||
private updateCountdownUI(force: boolean = false) {
|
||||
if (!this.isWaveCountdown) return;
|
||||
const remain = Math.max(0, Math.ceil(this.waveCountdown));
|
||||
if (!force && remain === this.lastTimeSecond) return;
|
||||
this.lastTimeSecond = remain;
|
||||
|
||||
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 = `下一波 ${remain}s`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 结束波次间倒计时 */
|
||||
private stopWaveCountdown() {
|
||||
this.isWaveCountdown = false;
|
||||
this.lastTimeSecond = -1;
|
||||
}
|
||||
|
||||
// ======================== 奖励与广告 ========================
|
||||
|
||||
/** 奖励发放(预留) */
|
||||
@@ -307,7 +352,7 @@ export class MissionComp extends CCComp {
|
||||
loading.active = false
|
||||
}, 0.5)
|
||||
}
|
||||
|
||||
|
||||
// 播放战斗背景音乐,并稍微降低音量
|
||||
oops.audio.volumeMusic = 0.5;
|
||||
oops.audio.playerMusicLoop("music/BATTLE");
|
||||
@@ -425,7 +470,13 @@ export class MissionComp extends CCComp {
|
||||
smc.mission.in_fight = false;
|
||||
smc.vmdata.mission_data.in_fight = false;
|
||||
smc.mission.stop_spawn_mon = true;
|
||||
// 不隐藏开始按钮,点击事件在 onStartFightBtnClick 内部做了阶段拦截
|
||||
// 波次间倒计时:隐藏开始按钮(nobg 激活表示不可点击状态)
|
||||
if (this.start_btn && this.start_btn.isValid) {
|
||||
const nobg = this.start_btn.getChildByName("nobg");
|
||||
if (nobg) nobg.active = true;
|
||||
}
|
||||
// 启动 5 秒倒计时,由 update 驱动自动进入下一波
|
||||
this.startWaveCountdown();
|
||||
oops.message.dispatchEvent("PhasePrepareStart");
|
||||
break;
|
||||
|
||||
@@ -526,7 +577,9 @@ export class MissionComp extends CCComp {
|
||||
private autoNextPhase() {
|
||||
switch (this.currentPhase) {
|
||||
case MissionPhase.PrepareStart:
|
||||
this.changePhase(MissionPhase.Prepare);
|
||||
// 波次间倒计时结束,停止倒计时状态,直接进入 PrepareEnd(不再等待玩家点击)
|
||||
this.stopWaveCountdown();
|
||||
this.changePhase(MissionPhase.PrepareEnd);
|
||||
break;
|
||||
case MissionPhase.PrepareEnd:
|
||||
this.changePhase(MissionPhase.BattleStart);
|
||||
@@ -643,7 +696,7 @@ export class MissionComp extends CCComp {
|
||||
if (!smc.mission.play) return;
|
||||
if (smc.mission.pause) return;
|
||||
if (this.currentPhase !== MissionPhase.Prepare) return;
|
||||
|
||||
|
||||
oops.audio.playEffect("music/button");
|
||||
this.to_fight();
|
||||
}
|
||||
@@ -728,7 +781,6 @@ export class MissionComp extends CCComp {
|
||||
this.heapTrendTimer = 0;
|
||||
this.heapTrendBaseMB = -1;
|
||||
this.monsterCountSyncTimer = 0;
|
||||
this.lastPrepareCoinWave = 0;
|
||||
|
||||
spawningEngine.reset();
|
||||
|
||||
@@ -746,8 +798,9 @@ export class MissionComp extends CCComp {
|
||||
* 新一波事件回调:
|
||||
* 1. 进入准备阶段。
|
||||
* 2. 更新当前波数。
|
||||
* 3. 发放本波金币奖励。
|
||||
* 4. 刷新时间显示。
|
||||
* 3. 刷新时间显示。
|
||||
*
|
||||
* 注意:金币不再按波次固定发放,改为怪物死亡时掉落(见 HeroAtkSystem)。
|
||||
*
|
||||
* @param event 事件名
|
||||
* @param data { wave: number }
|
||||
@@ -772,7 +825,7 @@ export class MissionComp extends CCComp {
|
||||
|
||||
this.currentWave = wave;
|
||||
smc.vmdata.mission_data.level = wave;
|
||||
this.grantPrepareCoinByWave(wave);
|
||||
// 金币改为怪物死亡掉落(见 HeroAtkSystem),不再每波固定发放
|
||||
this.lastTimeSecond = -1;
|
||||
this.clearTime = 0;
|
||||
this.update_time();
|
||||
@@ -794,26 +847,6 @@ export class MissionComp extends CCComp {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按波数发放固定金币奖励(外加技能加成)。
|
||||
* 第1波不发放(使用初始金币),从第2波起发放。
|
||||
* 仅在波数首次到达时发放,防止重复。
|
||||
*
|
||||
* @param wave 当前波数
|
||||
*/
|
||||
private grantPrepareCoinByWave(wave: number) {
|
||||
if (wave <= 1) return;
|
||||
if (wave <= this.lastPrepareCoinWave) return;
|
||||
|
||||
// 波次金币公式: baseReward + (wave-1) * waveGrow,且不超过 prepareMaxCoinReward
|
||||
const calculatedReward = FightSet.WAVE_COIN_BASE + (wave - 1) * FightSet.WAVE_COIN_GROW;
|
||||
const waveReward = Math.min(FightSet.WAVE_COIN_MAX, calculatedReward);
|
||||
const reward = MissionEconomy.executeWaveGold(waveReward);
|
||||
|
||||
this.lastPrepareCoinWave = wave;
|
||||
mLogger.log(this.debugMode, "MissionComp", "grantPrepareCoinByWave", { wave, waveReward, reward, coin: smc.vmdata.mission_data.coin });
|
||||
}
|
||||
|
||||
// ======================== 怪物数量管理 ========================
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user