🐞 fix(养成消耗): 多道具消耗判断不足时会多扣减一部分道具
This commit is contained in:
@@ -11,6 +11,7 @@ export class CheckMeterial {
|
|||||||
private notEnoughItems: Map<number, number> = new Map(); // 缺少的数量
|
private notEnoughItems: Map<number, number> = new Map(); // 缺少的数量
|
||||||
private consumes: ItemInter[] = []; // 消耗,正向数
|
private consumes: ItemInter[] = []; // 消耗,正向数
|
||||||
private canReplace: boolean = false; // 是否可以被通用的啥代替代替
|
private canReplace: boolean = false; // 是否可以被通用的啥代替代替
|
||||||
|
private tempConsumes: ItemInter[] = [];
|
||||||
|
|
||||||
private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
|
private goldId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD);
|
||||||
private coinId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
|
private coinId = CURRENCY_BY_TYPE.get(CURRENCY_TYPE.COIN);
|
||||||
@@ -44,6 +45,7 @@ export class CheckMeterial {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async decrease(goods: {id: number, count: number}[]) {
|
public async decrease(goods: {id: number, count: number}[]) {
|
||||||
|
this.tempConsumes.splice(0, this.tempConsumes.length);
|
||||||
this.notEnoughItems.clear();
|
this.notEnoughItems.clear();
|
||||||
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
let { items, gold, coin } = sortItems(goods, HANDLE_REWARD_TYPE.COST);
|
||||||
for(let { id, count} of items) {
|
for(let { id, count} of items) {
|
||||||
@@ -53,7 +55,7 @@ export class CheckMeterial {
|
|||||||
if(notEnoughCount > 0) {
|
if(notEnoughCount > 0) {
|
||||||
let isEnough = await this.checkReplaceItem(id, notEnoughCount);
|
let isEnough = await this.checkReplaceItem(id, notEnoughCount);
|
||||||
if(isEnough) {
|
if(isEnough) {
|
||||||
this.consumes.push({ id, count: count - notEnoughCount });
|
this.tempConsumes.push({ id, count: count - notEnoughCount });
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -68,6 +70,7 @@ export class CheckMeterial {
|
|||||||
let isEnough = await this.decreaseCoin(coin);
|
let isEnough = await this.decreaseCoin(coin);
|
||||||
if(!isEnough) return false;
|
if(!isEnough) return false;
|
||||||
}
|
}
|
||||||
|
this.consumes.push(...this.tempConsumes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +96,7 @@ export class CheckMeterial {
|
|||||||
return notEnoughCount;
|
return notEnoughCount;
|
||||||
} else {
|
} else {
|
||||||
this.itemsIndb.set(id, this.itemsIndb.get(id) - count);
|
this.itemsIndb.set(id, this.itemsIndb.get(id) - count);
|
||||||
this.consumes.push({ id, count });
|
this.tempConsumes.push({ id, count });
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,7 +131,7 @@ export class CheckMeterial {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.itemsIndb.set(this.goldId, this.itemsIndb.get(this.goldId) - goldCost);
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +149,7 @@ export class CheckMeterial {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.itemsIndb.set(this.coinId, this.itemsIndb.get(this.coinId) - coinCost);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user