74 lines
2.4 KiB
TypeScript
74 lines
2.4 KiB
TypeScript
import { readFileAndParse } from '../util'
|
|
import { FILENAME } from '../../consts'
|
|
import { decodeArrayListStr } from '../../pubUtils/util';
|
|
|
|
export interface AuctionBasicPool {
|
|
readonly id: number; // 物品id
|
|
readonly count: number; // 数量
|
|
readonly weight: number; // 随机权重
|
|
}
|
|
|
|
export interface DicAuctionBasicPool {
|
|
readonly id: number; // 唯一id
|
|
readonly rewardBasicPool: AuctionBasicPool[];
|
|
}
|
|
|
|
export interface DicAuctionReward {
|
|
|
|
readonly poolId: number;
|
|
// 目标品质
|
|
readonly rewardId: { id: number; count: number; }[]
|
|
}
|
|
|
|
interface DicAuctionPool {
|
|
readonly id: number; // basicPool的id
|
|
readonly count: number; // 份数
|
|
readonly basicPool: AuctionBasicPool[]; // 随机池
|
|
}
|
|
|
|
export const dicAuctionPool = new Map<number, DicAuctionPool[]>(); // poolId => DicAuctionPool
|
|
export function loadAuctionReward() {
|
|
dicAuctionPool.clear();
|
|
let basicPoolMap = new Map<number, AuctionBasicPool[]>(); // id => AuctionBasicPool
|
|
let arr = readFileAndParse(FILENAME.DIC_AUCTION_BASIC_POOL);
|
|
arr.forEach(o => {
|
|
let rewardBasicPool = parseRewardBasicPool(o.rewardBasicPool);
|
|
basicPoolMap.set(o.id, rewardBasicPool);
|
|
});
|
|
arr = undefined;
|
|
let arr2 = readFileAndParse(FILENAME.DIC_AUCTION_REWARD);
|
|
arr2.forEach(o => {
|
|
let rewardId = parseRewardId(o.rewardId);
|
|
dicAuctionPool.set(o.poolId, rewardId.map(({ id, count }) => {
|
|
let basicPool = basicPoolMap.get(id);
|
|
return { id, count, basicPool}
|
|
}));
|
|
});
|
|
arr2 = undefined;
|
|
}
|
|
|
|
function parseRewardBasicPool(str: string) {
|
|
let result = new Array<AuctionBasicPool>();
|
|
if (!str) return result;
|
|
let decodeArr = decodeArrayListStr(str);
|
|
for (let [id, count, weight] of decodeArr) {
|
|
if (isNaN(parseInt(id)) || isNaN(parseInt(count)) || isNaN(parseInt(weight))) {
|
|
throw new Error('data table format wrong');
|
|
}
|
|
result.push({ id: parseInt(id), count: parseInt(count), weight: parseInt(weight) });
|
|
}
|
|
return result
|
|
}
|
|
|
|
function parseRewardId(str: string) {
|
|
let result = new Array<{id: number, count: number}>();
|
|
if (!str) return result;
|
|
let decodeArr = decodeArrayListStr(str);
|
|
for (let [id, count] of decodeArr) {
|
|
if (isNaN(parseInt(id)) || isNaN(parseInt(count))) {
|
|
throw new Error('data table format wrong');
|
|
}
|
|
result.push({ id: parseInt(id), count: parseInt(count) });
|
|
}
|
|
return result
|
|
} |