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

export interface DicMainStarBox {
    // id
    readonly id: number;
    // 章节id
    readonly chapter: number;
    // 星数
    readonly star: number;
    // 奖励
    readonly reward: RewardInter[];
    // 主线类型
    readonly warType: number;
}

export const dicMainStarBox = new Map<number, DicMainStarBox>();
export const dicMainStarBoxByChapter = new Map<string, number[]>(); // chapter => ids;
export function loadMainStarBox() {
    dicMainStarBox.clear();
    dicMainStarBoxByChapter.clear();

    let arr = readFileAndParse(FILENAME.DIC_MAIN_STAR_BOX);

    arr.forEach(o => {
        o.reward = parseGoodStr(o.reward);
        o.warType = o.maintype;
        dicMainStarBox.set(o.id, o);
        if(!dicMainStarBoxByChapter.has(`${o.warType}_${o.chapter}`)) {
            dicMainStarBoxByChapter.set(`${o.warType}_${o.chapter}`, []);
        }
        dicMainStarBoxByChapter.get(`${o.warType}_${o.chapter}`).push(o.id);
    });
    arr = undefined;
}