feat(宝物): 添加宝物系统

This commit is contained in:
luying
2022-12-07 10:55:30 +08:00
parent b684307818
commit a83deeff5f
46 changed files with 15656 additions and 54 deletions

View File

@@ -0,0 +1,54 @@
// 物品表
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
}