// 天晶石表
import { readFileAndParse, parseGoodStr, parseNumberList } from '../util'
import { FILENAME } from '../../consts';
import { RewardInter } from '../interface';

export interface DicJewel {
    // 物品id
    readonly good_id: number;
    // 天晶石名
    readonly name: string;
    // 装备栏id
    readonly eplaceId: number;
    // itid
    readonly itid: number;
    // 天晶石阶
    readonly lv: number;
    // 天晶石品质
    readonly quality: number;
    // 天晶石属性条数
    readonly effectCount: number;
    // 套装效果
    readonly randomEffect: number[];
    // 稀有属性
    readonly rareEffect: number[];
    // 对应藏宝图id
    readonly mapGoodId: number;
    // 淬炼消耗
    readonly quenchConsume: RewardInter[];
    // 寻宝关卡id
    readonly gkId: number;
    // 继承消耗
    readonly inheritConsume: RewardInter[];
}

export const dicJewel = new Map<number, DicJewel>();
export const dicBlueprt = new Map<number, number>();
export const dicBlueprtByLv = new Map<number, number[]>();
export function loadJewel() {
    dicJewel.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_JEWEL);

    arr.forEach(o => {
        o.randomEffect = parseNumberList(o.randomEffect);
        o.rareEffect = parseNumberList(o.rareEffect);
        o.quenchConsume = parseGoodStr(o.quenchConsume);
        o.inheritConsume = parseGoodStr(o.inheritConsume);
        dicJewel.set(o.good_id, o);
        dicBlueprt.set(o.mapGoodId, o.good_id);
        if(!dicBlueprtByLv.has(o.lv)) {
            dicBlueprtByLv.set(o.lv, []);
        }
        dicBlueprtByLv.get(o.lv).push(o.mapGoodId);
    });
    arr = undefined;
}