// 武将升星表
import { readFileAndParse } from '../util'
import { ABI_STAGE, FILENAME } from '../../consts';
const _ = require('lodash');

export interface DicHeroStar {

    // 唯一id
    readonly id: number;
    // 职业类型
    readonly classType: number;
    // 品质
    readonly quality: number;
    // 星级
    readonly star: number;
    // 每小阶碎片数量
    readonly advanceUpFragmentNum: number;
    // 每阶升级属性
    readonly ceAttr: Map<number, number>

}


type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicHeroStarKeys: KeysEnum<DicHeroStar> = {id: true, classType: true, quality: true, star: true, advanceUpFragmentNum: true, ceAttr: true};

export const dicHeroStar = new Map<string, DicHeroStar>();
export function loadHeroStar() {
    dicHeroStar.clear();
    
    let arr = readFileAndParse(FILENAME.DIC_HERO_STAR);
    
    arr.forEach(o => {
        o.ceAttr = parseCeAttr(o);
        o.classType = o.class_type;
        dicHeroStar.set(`${o.classType}_${o.quality}_${o.star}`, _.pick(o, Object.keys(DicHeroStarKeys)));
    });
    arr = undefined;
}

function parseCeAttr(elem) {
    let ceAttr = new Map<number, number>();
    ceAttr.set(ABI_STAGE.HP, elem.hp_up);
    ceAttr.set(ABI_STAGE.ATK, elem.atk_up);
    ceAttr.set(ABI_STAGE.DEF, elem.def_up);
    ceAttr.set(ABI_STAGE.MDEF, elem.mdef_up);
    return ceAttr;
}