import { mergeSameGoods } from '../pubUtils/util'; import { getGoodById } from '../pubUtils/gamedata'; import { getJewelById } from '../pubUtils/data'; const _ = require('underscore'); export function checkMaterialEnough(consumes:Array<{id: number, count: number}>, jewel: number, jewelCount: number) { 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 || !jewelInfo.count) continue; 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 * comcount, id: jewelInfo.nextSpecialId}); jewelInfo = getJewelById(jewelInfo.nextJewelId); } } if (comJewelMap[jewel] != jewelCount || Object.keys(comJewelMap).length != 1) return false; return needConsumes; }