// 主线星级宝箱
import {readFileAndParse, parseGoodStr} from '../util'
import { FILENAME } from '../../consts'
import { RewardInter } from '../interface';

export interface DicMainWarReward {
    // id
    readonly id: number;
    // 章节id
    readonly chapter: number;
    // 主线类型
    readonly warType: number;
    // 关卡id
    readonly warId: number;
    // 奖励
    readonly cityReward: RewardInter[];
}

export const dicMainWarRewardByChapter = new Map<string, DicMainWarReward[]>(); // chapter => ids;
export function loadMainWarReward() {
    dicMainWarRewardByChapter.clear();

    let arr = readFileAndParse(FILENAME.DIC_MAIN_WAR_REWARD);

    arr.forEach(o => {
        o.cityReward = parseGoodStr(o.cityReward);
        if(!dicMainWarRewardByChapter.has(`${o.warType}_${o.chapter}`)) {
            dicMainWarRewardByChapter.set(`${o.warType}_${o.chapter}`, []);
        }
        dicMainWarRewardByChapter.get(`${o.warType}_${o.chapter}`)?.push(o);
    });
    arr = undefined;
}