添加字典表解析
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// 藏宝图掉落率
|
||||
import { decodeArrayListStr, readJsonFile } from '../util'
|
||||
import { FILENAME } from '../../consts/consts'
|
||||
|
||||
export interface DicBlueprtPossibility {
|
||||
|
||||
// 君主等级下限
|
||||
readonly min: number;
|
||||
// 君主等级上限
|
||||
readonly max: number;
|
||||
// 掉落概率
|
||||
readonly possibility: Array<{id: number, weight: number}>;
|
||||
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_BLUEPRT_POSSIBILITY);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicBlueprtPossibility = new Array<DicBlueprtPossibility>();
|
||||
arr.forEach(o => {
|
||||
o.possibility = parsePossibility(o.possibility);
|
||||
dicBlueprtPossibility.push(o);
|
||||
});
|
||||
|
||||
|
||||
function parsePossibility(str: string) {
|
||||
let result = new Array<{id: number, weight: number}>();
|
||||
if(!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for(let [id, weight] of decodeArr) {
|
||||
if(isNaN(parseInt(id)) || isNaN(parseInt(weight))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({id: parseInt(id), weight: parseInt(weight)});
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user