// 武将技能表
import { readFileAndParse } from '../util'
import { FILENAME, ABI_TYPE } from '../../consts'

export interface DicHeroScroll {

    // id
    readonly id: number;
    // 初始品质
    readonly quality: number;
    // 星级
    readonly stars: number;
    // 当前品质
    readonly qualityUp: number;
    // 觉醒星级
    readonly colorstars: number;
    // 每阶升级属性
    readonly ceAttr: Map<number, number>

}

export const dicHeroScroll = new Map<string, DicHeroScroll>();
export const preHeroScroll = new Map<number, DicHeroScroll>(); // 前一个
export function loadHeroScroll() {
    dicHeroScroll.clear();
    preHeroScroll.clear();
    let arr = readFileAndParse(FILENAME.DIC_HERO_SCROLL);
    let pre: DicHeroScroll;
    
    arr.forEach(o => {
        o.ceAttr = parseCeAttr(o);
        dicHeroScroll.set(`${o.quality}_${o.stars}_${o.qualityUp}_${o.colorstars}`, o);
        if(pre && pre.quality != o.quality) pre = null;
        if(pre && pre.quality == o.quality) preHeroScroll.set(o.id, pre);
        pre = o;
    });
    arr = undefined;
    pre = undefined;
}

function parseCeAttr(elem) {
    let ceAttr = new Map<number, number>();
    ceAttr.set(ABI_TYPE.ABI_HP, elem.hp);
    ceAttr.set(ABI_TYPE.ABI_ATK, elem.atk);
    ceAttr.set(ABI_TYPE.ABI_DEF, elem.def);
    ceAttr.set(ABI_TYPE.ABI_MDEF, elem.mdef);
    return ceAttr;
}