Files
ZYZ/shared/pubUtils/dictionary/DicGiftPackage.ts
2021-10-15 18:16:05 +08:00

43 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 礼包奖励表
import { decodeArrayListStr, readFileAndParse } from '../util';
import { FILENAME } from '../../consts';
import { RewardParam } from '../../domain/activityField/rewardField';
export interface DicGiftPackage {
// 礼包id
readonly id: number;
// 礼包类型 GIFT_PACKAGE_TYPE 1.全部2.选择3.随机
readonly type: number;
// 个数 type=1时无效
readonly count: number;
// 礼包内容
readonly reward: Array<RewardParam>;
// 描述
readonly des: string;
}
export const dicGiftPackage = new Map<number, DicGiftPackage>();
export function loadGiftPackage() {
dicGiftPackage.clear();
let arr = readFileAndParse(FILENAME.DIC_GIFT_PACKAGE);
arr.forEach(o => {
o.reward = parseAttr(o.reward);
dicGiftPackage.set(o.id, o);
});
arr = undefined;
}
function parseAttr(str: string) {
let result = new Array<{ type: number, id: number, count: number }>();
if (!str) return result;
let decodeArr = decodeArrayListStr(str);
for (let [type, id, count] of decodeArr) {
if (isNaN(parseInt(type)) || isNaN(parseInt(id)) || isNaN(parseInt(count))) {
throw new Error('data table format wrong');
}
result.push({ type: parseInt(type), id: parseInt(id), count: parseInt(count) });
}
return result
}