🐞 fix(养成消耗): 多道具消耗判断不足时会多扣减一部分道具
This commit is contained in:
@@ -11,6 +11,7 @@ export class CheckMeterial {
|
||||
private notEnoughItems: Map<number, number> = 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user