// 主线任务阶段内容
import {readFileAndParse, parseGoodStr} from '../util'
import { FILENAME, TASK_FUN_TYPE } from '../../consts'
import { RewardInter } from '../interface';

export interface DicTaskBox {
    // id
    readonly id: number;
    // 积分
    readonly point: number;
    // 奖励
    readonly reward: RewardInter[];
}

export const dicTaskBox = new Map<number, Map<number, DicTaskBox>>();
export function loadTaskBox() {
    dicTaskBox.clear();
    
    let arr1 = readFileAndParse(FILENAME.DIC_TASK_BOX);
    arr1.forEach(o => {
        if(!dicTaskBox.has(TASK_FUN_TYPE.DAILY)) {
            dicTaskBox.set(TASK_FUN_TYPE.DAILY, new Map<number, DicTaskBox>());
        }
        o.reward = parseGoodStr(o.reward);
        dicTaskBox.get(TASK_FUN_TYPE.DAILY).set(o.id, o);
    });
    arr1 = undefined;
    
    let arr2 = readFileAndParse(FILENAME.DIC_ACHIEVEMENT_BOX);
    arr2.forEach(o => {
        if(!dicTaskBox.has(TASK_FUN_TYPE.ACHIEVEMENT)) {
            dicTaskBox.set(TASK_FUN_TYPE.ACHIEVEMENT, new Map<number, DicTaskBox>());
        }
        o.reward = parseGoodStr(o.reward);
        dicTaskBox.get(TASK_FUN_TYPE.ACHIEVEMENT).set(o.id, o);
    });
    arr2 = undefined;
}