fix(game): 优化结算分数计算与胜利状态传递

1. 重构calculateTotalScore方法,新增胜利和全存活加分逻辑
2. 给MissionComp添加胜利状态缓存,修复结算弹窗参数错误
3. 修正超时强制结算和胜利分支的胜利参数传递
This commit is contained in:
pan
2026-09-01 17:10:38 +08:00
parent 4263997124
commit d943bc05ce
3 changed files with 26 additions and 44 deletions

View File

@@ -169,6 +169,8 @@ export class MissionComp extends CCComp {
public currentPhase: MissionPhase = MissionPhase.None;
/** 是否处于回合间倒计时状态 */
private isWaveCountdown: boolean = false;
/** 本局是否胜利(open_Victory 时记录,供结算弹窗使用) */
private _victory: boolean = false;
// ======================== ECS 查询匹配器(预缓存) ========================
@@ -632,7 +634,8 @@ export class MissionComp extends CCComp {
smc.mission.pause = true;
mLogger.log(this.debugMode, 'MissionComp', " autoNextPhase -> open_Victory logic", this.revive_times);
oops.gui.open(UIID.Victory, {
victory: false,
victory: this._victory,
all_alive: this.checkAllHeroAlive(),
rewards: this.rewards,
game_data: this.game_data,
can_revive: this.revive_times > 0
@@ -740,10 +743,13 @@ export class MissionComp extends CCComp {
*
* @param e 事件对象(未使用)
* @param is_hero_dead 是否因英雄全灭触发
* @param victory 是否胜利(默认 false)
*/
open_Victory(e: any, is_hero_dead: boolean = false) {
open_Victory(e: any, is_hero_dead: boolean = false, victory: boolean = false) {
// 战斗失败或胜利,标记暂停状态以切断回合流转逻辑
smc.mission.pause = true;
// 记录胜利标记,供 BattleEnd 阶段结算弹窗使用
this._victory = victory;
// 直接切入 BattleEnd,2s 后由 autoNextPhase 自动流转弹窗结算
this.changePhase(MissionPhase.BattleEnd);
}
@@ -907,7 +913,7 @@ export class MissionComp extends CCComp {
allAlive,
fastClear,
});
this.open_Victory(null, false);
this.open_Victory(null, false, true);
return;
}
@@ -961,7 +967,8 @@ export class MissionComp extends CCComp {
mLogger.log(this.debugMode, 'MissionComp', `[BattleTimeout] 超时强制结算`);
this.open_Victory(null, false);
// 超时按怪物全灭同等处理——视为胜利(但通常会有英雄死亡,all_alive 由结算时实时检测)
this.open_Victory(null, false, true);
}
// ======================== 清理 ========================

View File

@@ -172,7 +172,7 @@ export class VictoryComp extends CCComp {
this.node.getChildByName("btns").getChildByName("next").active = !args.can_revive
// 计算总分并写入历史纪录
this.calculateTotalScore();
this.calculateTotalScore(!!args.victory, !!args.all_alive);
// 计算并发放结算奖励(英雄碎片 + 金币 + 天赋经验)
this.grantRewards(!!args.victory);
@@ -248,10 +248,22 @@ export class VictoryComp extends CCComp {
/**
* 计算单局总分并更新到 smc.vmdata.scores.score。
* 同时刷新 smc.data.score 历史最高分。
*
* @param isVictory 是否胜利(胜利 +10 分,失败不加分)
* @param allAlive 是否全英雄存活获胜(额外 +5 分)
*/
private calculateTotalScore() {
private calculateTotalScore(isVictory: boolean, allAlive: boolean) {
const s = smc.vmdata.scores;
// 0. 胜负分:胜利 +10,全英雄存活获胜额外 +5,失败不加分
let score_result = 0;
if (isVictory) {
score_result = 10;
if (allAlive) {
score_result += 5;
}
}
// 1. 战绩分:衡量生存能力——活几回合、赢几场。
s.score_combat = (s.wave_win_count * 100)
- (s.wave_remain_monsters * 15)
@@ -288,7 +300,7 @@ export class VictoryComp extends CCComp {
}
// 取整并存储当前局分数
s.score = Math.floor(s.score_combat + s.score_output + s.score_defense + s.score_build + s.score_efficiency + highlightBonus);
s.score = Math.floor(score_result + s.score_combat + s.score_output + s.score_defense + s.score_build + s.score_efficiency + highlightBonus);
// 记录滚动前的历史最高分(动画起始值)
this._prevBestScore = smc.data.score;