// GVG任务
import { FILENAME } from '../../consts'
import { RewardInter } from '../interface';
import { parseGoodStr, parseNumberList, readFileAndParse } from '../util'

export interface DicGVGTask {
    // 唯一id
    readonly id: number;
    // 任务id
    readonly taskId: number;
    // 任务类型
    readonly taskType: number;
    // 任务参数
    readonly taskParam: number[];
    // 条件
    readonly condition: number;
    // 普通背包奖励
    readonly reward: RewardInter[];
    // 联军背包奖励
    readonly leagueReward: RewardInter[];
}

export const dicGVGTask = new Map<number, DicGVGTask>();
export const dicGVGTaskByType = new Map<number, number[]>(); // type => []
export function loadGVGTask() {
    dicGVGTask.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_GVG_TASK);
    arr.forEach(o => {
        o.taskParam = parseNumberList(o.taskParam);
        o.reward = parseGoodStr(o.reward);
        o.leagueReward = parseGoodStr(o.leagueReward);
        dicGVGTask.set(o.taskId, o);
        if(!dicGVGTaskByType.has(o.taskType)) {
            dicGVGTaskByType.set(o.taskType, []);
        }
        dicGVGTaskByType.get(o.taskType)?.push(o.taskId);
    });
    arr = undefined;
}