品质统一在boxset设定

This commit is contained in:
2025-08-18 21:03:47 +08:00
parent 3884b35829
commit 9e1459973c
18 changed files with 368 additions and 377 deletions

View File

@@ -35,14 +35,7 @@ export class SingletonModuleComp extends ecs.Comp {
diamond:100, //商店购买 及 双倍奖励资源
meat:0,
exp:0, //升级经验
ghstone:0, //英雄石 绿色 普通英雄升星
bhstone:0, //英雄石 蓝色 稀有英雄升星
phlestone:0, //英雄石 紫色 史诗英雄升星
rhstone:0, //英雄石 红色 传说英雄升星
herocard:0, //英雄卡,抽卡凭证
ckey:0, //铜钥匙 解锁稀有英雄 也可以直接兑换金币
skey:0, //银钥匙 解锁史诗英雄 也可以直接兑换金币
gkey:0, //金钥匙 解锁传说英雄 也可以直接兑换金币
}
fight_heros:any={ 0:5001, 1:5005, 2:0, 3:0, 4:0, }
heros:any = {
@@ -188,21 +181,53 @@ export class SingletonModuleComp extends ecs.Comp {
/**
* 消耗游戏数据属性(统一接口)
* @param property 属性名
* @param value 消耗的值
* - 支持单个字段spendGameProperty('gold', 10)
* - 支持多个字段spendGameProperty({ gold: 10, exp: 5 })
* 只有当所有字段都满足扣除条件时,才会一次性扣减
* @param property 属性名或属性映射
* @param value 消耗的值(当 property 为字符串时有效)
* @param autoSave 是否自动保存 (默认true)
* @returns 是否成功消耗
*/
async spendGameProperty(property: string, value: any, autoSave: boolean = true): Promise<boolean> {
const currentValue = this.data[property] || 0;
if (currentValue < value) {
console.warn(`[SMC]: ${property} 不足,当前: ${currentValue}, 需要: ${value}`);
return false;
async spendGameProperty(property: string | Record<string, number>, value: any = undefined, autoSave: boolean = true): Promise<boolean> {
// 单字段扣除
if (typeof property === 'string') {
const currentValue = this.data[property] || 0;
if (currentValue < value) {
console.warn(`[SMC]: ${property} 不足,当前: ${currentValue}, 需要: ${value}`);
return false;
}
const newValue = currentValue - value;
this.data[property] = newValue;
this.vmdata.data[property] = newValue;
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}, 当前值: ${newValue}`);
return true;
}
const newValue = currentValue - value;
this.data[property] = newValue;
this.vmdata.data[property] = newValue;
console.log(`[SMC]: 消耗游戏数据 ${property} = ${value}, 当前值: ${newValue}`);
// 多字段扣除(原子性:全部满足才扣)
const deductions = property as Record<string, number>;
// 1) 校验是否全部满足
for (const key in deductions) {
if (!Object.prototype.hasOwnProperty.call(deductions, key)) continue;
const need = deductions[key] ?? 0;
const current = this.data[key] || 0;
if (current < need) {
console.warn(`[SMC]: ${key} 不足,当前: ${current}, 需要: ${need}`);
return false;
}
}
// 2) 统一扣减
for (const key in deductions) {
if (!Object.prototype.hasOwnProperty.call(deductions, key)) continue;
const need = deductions[key] ?? 0;
const current = this.data[key] || 0;
const next = current - need;
this.data[key] = next;
this.vmdata.data[key] = next;
console.log(`[SMC]: 消耗游戏数据 ${key} = ${need}, 当前值: ${next}`);
}
return true;
}