// 物品表 import {decodeArrayListStr, readJsonFile, parseGoodStr, parseNumberList, decodeArrayStr} from '../util' import { FILENAME, IT_TYPE, ABI_TYPE , GOOD_TYPE} from '../../consts' import { RewardInter } from '../interface'; const _ = require('lodash'); const underscore = require('underscore'); export interface SpecialMaterial { readonly ids: number[]; readonly count: number; } export interface DicGoods { // 物品id readonly good_id: number; // 物品名 readonly name: string; // 等级限制 readonly lvLimited: number; // 合成装备需要的碎片数 readonly pieces: number; // 对应的碎片id readonly pieceId: number; // 合成材料 readonly composeMaterial: Array; // 特殊材料 readonly specialMaterial: SpecialMaterial; // 分解所得 readonly decomposeItem: Array; // 物品品质 readonly quality: number; // 洞数 readonly hole: number; // 随机属性范围 readonly randomEffect: Array; // 类型id readonly itid: number; // 物品类型 readonly goodType: number; // 将魂对应武将id readonly hid: number; // 属性 readonly goodsAbility:Map; // 强化属性 readonly goodsAbilityUp:Map; // 套装id readonly suitId: number; // 特殊属性 readonly specialAttr: Map; // 属性外加的值,经验,好感 readonly value: number; readonly count?: number; readonly nextJewelId?: number; readonly specialCount?: number; readonly nextSpecialId?: number; } const str = readJsonFile(FILENAME.DIC_GOODS); let arr = JSON.parse(str); type KeysEnum = { [P in keyof Required]: true }; const DicGoodsKeys: KeysEnum = { good_id: true, name: true, lvLimited: true, pieces: true, composeMaterial: true, specialMaterial: true, decomposeItem: true, quality: true, hole: true, randomEffect: true, itid: true, goodType: true, hid: true, goodsAbility: true, goodsAbilityUp: true, suitId: true, specialAttr: true, value: true, pieceId: true, count: true, nextJewelId: true, specialCount: true, nextSpecialId: true } export const dicJewel = new Map(); export const dicGoods = new Map(); export const blueprt = new Map>(); arr.forEach(o => { o.goodsAbility = parseAbility(o); o.goodsAbilityUp = parseAbilityUp(o); o.composeMaterial = parseGoodStr(o.composeMaterial); o.decomposeItem = parseGoodStr(o.decomposeItem); o.specialAttr = parseSpecialAttr(o.specialAttr); o.specialMaterial = parseSpecialMaterial(o.specialMaterial); o.randomEffect = parseNumberList(o.randomEffect); dicGoods.set(o.good_id, _.pick(o, Object.keys(DicGoodsKeys))); if (o.itid == IT_TYPE.BLUEPRT) { let arr = blueprt.get(o.quality)||new Array(); arr.push(o.good_id); blueprt.set(o.quality, arr); } else if (o.goodType == GOOD_TYPE.JEWEL) { let material = o.composeMaterial[0]; if (!!material && !!material.id) { let lastJewel = underscore.findWhere(arr,{good_id:material.id}); if (!!lastJewel) { lastJewel.count = material.count; lastJewel.nextJewelId = o.good_id; if (!!o.specialMaterial.ids[0]) { lastJewel.specialCount = o.specialMaterial.count; lastJewel.nextSpecialId = o.specialMaterial.ids[0]; } dicJewel.set(lastJewel.good_id, _.pick(lastJewel, Object.keys(DicGoodsKeys))); } } else { dicJewel.set(o.good_id, _.pick(o, Object.keys(DicGoodsKeys))); } } }); arr = undefined; function parseSpecialAttr(str: string) { let specialAttr = new Map(); if(str) { let decodeArr = decodeArrayListStr(str); for(let [type, count] of decodeArr) { if(isNaN(parseInt(type)) || isNaN(parseInt(count))) { throw new Error('data table format wrong'); } specialAttr.set(parseInt(type), parseInt(count)); } } return specialAttr; } function parseAbility(json) { let map = new Map(); map.set(ABI_TYPE.ABI_HP, json.hp||0); map.set(ABI_TYPE.ABI_ATK, json.atk||0); map.set(ABI_TYPE.ABI_MATK, json.matk||0); map.set(ABI_TYPE.ABI_DEF, json.def||0); map.set(ABI_TYPE.ABI_MDEF, json.mdef||0); map.set(ABI_TYPE.ABI_AGI, json.agi||0); map.set(ABI_TYPE.ABI_LUK, json.luk||0); map.set(ABI_TYPE.ABI_SPEED, json.speed||0); return map } function parseAbilityUp(json) { let map = new Map(); map.set(ABI_TYPE.ABI_HP, json.hp_up||0); map.set(ABI_TYPE.ABI_ATK, json.atk_up||0); map.set(ABI_TYPE.ABI_MATK, json.matk_up||0); map.set(ABI_TYPE.ABI_DEF, json.def_up||0); map.set(ABI_TYPE.ABI_MDEF, json.mdef_up||0); map.set(ABI_TYPE.ABI_AGI, json.agi_up||0); map.set(ABI_TYPE.ABI_LUK, json.luk_up||0); map.set(ABI_TYPE.ABI_SPEED, json.speed_up||0); return map } function parseSpecialMaterial(str: string) { let specialAttr = {ids: new Array(), count: 0} if(!str) return specialAttr; let decodeArr = decodeArrayStr(str); if(decodeArr.length >= 2) { let ids = parseNumberList(decodeArr[0]); let count = parseInt(decodeArr[1]); if(isNaN(count)) return specialAttr; specialAttr.ids = ids; specialAttr.count = count; } return specialAttr; }