fix 合成藏宝图中的bug
This commit is contained in:
@@ -422,7 +422,7 @@ export class ComBattleHandler {
|
||||
const { original } = msg;
|
||||
|
||||
// 原材料检查
|
||||
let originalQuality: number, originalSum: number;
|
||||
let originalQuality: number, originalSum: number = 0;
|
||||
for(let {id, count} of original) {
|
||||
const goodInfo = getGoodById(id);
|
||||
if(!originalQuality) originalQuality = goodInfo.quality;
|
||||
@@ -450,7 +450,7 @@ export class ComBattleHandler {
|
||||
}
|
||||
// 添加寻宝币
|
||||
original.push({
|
||||
id: CURRENCY_BY_TYPE[CURRENCY_TYPE.TREASURE_POINT],
|
||||
id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.TREASURE_POINT),
|
||||
count: dicCompose.coinNum
|
||||
});
|
||||
// 消耗藏宝图和寻宝币
|
||||
@@ -467,6 +467,6 @@ export class ComBattleHandler {
|
||||
const goods = await handleReward(roleId, roleName, reward);
|
||||
|
||||
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
return resResult(STATUS.SUCCESS, { ...goods, costGold });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,15 +39,17 @@ export default class Item extends BaseModel {
|
||||
}
|
||||
|
||||
public static async decreaseItems(roleId: string, items: Array<{id: number, count: number}>, lean = true) {
|
||||
let wrongItems = new Array<{id: number, count: number}>();
|
||||
let updateItems = new Array<{id: number, count: number}>(), hasError: boolean = false;
|
||||
for(let {id, count} of items) {
|
||||
const rec = await ItemModel.findOneAndUpdate({roleId, id, count: {$gte: count} },{ $inc: { count: -1 * count }}, {new: true}).lean(lean);
|
||||
if(!rec) {
|
||||
wrongItems.push({id, count}); break;
|
||||
if(rec) {
|
||||
updateItems.push({id, count});
|
||||
} else {
|
||||
hasError = true; break;
|
||||
}
|
||||
}
|
||||
if(wrongItems.length > 0) { // 数量不足
|
||||
for(let {id, count} of wrongItems) {
|
||||
if(hasError) { // 数量不足
|
||||
for(let {id, count} of updateItems) {
|
||||
await ItemModel.findOneAndUpdate({roleId, id },{ $inc: { count }}, {new: true}).lean(lean);
|
||||
}
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user