抽卡:获取抽卡列表
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { readJsonFile, parseNumberList, parseGoodStr, decodeArrayListStr } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
import { RewardInter } from '../interface';
|
||||
|
||||
export interface DicGacha {
|
||||
// 抽卡id
|
||||
readonly id: number;
|
||||
// 抽卡次数 1次,10次
|
||||
readonly count: number[];
|
||||
// 免费次数
|
||||
readonly free: { day: number, count: number };
|
||||
// 消耗的招募券
|
||||
readonly cost: RewardInter[];
|
||||
// 概率
|
||||
readonly percent: { id: number, percent: number }[];
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_GACHA);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGacha = new Map<number, DicGacha>();
|
||||
arr.forEach(o => {
|
||||
o.count = parseNumberList(o.count);
|
||||
o.free = parseFree(o.free);
|
||||
o.cost = parseGoodStr(o.cost);
|
||||
o.percent = parsePercent(o.percent);
|
||||
dicGacha.set(o.id, o);
|
||||
});
|
||||
|
||||
|
||||
function parseFree(str: string) {
|
||||
let arr = parseNumberList(str);
|
||||
if(arr.length > 0 && arr.length != 2) {
|
||||
throw new Error('dic_gacha free format err');
|
||||
}
|
||||
if(arr.length == 0) {
|
||||
return { day: 0, count: 0 }
|
||||
} else {
|
||||
return { day: arr[0], count: arr[1] }
|
||||
}
|
||||
}
|
||||
|
||||
function parsePercent(str: string) {
|
||||
let result = new Array<{ id: number, percent: number }>();
|
||||
if (!str) return result;
|
||||
let decodeArr = decodeArrayListStr(str);
|
||||
for (let [id, percent] of decodeArr) {
|
||||
if (isNaN(parseInt(id)) || isNaN(parseInt(percent))) {
|
||||
throw new Error('data table format wrong');
|
||||
}
|
||||
result.push({ id: parseInt(id), percent: parseInt(percent) });
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { readJsonFile, parseNumberList } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicGachaContent {
|
||||
// 内容id
|
||||
readonly id: number;
|
||||
// 道具类型 见sysConst 中的 GACHA_CONTENT_TYPE
|
||||
readonly type: number;
|
||||
// 对应参数 品质,等级,物品id 等
|
||||
readonly param: number[];
|
||||
// 道具数量
|
||||
readonly count: number;
|
||||
}
|
||||
|
||||
const str = readJsonFile(FILENAME.DIC_GACHA_CONTENT);
|
||||
let arr = JSON.parse(str);
|
||||
|
||||
export const dicGachaContent = new Map<number, DicGachaContent>();
|
||||
arr.forEach(o => {
|
||||
o.param = parseNumberList(o.param);
|
||||
dicGachaContent.set(o.id, o);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user