// 镇念塔表
import { decodeArrayListStr, readFileAndParse, parseNumberList } from '../util'
import { FILENAME } from '../../consts';

export interface DicSuit {
    // 套装id
    readonly id: number;
    // 包含关卡
    readonly name: string;
    // 总件数
    readonly totalCount: number;
    // 套装效果
    readonly effect: Array<{ count: number, seid: number }>;
    readonly tireInfo: Array<number>;
}


export const dicSuit = new Map<number, DicSuit>();
export function loadSuit() {
    let arr = readFileAndParse(FILENAME.DIC_SUIT);

    arr.forEach(o => {
        o.effect = parseSuitEffect(o.effect);
        o.tireInfo = parseNumberList(o.tireInfo);
        dicSuit.set(o.id, o);
    });
    arr = undefined;
}

function parseSuitEffect(str: string) {
    let result = new Array<{ count: number, seid: number }>();
    if (!str) return result;
    let decodeArr = decodeArrayListStr(str);
    for (let [count, seid] of decodeArr) {
        if (isNaN(parseInt(count)) || isNaN(parseFloat(seid))) {
            throw new Error('data table format wrong');
        }
        result.push({ count: parseInt(count), seid: parseFloat(seid) });
    }
    return result
}