import { PeiJian } from '../protocols/peijian/PtlGetList';
import { HeroShared } from './hero';


export class PeijianShared {
    /**
     * 格式化装备数据
     */
    static fmt(v: Partial<PeiJian>): string;
    static fmt(v: string): Omit<PeiJian, 'wearId'>;
    static fmt(v: Partial<PeiJian> | string) {
        if (typeof v == 'string') {
            let [_id, peijianId, lv, jinglian] = v.split('_');
            return { _id: _id, peijianId: peijianId, lv: Number(lv) || 1, jinglian: Number(jinglian) || 0 };
        } else {
            return [v._id, v.peijianId, v.lv, v.jinglian].join('_');
        }
    }
    /**
     * 获取配件属性
     */
    static getAttr(v: Pick<PeiJian, 'lv' | 'jinglian' | 'peijianId'>) {
        let conf = G.gc.peijian[v.peijianId];
        let buff = Object.fromEntries([conf.buff]);

        let lvConf = G.gc.peijian_lv[conf.colour]?.[v.lv];
        if (lvConf) buff[conf.buff[0]] += lvConf.buff[conf.buff[0]] || 0;

        let jlConf = G.gc.peijian_jl[v.jinglian];
        if (jlConf) {
            for (let k in buff) {
                buff[k] += buff[k] * jlConf.pro;
            }
        }

        HeroShared.amendAttr(buff);

        return buff;
    }
}