宝石
This commit is contained in:
@@ -14,22 +14,30 @@ import { gameData, getJewelById } from '../pubUtils/data';
|
||||
const _ = require('underscore');
|
||||
|
||||
export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) {
|
||||
consumes = mergeSameGoods(consumes);
|
||||
let comJewelMap = {};
|
||||
consumes = mergeSameGoods(consumes);
|
||||
let needConsumes: Array<{id: number, count: number}> = [];
|
||||
let gidJewelInfo = getGoodById(jewel);
|
||||
for (let { id, count } of consumes) {
|
||||
let jewelInfo = getJewelById(id);
|
||||
if (!jewelInfo)
|
||||
if (!jewelInfo || !jewelInfo.count)
|
||||
continue;
|
||||
let comcount = Math.floor((count + (comJewelMap[jewelInfo.good_id] || 0)) / jewelInfo.count);
|
||||
if (comcount < 1) {
|
||||
return false;
|
||||
needConsumes.push({ id, count});
|
||||
comJewelMap[jewelInfo.good_id] = count + (comJewelMap[jewelInfo.good_id] || 0);
|
||||
for (let i = jewelInfo.lvLimited; i < gidJewelInfo.lvLimited; i++) {
|
||||
if (((comJewelMap[jewelInfo.good_id] || 0) % jewelInfo.count != 0)) {
|
||||
break;
|
||||
}
|
||||
let comcount = Math.floor(((comJewelMap[jewelInfo.good_id] || 0)) / jewelInfo.count);
|
||||
if (comcount < 1) {
|
||||
break;
|
||||
}
|
||||
comJewelMap[jewelInfo.nextJewelId] = comcount + (comJewelMap[jewelInfo.nextJewelId] || 0);
|
||||
delete comJewelMap[jewelInfo.good_id];
|
||||
if (!!jewelInfo.specialCount)
|
||||
needConsumes.push({ count: jewelInfo.specialCount, id: jewelInfo.nextSpecialId});
|
||||
jewelInfo = getJewelById(jewelInfo.nextJewelId);
|
||||
}
|
||||
needConsumes.push({ id, count });
|
||||
if (!!jewelInfo.specialMaterial.ids.length)
|
||||
needConsumes.push({ id: jewelInfo.specialMaterial.ids[0], count: jewelInfo.specialMaterial.count});
|
||||
delete comJewelMap[jewelInfo.good_id];
|
||||
comJewelMap[jewelInfo.nextJewelId] = comcount + (comJewelMap[jewelInfo.nextJewelId] || 0);
|
||||
}
|
||||
if (comJewelMap[jewel] != jewelCount || Object.keys(comJewelMap).length != 1)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user