feat(卡牌): 添加金币消耗机制

- 在 CardComp 中检查使用卡牌所需金币,不足时播放反弹动画并提示
- 在 MissionCardComp 中检查刷新卡牌所需金币,不足时提示
- 添加金币获取和设置方法,统一处理金币数值的取整和边界
- 更新 UI 显示逻辑,同时显示金币余额和刷新/升级消耗
- 使用卡牌或刷新时扣除相应金币并发送金币变更事件
This commit is contained in:
panw
2026-03-27 10:38:42 +08:00
parent ad5758c6e7
commit da83c89427
2 changed files with 83 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import { HeroInfo } from "../common/config/heroSet";
import { SkillSet } from "../common/config/SkillSet";
import { GameEvent } from "../common/config/GameEvent";
import { oops } from "db://oops-framework/core/Oops";
import { smc } from "../common/SingletonModuleComp";
@@ -161,6 +162,19 @@ export class CardComp extends CCComp {
useCard(): CardConfig | null {
if (!this.cardData || this.isUsing) return null;
const cardCost = Math.max(0, Math.floor(this.cardData.cost ?? 0));
const currentCoin = this.getMissionCoin();
if (currentCoin < cardCost) {
oops.gui.toast(`金币不足,召唤需要${cardCost}`);
this.playReboundAnim();
mLogger.log(this.debugMode, "CardComp", "use card coin not enough", {
uuid: this.cardData.uuid,
type: this.cardData.type,
cardCost,
currentCoin
});
return null;
}
if (this.cardData.type === CardType.Hero) {
const guard = {
cancel: false,
@@ -174,11 +188,18 @@ export class CardComp extends CCComp {
return null;
}
}
this.setMissionCoin(currentCoin - cardCost);
oops.message.dispatchEvent(GameEvent.CoinAdd, {
syncOnly: true,
delta: -cardCost
});
this.isUsing = true;
const used = this.cardData;
mLogger.log(this.debugMode, "CardComp", "use card", {
uuid: used.uuid,
type: used.type
type: used.type,
cost: cardCost,
leftCoin: this.getMissionCoin()
});
this.playUseDisappearAnim(() => {
this.cardUseComp?.onCardUsed(used);
@@ -481,6 +502,17 @@ export class CardComp extends CCComp {
[...clips].forEach(clip => anim.removeClip(clip, true));
}
private getMissionCoin(): number {
const missionData = smc?.vmdata?.mission_data;
return Math.max(0, Math.floor(missionData?.coin ?? 0));
}
private setMissionCoin(value: number) {
const missionData = smc?.vmdata?.mission_data;
if (!missionData) return;
missionData.coin = Math.max(0, Math.floor(value));
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();