From e14368a6e79eb3437e996c1811cba23f30701183 Mon Sep 17 00:00:00 2001 From: luying Date: Wed, 26 Oct 2022 11:04:56 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix(=E9=80=9A=E7=94=A8=E4=B8=B9)?= =?UTF-8?q?:=20=E5=BD=93=E7=AC=AC=E4=B8=80=E9=98=B6=E6=B6=88=E8=80=97?= =?UTF-8?q?=E5=A4=9F=E7=AC=AC=E4=BA=8C=E9=98=B6=E4=B8=8D=E8=B6=B3=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E5=A4=9A=E6=89=A3=E9=99=A4=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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/game-server/app/services/role/checkMaterial.ts b/game-server/app/services/role/checkMaterial.ts index 8e21d073b..4464dd130 100644 --- a/game-server/app/services/role/checkMaterial.ts +++ b/game-server/app/services/role/checkMaterial.ts @@ -52,7 +52,11 @@ export class CheckMeterial { console.log('##### notEnoughCount', id, notEnoughCount, this.canReplace) if(notEnoughCount > 0) { let isEnough = await this.checkReplaceItem(id, notEnoughCount); - if(!isEnough) return false; + if(isEnough) { + this.consumes.push({ id, count: count - notEnoughCount }); + } else { + return false; + } } } @@ -83,11 +87,10 @@ export class CheckMeterial { this.itemsIndb.set(id, item.count); } if(this.itemsIndb.get(id) < count) { - this.pushToNotEnoughItems(id, count - this.itemsIndb.get(id)); - - this.consumes.push({ id, count: this.itemsIndb.get(id) }); + let notEnoughCount = count - this.itemsIndb.get(id); + this.pushToNotEnoughItems(id, notEnoughCount); this.itemsIndb.set(id, 0); - return count - this.itemsIndb.get(id); + return notEnoughCount; } else { this.itemsIndb.set(id, this.itemsIndb.get(id) - count); this.consumes.push({ id, count }); @@ -121,7 +124,6 @@ export class CheckMeterial { let goldCost = gold.reduce((pre, cur) => { return pre + cur.count }, 0); if(this.itemsIndb.get(this.goldId) < goldCost) { this.pushToNotEnoughItems(this.goldId, goldCost - this.itemsIndb.get(this.goldId)); - this.consumes.push({ id: this.goldId, count: this.itemsIndb.get(this.goldId) }); this.itemsIndb.set(this.goldId, 0); return false; } @@ -140,7 +142,6 @@ export class CheckMeterial { let coinCost = coin.reduce((pre, cur) => pre + cur, 0); if(this.itemsIndb.get(this.coinId) < coinCost) { this.pushToNotEnoughItems(this.coinId, coinCost - this.itemsIndb.get(this.coinId)); - this.consumes.push({ id: this.coinId, count: this.itemsIndb.get(this.coinId) }); this.itemsIndb.set(this.coinId, 0); return false; }