Files
ZYZ/shared/pubUtils/dictionary/DicArtifactLvPlan.ts
2022-12-08 15:49:51 +08:00

54 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 物品表
import { readFileAndParse, parseGoodStr, decodeArrayListStr, } from '../util'
import { FILENAME, } from '../../consts'
import { RewardInter } from '../interface';
const _ = require('lodash');
export interface DicArtifactLvPlan {
// 方案id
planId: number;
// 等级
lv: number;
// 升到这级需要消耗什么id&count
consumes: RewardInter[];
// 这级的属性
attr: {id: number, attr: number}[];
}
type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicArtifactLvPlanKeys: KeysEnum<DicArtifactLvPlan> = {
planId: true,
lv: true,
consumes: true,
attr: true,
}
export const dicArtifactLvPlan = new Map<number, Map<number, DicArtifactLvPlan>>(); // planId => lv => dic
export function loadArtifactLvPlan() {
dicArtifactLvPlan.clear();
let arr = readFileAndParse(FILENAME.DIC_ARTIFACT_LV_PLAN);
arr.forEach(o => {
o.consumes = parseGoodStr(o.consumes);
o.attr = parseAttr(o.attr);
if(!dicArtifactLvPlan.has(o.planId)) {
dicArtifactLvPlan.set(o.planId, new Map());
}
dicArtifactLvPlan.get(o.planId)?.set(o.lv, _.pick(o, Object.keys(DicArtifactLvPlanKeys)));
});
arr = undefined;
}
function parseAttr(str: string) {
let result = new Array<{id: number, attr: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [id, attr] of decodeArr) {
if(isNaN(parseInt(id)) || isNaN(parseInt(attr))) {
throw new Error('data table format wrong');
}
result.push({id: parseInt(id), attr: parseInt(attr)});
}
return result
}