Files
ZYZ/shared/pubUtils/dictionary/DicRandomEffectPool.ts
2022-02-17 14:26:07 +08:00

52 lines
1.5 KiB
TypeScript

// 武将特技表
import { readFileAndParse, decodeArrayListStr, parseNumberList } from '../util'
import { FILENAME } from '../../consts'
export interface DicRandomEffectPool {
// 特技id
readonly id: number;
// 类型
readonly type: number;
// 包含的值
readonly gainValueArr: Array<number>;
// 随机值位置
readonly index: number;
// 随机最小值
readonly Min: number;
// 随机最大值
readonly Max: number;
// 分割
readonly gap: number;
// 分割
readonly rate: {min: number, max: number, weight: number}[];
}
export const dicRandomEffectPool = new Map<number, DicRandomEffectPool>();
export function loadRandomEffectPool() {
dicRandomEffectPool.clear();
let arr = readFileAndParse(FILENAME.DIC_RANDOM_EFFECT_POOL);
arr.forEach(o => {
o.rate = parseRate(o.count);
o.gainValueArr = parseNumberList(o.gainvalue);
dicRandomEffectPool.set(o.id, o);
});
arr = undefined;
}
function parseRate(str: string) {
let result: {min: number, max: number, weight: number}[] = [];
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [min, max, weight] of decodeArr) {
if(isNaN(parseInt(min)) || isNaN(parseInt(max)) || isNaN(parseInt(weight))) {
throw new Error('data table format wrong');
}
result.push({min: parseInt(min), max: parseInt(max), weight: parseInt(weight) });
}
return result
}