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; }