diff --git a/game-server/app/services/rewardService.ts b/game-server/app/services/rewardService.ts index 5833d343d..520288f3d 100644 --- a/game-server/app/services/rewardService.ts +++ b/game-server/app/services/rewardService.ts @@ -73,13 +73,14 @@ export class CheckMeterial { let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0); if(this.itemsIndb.get(this.goldId) < goldCost) isEnough = false; } - if(isEnough && coin > 0) { + if(isEnough && coin.length > 0) { if(!this.itemsIndb.has(this.coinId)) { let role = await RoleModel.findByRoleId(this.roleId, 'gold coin'); this.itemsIndb.set(this.goldId, role.gold); this.itemsIndb.set(this.coinId, role.coin); } - if(this.itemsIndb.get(this.coinId) < coin) isEnough = false; + let coinCost = coin.reduce((pre, cur) => pre + cur, 0); + if(this.itemsIndb.get(this.coinId) < coinCost) isEnough = false; } if(isEnough) this.consumes.push(...goods); @@ -101,10 +102,11 @@ export async function handleCost(roleId: string, sid: string, goods: Array 0 || coin > 0) { + if (gold.length > 0 || coin.length > 0) { let { gold: originGold, coin: originCoin } = role; for(let {count} of gold) { originGold -= count }; - if(originGold < 0 || originCoin < coin) return false; + for(let count of coin) { originCoin -= count }; + if(originGold < 0 || originCoin < 0) return false; } //检查装备是否存在 if (equips.length > 0) { @@ -147,8 +149,9 @@ export async function handleCost(roleId: string, sid: string, goods: Array 0 || coin > 0) { - role = await RoleModel.decreaseGoldAndCoin(roleId, gold, coin); + if (gold.length > 0 || coin.length > 0) { + let costCoin = coin.reduce((pre, cur) => pre + cur, 0); + role = await RoleModel.decreaseGoldAndCoin(roleId, gold, costCoin); pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, { gold: role.gold, coin: role.coin }), uids); @@ -210,10 +213,10 @@ export async function addItems(roleId: string, roleName: string, sid: string, go } // 3. 货币推送 - if(gold.length > 0 || coin > 0 || ap > 0) { + if(gold.length > 0 || coin.length > 0 || ap > 0) { let { ap: addAp } = await setAp(roleId, role.lv, ap, sid); - - role = await RoleModel.increaseGoldAndCoin(roleId, gold, coin); + let incCoin = coin.reduce((pre, cur) => pre + cur, 0); + role = await RoleModel.increaseGoldAndCoin(roleId, gold, incCoin); pinus.app.get('channelService').pushMessageByUids('onPlayerDataChange', resResult(STATUS.SUCCESS, { gold: role.gold, coin: role.coin, ap: addAp }), uids); @@ -222,8 +225,10 @@ export async function addItems(roleId: string, roleName: string, sid: string, go showItems.push(getGoldObject(count)); }); } - if(coin > 0) { - showItems.push(getCoinObject(coin)); + if(coin.length > 0) { + coin.forEach(count => { + showItems.push(getCoinObject(count)); + }); } if(ap > 0) { showItems.push(getApObject(ap)); @@ -292,7 +297,7 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) { let items: { id: number, count: number }[] = []; // 可叠加道具 let equips: { seqId?: number, id?: number, hid?: number }[] = []; // 不可叠加装备 let gold: { count: number, isPay: boolean }[] = []; // 金币 - let coin: number = 0; + let coin: number[] = []; let ap: number = 0; let skins: number[] = []; let figures: number[] = []; @@ -346,7 +351,7 @@ function sortItems(goods: ItemInter[], handleType: HANDLE_REWARD_TYPE) { gold.push({ count: good.count, isPay: !!good.isPay }); } } else if (dicCurrency.type == CURRENCY_TYPE.COIN) { // 铜钱 - coin += good.count; + coin.push(good.count); } else if (dicCurrency.type == CURRENCY_TYPE.ACTION_POINT) { // 体力 ap += good.count; }