diff --git a/game-server/app/services/role/checkMaterial.ts b/game-server/app/services/role/checkMaterial.ts index ad62481d3..8e21d073b 100644 --- a/game-server/app/services/role/checkMaterial.ts +++ b/game-server/app/services/role/checkMaterial.ts @@ -86,11 +86,13 @@ export class CheckMeterial { this.pushToNotEnoughItems(id, count - this.itemsIndb.get(id)); this.consumes.push({ id, count: this.itemsIndb.get(id) }); + this.itemsIndb.set(id, 0); return count - this.itemsIndb.get(id); + } else { + this.itemsIndb.set(id, this.itemsIndb.get(id) - count); + this.consumes.push({ id, count }); + return 0 } - this.itemsIndb.set(id, this.itemsIndb.get(id) - count); - this.consumes.push({ id, count }); - return 0 } private async checkReplaceItem(id: number, count: number) { @@ -120,6 +122,7 @@ export class CheckMeterial { 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; } this.itemsIndb.set(this.goldId, this.itemsIndb.get(this.goldId) - goldCost); @@ -138,6 +141,7 @@ export class CheckMeterial { 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; } this.itemsIndb.set(this.coinId, this.itemsIndb.get(this.coinId) - coinCost);