From 8b68f9e2676ec753675953bb057fb29342a75bb0 Mon Sep 17 00:00:00 2001 From: luying Date: Fri, 11 Nov 2022 17:47:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(=E5=85=BB=E6=88=90=E6=B6=88?= =?UTF-8?q?=E8=80=97):=20=E5=A4=9A=E9=81=93=E5=85=B7=E6=B6=88=E8=80=97?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=8D=E8=B6=B3=E6=97=B6=E4=BC=9A=E5=A4=9A?= =?UTF-8?q?=E6=89=A3=E5=87=8F=E4=B8=80=E9=83=A8=E5=88=86=E9=81=93=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game-server/app/services/role/checkMaterial.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/game-server/app/services/role/checkMaterial.ts b/game-server/app/services/role/checkMaterial.ts index 4464dd130..c4f95738e 100644 --- a/game-server/app/services/role/checkMaterial.ts +++ b/game-server/app/services/role/checkMaterial.ts @@ -11,6 +11,7 @@ export class CheckMeterial { private notEnoughItems: Map = new Map(); // 缺少的数量 private consumes: ItemInter[] = []; // 消耗,正向数 private canReplace: boolean = false; // 是否可以被通用的啥代替代替 + private tempConsumes: ItemInter[] = []; private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD); private coinId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN); @@ -44,6 +45,7 @@ export class CheckMeterial { } public async decrease(goods: {id: number, count: number}[]) { + this.tempConsumes.splice(0, this.tempConsumes.length); this.notEnoughItems.clear(); let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST); for(let { id, count} of items) { @@ -53,7 +55,7 @@ export class CheckMeterial { if(notEnoughCount > 0) { let isEnough = await this.checkReplaceItem(id, notEnoughCount); if(isEnough) { - this.consumes.push({ id, count: count - notEnoughCount }); + this.tempConsumes.push({ id, count: count - notEnoughCount }); } else { return false; } @@ -68,6 +70,7 @@ export class CheckMeterial { let isEnough = await this.decreaseCoin(coin); if(!isEnough) return false; } + this.consumes.push(...this.tempConsumes); return true; } @@ -93,7 +96,7 @@ export class CheckMeterial { return notEnoughCount; } else { this.itemsIndb.set(id, this.itemsIndb.get(id) - count); - this.consumes.push({ id, count }); + this.tempConsumes.push({ id, count }); return 0 } } @@ -128,7 +131,7 @@ export class CheckMeterial { return false; } this.itemsIndb.set(this.goldId, this.itemsIndb.get(this.goldId) - goldCost); - this.consumes.push({ id: this.goldId, count: goldCost }); + this.tempConsumes.push({ id: this.goldId, count: goldCost }); return true } @@ -146,7 +149,7 @@ export class CheckMeterial { return false; } this.itemsIndb.set(this.coinId, this.itemsIndb.get(this.coinId) - coinCost); - this.consumes.push({ id: this.coinId, count: coinCost }); + this.tempConsumes.push({ id: this.coinId, count: coinCost }); return true; }