import { ITID, CONSUME_TYPE, getCurNameById, ITEM_TABLE } from './../consts'; import { EquipModel } from './../db/Equip'; import { resResult, deepCopy, mergeSameGoods } from '../pubUtils/util'; import { getGoodById } from '../pubUtils/gamedata'; import { RoleModel } from '../db/Role'; importĀ { setAp } from './actionPointService'; import { calAllHeroCe } from './playerCeService'; import { ItemModel } from '../db/Item'; import { STATUS } from '../consts/statusCode'; import { pinus } from 'pinus'; import { addEquips, addBags, addSkins } from '../pubUtils/itemUtils'; import { EquipInter, ItemInter, BagInter } from '../pubUtils/interface'; import { gameData, 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; }