Files
ZYZ/shared/pubUtils/dictionary/DicTitle.ts
mamengke01 8cad1f80d4 战力
2020-12-28 17:11:53 +08:00

64 lines
1.7 KiB
TypeScript

// 物品表
import { decodeArrayListStr, readJsonFile, parseGoodStr } from '../util'
import { FILENAME} from '../../consts'
const _ = require('lodash');
export interface SpecialMaterial {
readonly ids: number[];
readonly count: number;
}
export interface DicTitle {
// 等级
readonly id: number;
readonly hp: number;
readonly atk: number;
readonly def: number;
readonly mdef: number;
readonly agi: number;
readonly luk: number;
readonly assiAttrValue: Array<{id: number, number: number}>;
// 等级现在
readonly lvLimited: number;
// 升级消耗
readonly material:Array<{id: number, number: number}>;
}
const str = readJsonFile(FILENAME.DIC_TITLE);
let arr = JSON.parse(str);
type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicTitleKeys: KeysEnum<DicTitle> = {
id: true,
hp: true,
atk: true,
def: true,
mdef: true,
agi: true,
luk: true,
assiAttrValue: true,
lvLimited: true,
material: true
}
export const dicTitle = new Map<number, DicTitle>();
arr.forEach(o => {
o.assiAttrValue = parseAttr(o.assiAttrValue);
o.material = parseGoodStr(o.material);
dicTitle.set(o.id, _.pick(o, Object.keys(DicTitleKeys)));
});
arr = undefined;
function parseAttr(str: string) {
let result = new Array<{id: number, number: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [id, number] of decodeArr) {
if(isNaN(parseInt(id)) || isNaN(parseInt(number))) {
throw new Error('data table format wrong');
}
result.push({id: parseInt(id), number: parseInt(number)});
}
return result
}