refactor(map): 重构局内经济系统,统一封装金币操作逻辑
新建MissionEconomy类作为局内经济统一管理入口,整合原分散在HInfoComp、MissionComp、CardComp、MissionCardComp中的金币计算、消费、收益统计逻辑,移除各组件中重复的getMissionCoin、setMissionCoin、getRefreshCost等工具方法,统一维护评分系统的金币统计,提升代码可维护性。
This commit is contained in:
@@ -49,6 +49,7 @@ import { FacSet, FightSet } from "../common/config/GameSet";
|
||||
import { MoveComp } from "../hero/MoveComp";
|
||||
import { MissionHeroCompComp } from "./MissionHeroComp";
|
||||
import { TalentType } from "../common/config/TalentSet";
|
||||
import { MissionEconomy } from "./MissionEconomy";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@@ -315,24 +316,15 @@ export class MissionCardComp extends CCComp {
|
||||
|
||||
/**
|
||||
* 金币变化事件回调:
|
||||
* - syncOnly=true:仅同步 UI 显示(金币已被外部修改过)。
|
||||
* - 否则:累加 delta 到 mission_data.coin 后刷新 UI。
|
||||
* 仅负责 UI 更新和动画表现。数据更新已由 MissionEconomy 统一处理。
|
||||
*/
|
||||
private onCoinAdd(event: string, args: any){
|
||||
const payload = args ?? event;
|
||||
if (payload?.syncOnly) {
|
||||
this.updateCoinAndCostUI();
|
||||
this.playCoinChangeAnim((payload?.delta ?? 0) > 0);
|
||||
return;
|
||||
}
|
||||
const v = typeof payload === 'number' ? payload : (payload?.delta ?? payload?.value ?? 0);
|
||||
if (v === 0) return;
|
||||
this.setMissionCoin(this.getMissionCoin() + v);
|
||||
// 【评分系统 - 效率分】精确统计整局游戏的总收入与额外支出(如卖卡、技能扣费等)
|
||||
if (v > 0) smc.vmdata.scores.gold_earned += v;
|
||||
else smc.vmdata.scores.gold_spent -= v;
|
||||
this.updateCoinAndCostUI();
|
||||
this.playCoinChangeAnim(v > 0);
|
||||
if (v !== 0) {
|
||||
this.playCoinChangeAnim(v > 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** 战斗开始:不收起面板,不再强制清空卡牌 */
|
||||
@@ -583,27 +575,22 @@ export class MissionCardComp extends CCComp {
|
||||
// oops.gui.toast("战斗阶段无法抽卡");
|
||||
// return;
|
||||
// }
|
||||
const cost = this.getRefreshCost();
|
||||
const currentCoin = this.getMissionCoin();
|
||||
if (currentCoin < cost) {
|
||||
const cost = MissionEconomy.getRefreshCost(this.refreshCost);
|
||||
const success = MissionEconomy.executeRefresh(this.refreshCost);
|
||||
if (!success) {
|
||||
oops.gui.toast(`金币不足,刷新需要${cost}`);
|
||||
this.updateCoinAndCostUI();
|
||||
mLogger.log(this.debugMode, "MissionCardComp", "draw coin not enough", {
|
||||
currentCoin,
|
||||
currentCoin: MissionEconomy.getCoin(),
|
||||
cost
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.setMissionCoin(currentCoin - cost);
|
||||
// 【评分系统 - 效率分】记录因刷新卡池消耗的金币,以及刷新次数
|
||||
smc.vmdata.scores.gold_spent += cost;
|
||||
smc.vmdata.scores.refresh_count++;
|
||||
this.playCoinChangeAnim(false);
|
||||
this.updateCoinAndCostUI();
|
||||
|
||||
mLogger.log(this.debugMode, "MissionCardComp", "click draw", {
|
||||
poolLv: this.poolLv,
|
||||
cost,
|
||||
leftCoin: this.getMissionCoin()
|
||||
leftCoin: MissionEconomy.getCoin()
|
||||
});
|
||||
this.layoutCardSlots();
|
||||
const cards = this.buildDrawCards();
|
||||
@@ -797,12 +784,12 @@ export class MissionCardComp extends CCComp {
|
||||
}
|
||||
private canUpPool() {
|
||||
if (this.poolLv >= CARD_POOL_MAX_LEVEL) return false;
|
||||
const currentCoin = this.getMissionCoin();
|
||||
const currentCoin = MissionEconomy.getCoin();
|
||||
return currentCoin >= this.getUpgradeCost(this.poolLv);
|
||||
}
|
||||
|
||||
private canDrawCards() {
|
||||
return this.getMissionCoin() >= this.getRefreshCost();
|
||||
return MissionEconomy.getCoin() >= MissionEconomy.getRefreshCost(this.refreshCost);
|
||||
}
|
||||
/** 更新升级按钮上的等级文案,反馈当前卡池层级 */
|
||||
private updatePoolLvUI() {
|
||||
@@ -860,7 +847,7 @@ export class MissionCardComp extends CCComp {
|
||||
const coinNode = this.cards_chou.getChildByName("coin");
|
||||
const numLabel = coinNode?.getChildByName("num")?.getComponent(Label);
|
||||
if (numLabel) {
|
||||
numLabel.string = `${this.getRefreshCost()}`;
|
||||
numLabel.string = `${MissionEconomy.getRefreshCost(this.refreshCost)}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -887,12 +874,7 @@ export class MissionCardComp extends CCComp {
|
||||
return Math.max(0, baseCost - discount);
|
||||
}
|
||||
|
||||
private getRefreshCost(): number {
|
||||
let cost = this.refreshCost;
|
||||
const discount = HeroAttrsComp.getTalentValue(TalentType.RefreshDiscount);
|
||||
cost = Math.max(0, cost - discount);
|
||||
return Math.floor(cost);
|
||||
}
|
||||
|
||||
|
||||
private clearHeroInfoPanels() {
|
||||
if (this.cachedHInfoComps) {
|
||||
@@ -1050,21 +1032,14 @@ export class MissionCardComp extends CCComp {
|
||||
return Math.max(0, Math.floor(missionData?.hero_num ?? 0));
|
||||
}
|
||||
|
||||
private getMissionCoin(): number {
|
||||
const missionData = this.getMissionData();
|
||||
return Math.max(0, Math.floor(missionData?.coin ?? 0));
|
||||
}
|
||||
|
||||
|
||||
private getCurrentWave(): number {
|
||||
const missionData = this.getMissionData();
|
||||
return Math.max(1, Math.floor(missionData?.level ?? 1));
|
||||
}
|
||||
|
||||
private setMissionCoin(value: number) {
|
||||
const missionData = this.getMissionData();
|
||||
if (!missionData) return;
|
||||
missionData.coin = Math.max(0, Math.floor(value));
|
||||
}
|
||||
|
||||
|
||||
private getMissionHeroMaxNum(): number {
|
||||
const missionData = this.getMissionData();
|
||||
|
||||
Reference in New Issue
Block a user