import { readFileAndParse } from '../util'
import { FILENAME } from '../../consts'
type KeysEnum<T> = { [P in keyof Required<T>]: true };
const _ = require('lodash');

export interface DicAp {
    // 等级
    readonly level: number;
    // 体力上限
    readonly maxAp: number;
    // 升到这一级恢复的体力
    readonly restoreAp: number;
    // 多少秒恢复1点体力
    readonly perApRestoreTime: number;
}

const DicApKeys: KeysEnum<DicAp> = {
    level: true,
    maxAp: true,
    restoreAp: true,
    perApRestoreTime: true,
};

export const dicApMaxLevel = { max: 0 };
export const dicAp = new Map<number, DicAp>();
export function loadAp() {
    dicApMaxLevel.max = 0;
    dicAp.clear();
    let arr = readFileAndParse(FILENAME.DIC_AP);
    arr.forEach(o => {
        o.maxAp = o.maxAP;
        o.restoreAp = o.restoreAP;
        o.perApRestoreTime = o.perAPRestoreTime;
        dicAp.set(o.level, _.pick(o, Object.keys(DicApKeys)));
        if(o.level > dicApMaxLevel.max) dicApMaxLevel.max = o.level;
    });
    arr = undefined;
}