抽卡:添加抽卡接口

This commit is contained in:
luying
2021-04-23 15:46:04 +08:00
parent 1f6839cafb
commit beadccf778
23 changed files with 591 additions and 85 deletions
+6 -6
View File
@@ -12,13 +12,13 @@ export interface DicGacha {
// 消耗的招募券
readonly cost: RewardInter[];
// 概率
readonly percent: { id: number, percent: number }[];
readonly percent: { id: number, weight: number }[];
}
const str = readJsonFile(FILENAME.DIC_GACHA);
let arr = JSON.parse(str);
export const dicGacha = new Map<number, DicGacha>();
export const dicGacha = new Map<number, DicGacha>(); // id => dic
arr.forEach(o => {
o.count = parseNumberList(o.count);
o.free = parseFree(o.free);
@@ -41,14 +41,14 @@ function parseFree(str: string) {
}
function parsePercent(str: string) {
let result = new Array<{ id: number, percent: number }>();
let result = new Array<{ id: number, weight: number }>();
if (!str) return result;
let decodeArr = decodeArrayListStr(str);
for (let [id, percent] of decodeArr) {
if (isNaN(parseInt(id)) || isNaN(parseInt(percent))) {
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), percent: parseInt(percent) });
result.push({ id: parseInt(id), weight: parseInt(weight) });
}
return result
}