feat(卡牌): 新增卡池升级消耗金币机制
- 添加 CoinAdd 游戏事件用于金币变化通知 - 新增卡池升级消耗配置 CardsUpSet 和初始金币常量 CardInitCoins - 修改升级逻辑:检查金币是否足够,扣除相应金币后才能升级 - 更新UI显示:升级按钮显示所需金币,添加金币数量显示面板 - 禁用通知面板的动画组件以优化性能
This commit is contained in:
@@ -583,7 +583,7 @@
|
|||||||
},
|
},
|
||||||
"_type": 0,
|
"_type": 0,
|
||||||
"_fillType": 0,
|
"_fillType": 0,
|
||||||
"_sizeMode": 1,
|
"_sizeMode": 0,
|
||||||
"_fillCenter": {
|
"_fillCenter": {
|
||||||
"__type__": "cc.Vec2",
|
"__type__": "cc.Vec2",
|
||||||
"x": 0,
|
"x": 0,
|
||||||
@@ -691,21 +691,13 @@
|
|||||||
"node": {
|
"node": {
|
||||||
"__id__": 1
|
"__id__": 1
|
||||||
},
|
},
|
||||||
"_enabled": true,
|
"_enabled": false,
|
||||||
"__prefab": {
|
"__prefab": {
|
||||||
"__id__": 31
|
"__id__": 31
|
||||||
},
|
},
|
||||||
"playOnLoad": true,
|
"playOnLoad": true,
|
||||||
"_clips": [
|
"_clips": [],
|
||||||
{
|
"_defaultClip": null,
|
||||||
"__uuid__": "4cecde51-d46d-4b20-b02e-e58f063ec56f",
|
|
||||||
"__expectedType__": "cc.AnimationClip"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"_defaultClip": {
|
|
||||||
"__uuid__": "4cecde51-d46d-4b20-b02e-e58f063ec56f",
|
|
||||||
"__expectedType__": "cc.AnimationClip"
|
|
||||||
},
|
|
||||||
"_id": ""
|
"_id": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
|||||||
|
import * as exp from "constants"
|
||||||
|
|
||||||
/** 卡牌大类定义 */
|
/** 卡牌大类定义 */
|
||||||
export enum CardType {
|
export enum CardType {
|
||||||
Hero = 1,
|
Hero = 1,
|
||||||
@@ -27,7 +29,14 @@ export interface CardConfig {
|
|||||||
lv: CardKind
|
lv: CardKind
|
||||||
hero_lv?: number
|
hero_lv?: number
|
||||||
}
|
}
|
||||||
|
export const CardsUpSet: Record<number, number> = {
|
||||||
|
1: 50,
|
||||||
|
2: 100,
|
||||||
|
3: 150,
|
||||||
|
4: 200,
|
||||||
|
5: 250,
|
||||||
|
}
|
||||||
|
export const CardInitCoins = 4
|
||||||
/** 卡池默认初始等级 */
|
/** 卡池默认初始等级 */
|
||||||
export const CARD_POOL_INIT_LEVEL = CardKind.LV1
|
export const CARD_POOL_INIT_LEVEL = CardKind.LV1
|
||||||
/** 卡池等级上限 */
|
/** 卡池等级上限 */
|
||||||
|
|||||||
@@ -72,4 +72,5 @@ export enum GameEvent {
|
|||||||
UpdateCollection = "UpdateCollection",
|
UpdateCollection = "UpdateCollection",
|
||||||
UpdateMissionGet = "UpdateMissionGet",
|
UpdateMissionGet = "UpdateMissionGet",
|
||||||
GlobalAttrChange = "GlobalAttrChange",
|
GlobalAttrChange = "GlobalAttrChange",
|
||||||
|
CoinAdd = "CoinAdd",
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,10 @@ import { _decorator, Label, Node, NodeEventType, SpriteAtlas } from "cc";
|
|||||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||||
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
||||||
import { GameEvent } from "../common/config/GameEvent";
|
import { GameEvent } from "../common/config/GameEvent";
|
||||||
import { CARD_POOL_INIT_LEVEL, CARD_POOL_MAX_LEVEL, CardConfig, getCardsByLv } from "../common/config/CardSet";
|
import { CARD_POOL_INIT_LEVEL, CARD_POOL_MAX_LEVEL, CardConfig, CardInitCoins, CardsUpSet, getCardsByLv } from "../common/config/CardSet";
|
||||||
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
import { CardComp } from "./CardComp";
|
import { CardComp } from "./CardComp";
|
||||||
|
import { oops } from "db://oops-framework/core/Oops";
|
||||||
|
|
||||||
const { ccclass, property } = _decorator;
|
const { ccclass, property } = _decorator;
|
||||||
|
|
||||||
@@ -28,14 +30,14 @@ export class MissionCardComp extends CCComp {
|
|||||||
cards_chou:Node = null!
|
cards_chou:Node = null!
|
||||||
@property(Node)
|
@property(Node)
|
||||||
cards_up:Node = null!
|
cards_up:Node = null!
|
||||||
|
@property(Node)
|
||||||
|
coins:Node = null!
|
||||||
/** 预留图集缓存(后续接入按钮/卡面图标时复用) */
|
/** 预留图集缓存(后续接入按钮/卡面图标时复用) */
|
||||||
private uiconsAtlas: SpriteAtlas | null = null;
|
private uiconsAtlas: SpriteAtlas | null = null;
|
||||||
/** 四个槽位对应的单卡控制器缓存 */
|
/** 四个槽位对应的单卡控制器缓存 */
|
||||||
private cardComps: CardComp[] = [];
|
private cardComps: CardComp[] = [];
|
||||||
/** 当前卡池等级(仅影响抽卡来源,不直接改卡槽现有内容) */
|
/** 当前卡池等级(仅影响抽卡来源,不直接改卡槽现有内容) */
|
||||||
private poolLv: number = CARD_POOL_INIT_LEVEL;
|
private poolLv: number = CARD_POOL_INIT_LEVEL;
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
/** 绑定事件 -> 缓存子控制器 -> 初始化UI状态 */
|
/** 绑定事件 -> 缓存子控制器 -> 初始化UI状态 */
|
||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
@@ -58,12 +60,14 @@ export class MissionCardComp extends CCComp {
|
|||||||
/** 任务开始时:重置卡池等级、清空4槽、显示面板 刷新一次卡池*/
|
/** 任务开始时:重置卡池等级、清空4槽、显示面板 刷新一次卡池*/
|
||||||
onMissionStart() {
|
onMissionStart() {
|
||||||
this.poolLv = CARD_POOL_INIT_LEVEL;
|
this.poolLv = CARD_POOL_INIT_LEVEL;
|
||||||
|
smc.vmdata.mission_data.coin=CardInitCoins //这里负责卡牌相关数据舒适化
|
||||||
this.layoutCardSlots();
|
this.layoutCardSlots();
|
||||||
this.clearAllCards();
|
this.clearAllCards();
|
||||||
if (this.cards_up) {
|
if (this.cards_up) {
|
||||||
this.cards_up.active = true;
|
this.cards_up.active = true;
|
||||||
}
|
}
|
||||||
this.updatePoolLvUI();
|
this.updatePoolLvUI();
|
||||||
|
this.updateCoinUI();
|
||||||
this.node.active = true;
|
this.node.active = true;
|
||||||
const cards = this.buildDrawCards();
|
const cards = this.buildDrawCards();
|
||||||
this.dispatchCardsToSlots(cards);
|
this.dispatchCardsToSlots(cards);
|
||||||
@@ -94,11 +98,17 @@ export class MissionCardComp extends CCComp {
|
|||||||
/** 生命周期事件 */
|
/** 生命周期事件 */
|
||||||
this.on(GameEvent.MissionStart, this.onMissionStart, this);
|
this.on(GameEvent.MissionStart, this.onMissionStart, this);
|
||||||
this.on(GameEvent.MissionEnd, this.onMissionEnd, this);
|
this.on(GameEvent.MissionEnd, this.onMissionEnd, this);
|
||||||
|
this.on(GameEvent.CoinAdd, this.onCoinAdd, this);
|
||||||
|
|
||||||
/** 按钮事件:抽卡与卡池升级 */
|
/** 按钮事件:抽卡与卡池升级 */
|
||||||
this.cards_chou?.on(NodeEventType.TOUCH_END, this.onClickDraw, this);
|
this.cards_chou?.on(NodeEventType.TOUCH_END, this.onClickDraw, this);
|
||||||
this.cards_up?.on(NodeEventType.TOUCH_END, this.onClickUpgrade, this);
|
this.cards_up?.on(NodeEventType.TOUCH_END, this.onClickUpgrade, this);
|
||||||
}
|
}
|
||||||
|
private onCoinAdd(args:any){
|
||||||
|
this.updatePoolLvUI();
|
||||||
|
this.updateCoinUI();
|
||||||
|
}
|
||||||
|
|
||||||
/** 解除按钮监听,避免节点销毁后回调泄漏 */
|
/** 解除按钮监听,避免节点销毁后回调泄漏 */
|
||||||
private unbindEvents() {
|
private unbindEvents() {
|
||||||
this.cards_chou?.off(NodeEventType.TOUCH_END, this.onClickDraw, this);
|
this.cards_chou?.off(NodeEventType.TOUCH_END, this.onClickDraw, this);
|
||||||
@@ -129,12 +139,27 @@ export class MissionCardComp extends CCComp {
|
|||||||
mLogger.log(this.debugMode, "MissionCardComp", "pool already max", this.poolLv);
|
mLogger.log(this.debugMode, "MissionCardComp", "pool already max", this.poolLv);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.poolLv += 1;
|
const cost = this.getUpgradeCost(this.poolLv);
|
||||||
if (this.poolLv >= CARD_POOL_MAX_LEVEL && this.cards_up) {
|
const currentCoin = smc.vmdata.mission_data.coin ?? 0;
|
||||||
this.cards_up.active = false;
|
if (currentCoin < cost) {
|
||||||
|
oops.gui.toast(`金币不足,升级需要${cost}`);
|
||||||
|
this.updatePoolLvUI();
|
||||||
|
mLogger.log(this.debugMode, "MissionCardComp", "pool upgrade coin not enough", {
|
||||||
|
poolLv: this.poolLv,
|
||||||
|
currentCoin,
|
||||||
|
cost
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
smc.vmdata.mission_data.coin = currentCoin - cost;
|
||||||
|
this.poolLv += 1;
|
||||||
|
this.updateCoinUI();
|
||||||
this.updatePoolLvUI();
|
this.updatePoolLvUI();
|
||||||
mLogger.log(this.debugMode, "MissionCardComp", "pool level up", this.poolLv);
|
mLogger.log(this.debugMode, "MissionCardComp", "pool level up", {
|
||||||
|
poolLv: this.poolLv,
|
||||||
|
cost,
|
||||||
|
leftCoin: smc.vmdata.mission_data.coin
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 构建本次抽卡结果,保证最终可分发4条数据 */
|
/** 构建本次抽卡结果,保证最终可分发4条数据 */
|
||||||
@@ -183,14 +208,40 @@ export class MissionCardComp extends CCComp {
|
|||||||
startX
|
startX
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
private canUpPool() {
|
||||||
|
if (this.poolLv >= CARD_POOL_MAX_LEVEL) return false;
|
||||||
|
const currentCoin = smc.vmdata.mission_data.coin ?? 0;
|
||||||
|
return currentCoin >= this.getUpgradeCost(this.poolLv);
|
||||||
|
}
|
||||||
/** 更新升级按钮上的等级文案,反馈当前卡池层级 */
|
/** 更新升级按钮上的等级文案,反馈当前卡池层级 */
|
||||||
private updatePoolLvUI() {
|
private updatePoolLvUI() {
|
||||||
if (!this.cards_up) return;
|
if (!this.cards_up) return;
|
||||||
const label = this.cards_up.getComponentInChildren(Label);
|
const nobg = this.cards_up.getChildByName("nobg");
|
||||||
|
if (nobg) {
|
||||||
|
nobg.active = !this.canUpPool();
|
||||||
|
}
|
||||||
|
const label = this.cards_up.getChildByName("coin").getChildByName("num").getComponent(Label);
|
||||||
if (!label) return;
|
if (!label) return;
|
||||||
label.string = `卡池Lv.${this.poolLv}`;
|
if (this.poolLv >= CARD_POOL_MAX_LEVEL) {
|
||||||
mLogger.log(this.debugMode, "MissionCardComp", "pool lv ui update", this.poolLv);
|
label.string = `0`;
|
||||||
|
} else {
|
||||||
|
label.string = `${this.getUpgradeCost(this.poolLv)}`;
|
||||||
|
}
|
||||||
|
mLogger.log(this.debugMode, "MissionCardComp", "pool lv ui update", {
|
||||||
|
poolLv: this.poolLv,
|
||||||
|
cost: this.getUpgradeCost(this.poolLv)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateCoinUI() {
|
||||||
|
if (!this.coins) return;
|
||||||
|
const label = this.coins.getChildByName("num")?.getComponent(Label);
|
||||||
|
if (!label) return;
|
||||||
|
label.string = `${smc.vmdata.mission_data.coin ?? 0}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getUpgradeCost(lv: number): number {
|
||||||
|
return CardsUpSet[lv] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||||
|
|||||||
Reference in New Issue
Block a user