Files
ZYZ/game-server/app/services/equipService.ts
mamengke01 8a2b9d393a 宝石
2020-12-24 13:59:49 +08:00

46 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}