import * as Xys from "./Xys";
import Gamecfg from "./gameCfg";

const gezi: number[] = [
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
    39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
];

class GameMethod {
    /**
     * 钻石购买金币获得道具公式
     * @param id 配置表档位ID
     * @param level 角色等级
     */
    shopCoinItem(id: string, level: number): Xys.KindItem {
        let cfg = Gamecfg.shopCoin.getItem(id);
        if (cfg == null) {
            return [1, 2, 1];
        }
        let count = cfg.rate * Math.min(10 + Math.floor(level / 10), 50);
        return [1, 2, count];
    }

    /**
     * 两个对象合并
     * @param obj1 from object
     * @param obj2 to object
     * @return obj2
     */
    objMerge(obj1: any, obj2: any) {
        obj1 = typeof obj1 != "object" ? {} : obj1;
        obj2 = typeof obj2 != "object" ? {} : obj2;

        for (const key in obj2) {
            if (obj1[key] == null) {
                obj1[key] = obj2[key];
                continue;
            }
            if (typeof obj2[key] == "object") {
                this.objMerge(obj1[key], obj2[key]);
                continue;
            }
            obj1[key] = obj2[key];
        }

        return obj1; //然后在把复制好的对象给return出去
    }
    /**
     * 两个对象合并 值相加
     */
    objMergeNum(_eps1: { [key: string]: number }, _eps2: { [key: string]: number }): { [key: string]: number } {
        let eps: any = this.objCopy(_eps1);
        let ep2: any = this.objCopy(_eps2);
        for (const key in ep2) {
            if (eps[key] == null) {
                eps[key] = 0;
            }
            eps[key] += ep2[key];
        }
        return eps;
    }

    /**
     * 数组合并
     */
    addArr(arr1: any[], arr2: any[]) {
        let _arr1 = JSON.parse(JSON.stringify(arr1));
        let _arr2 = JSON.parse(JSON.stringify(arr2));
        for (const arr of _arr2) {
            _arr1.push(arr);
        }
        return _arr1;
    }

    /**
     * 业务判空 以下情况返回true
     * 字符串 : 空字符的为空
     * 数值: 0 为空 负数不为空
     * 数组: 长度为0
     * 对象: 没有节点
     * 布尔型 false
     */
    isEmpty(value: any): boolean {
        if (value == null) {
            return true;
        }
        switch (typeof value) {
            case "string":
                if (value.length == null || value.length <= 0) {
                    return true;
                }
                break;
            case "object":
                if (Object.keys(value).length > 0) {
                    return false;
                }
                return true;
            case "number":
                if (value == 0) {
                    return true;
                }
                break;
            case "boolean":
                if (value == false) {
                    return true;
                }
                break;
        }
        return false;
    }
    /**
     * 通用深拷贝函数。
     * @param obj from object
     * @return obj2
     */
    objCopy<T>(obj: T): T {
        return JSON.parse(JSON.stringify(obj));
    }

    /**
     *  相同kind 和 itemid 数组合并
     */
    mergeArr(arrs: Xys.KindItem[]) {
        let resObj: { [kind: number]: { [itemid: number]: number } } = {};
        for (const arr of arrs) {
            if (resObj[arr[0]] == null) {
                resObj[arr[0]] = {};
            }
            if (resObj[arr[0]][arr[1]] == null) {
                resObj[arr[0]][arr[1]] = 0;
            }
            resObj[arr[0]][arr[1]] += arr[2];
        }
        let resArr = [];
        for (const kind in resObj) {
            for (const id in resObj[kind]) {
                resArr.push([parseInt(kind), parseInt(id), resObj[kind][id]]);
            }
        }
        return resArr;
    }

    // 判断字符长度
    getStrCharacterLength(str: string): number {
        let patternChinese = new RegExp("[\u4E00-\u9FA5]+"); // 中文
        let leng = 0;
        for (let index = 0; index < str.length; index++) {
            if (patternChinese.test(str[index])) {
                leng += 2;
            } else {
                leng += 1;
            }
        }
        return leng;
    }

    /**
     * 随机数
     * @param min
     * @param max
     */
    rand(min: number, max: number) {
        return Math.round((max - min + 1) * Math.random() - 0.5) + min;
    }

    //判断uuid是否npc
    isNpc(fuuid: string): boolean {
        if (Number(fuuid) < 10000) {
            return true;
        }
        return false;
    }
    hdDiZiModelRate(out: Xys.HdDiZiOut, data: Xys.HdDiZiData, actDiZiList: { [dzid: string]: Xys.ActDiZi_Info }) {
        let rate = 0;
        let zRate = 0;
        
        for (const pzid in out.tree.list) {
            if (!data.list[pzid]) {
                console.error(`hd_cfg_err:hdQiYuanModelRate: 无效的品质ID ${pzid}`);
                continue;
            }
            
            for (let ygzid = 1; ygzid <= out.tree.list[pzid].open; ygzid++) {
                let _rate = 0;
                let _zRate = 0;
                let dzid = out.tree.list[pzid].dzList[ygzid];
                
                if (!dzid || !actDiZiList[dzid]) {
                    _rate += Number(data.make["2"].item[0]);
                    _zRate += Number(data.make["2"].zItem[0]);
                    continue;
                }
                
                let dzInfo = actDiZiList[dzid];
                let cfgDzInfo = Gamecfg.huobanBase.getItem(dzInfo.id);
                if (!cfgDzInfo) {
                    continue;
                }
                
                let dzpinzhi = cfgDzInfo.pinzhi;
             
                
                // 等级加成
                for (let chanchu of data.make[dzpinzhi.toString()].levelItem) {
                    if (chanchu[0] <= dzInfo.level && dzInfo.level <= chanchu[1]) {
                        _rate += Number(chanchu[2]);
                        break;
                    }
                }
                for (let chanchu of data.make[dzpinzhi.toString()].levelZItem) {
                    if (chanchu[0] <= dzInfo.level && dzInfo.level <= chanchu[1]) {
                        _zRate += Number(chanchu[2]);
                        break;
                    }
                }
                
                // 星级加成
                for (let chanchu of data.make[dzpinzhi.toString()].starItem) {
                    if (chanchu[0] <= dzInfo.star && dzInfo.star <= chanchu[1]) {
                        _rate += Number(chanchu[2]);
                        break;
                    }
                }
                for (let chanchu of data.make[dzpinzhi.toString()].starZItem) {
                    if (chanchu[0] <= dzInfo.star && dzInfo.star <= chanchu[1]) {
                        _zRate += Number(chanchu[2]);
                        break;
                    }
                }

                if (Number(cfgDzInfo.liupai) === Number(pzid)) {
                    _rate *= Number(data.make[dzpinzhi.toString()].item[2]);
                    _zRate *= Number(data.make[dzpinzhi.toString()].zItem[2]);
                } else {
                    _rate *= Number(data.make[dzpinzhi.toString()].item[1]);
                    _zRate *= Number(data.make[dzpinzhi.toString()].zItem[1]);
                }
                rate += _rate;
                zRate += _zRate;

            }
        }
        
        return { rate, zRate };
    }

    
    //根据速度和 当前XX 计算出当前总积分  兽灵
    hdDiZiModelTotol(out: Xys.HdDiZiOut, data: Xys.HdDiZiData, rate: number, zRate: number, nowTime: number) {
        //过了多长时间
        let dtime = nowTime - out.tree.s_time;
        //根据速度 掉落
        //现在改为限制产出时间，而不是限制产出数量
        dtime = Math.min(dtime, data.tree.scoreTimeMax);
        let score = Math.round((rate * dtime) / 3600);
        let totol = score + out.tree.s_num;
        const zScore = Math.round((zRate * dtime) / 3600);
        let zTotal = zScore + out.tree.z_num;
        // if (totol > data.tree.scoreMax) {
        //     //实际产出
        //     let sj = data.tree.scoreMax - out.tree.s_num;
        //     //实际产出 所需时间
        //     dtime = Math.round((sj / rate) * 3600);
        //     //获得的总产出
        //     totol = data.tree.scoreMax;
        // }
        //根据速率 结算
        return {
            totol: totol, //当前总产出
            zTotal: zTotal, //起源之征总产出
            dtime: dtime, //本次计算 实际产出时长
        };
    }

    /**
     * 计算心魔积分范围
     */
    hdShouLingScore(
        xmId: string,
        cfg: Xys.HdShouLingData,
        actShouLing: { [gzid: string]: Omit<Xys.ActShouLing_ListOne, 'sk'> } = {},
        gzids: string[] = []
    ): [number, number] {
        let shoulingCfg = cfg.shouling[xmId];
        if (shoulingCfg == null) {
            console.error(`xmId_err :${xmId}`);
            return [0, 0];
        }
        //初始积分: 心魔积分
        let scores: [number, number] = [shoulingCfg.score[0], shoulingCfg.score[1]];
        for (let i = 0; i < gzids.length; i++) {
            let gzid = gzids[i];
            let addOne = gameMethod.hdShouLingScoreOne(cfg, actShouLing, gzid);
            scores[0] += addOne[0];
            scores[1] += addOne[1];
        }
        return scores;
    }
    /**
     * 心魔计算 一个宠物加的积分
     */
    hdShouLingScoreOne(cfg: Xys.HdShouLingData, slinfo: { [gzid: string]: Omit<Xys.ActShouLing_ListOne, 'sk'> }, gzid: string): [number, number] {
        //初始积分: 心魔积分
        let sadd: [number, number] = [0, 0];

        //是否存在
        if (slinfo[gzid] == null) {
            console.error(`fzInfo_null :${gzid}`);
            return sadd;
        }

        //获取法阵等级配置
        let cfgsl = Gamecfg.shoulingInfo.getItem(slinfo[gzid].slid);
        if (cfgsl == null) {
            console.error(`cfgsl_null :${gzid}`);
            return sadd;
        }

        //等级积分累加
        if (cfg.sMath[cfgsl.pinzhi.toString()] != null) {
            //[积分价值,积分下限,积分上限,系数下限,系数上限]
            let pzcfg = cfg.sMath[cfgsl.pinzhi.toString()];
            //积分价值
            sadd[0] += pzcfg.xishu[0];
            sadd[1] += pzcfg.xishu[0];
            //积分上下限
            sadd[0] += pzcfg.xishu[1];
            sadd[1] += pzcfg.xishu[2];
            //积分系数 * 等级(saveId)
            sadd[0] += slinfo[gzid].level * pzcfg.xishu[3];
            sadd[1] += slinfo[gzid].level * pzcfg.xishu[4];
            //积分系数 * 星级(saveId)
            sadd[0] += slinfo[gzid].star * pzcfg.xishu[5];
            sadd[1] += slinfo[gzid].star * pzcfg.xishu[6];
        }
        return sadd;
    }

    /**
     * 计算灵脉积分产出
     */
    lingMaiScore(jingjieId: string, chenghaoId: string): number {
        let cfgBase = Gamecfg.mathInfo.getItem("lingmai_base_score");
        if (cfgBase == null || cfgBase.pram == null || cfgBase.pram.count == null) {
            return 0;
        }

        //计算境界加成
        let jingjieAdd = 0;
        let jingjieCfg = Gamecfg.jingjieStep.getItem(jingjieId);
        if (jingjieCfg != null) {
            jingjieAdd = jingjieCfg.lmjc;
        }
        //计算称号加成
        let titleAdd = 0;
        let titleCfg = Gamecfg.chenghaoInfo.getItem(chenghaoId);
        if (titleCfg != null) {
            titleAdd = titleCfg.jc;
        }
        //初始积分: 心魔积分
        let scores = Math.round(cfgBase.pram.count * (1 + jingjieAdd / 100) * (1 + titleAdd / 100));
        return scores;
    }
    //--------------属性计算 （主角基础属性 ） -------------------------
    // （天赋数值+装备数值+基础属性）*（1+百分比加成）=面板属性

    /**
     * 属性合并
     */
    ep_merge(_eps1: { [key: string]: number }, _eps2: { [key: string]: number }): { [key: string]: number } {
        let eps: any = this.objCopy(_eps1);
        let ep2: any = this.objCopy(_eps2);
        for (const key in ep2) {
            if (eps[key] == null) {
                eps[key] = 0;
            }
            eps[key] += ep2[key];
        }
        eps.hp = eps.hp_max || 0;
        return eps;
    }

    /**
     * {[key:string]:number} 属性合并 _eps2的key _eps1没有就不加
     */
    ep_mergeKv_has(_eps1: { [key: string]: number }, _eps2: { [key: string]: number }): { [key: string]: number } {
        let eps: any = this.objCopy(_eps1);
        let ep2: any = this.objCopy(_eps2);
        for (const key in ep2) {
            if (eps[key] == null) {
                continue;
            }
            eps[key] += ep2[key];
        }
        eps["hp"] = eps["hp_max"]; //不要删
        return eps;
    }

    /**
     * {[key:string]:number} 属性合并 x 系数
     */
    ep_KvRate(_eps1: { [key: string]: number }, rate: number): { [key: string]: number } {
        let eps: any = this.objCopy(_eps1);
        for (const key in eps) {
            eps[key] = Math.floor(eps[key] * rate);
        }
        return eps;
    }

    /**
     * 属性初始化
     */
    ep_init(): { [key: string]: number } {
        let eps: any = {};
        let userEpPool = Gamecfg.userEp.pool;
        for (const key in userEpPool) {
            eps[userEpPool[key].key] = 0;
        }
        return eps;
    }

    /**
     * 角色基础属性
     */
    ep_user(): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        let userEpPool = Gamecfg.userEp.pool;
        for (const key in userEpPool) {
            eps[userEpPool[key].key] = userEpPool[key].initEp;
        }
        return eps;
    }
    /**
     * 属性展示总属性
     */
    ep_all_base(sevBack: Xys.SevBack): { [key: string]: number } {
        //属性初始化
        let eps: { [key: string]: number } = this.ep_init();
        //+角色基础属性
        eps = this.ep_merge(eps, this.ep_user());

        //后端记录的属性
        if (sevBack.actEps != null && sevBack.actEps.a != null) {
            for (const kid in sevBack.actEps.a) {
                eps = gameMethod.ep_merge(eps, sevBack.actEps.a[kid]);
            }
        }

        eps["hp"] = Math.round(eps["hp"]);
        eps["atk"] = Math.round(eps["atk"]);
        eps["def"] = Math.round(eps["def"]);
        return gameMethod.objCopy(eps);
    }

    /**
     * 属性展示总属性 （面板属性）
     * 面板属性 = 角色基础属性
     */
    ep_all(sevBack: Xys.SevBack): { [key: string]: number } {
        let eps = this.ep_all_base(sevBack);
        //攻速
        eps.speed += Math.floor((eps.speed * eps.speed_per) / 10000);
        //攻击
        eps.atk += Math.floor((eps.atk * eps.atk_per) / 10000);
        eps.atk += Math.floor((eps.atk * eps.finally_atk_per) / 10000);
        //防御
        eps.def += Math.floor((eps.def * eps.def_per) / 10000);
        eps.def += Math.floor((eps.def * eps.finally_def_per) / 10000);
        //血量
        eps.hp_max += Math.floor((eps.hp_max * eps.hp_max_per) / 10000);
        eps.hp_max += Math.floor((eps.hp_max * eps.finally_hp_max_per) / 10000);
        eps.hp = eps.hp_max;

        //攻速
        eps.speed_per = 0;
        //攻击
        eps.atk_per = 0
        eps.finally_atk_per = 0
        //防御
        eps.def_per = 0
        eps.finally_def_per = 0;
        //血量
        eps.hp_max_per = 0;
        eps.finally_hp_max_per = 0;

        return gameMethod.objCopy(eps);
    }

    /**
     * 属性展示总属性 （面板属性）
     * 面板属性 = 角色基础属性
     */
    ep_all_fight(eps: { [key: string]: number }): { [key: string]: number } {
        eps = gameMethod.objCopy(eps)
        //攻速
        eps.speed += Math.floor((eps.speed * eps.speed_per) / 10000);
        //攻击
        eps.atk += Math.floor((eps.atk * eps.atk_per) / 10000);
        eps.atk += Math.floor((eps.atk * eps.finally_atk_per) / 10000);
        eps.atk += eps.finally_atk
        //防御
        eps.def += Math.floor((eps.def * eps.def_per) / 10000);
        eps.def += Math.floor((eps.def * eps.finally_def_per) / 10000);
        eps.def += eps.finally_def
        //血量
        eps.hp_max += Math.floor((eps.hp_max * eps.hp_max_per) / 10000);
        eps.hp_max += Math.floor((eps.hp_max * eps.finally_hp_max_per) / 10000);
        eps.hp_max += eps.finally_hp_max
        eps.hp = eps.hp_max;

        //攻速
        eps.speed_per = 0;
        //攻击
        eps.atk_per = 0
        eps.finally_atk_per = 0
        eps.finally_atk = 0
        //防御
        eps.def_per = 0
        eps.finally_def_per = 0;
        eps.finally_def = 0;
        //血量
        eps.hp_max_per = 0;
        eps.finally_hp_max_per = 0;
        eps.finally_hp_max = 0;

        return eps;
    }

    /**
     * 属性展示总属性 （面板属性）显示最终属性
     */
    ep_all_zz(eps: { [key: string]: number }): { [key: string]: number } {
        eps = gameMethod.objCopy(eps)
        //攻击
        let atk:number = eps.atk
        atk += eps.atk_per? Math.floor((atk * eps.atk_per) / 10000):0;
        atk += eps.finally_atk_per?Math.floor((atk * eps.finally_atk_per) / 10000):0;
        atk += eps.finally_atk
        //防御
        let def:number = eps.def
        def += eps.def_per? Math.floor((def * eps.def_per) / 10000):0;
        def += eps.finally_def_per?Math.floor((def * eps.finally_def_per) / 10000):0;
        def += eps.finally_def
        //血量
        let hp_max:number = eps.hp_max
        hp_max += eps.hp_max_per?Math.floor((hp_max * eps.hp_max_per) / 10000):0;
        hp_max += eps.finally_hp_max_per?Math.floor((hp_max * eps.finally_hp_max_per) / 10000):0;
        hp_max += eps.finally_hp_max
        return {
            "finally_atk":atk,
            "finally_def":def,
            "finally_hp_max":hp_max,
        };
    }
    /**
     * 主角战斗属性
     */
    ep_fight(sevBack: Xys.SevBack): { [key: string]: number } {
        let eps = this.ep_all(sevBack);
        //攻速
        eps.speed_per = 0;
        //攻击
        eps.atk_per = 0
        eps.finally_atk_per = 0
        //防御
        eps.def_per = 0
        eps.finally_def_per = 0;
        //血量
        eps.hp_max_per = 0;
        eps.finally_hp_max_per = 0;
        return eps;
    }


    /**
     * 弟子战斗属性
     * @param dzInfo 弟子信息
     * @param eps 主角属性
     * @returns
     */
    ep_fight_dizi(dzInfo: Xys.ActDiZi_Info, epsAll: { [key: string]: number }): { [key: string]: number } {
        let dzEps: { [key: string]: number } = gameMethod.ep_init(); //初始化属性
        let cfgdz = Gamecfg.huobanBase.getItem(dzInfo.id);
        if (cfgdz == null) {
            return dzEps;
        }
        let cfgZhongZu = Gamecfg.huobanZhongzu.getItem(cfgdz.pinzhi, cfgdz.zhongzu.toString());
        if (cfgZhongZu == null) {
            return dzEps;
        }
        dzEps = gameMethod.ep_merge(dzEps, cfgdz.eps);
        for (const key in cfgZhongZu.inherit_attr) {
            //继承主角属性
            dzEps[key] += Math.floor((epsAll[key] * cfgZhongZu.inherit_attr[key]) / 10000);
        }
        for (const key in cfgZhongZu.inherit_attr_hide) {
            //继承主角属性
            dzEps[key] += Math.floor((epsAll[key] * cfgZhongZu.inherit_attr_hide[key]) / 10000);
        }
        dzEps.hp = dzEps.hp_max;
        return dzEps;
    }

    /**
     * 阵法
     */
    ep_zhenfa(actZhenfa: Xys.ActZhenfaNew): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        const chuanKeys = Object.keys(actZhenfa.chuan);
        for (let i = 0; i < chuanKeys.length; i++) {
            const buwei = chuanKeys[i];
            //装备属性
            eps = this.ep_merge(eps, actZhenfa.chuan[buwei].eps);
            //附魔属性
            let addEps: { [key: string]: number } = {};
            for (const fmEps of actZhenfa.chuan[buwei].fmEps) {
                if (addEps[fmEps[0]] == null) {
                    addEps[fmEps[0]] = 0;
                }
                addEps[fmEps[0]] += fmEps[1];
            }

            // 洗练属性
            for (const posId in actZhenfa.chuan[buwei].xilianEps) {
                if (actZhenfa.chuan[buwei].xilianEps[posId].id == null || actZhenfa.chuan[buwei].xilianEps[posId].id == "") {
                    continue;
                }
                let xilian_c = Gamecfg.zhenfaXilianWord.getItem(actZhenfa.chuan[buwei].xilianEps[posId].id);
                if (xilian_c != null) {
                    eps = this.ep_merge(eps, xilian_c.attr);
                }

            }
            eps = this.ep_merge(eps, addEps);
        }

        return eps;
    }

    /**
     * 阵法
     */
    ep_zhenfa_list(actZhenfa: Xys.ActZhenfaNew): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        // 阵法New
        let keys = Object.keys(actZhenfa.zfList);
        for (let i = 0; i < keys.length; i++) {
            let zfBase = Gamecfg.zfxtZfbase.getItem(keys[i]);
            if (zfBase != null) {
                let zfShengji = Gamecfg.zfxtZfshengji.getItem(zfBase.pinzhi, actZhenfa.zfList[keys[i]].level.toString());
                if (zfShengji != null) {
                    eps = this.ep_merge(eps, zfShengji.attr);
                }
            }
        }
        return eps;
    }

    /**
     * 大帝古字
     */
    ep_dadiguzi(actDadiGuzi: Xys.ActDadiGuzi, mfList: { [mfid: string]: Xys.mfInfo }): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        const keys = Object.keys(actDadiGuzi.mpList[actDadiGuzi.mpXhid]);
        for (let i = 0; i < keys.length; i++) {
            const buwei = keys[i];
            if (gameMethod.isEmpty(actDadiGuzi.mpList[actDadiGuzi.mpXhid][buwei]) == true) {
                continue;
            }
            eps = this.ep_merge(eps, actDadiGuzi.mpList[actDadiGuzi.mpXhid][buwei].eps);
        }

        //上阵列表
        let szMfids: string[] = [];
        const mfZhanKeys = Object.keys(actDadiGuzi.mfZhan);
        for (let i = 0; i < mfZhanKeys.length; i++) {
            const _type = mfZhanKeys[i];
            if (actDadiGuzi.mfZhan[_type] == "") {
                continue;
            }
            szMfids.push(actDadiGuzi.mfZhan[_type]);
        }

        //仙法 + 铭文
        const mfListKeys = Object.keys(mfList);
        for (let i = 0; i < mfListKeys.length; i++) {
            const mfid = mfListKeys[i];
            let cfgXfInfo = Gamecfg.dadiguziXfinfo.getItem(mfid);
            if (cfgXfInfo == null) {
                continue;
            }
            let cfg = Gamecfg.dadiguziXflv.getItem(cfgXfInfo.pinzhi.toString(), mfList[mfid].level.toString());
            if (cfg != null) {
                if (eps["hp_max"] == null) {
                    eps["hp_max"] = 0;
                }
                if (eps["atk"] == null) {
                    eps["atk"] = 0;
                }
                if (eps["def"] == null) {
                    eps["def"] = 0;
                }

                eps["hp_max"] += cfg.hp_max;
                eps["atk"] += cfg.atk;
                eps["def"] += cfg.def;
            }

            if (szMfids.indexOf(mfid) == -1) {
                continue; //没上阵 不加铭文属性
            }
            for (const mwid of mfList[mfid].mwLock) {
                if (mwid == null || mwid == "") {
                    continue;
                }
                let cfgMw = Gamecfg.dadiguziMingwen.getItem(mwid);
                if (cfgMw != null) {
                    eps = this.ep_merge(eps, cfgMw.eps);
                }
            }
        }

        //图鉴
        const tjlistKeys = Object.keys(actDadiGuzi.tjlist);
        for (let i = 0; i < tjlistKeys.length; i++) {
            const _key = tjlistKeys[i];
            let cfgtjNew = Gamecfg.dadiguziXftj.getItem(_key, actDadiGuzi.tjlist[_key].toString());
            if (cfgtjNew == null) {
                continue;
            }
            eps = this.ep_merge(eps, cfgtjNew.eps);
        }

        return eps;
    }

    /**
     * 计算弟子全局属性 弟子加成只有突破属性和图鉴加成
     */
    ep_dizi_base(actDiZi: Xys.ActDiZi, actDiZiList: { [dizi: string]: Xys.ActDiZi_Info}): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        const dzListKeys = Object.keys(actDiZiList);
        for (let i = 0; i < dzListKeys.length; i++) {
            const dzid = dzListKeys[i];
            //计算弟子阶级属性
            let dizi = actDiZiList[dzid];
            // let num = dizi.level % 5;
            const diZiStar_c = Gamecfg.huobanStar.getItem(dzid, dizi.star.toString());
            if (diZiStar_c != null) {
                for (let i = 0; i <= Number(diZiStar_c.star); i++) {
                    const cfgStep = Gamecfg.huobanStar.getItem(dzid, i.toString());
                    if (cfgStep != null) {
                        let stepEps = cfgStep.attr;
                        eps = this.ep_merge(eps, stepEps);
                    }
                }
            }
        }

        //计算弟子图鉴属性
        const tujianKeys = Object.keys(actDiZi.tujian);
        for (let i = 0; i < tujianKeys.length; i++) {
            const tujianKey = tujianKeys[i];
            const diziTuJian_c = Gamecfg.huobanTujian.getItem(tujianKey, actDiZi.tujian[tujianKey].toString());
            if (diziTuJian_c == null) {
                continue;
            }
            eps = this.ep_merge(eps, diziTuJian_c.attr);
        }

        //皮肤属性
        for (let i = 0; i < dzListKeys.length; i++) {
            const dzid = dzListKeys[i];
            let dizi = actDiZiList[dzid];
            if(!actDiZiList[dzid].skins){
                continue;
            }
            for (const key in actDiZiList[dzid].skins) {
                let level = actDiZiList[dzid].skins[key].level;
                let skinCfg = Gamecfg.huobanSkinlevel.getItem(key, level.toString());
                if(skinCfg){
                    eps = this.ep_merge(eps, skinCfg.levelEps);
                }
            }
           
        }
        return eps;
    }

    ep_shouling_shengxiao(actShouLingList: { [gzid: string]: Xys.ActShouLing_ListOne }) {
        let shoulingList: { [slid: string]: number } = {};
        let gzList: { [slid: string]: string } = {};
        const listKeys = Object.keys(actShouLingList);
        for (let i = 0; i < listKeys.length; i++) {
            const index = listKeys[i];
            if (actShouLingList[index] != null && gameMethod.isEmpty(actShouLingList[index].slid) == false) {
                const slid = actShouLingList[index].slid;
                const eps = this.ep_shouling_gezi(actShouLingList[index]);
                const zhanli = eps["hp_max_per"];
                const existingZhanli = shoulingList[slid];
                if (existingZhanli === undefined || zhanli > existingZhanli) {
                    shoulingList[slid] = zhanli;
                    gzList[slid] = index;
                }
            }
        }
        let gzIdlist: any[] = [];
        let gzListKeys = Object.keys(gzList);
        for (let i = 0; i < gzListKeys.length; i++) {
            gzIdlist.push(gzList[gzListKeys[i]]);
        }
        return gzIdlist;
    }

    /**
     * 计算兽灵总属性加成
     */
    ep_shouling(actShouLingList: { [gzid: string]: Xys.ActShouLing_ListOne }, actShouLing: Xys.ActShouLing, jiuxiao: number = 0): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        //计算兽灵属性总加成(不包含技能)
        let shoulingList: { [slid: string]: number } = {};
        let gzList: { [slid: string]: string } = {};
        //遍历出最高属性的兽灵的格子id
        const listKeys = Object.keys(actShouLingList);
        for (let i = 0; i < listKeys.length; i++) {
            const index = listKeys[i];
            if (actShouLingList[index] != null && gameMethod.isEmpty(actShouLingList[index].slid) == false) {
                const slid = actShouLingList[index].slid;
                const eps = this.ep_shouling_gezi(actShouLingList[index]);
                const zhanli = eps["hp_max_per"];
                const existingZhanli = shoulingList[slid];
                if (existingZhanli === undefined || zhanli > existingZhanli) {
                    shoulingList[slid] = zhanli;
                    gzList[slid] = index;
                }
            }
        }
        const gzListKeys = Object.keys(gzList);
        for (let i = 0; i < gzListKeys.length; i++) {
            const gz = gzListKeys[i];
            if (gameMethod.isEmpty(gzList[gz]) == false) {
                eps = this.ep_merge(eps, this.ep_shouling_gezi(actShouLingList[gzList[gz]], jiuxiao));
            }
        }
        //羁绊属性加成
        let jiban = actShouLing.jiban;
        const jibanKeys = Object.keys(actShouLing.jiban);
        for (let i = 0; i < jibanKeys.length; i++) {
            const jbid = jibanKeys[i];
            if (gameMethod.isEmpty(jiban[jbid].level)) {
                continue;
            }
            let cfgJiBan = Gamecfg.shoulingJiban.getItem(jbid, jiban[jbid].level.toString());
            if (cfgJiBan == null || cfgJiBan.eps == null) {
                continue;
            }
            eps = this.ep_merge(eps, cfgJiBan.eps);
        }
        //上阵兽灵被动属性加成
        const useGzIdKeys = Object.keys(actShouLing.useGzId);
        for (let i = 0; i < useGzIdKeys.length; i++) {
            const useGzId = useGzIdKeys[i];
            let skBdeps: { [key: string]: number } = {};
            let gzid = actShouLing.useGzId[useGzId];
            if (gzid == null || gzid == "") {
                continue;
            }
            let shouling = actShouLingList[gzid];
            if (shouling == null) {
                continue;
            }
            let cfg = Gamecfg.shoulingInfo.getItem(shouling.slid);
            if (cfg == null) {
                continue;
            }
            let pinzhiCfg = Gamecfg.shoulingPinzhi.getItem(cfg.pinzhi);
            if (pinzhiCfg == null) {
                continue;
            }
            //主站
            if (useGzId == "0") {
                const skBdKeys = Object.keys(shouling.skBd);
                for (let i = 0; i < skBdKeys.length; i++) {
                    let caoId = skBdKeys[i];
                    let skill = shouling.skBd[caoId];
                    let cfgEffect = Gamecfg.shoulingBeidong.getItem(skill.skillId.toString());
                    if (cfgEffect == null) {
                        continue;
                    }
                    let newEps: { [key: string]: number } = {};
                    newEps[cfgEffect.type] = cfgEffect.esp[skill.lv - 1];
                    skBdeps = this.ep_merge(skBdeps, newEps);
                }
            } else {
                const skBdKeys = Object.keys(shouling.skBd);
                for (let i = 0; i < skBdKeys.length; i++) {
                    let caoId = skBdKeys[i];
                    let skill = shouling.skBd[caoId];
                    let cfgEffect = Gamecfg.shoulingBeidong.getItem(skill.skillId.toString());
                    if (cfgEffect == null) {
                        continue;
                    }
                    let newEps: { [key: string]: number } = {};
                    newEps[cfgEffect.type] = cfgEffect.esp[skill.lv - 1];
                    let bdEps = gameMethod.objCopy(newEps);
                    let bdEpsKeys = Object.keys(bdEps);
                    for (let i = 0; i < bdEpsKeys.length; i++) {
                        let key = bdEpsKeys[i];
                        bdEps[key] = Math.round((bdEps[key] * pinzhiCfg.skOdds) / 100);
                    }
                    skBdeps = this.ep_merge(skBdeps, bdEps);
                }
            }
            eps = this.ep_merge(eps, skBdeps);
        }

        return eps;
    }

    /**
     * 单个道友的属性
     */
    ep_daoyou(daoyou: Xys.ActDaoyou): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        for (let one in daoyou.daoyouMap) {
            let dyid = daoyou.daoyouMap[one].did;
            let level = daoyou.daoyouMap[one].favorLv;
            let skkills = daoyou.daoyouMap[one].skill;
            //计算等级属性加成
            for (let i = 1; i <= level; i++) {
                let cfg = Gamecfg.daoyouFavorLv.getItem(dyid, i.toString());
                if (cfg != null) {
                    eps = this.ep_merge(eps, cfg.eps);
                }
            }
            //计算技能属性加成
            for (let sk of skkills) {
                let cfgSkill = Gamecfg.daoyouSkillLv.getItem(sk.toString());
                if (cfgSkill != null) {
                    let cfgSkillType = Gamecfg.daoyouSkillType.getItem(cfgSkill.sid);
                    if (cfgSkillType != null && cfgSkillType.type == 2) {
                        for (let key of Object.keys(cfgSkillType.param)) {
                            let num = cfgSkill.value[Object.keys(cfgSkillType.param).indexOf(key)];
                            cfgSkillType.param[key] = num;
                        }
                        eps = this.ep_merge(eps, cfgSkillType.param);
                    }
                }
            }
        }
        return eps;
    }
    /**
     * 单个法宝的属性
     */
    ep_fabao(actFaBao: Xys.ActFaBao): { [key: string]: number } {
        let eps = {};
        for (const fabao of Object.values(actFaBao.fabaoList)) {
            // 基础属性
            let cfgFbInfo = Gamecfg.fabaoInfo.getItem(fabao.fbId);
            if (cfgFbInfo != null) {
                eps = this.ep_merge(eps, cfgFbInfo.attributes);
            }
            // 升级属性
            for (const cfg of Object.values(Gamecfg.fabaoUplevel.pool)) {
                if (cfg.id.toString() === fabao.fbId && cfg.level <= fabao.level) {
                    eps = this.ep_merge(eps, cfg.attributes);
                }
            }
            // 升星属性
            for (const cfg of Object.values(Gamecfg.fabaoUpstar.pool)) {
                if (cfg.id.toString() === fabao.fbId && cfg.level <= fabao.star) {
                    eps = this.ep_merge(eps, cfg.attributes);
                }
            }
        }
        return eps;
    }

    /**
     * 法宝羁绊的属性
     */
    ep_fabaoJiban(actFaBao: Xys.ActFaBao): { [key: string]: number } {
        let eps = {};
        const jibanListKeys = Object.keys(actFaBao.jibanList);
        for (let i = 0; i < jibanListKeys.length; i++) {
            const jbId = jibanListKeys[i];
            // 羁绊属性
            let cfgJbInfo = Gamecfg.fabaoJiban.getItem(jbId, actFaBao.jibanList.star.toString());
            if (cfgJbInfo !== null) {
                eps = this.ep_merge(eps, cfgJbInfo.attributes);
            }
        }
        return eps;
    }

    /**
     * 当前境界的属性
     */
    ep_jingjie(actJingJie: Xys.ActJingJie, jingjieId: string): { [key: string]: number } {
        let eps: { [key: string]: number } = {};

        //突破后获得属性
        let pool = Gamecfg.jingjieStep.pool
        let maxLv:number = 0
        for (const key in pool) {
            //境界属性(目标型)
            if(Number(jingjieId) == Number(pool[key].id)){
                eps = this.ep_merge(eps, pool[key].tp_eps);
            }
            let addCount = 0
            for (let i = maxLv+1; i <= pool[key].maxlv; i++) {
                if(i > actJingJie.level){
                    break
                }
                let cfg = Gamecfg.jingjieLevel.getItem(i.toString());
                if (cfg == null) {
                    continue;
                }
                //等级获得属性(目标型)
                if(i == actJingJie.level){
                    eps = this.ep_merge(eps, cfg.eps);
                }
                
                if(i == actJingJie.level){
                    addCount += Math.round(actJingJie.exp /cfg.exp[2]);
                }else{
                    addCount += Math.round(cfg.needExp /cfg.exp[2]);
                }
            }
            //因为属性是3次一个循环
            // 计算每个 eps 的执行次数
            const eps1Count = Math.floor((addCount + 2) / 3); // eps1 应用的次数
            const eps2Count = Math.floor((addCount + 1) / 3); // eps2 应用的次数
            const eps3Count = Math.floor(addCount / 3); // eps3 应用的次数

            eps = this.ep_merge(eps, this.ep_KvRate(pool[key].eps1,eps1Count)); 
            eps = this.ep_merge(eps, this.ep_KvRate(pool[key].eps2,eps2Count)); 
            eps = this.ep_merge(eps, this.ep_KvRate(pool[key].eps3,eps3Count)); 

            maxLv = pool[key].maxlv
            if(maxLv >= actJingJie.level){
                break
            }
        }
        return eps;
    }

    /**
     * 世家秘术
     *
     */
    ep_clubMiShu(actClubMiShu: Xys.ActClubMiShu): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        // 世家筋骨
        const jinGuKeys = Object.keys(actClubMiShu.jinGu);
        for (let i = 0; i < jinGuKeys.length; i++) {
            const type = jinGuKeys[i];
            let lv = actClubMiShu.jinGu[type];
            let cfg = Gamecfg.clubMiShuJinGu.getItem(type, lv.toString());
            if (cfg != null) {
                eps = this.ep_merge(eps, cfg.eps);
            }
        }
        // 世家秘术筋骨筋骨全等级达到 ,额外加成属性
        let minLvKey = Object.keys(actClubMiShu.jinGu).reduce((pre, cur) => {
            if (actClubMiShu.jinGu[cur] < actClubMiShu.jinGu[pre]) {
                return cur;
            }
            return pre;
        });
        let minLv1 = actClubMiShu.jinGu[minLvKey];
        // 0,10,20,30...
        let JinGuJc = Gamecfg.clubMiShuJinGuJc.getItem((Math.floor(minLv1 / 10) * 10).toString());
        if (JinGuJc != null) {
            eps = this.ep_merge(eps, JinGuJc.eps);
        }

        // 世家经络
        let jlList = actClubMiShu.jllist;
        for (let jlid in jlList) {
            let cfgJl = Gamecfg.clubMiShuJingluo.getItem(jlid, jlList[jlid].level.toString());
            if (cfgJl != null) {
                eps = this.ep_merge(eps, cfgJl.addEp);
            }
        }
        let cfgJlQ = Gamecfg.clubMiShuJlquality.getItem(actClubMiShu.curJlQuality.toString());
        if (cfgJlQ != null) {
            eps = this.ep_merge(eps, cfgJlQ.qualityEp);
        }
        return eps;
    }

    /**
     * 世家圣兵
     *
     */
    ep_clubShengB(actClubShengB: Xys.ActClubShengB): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        // 获取当前方案的所有位置的词条
        for (let posId in actClubShengB.plan[actClubShengB.curPlan]) {
            // 获取词条配置
            let cfg = Gamecfg.clubShengBWord.getItem(actClubShengB.plan[actClubShengB.curPlan][posId].id);
            if (cfg != null) {
                // 算一下第一个属性的值
                let n = cfg.attr[Object.keys(cfg.attr)[0]] + actClubShengB.plan[actClubShengB.curPlan][posId].range;
                eps = this.ep_merge(eps, { [Object.keys(cfg.attr)[0]]: n });
            }
        }

        return eps;
    }

     /**
     * 宗门-门徒
     *
     */
     eps_zongMen_mentu(mentu: Xys.mentu, jiuxiao: number = 0){
        let mentu_eps: { [key: string]: number } = {};
        if(!mentu.basicAttr){
            return mentu_eps
        }
        mentu_eps = mentu.basicAttr
        let _mentu = mentu.married?.[Object.keys(mentu.married)[0]]?.mentuInfo;
        if (_mentu && _mentu.basicAttr) {
            // _mentu.basicAttr的值最多不超过mentu.basicAttr的300%
            for (const key in _mentu.basicAttr) {
                if (mentu.basicAttr[key] == null) {
                    mentu.basicAttr[key] = 0;
                }
                if (_mentu.basicAttr[key] == null) {
                    _mentu.basicAttr[key] = 0;
                }
                let nCfg = Gamecfg.mathInfo.getItem("zongMen_add_basicAttr_limit");
                if (nCfg != null && nCfg.pram != null && nCfg.pram.count != null) {
                    _mentu.basicAttr[key] = Math.min( Math.floor(mentu.basicAttr[key] * nCfg.pram.count), _mentu.basicAttr[key] );
                }
            }
            mentu_eps = this.ep_merge(mentu_eps, _mentu.basicAttr);
        }
        return this.ep_KvRate(mentu_eps, 1 + jiuxiao);
     }
        
    /**
     * 宗门
     *
     */
    ep_zongMen(
        _actZongMenMentuLs1: { [id: string]: Xys.mentu },
        _actZongMenMentuLs2: { [id: string]: Xys.mentu },
        _actZongMen: Xys.ActZongMen,showBasicAttr:boolean = true,
        jiuxiao: number = 0
    ): { [key: string]: number } {
        // 记录基础
        let eps: { [key: string]: number } = {};

        // 记录委任的特殊属性
        let speEps: { [key: string]: number } = {};

        // 拷贝一份数据
        let actZongMenMentuLs1 = gameMethod.objCopy(_actZongMenMentuLs1);
        let actZongMenMentuLs2 = gameMethod.objCopy(_actZongMenMentuLs2);
        let actZongMen = gameMethod.objCopy(_actZongMen);
        // 获取宗门等级配置
        let zm_cfg = Gamecfg.zongMenInfo.getItem(actZongMen.level.toString());
        if (zm_cfg == null) return eps;

        // 委任加属性
        for (const id in actZongMen.appointPos) {
            let mentuId = actZongMen.appointPos[id].mentuId;
            // 获取未结好的门徒信息
            let mentu = actZongMen.mentu[mentuId] || actZongMenMentuLs1[mentuId];
            // 如果获取不到门徒信息，说明是已经结好的门徒，从已结好的门徒列表中获取
            // --------------------------------已经结好的门徒Start--------------------------------
            if (mentu == null) {
                // 结好的门徒有两个门徒，需要分别计算 一个是自己，一个是配偶
                // 1. 特殊属性
                //自己
                mentu = actZongMenMentuLs2[mentuId];
                if (mentu == null) continue;
                let speAttr1 = mentu.speAttr || [];
                // 配偶

                let _mentu = mentu.married?.[Object.keys(mentu.married)[0]]?.mentuInfo;
                let speAttr2 = _mentu?.speAttr || [];

                for (const attrId of speAttr1.concat(speAttr2)) {
                    let cfg = Gamecfg.zongMenSpeAttr.getItem(attrId);
                    if (cfg != null) {
                        if (cfg != null) {
                            let [attrKey, attrValue] = Object.entries(cfg.attr)[0];
                            const EpsObj = { [attrKey]: attrValue };
                            speEps = this.ep_merge(speEps, EpsObj);
                        }
                    }
                }

                // 2. 出师属性

                let graduateAttr1 = mentu.graduateAttr || {};
                let graduateAttr2 = _mentu?.graduateAttr || {};

                // 先确定值-graduateAttr2不超过graduateAttr1的x倍
                let nCfg = Gamecfg.mathInfo.getItem("zongMen_add_graduateAttr_limit");
                if (nCfg != null && nCfg.pram != null && nCfg.pram.count != null) {
                    let value = graduateAttr1[Object.keys(graduateAttr1)[0]]
                    graduateAttr2[Object.keys(graduateAttr2)[0]] = Math.min(value * nCfg.pram.count, graduateAttr2[Object.keys(graduateAttr2)[0]]);
                }

                // 根据委任的位置id获取加成配置
                let cfg = Gamecfg.zongMenAppointPos.getItem(id);
                if (cfg == null) continue;
                for (const key in graduateAttr1) {
                    graduateAttr1[key] = Math.floor(graduateAttr1[key] * (1 + cfg.add / 100));
                }

                speEps = this.ep_merge(speEps, graduateAttr1);


                for (const key in graduateAttr2) {
                    graduateAttr2[key] = Math.floor(graduateAttr2[key] * (1 + cfg.add / 100));
                }

                speEps = this.ep_merge(speEps, graduateAttr2);

            }

            // --------------------------------已经结好的门徒End--------------------------------

            // --------------------------------未结好的门徒Start--------------------------------
            else {
                // 特殊属性
                let speAttr = mentu.speAttr || [];
                for (const attrId of speAttr) {
                    let cfg = Gamecfg.zongMenSpeAttr.getItem(attrId);
                    if (cfg != null) {
                        let [attrKey, attrValue] = Object.entries(cfg.attr)[0];
                        const EpsObj = { [attrKey]: attrValue };
                        speEps = this.ep_merge(speEps, EpsObj);
                    }
                }
                let graduateAttr = mentu.graduateAttr || {};
                // 根据id获取配置
                let cfg = Gamecfg.zongMenAppointPos.getItem(id);
                if (cfg == null) continue;
                for (const key in graduateAttr) {
                    graduateAttr[key] = Math.floor(graduateAttr[key] * (1 + cfg.add / 100));
                }

                speEps = this.ep_merge(speEps, graduateAttr);
            }
            // --------------------------------未结好的门徒End--------------------------------
        }

        // 每个门徒的基础属性全部加起来给主角
        if(showBasicAttr){
            for (const id in actZongMen.mentu) {
                eps = this.ep_merge(eps, this.eps_zongMen_mentu(actZongMen.mentu[id], jiuxiao));
            }
            for (const id in actZongMenMentuLs1) {
                eps = this.ep_merge(eps, this.eps_zongMen_mentu(actZongMenMentuLs1[id], jiuxiao));
            }

            for (const id in actZongMenMentuLs2) {
                eps = this.ep_merge(eps, this.eps_zongMen_mentu(actZongMenMentuLs2[id], jiuxiao));
            }
        }


        // 每一条委任的特殊属性都不能超过配置的最大值 zm_cfg.maxSpeAttrAdd
        for (const key in speEps) {
            speEps[key] = Math.min(speEps[key], zm_cfg.maxSpeAttrAdd);
        }

        eps = this.ep_merge(eps, speEps);

        return eps;
    }

    /**
     * 道纹
     * 镶嵌道纹的基础属性 + 词条属性 + 解封等级的属性 + 套装buff
     */
    ep_daowen(actDaoWen: Xys.ActDaoWen, actDdaoWenList: { [iid: string]: Xys.DaoWen_Stone }): { [key: string]: number } {
        let eps_zhu: { [key: string]: number } = this.ep_daowen_zhu(actDaoWen, actDdaoWenList); //主属性
        let eps_other: { [key: string]: number } = this.ep_daowen_other(actDaoWen, actDdaoWenList);; //副属性
        return this.ep_merge(eps_zhu, eps_other);
    }

    
    /**
     * 道纹
     * 镶嵌道纹的主属性
     */
    ep_daowen_zhu(actDaoWen: Xys.ActDaoWen, actDdaoWenList: { [iid: string]: Xys.DaoWen_Stone }): { [key: string]: number } {
        let eps_zhu: { [key: string]: number } = {}; //主属性
        
        let real_dc = actDaoWen.dc || "1";
        if (actDaoWen.dcs[real_dc] != null) {
            const slotKeys = Object.keys(actDaoWen.dcs[real_dc].slot);
            for (let i = 0; i < slotKeys.length; i++) {
                const slot = slotKeys[i];
                let iid = actDaoWen.dcs[real_dc].slot[slot];
                let stone = actDdaoWenList[iid.toString()];
                if (stone == null) {
                    continue;
                }

                const base_eps_c = Gamecfg.daowenZhushuxing.getItem(stone.baseEps.sxid, stone.baseEps.level.toString());
                if (base_eps_c != null) {
                    eps_zhu = this.ep_merge(eps_zhu, base_eps_c.eps);
                }
            }
        }
        return eps_zhu;
    }

    
    /**
     * 道纹
     * 镶嵌道纹的其他属性
     */
    ep_daowen_other(actDaoWen: Xys.ActDaoWen, actDdaoWenList: { [iid: string]: Xys.DaoWen_Stone }): { [key: string]: number } {
        let eps_fu: { [key: string]: number } = {}; //副属性
        let eps_level: { [key: string]: number } = {}; //解封等级属性

        let real_dc = actDaoWen.dc || "1";
        if (actDaoWen.dcs[real_dc] != null) {
            const slotKeys = Object.keys(actDaoWen.dcs[real_dc].slot);
            for (let i = 0; i < slotKeys.length; i++) {
                const slot = slotKeys[i];
                let iid = actDaoWen.dcs[real_dc].slot[slot];
                let stone = actDdaoWenList[iid.toString()];
                if (stone == null) {
                    continue;
                }

                //词条属性
                const fuEpsKeys = Object.keys(stone.fuEps);
                for (let i = 0; i < fuEpsKeys.length; i++) {
                    const eps_id = fuEpsKeys[i];
                    const ct_info_c = Gamecfg.daowenFushuxing.getItem(
                        eps_id,
                        stone.fuEps[eps_id].pinzhi.toString(),
                        stone.fuEps[eps_id].level.toString()
                    );
                    if (ct_info_c != null) {
                        eps_fu = this.ep_merge(eps_fu, ct_info_c.eps);
                    }
                }
            }
        }

        //解封等级的属性
        let level = actDaoWen.unlockLevel;
        const unlock_level_c = Gamecfg.daowenUnlock_level.getItem(level.toString());
        if (unlock_level_c != null) {
            eps_level = this.ep_merge(eps_level, unlock_level_c.eps); //镶嵌效果
        }

        return this.ep_merge(eps_fu, eps_level);
    }

    /**
     * 计算兽灵单个格子属性加成
     */
    ep_shouling_gezi(actShouLingOne: Xys.ActShouLing_ListOne, jiuxiao: number = 0): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        if (actShouLingOne == null || actShouLingOne.slid == "") {
            return eps;
        }
        let slid = actShouLingOne.slid;
        let cfgInfo = Gamecfg.shoulingInfo.getItem(slid);
        if (cfgInfo == null) {
            return eps;
        }
        let cfgPinzhi = Gamecfg.shoulingPinzhi.getItem(cfgInfo.pinzhi);

        if (cfgPinzhi == null) {
            return eps;
        }
        //兽灵基础属性
        eps = this.ep_merge(eps, cfgPinzhi.eps);

        //九霄天枢对兽灵基本属性加成
        if(jiuxiao > 0){
            eps = this.ep_KvRate(eps, 1 + jiuxiao);
        }

        //升级属性加成
        const level = actShouLingOne.level;
        let levelEps: { [key: string]: number } = {};
        for (let i = 1; i <= level; i++) {
            let lv = Gamecfg.shoulingLevel.getItem(cfgPinzhi.id, i.toString());
            if (lv == null) {
                continue;
            }
            levelEps = this.ep_merge(levelEps, lv.levelEps);
        }
        eps = this.ep_merge(eps, levelEps);
        //计算升星属性加成
        const star = actShouLingOne.star;
        let starEps: { [key: string]: number } = {};
        for (let index = star; index >= 0; index--) {
            let star_c = Gamecfg.shoulingStar.getItem(cfgPinzhi.id, index.toString());
            if (star_c == null) {
                continue;
            }
            starEps = this.ep_merge(starEps, star_c.starEps);
        }
        eps = this.ep_merge(eps, starEps);

        //计算觉醒属性加成
        let stepEps: { [key: string]: number } = {};
        const step = actShouLingOne.step;
        let jueXingCfg = Gamecfg.shoulingJuexing.getItem(step.toString());
        if(jueXingCfg){
            stepEps = this.ep_merge(stepEps, jueXingCfg.eps);
        }
        eps = this.ep_merge(eps, stepEps);

        //皮肤属性
        let skinEps: { [key: string]: number } = {};
        if (actShouLingOne.skins == null) {
            return eps;
        }
        
        for (const skinId in actShouLingOne.skins) {
            let skin = actShouLingOne.skins[skinId];
            let skinCfg = Gamecfg.shoulingLevel.getItem(skinId, skin.level.toString());
            if (skinCfg) {
                skinEps = this.ep_merge(skinEps, skinCfg.levelEps);
            }
        }
        eps = this.ep_merge(eps, skinEps);
        return eps;
    }

    /**
     * 计算异象属性加成
     */
    ep_yixiang(actYiXiang: Xys.ActYiXiang): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        //计算升级升阶异象属性
        const cfg = Gamecfg.yixiangLevel.getItem(actYiXiang.id.toString());
        if (cfg == null) {
            return eps;
        }
        const cfgJieJi = Gamecfg.yixiangJieji.getItem(cfg.step.toString());
        if (cfgJieJi == null) {
            return eps;
        }
        eps = this.ep_merge(eps, cfg.ep0);
        eps = this.ep_merge(eps, cfgJieJi.ep1);
        //计算上阵异象属性
        const cfgStep = Gamecfg.yixiangStep.getItem(actYiXiang.hh, cfg.step.toString());
        if (cfgStep == null) {
            return eps;
        }
        // 计算化形属性
        for(let id in actYiXiang.hxData){
            let cfgHx = Gamecfg.yixiangHuaxing.getItem(id,actYiXiang.hxData[id].level.toString())
            if(cfgHx != null){
                eps = this.ep_merge(eps, cfgHx.levelEps);
            }
        }
        eps = this.ep_merge(eps, cfgStep.ep);
        return eps;
    }

    /**
     * 计算皮肤属性加成
     */
    ep_pifu(actPifu: Xys.ActPifu): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        for (const key in actPifu.list) {
            let pifu = actPifu.list[key];
            if(!pifu){
                continue;
            }
            if(!pifu.level){
                pifu.level = 1;
            }
            //计算皮肤属性属性
            const cfg = Gamecfg.skinSkinlevel.getItem(key.toString(), pifu.level.toString());
            if (cfg == null) {
                continue;
            }
            eps = this.ep_merge(eps, cfg.levelEps);
        }
        return eps;
    }

    /**
     * 计算洞天道童属性加成
     */
    ep_dongtian(actDongTian: Xys.ActDongTian): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        //计算道童等级属性加成
        const xlLvKeys = Object.keys(actDongTian.xlLv);
        for (let i = 0; i < xlLvKeys.length; i++) {
            const type = xlLvKeys[i];
            let cfg = Gamecfg.dongtianXlLv.getItem(type, actDongTian.xlLv[type].toString());
            if (cfg == null) {
                continue;
            }
            eps = this.ep_merge(eps, cfg.eps);
        }
        let cfgStep = Gamecfg.dongtianXlStep.getItem(actDongTian.xlStep.toString());
        if (cfgStep == null) {
            return eps;
        }
        const epsKeys = Object.keys(eps);
        for (let i = 0; i < epsKeys.length; i++) {
            const key = epsKeys[i];
            eps[key] *= cfgStep.eps / 10000;
        }
        return eps;
    }

    /**
     * 计算药田属性加成
     */
    ep_yaotian(actYaoTianEps: Xys.ActYaoTianEps): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        for (let key in actYaoTianEps) {
            eps[key] = Math.floor(actYaoTianEps[key]);
        }
        return eps;
    }

    /**
     * 计算称号属性加成
     */
    ep_chenghao(actChenghao: Xys.ActChenghao): { [key: string]: number } {
        let eps: { [key: string]: number } = {};
        for(let id in actChenghao.list){
            let cfg = Gamecfg.chenghaoShuxing.getItem(id)
            if(cfg != null){
                eps = this.ep_merge(eps, cfg.eps)
            }
        }
        return eps;
    }

    // /**
    //  * 分别统计主角和弟子的的战斗属性
    //  */
    ep_userAndDiZi(sevBack: Xys.SevBack) {
        let allEps: any = {};
        let userBase = gameMethod.ep_all_base(sevBack);
        allEps["user"] = userBase
        let userEps = gameMethod.ep_all_fight(userBase);

        for (let gzid in sevBack.actDiZi?.a?.shangZhen) {
            let eps: { [key: string]: number } = {};
            let dzId = sevBack.actDiZi?.a?.shangZhen[gzid];
            if (dzId == null || dzId == "") {
                continue;
            }
            let cfgdz = Gamecfg.huobanBase.getItem(dzId);
            let dizi = sevBack.actDiZiList?.a?.[dzId];
            if (cfgdz == null || dizi == null || cfgdz.zhanli == 0) {
                continue;
            }
            let cfgZhongZu = Gamecfg.huobanZhongzu.getItem(cfgdz.pinzhi, cfgdz.zhongzu.toString());
            if (cfgZhongZu == null) {
                continue;
            }
            //计算弟子升级属性
            let levelEps: { [key: string]: number } = {};
            for (let i = 1; i <= dizi.level; i++) {
                const diziLevel = Gamecfg.huobanShengji.getItem(cfgdz.pinzhi, i.toString());
                if (diziLevel == null) {
                    continue;
                }
                levelEps = this.ep_merge(levelEps, diziLevel.attr);
            }
           //九霄天枢对弟子基础属性加成
            for (const hdcid in sevBack.hdJiuXiaoTianShu) {
                // 检查属性是否存在
                if (!Object.prototype.hasOwnProperty.call(sevBack.hdJiuXiaoTianShu, hdcid)) {
                    continue;
                }
                let jiuxiao = sevBack.hdJiuXiaoTianShu?.[hdcid]?.a;
                if (!jiuxiao) {
                    continue;
                }
                // 检查伙伴属性加成是否大于0
                if (jiuxiao.huoBanEps > 0) {
                    let rate = 1 + (jiuxiao.huoBanEps / 100);
                    levelEps = this.ep_KvRate(levelEps, rate);
                }
            }
            eps = this.ep_merge(eps, levelEps);
            //计算弟子升星的基础属性加成
            let starEps: { [key: string]: number } = {};
            for (let i = 1; i <= dizi.star; i++) {
                const diziStar = Gamecfg.huobanStar.getItem(cfgdz.id, i.toString());
                if (diziStar == null) {
                    continue;
                }
                starEps = this.ep_merge(starEps, diziStar.attr2);
            }
            eps = this.ep_merge(eps, starEps);
            //计算弟子境界属性
            let jingjieEps: { [key: string]: number } = {};
            for (let i = 1; i <= dizi.jingjie; i++) {
                const diziJingjie = Gamecfg.huobanTupo.getItem(cfgdz.pinzhi, i.toString());
                if (diziJingjie == null) {
                    continue;
                }
                jingjieEps = this.ep_merge(jingjieEps, diziJingjie.attr);
            }
            eps = this.ep_merge(eps, jingjieEps);
            let dzEps: { [key: string]: number } = gameMethod.ep_init(); //初始化属性
            dzEps = gameMethod.ep_merge(dzEps, cfgdz.eps);
            for (const key in cfgZhongZu.inherit_attr) {
                //继承主角属性
                dzEps[key] += Math.floor((userEps[key] * cfgZhongZu.inherit_attr[key]) / 10000);
            }
            for (const key in cfgZhongZu.inherit_attr_hide) {
                //继承主角属性
                dzEps[key] += Math.floor((userEps[key] * cfgZhongZu.inherit_attr_hide[key]) / 10000);
            }
            eps = gameMethod.ep_merge(eps, dzEps);
            allEps[`${dzId}_${cfgdz.dzName}`] = eps;
        }
        return allEps;
    }

    /**
     * 计算角色总战力
     * jiuxiao: 对弟子基础属性加成
     */
    ep_power_all(sevBack: Xys.SevBack, ep_all_base: { [key: string]: number } = {}) {
        let userBase: { [key: string]: number } = {};
        if (gameMethod.isEmpty(ep_all_base) == false) {
            userBase = ep_all_base;
        } else {
            userBase = gameMethod.ep_all_base(sevBack);
        }
        let userEps = gameMethod.ep_all_fight(userBase)

        let diziPower: number = 0;
        for (let gzid in sevBack.actDiZi?.a?.shangZhen) {
            let diziEps: { [key: string]: number } = {};
            let dzId = sevBack.actDiZi?.a?.shangZhen[gzid];
            if (dzId == null || dzId == "") {
                continue;
            }
            let cfgdz = Gamecfg.huobanBase.getItem(dzId);
            let dizi = sevBack.actDiZiList?.a?.[dzId];
            if (cfgdz == null || dizi == null || cfgdz.zhanli == 0) {
                continue;
            }
            let cfgZhongZu = Gamecfg.huobanZhongzu.getItem(cfgdz.pinzhi, cfgdz.zhongzu.toString());
            if (cfgZhongZu == null) {
                continue;
            }
            //计算弟子升级属性
            let levelEps: { [key: string]: number } = {};
            for (let i = 1; i <= dizi.level; i++) {
                const diziLevel = Gamecfg.huobanShengji.getItem(cfgdz.pinzhi, i.toString());
                if (diziLevel == null) {
                    continue;
                }
                levelEps = this.ep_merge(levelEps, diziLevel.attr);
            }
            //九霄天枢对弟子基础属性加成
            for (const hdcid in sevBack.hdJiuXiaoTianShu) {
                // 检查属性是否存在
                if (!Object.prototype.hasOwnProperty.call(sevBack.hdJiuXiaoTianShu, hdcid)) {
                    continue;
                }
                let jiuxiao = sevBack.hdJiuXiaoTianShu?.[hdcid]?.a;
                if (!jiuxiao) {
                    continue;
                }
                // 检查伙伴属性加成是否大于0
                if (jiuxiao.huoBanEps > 0) {
                    let rate = 1 + (jiuxiao.huoBanEps / 100);
                    levelEps = this.ep_KvRate(levelEps, rate);
                }
            }
            diziEps = this.ep_merge(diziEps, levelEps);

            //计算弟子升星的基础属性加成
            let starEps: { [key: string]: number } = {};
            for (let i = 1; i <= dizi.star; i++) {
                const diziStar = Gamecfg.huobanStar.getItem(cfgdz.id, i.toString());
                if (diziStar == null) {
                    continue;
                }
                starEps = this.ep_merge(starEps, diziStar.attr2);
            }
            diziEps = this.ep_merge(diziEps, starEps);
            //计算弟子境界属性
            let jingjieEps: { [key: string]: number } = {};
            for (let i = 1; i <= dizi.jingjie; i++) {
                const diziJingjie = Gamecfg.huobanTupo.getItem(cfgdz.pinzhi, i.toString());
                if (diziJingjie == null) {
                    continue;
                }
                jingjieEps = this.ep_merge(jingjieEps, diziJingjie.attr);
            }
            diziEps = this.ep_merge(diziEps, jingjieEps);
            let dzEps: { [key: string]: number } = gameMethod.ep_init(); //初始化属性
            dzEps = gameMethod.ep_merge(dzEps, cfgdz.eps);
            for (const key in cfgZhongZu.inherit_attr) {
                //继承主角属性
                dzEps[key] += Math.floor((userEps[key] * cfgZhongZu.inherit_attr[key]) / 10000);
            }
            for (const key in cfgZhongZu.inherit_attr_hide) {
                //继承主角属性
                dzEps[key] += Math.floor((userEps[key] * cfgZhongZu.inherit_attr_hide[key]) / 10000);
            }
            diziEps = this.ep_merge(diziEps, dzEps);
            diziPower += gameMethod.ep_power(0, diziEps);
        }
        // 兽灵战力
        let slPower: number = 0;
        if (sevBack.actShouLing != null && sevBack.actShouLingList != null && sevBack.actShouLing.a && sevBack.actShouLingList.a) {
            const useGzIdKeys = Object.keys(sevBack.actShouLing.a.useGzId);
            for (let i = 0; i < useGzIdKeys.length; i++) {
                const useGzId = useGzIdKeys[i];
                let gzid = sevBack.actShouLing.a.useGzId[useGzId];
                if (gzid == null || gzid == "") {
                    continue;
                }
                let shouling = sevBack.actShouLingList.a[gzid];
                if (shouling == null) {
                    continue;
                }
                /*let cfg = Gamecfg.shoulingInfo.getItem(shouling.slid);
                if (cfg == null) {
                    continue;
                }
                let pinzhiCfg = Gamecfg.shoulingPinzhi.getItem(cfg.pinzhi);
                if (pinzhiCfg == null) {
                    continue;
                }*/
                //主战
                if (useGzId == "0") {
                    let skill = shouling.sk;
                    let step  = shouling.step
                    let skillCfg = Gamecfg.spellSkill.getItem(skill.skillId, skill.lv.toString(), step.toString());
                    if (skillCfg == null) {
                        continue;
                    }
                    slPower += skillCfg.zhanli;
                } else {
                    // 助战位
                    let skill = shouling.sk;
                    let step = shouling.step
                    let skillCfg = Gamecfg.spellSkill.getItem(skill.skillId, skill.lv.toString(), step.toString());
                    if (skillCfg == null) {
                        continue;
                    }
                    slPower += skillCfg.zhanli;
                }
            }
        }
        return diziPower + gameMethod.ep_power(0, userBase) + slPower;
    }

    ep_power_dizi(sevBack: Xys.SevBack, dzId: string) {
        let userEps = gameMethod.ep_all(sevBack);
        let diziEps: { [key: string]: number } = {};
        if (dzId == null || dzId == "") {
            return 0;
        }
        let cfgdz = Gamecfg.huobanBase.getItem(dzId);
        let dizi = sevBack.actDiZiList?.a?.[dzId];
        if (cfgdz == null || dizi == null || cfgdz.zhanli == 0) {
            return 0;
        }
        let cfgZhongZu = Gamecfg.huobanZhongzu.getItem(cfgdz.pinzhi, cfgdz.zhongzu.toString());
        if (cfgZhongZu == null) {
            return 0;
        }
        //计算弟子升级属性
        let levelEps: { [key: string]: number } = {};
        for (let i = 1; i <= dizi.level; i++) {
            const diziLevel = Gamecfg.huobanShengji.getItem(cfgdz.pinzhi, i.toString());
            if (diziLevel == null) {
                continue;
            }
            levelEps = this.ep_merge(levelEps, diziLevel.attr);
        }
        //九霄天枢对弟子基础属性加成
        for (const hdcid in sevBack.hdJiuXiaoTianShu) {
            // 检查属性是否存在
            if (!Object.prototype.hasOwnProperty.call(sevBack.hdJiuXiaoTianShu, hdcid)) {
                continue;
            }
            let jiuxiao = sevBack.hdJiuXiaoTianShu?.[hdcid]?.a;
            if (!jiuxiao) {
                continue;
            }
            // 检查伙伴属性加成是否大于0
            if (jiuxiao.huoBanEps > 0) {
                let rate = 1 + (jiuxiao.huoBanEps / 100);
                levelEps = this.ep_KvRate(levelEps, rate);
            }
        }
        diziEps = this.ep_merge(diziEps, levelEps);
        //计算弟子升星的基础属性加成
        let starEps: { [key: string]: number } = {};
        for (let i = 1; i <= dizi.star; i++) {
            const diziStar = Gamecfg.huobanStar.getItem(cfgdz.id, i.toString());
            if (diziStar == null) {
                continue;
            }
            starEps = this.ep_merge(starEps, diziStar.attr2);
        }
        diziEps = this.ep_merge(diziEps, starEps);
        //计算弟子境界属性
        let jingjieEps: { [key: string]: number } = {};
        for (let i = 1; i <= dizi.jingjie; i++) {
            const diziJingjie = Gamecfg.huobanTupo.getItem(cfgdz.pinzhi, i.toString());
            if (diziJingjie == null) {
                continue;
            }
            jingjieEps = this.ep_merge(jingjieEps, diziJingjie.attr);
        }
        diziEps = this.ep_merge(diziEps, jingjieEps);
        let dzEps: { [key: string]: number } = gameMethod.ep_init(); //初始化属性
        dzEps = gameMethod.ep_merge(dzEps, cfgdz.eps);
        for (const key in cfgZhongZu.inherit_attr) {
            //继承主角属性
            dzEps[key] += Math.floor((userEps[key] * cfgZhongZu.inherit_attr[key]) / 10000);
        }
        for (const key in cfgZhongZu.inherit_attr_hide) {
            //继承主角属性
            dzEps[key] += Math.floor((userEps[key] * cfgZhongZu.inherit_attr_hide[key]) / 10000);
        }
        diziEps = this.ep_merge(diziEps, dzEps);
        return gameMethod.ep_power(0, diziEps);
    }

    /**
     * 计算阵法更换的战力变化值 (弃用)
     */
    ep_power_zhenfa(sevBack: Xys.SevBack, linshi: { pfid: string; level: number; eps: { [key: string]: number }; pinzhi: string }): number {
        //原本的战力
        const initPower = this.ep_power_all(sevBack);
        let newSevBack = gameMethod.objCopy(sevBack);
        if (newSevBack.actZhenfa == null || newSevBack.actZhenfa.a == null) {
            return 0;
        }
        let cfgpf = Gamecfg.zhenfaPifu.getItem(linshi.pfid);
        if (cfgpf == null) {
            return 0;
        }
        if (newSevBack.actZhenfa.a.chuan[cfgpf.buwei] == null) {
            newSevBack.actZhenfa.a.chuan[cfgpf.buwei] = {
                pfid: "",
                level: 0,
                eps: {},
                fmLv: 0,
                fmBd: 0,
                fmEps: [],
                fmZhBd: [],
                fmZhls: [],
                pinzhi: "",
            };
        }
        newSevBack.actZhenfa.a.chuan[cfgpf.buwei].pfid = linshi.pfid;
        newSevBack.actZhenfa.a.chuan[cfgpf.buwei].level = linshi.level;
        newSevBack.actZhenfa.a.chuan[cfgpf.buwei].eps = linshi.eps;
        newSevBack.actZhenfa.a.chuan[cfgpf.buwei].pinzhi = linshi.pinzhi;
        const newPower = this.ep_power_all(newSevBack);

        return newPower - initPower;
    }

    /**
     * 计算阵法更换的战力变化值
     */
    ep_power_zhenfaNew(sevBack: Xys.SevBack, linshi: { pfid: string; level: number; eps: { [key: string]: number }; pinzhi: string }): number {
        if (sevBack.actZhenfaNew == null || sevBack.actZhenfaNew.a == null || sevBack.actZhenfaNew.a.chuan == null) {
            return 0;
        }
        let cfgpf = Gamecfg.zhenfaPifu.getItem(linshi.pfid);
        if (cfgpf == null) {
            return 0;
        }
        let oldCeps: { [key: string]: number } = {};
        if (sevBack.actZhenfaNew.a.chuan[cfgpf.buwei] != null) {
            oldCeps = sevBack.actZhenfaNew.a.chuan[cfgpf.buwei].eps;
        }
        //原本的战力
        const initPower = this.ep_power_all(sevBack);
        let ep_base = this.ep_all_base(sevBack);
        for (const key in oldCeps) {
            ep_base[key] -= oldCeps[key];
        }
        for (const key in linshi.eps) {
            ep_base[key] += linshi.eps[key];
        }
        const newPower = this.ep_power_all(sevBack, ep_base);
        return newPower - initPower;
    }

    /**
     * 计算已经穿戴的装备属性
     */
    ep_power_zhenfaNew_chuan(sevBack: Xys.SevBack, buwei:string): number {
        if (sevBack.actZhenfaNew == null || sevBack.actZhenfaNew.a == null || sevBack.actZhenfaNew.a.chuan == null) {
            return 0;
        }
        //原本的战力
        const initPower = this.ep_power_all(sevBack);
        let oldCeps: { [key: string]: number } = {};
        if (sevBack.actZhenfaNew.a.chuan[buwei] != null) {
            let chuan = sevBack.actZhenfaNew.a.chuan[buwei]
            oldCeps = this.ep_merge(oldCeps, chuan.eps);
            for (const fmEps of chuan.fmEps) {
                if (oldCeps[fmEps[0]] == null) {
                    oldCeps[fmEps[0]] = 0;
                }
                oldCeps[fmEps[0]] += fmEps[1];
            }
    
            // 洗练属性
            for (const posId in chuan.xilianEps) {
                if (chuan.xilianEps[posId].id == null || chuan.xilianEps[posId].id == "") {
                    continue;
                }
                let xilian_c = Gamecfg.zhenfaXilianWord.getItem(chuan.xilianEps[posId].id);
                if (xilian_c != null) {
                    oldCeps = this.ep_merge(oldCeps, xilian_c.attr);
                }
            }
        }
        let ep_base = this.ep_all_base(sevBack);
        for (const key in oldCeps) {
            ep_base[key] -= oldCeps[key];
        }
        const newPower = this.ep_power_all(sevBack, ep_base);
        return newPower - initPower;
    }

    /**
     * 计算阵法更换的战力变化值
     */
    ep_power_guzi(sevBack: Xys.SevBack, linshi: Xys.lishiGZInfo): number {
        //原本的战力
        let oldCeps: { [key: string]: number } = {};
        if (
            sevBack.actDadiGuzi != null &&
            sevBack.actDadiGuzi.a != null &&
            sevBack.actDadiGuzi.a.mpList != null &&
            sevBack.actDadiGuzi.a.mpXhid != null &&
            sevBack.actDadiGuzi.a.mpList[sevBack.actDadiGuzi.a.mpXhid] != null &&
            sevBack.actDadiGuzi.a.mpList[sevBack.actDadiGuzi.a.mpXhid][linshi.buwei] != null
        ) {
            oldCeps = sevBack.actDadiGuzi.a.mpList[sevBack.actDadiGuzi.a.mpXhid][linshi.buwei].eps;
        }

        let ep_base = this.ep_all_base(sevBack);
        let ep_base2 = gameMethod.objCopy(ep_base);
        ep_base.atk += Math.floor((ep_base.atk * ep_base.atk_per) / 10000);
        ep_base.def += Math.floor((ep_base.def * ep_base.def_per) / 10000);
        ep_base.hp_max += Math.floor((ep_base.hp_max * ep_base.hp_max_per) / 10000);
        ep_base.hp = ep_base.hp_max;
        const initPower = this.ep_power(0, ep_base);
        for (const key in oldCeps) {
            ep_base2[key] -= oldCeps[key];
        }
        for (const key in linshi.eps) {
            ep_base2[key] += linshi.eps[key];
        }
        ep_base2.atk += Math.floor((ep_base2.atk * ep_base2.atk_per) / 10000);
        ep_base2.def += Math.floor((ep_base2.def * ep_base2.def_per) / 10000);
        ep_base2.hp_max += Math.floor((ep_base2.hp_max * ep_base2.hp_max_per) / 10000);
        ep_base2.hp = ep_base2.hp_max;
        const newPower = this.ep_power(0, ep_base2);

        return newPower - initPower;
    }

    // 计算门徒的战力
    ep_power_mentu(mentu: Xys.mentu) {
        let power = 0;

        // 基础属性
        power += this.ep_power(0, mentu.basicAttr);

        // 特殊属性
        if (mentu.speAttr != null) {
            for (const id of mentu.speAttr) {
                let specialCfg = Gamecfg.zongMenSpeAttr.getItem(id + "");
                if (specialCfg == null) {
                    continue;
                }
                power += this.ep_power(0, specialCfg.attr);
            }
        }

        return power;
    }

    /**
     * 属性转化成战力
     * @param type 默认  0默认  1怪物
     * @param eps 属性消息
     * @returns
     */
    ep_power(type: number, _eps: { [key: string]: number } | any): number {
        let eps = gameMethod.ep_init();
        eps = gameMethod.ep_merge(eps, _eps);
        eps = gameMethod.ep_all_fight(eps)

        let power: number = 0;
        let cfgEpPool = Gamecfg.userEp.pool;
        for (const key in cfgEpPool) {
            let rpKey = cfgEpPool[key].key;
            if (eps[rpKey] == null || typeof eps[rpKey] != "number") {
                continue;
            }
            let xishu = 0;
            switch (type) {
                case 1:
                    if (gameMethod.isEmpty(cfgEpPool[key].momPower) == true) {
                        continue;
                    }
                    xishu = cfgEpPool[key].momPower;
                    break;
                default:
                    if (gameMethod.isEmpty(cfgEpPool[key].power) == true) {
                        continue;
                    }
                    xishu = cfgEpPool[key].power;
                    break;
            }
            let addPower = Math.floor(xishu * eps[rpKey]);
            power += addPower;
        }
        return power;
    }

    //获取药田吃药加成的属性
    eps_yaofang(count: number, danyao: { naiyao: number; shiyong: number }, yx: number[], eps: { [key: string]: number }) {
        let needCount = count;
        let shiyong: any = {};
        while (needCount > 0) {
            //要降级
            if (danyao.shiyong + needCount >= yx[0] && danyao.naiyao > yx[2]) {
                needCount -= yx[0] - danyao.shiyong;
                //记录食用
                shiyong[danyao.naiyao] = yx[0] - danyao.shiyong;
                danyao.shiyong = 0;
                danyao.naiyao -= yx[1];
                danyao.naiyao = Math.max(danyao.naiyao, yx[2]);
            } else {
                if (danyao.naiyao == 100) {
                    //耐药等于最低的时候不加shiyong数量只加count数量
                    shiyong[danyao.naiyao] = needCount;
                    needCount -= needCount;
                } else {
                    danyao.shiyong += needCount;
                    //记录食用
                    shiyong[danyao.naiyao] = needCount;
                    needCount -= needCount;
                }
            }
        }
        let epsAll: any = {};
        for (let naiyao in shiyong) {
            //遍历食用加属性
            for (let key in eps) {
                if (epsAll[key] == null) {
                    epsAll[key] = 0;
                }
                epsAll[key] += (eps[key] * shiyong[naiyao] * Number(naiyao)) / 10000;
            }
        }
        for (let key in epsAll) {
            epsAll[key] = Math.floor(epsAll[key]);
        }
        return epsAll;
    }

    //计算弟子战斗自身属性（不包括继承主角的属性）
    ep_diziEps(sevBack: Xys.SevBack, dzId: string): { [key: string]: number } {
        let diziEps: { [key: string]: number } = gameMethod.ep_init(); //初始化属性
        if (dzId == null || dzId == "") {
            return diziEps;
        }
        let cfgdz = Gamecfg.huobanBase.getItem(dzId);
        let dizi = sevBack.actDiZiList?.a?.[dzId];
        if (cfgdz == null || dizi == null || cfgdz.zhanli == 0) {
            return diziEps;
        }
        //弟子基础属性
        diziEps = this.ep_merge(diziEps, cfgdz.eps);
        let cfgZhongZu = Gamecfg.huobanZhongzu.getItem(cfgdz.pinzhi, cfgdz.zhongzu.toString());
        if (cfgZhongZu == null) {
            return diziEps;
        }
        //计算弟子升级属性
        let levelEps: { [key: string]: number } = {};
        for (let i = 1; i <= dizi.level; i++) {
            const diziLevel = Gamecfg.huobanShengji.getItem(cfgdz.pinzhi, i.toString());
            if (diziLevel == null) {
                continue;
            }
            levelEps = this.ep_merge(levelEps, diziLevel.attr);
        }
       //九霄天枢对弟子基础属性加成
       for (const hdcid in sevBack.hdJiuXiaoTianShu) {
            // 检查属性是否存在
            if (!Object.prototype.hasOwnProperty.call(sevBack.hdJiuXiaoTianShu, hdcid)) {
                continue;
            }
            let jiuxiao = sevBack.hdJiuXiaoTianShu?.[hdcid]?.a;
            if (!jiuxiao) {
                continue;
            }
            // 检查伙伴属性加成是否大于0
            if (jiuxiao.huoBanEps > 0) {
                let rate = 1 + (jiuxiao.huoBanEps / 100);
                levelEps = this.ep_KvRate(levelEps, rate);
            }
        }
        diziEps = this.ep_merge(diziEps, levelEps);
        //计算弟子升星的基础属性加成
        let starEps: { [key: string]: number } = {};
        for (let i = 1; i <= dizi.star; i++) {
            const diziStar = Gamecfg.huobanStar.getItem(cfgdz.id, i.toString());
            if (diziStar == null) {
                continue;
            }
            starEps = this.ep_merge(starEps, diziStar.attr2);
        }
        diziEps = this.ep_merge(diziEps, starEps);
        //计算弟子境界属性
        let jingjieEps: { [key: string]: number } = {};
        for (let i = 1; i <= dizi.jingjie; i++) {
            const diziJingjie = Gamecfg.huobanTupo.getItem(cfgdz.pinzhi, i.toString());
            if (diziJingjie == null) {
                continue;
            }
            jingjieEps = this.ep_merge(jingjieEps, diziJingjie.attr);
        }
        diziEps = this.ep_merge(diziEps, jingjieEps);
        return diziEps;
    }

    //获取模块的属性加成
    ep_act(sevBack: Xys.SevBack, key: string): { [key: string]: number } {
        let eps = this.ep_init();
        if (sevBack.actEps != null && sevBack.actEps.a != null && sevBack.actEps.a[key] != null) {
            eps = gameMethod.ep_merge(eps, sevBack.actEps.a[key]);
        }
        return eps;
    }

    /**
     * 解析洞天 矿车数据
     * @param carInfo
     * @param now
     * @returns edtime //离结束 还有多长时间 (0 已完成 )(未开始 -1)
     * @returns win //胜利方是谁 0守方 1攻方 (未开始默认0)
     * @returns nowpos nowpos, //当前位置
     */
    getDongTianCar(carInfo: Xys.ActDongTian_CarInfo | any, now: number): Xys.ActDongTian_Carshow {
        if (carInfo.stime <= 0) {
            //未启动
            return {
                edtime: -1, //离结束 还有多长时间
                win: 0, //胜利方是谁 0守方 1攻方 (未开始默认0)
                nowpos: carInfo.dpos, //当前位置
            };
        }
        //获取矿车配置
        let carCfg = Gamecfg.dongtianCar.getItem(carInfo.id);
        if (carCfg == null) {
            console.error(`dongtianCar_err:${carInfo.id}`);
            return {
                edtime: -1, //离结束 还有多长时间
                win: 0, //胜利方是谁 0守方 1攻方 (未开始默认0)
                nowpos: carInfo.dpos, //当前位置
            };
        }

        let dnum = 0; //胜利方多出来的人数
        let pow = 1; //胜利方状态值
        let leng = carInfo.dpos; //距离(本方距离)
        let win: 0 | 1 = 0;
        let fevCard: boolean = false; //胜利方是否有终生卡
        //人数对比
        if (carInfo.he.knum.length > carInfo.my.knum.length) {
            //进攻方胜利
            dnum = carInfo.he.knum.length - carInfo.my.knum.length;
            pow = carInfo.he.pow;
            leng = carCfg.lengs[2] - carInfo.dpos; //反向距离
            win = 1; //进攻方胜利
            fevCard = carInfo.he.fevCard; //终生卡
        } else {
            //防守方胜利
            dnum = carInfo.my.knum.length - carInfo.he.knum.length;
            pow = carInfo.my.pow;
            fevCard = carInfo.my.fevCard; //终生卡
        }
        //如果人数 <= 0 (防守方胜利 系数0.7)  就当防守方有0.7个人
        dnum = Math.max(dnum, 0.7);

        //哥布林速度系数
        let wkVel = 1;
        let cfgMath = Gamecfg.mathInfo.getItem("dongtian_wkVel");
        if (cfgMath == null || cfgMath.pram.count == null) {
            console.error(`dongtian_wkVel`);
        } else {
            wkVel = cfgMath.pram.count;
        }
        let tilixs = 200; //根据体力获得系数

        //总速度
        let vel = (dnum * wkVel * tilixs) / 100;
        //终生卡 速度加成 +5%
        let sdadd = 10000;
        if (fevCard) {
            sdadd += 1500;
        }
        vel = (vel * sdadd) / 10000;

        //总的需要时间 计算公式
        let allTime = Math.ceil(leng / vel);

        //经过时间
        let dtime = now - carInfo.stime;
        if (dtime >= allTime) {
            //已完成
            return {
                edtime: 0, //离结束 还有多长时间 (未开始 -1)
                win: win, //胜利方是谁 0守方 1攻方 (未开始默认0)
                nowpos: win ? carCfg.lengs[2] : 0, //当前位置 防守方胜利 就是0 进攻方胜利 就是最大值
            };
        } else {
            //未完成 计算 当前位置偏移量
            let dpos = dtime * vel;
            //当前位置
            let nowpos = carInfo.dpos;
            if (win > 0) {
                nowpos += dpos;
                nowpos = Math.floor(nowpos); //进攻方胜利 取余偏向防守方(小值)
            } else {
                nowpos -= dpos;
                nowpos = Math.ceil(nowpos); //防守方胜利 取余偏向进攻方(大值)
            }
            return {
                edtime: allTime - dtime, //离结束 还有多长时间 (未开始 -1)
                win: win, //胜利方是谁 0守方 1攻方 (未开始默认0)
                nowpos: nowpos, //当前位置
            };
        }
    }

    /**
     * 章节挂机计算
     * @param actZhangjie 章节信息
     * @param newTime 现在时间
     * @param zflevel 阵法等级
     * @returns
     */
    guajiItems(
        _actZhangjie: Xys.ActZhangjie,
        newTime: number,
        zflevel: number
    ): { items: Xys.KindItem[]; zy_items: Xys.KindItem[]; dj_items: Xys.KindItem[]; actZhangjie: Xys.ActZhangjie } {
        let actZhangjie: Xys.ActZhangjie = this.objCopy(_actZhangjie);
        let items: Xys.KindItem[] = []; //挂机奖励(总)
        let zy_items: Xys.KindItem[] = []; //挂机奖励（金币/玩家经验/阵法经验）
        let dj_items: Xys.KindItem[] = []; //挂机奖励（道具）
        let cfgzj = Gamecfg.zhangjieInfo.getItem(actZhangjie.zjid);
        if (cfgzj == null) {
            return {
                actZhangjie: actZhangjie,
                items: items,
                zy_items: zy_items,
                dj_items: dj_items,
            };
        }
        for (const item of cfgzj.gjRwd_zy) {
            let cAt: number = newTime - actZhangjie.gjtime;
            cAt = Math.min(cAt, actZhangjie.gjMax * 3600); //8小时上限
            let count = Math.floor(cAt / (item[3] / item[2]));
            if (count > 0) {
                items.push([item[0], item[1], count]);
                zy_items.push([item[0], item[1], count]);
            }
        }

        for (const item of cfgzj.gjRwd_dj) {
            if (item[4] != null && item[4] > zflevel) {
                continue; //未达到阵法等级
            }
            if (actZhangjie.gjRwd_dj[item[0].toString()] == null) {
                actZhangjie.gjRwd_dj[item[0].toString()] = {};
            }
            if (actZhangjie.gjRwd_dj[item[0].toString()][item[1].toString()] == null) {
                actZhangjie.gjRwd_dj[item[0].toString()][item[1].toString()] = 0;
            }
            let cAt: number = newTime - actZhangjie.gjtime;
            cAt = Math.min(cAt, actZhangjie.gjMax * 3600) + actZhangjie.gjRwd_dj[item[0].toString()][item[1].toString()];

            //获得一个道具 需要多长时间
            let oneTime = item[3] / item[2];
            let count = Math.floor(cAt / oneTime);
            if (count > 0) {
                items.push([item[0], item[1], count]);
                dj_items.push([item[0], item[1], count]);
                actZhangjie.gjRwd_dj[item[0].toString()][item[1].toString()] = 0;
            }
            actZhangjie.gjRwd_dj[item[0].toString()][item[1].toString()] = Math.floor(cAt % oneTime);
        }
        actZhangjie.gjtime = newTime;
        return {
            actZhangjie: actZhangjie,
            // items: gameMethod.mergeArr(items),
            items: items,
            zy_items: gameMethod.mergeArr(zy_items),
            dj_items: gameMethod.mergeArr(dj_items),
        };
    }

    //异或加解密
    xorEncrypt(str: string, x:boolean = true, key: string = "zgyx2024888") {
        if(!x){
            return str
        }
        const result = [];
        for (let i = 0; i < str.length; i++) {
            const charCode = str.charCodeAt(i) ^ key.charCodeAt(i % key.length);
            result.push(String.fromCharCode(charCode));
        }
        return result.join("");
    }

    // 用随机种子获取太初古矿地图
    getGuKuangMap(randNum: number, cs: number): { id: string; hp: number; item: number[][]; icon: string }[][] {
        let geziCp: number[] = Object.values(gezi);
        let map: {
            id: string;
            hp: number;
            item: number[][];
            icon: string;
        }[][] = []; // 地图数据
        let sendRand = new SeedRand(randNum);
        sendRand.random();
        geziCp = sendRand.arrayShuffle(geziCp);
        let index = 1;
        let tcInfo;
        let tsInfo;
        let tcInfoLast;
        let tsInfoLast;
        while (index > 0) {
            let tcInfo2;
            let tsInfo2;
            if (tcInfo == null) {
                tcInfo2 = Gamecfg.taichuInfo.getItem(index.toString());
            }
            if (tsInfo == null) {
                tsInfo2 = Gamecfg.taichuTs.getItem(index.toString());
            }
            if (tcInfo2 && tcInfo2.cs[0] <= cs && tcInfo2.cs[1] >= cs) {
                tcInfo = tcInfo2;
            } else if (tcInfo2) {
                tcInfoLast = tcInfo2;
            }
            if (tsInfo2 && tsInfo2.cs[0] <= cs && tsInfo2.cs[1] >= cs) {
                tsInfo = tsInfo2;
            } else if (tsInfo2) {
                tsInfoLast = tsInfo2;
            }
            if (tcInfo && tsInfo) {
                index = -1;
            } else if (tcInfo2 == null && tsInfo2 == null && tcInfoLast && tsInfoLast) {
                tcInfo = gameMethod.objCopy(tcInfoLast);
                tsInfo = gameMethod.objCopy(tsInfoLast);
                let ts_cs_min = tsInfo.cs[0];
                let ts_cs_max = tsInfo.cs[1];
                let cha = 0;
                while (ts_cs_max + cha < cs) {
                    cha = ts_cs_max - ts_cs_min;
                    ts_cs_min = ts_cs_max + 1;
                    ts_cs_max = ts_cs_min + cha;
                    cha = 0;
                }
                tsInfo.cs = [ts_cs_min, ts_cs_max];
                index = -1;
            } else {
                index++;
            }
        }
        if (tcInfo == null || tsInfo == null) {
            return map;
        }
        let jlCs: number[] = [];
        for (let i = tsInfo.cs[0]; i <= tsInfo.cs[1]; i++) {
            jlCs.push(i);
        }
        let jlC = sendRand.getRandArr2(jlCs, 1).result[0]; // 当前层数区间 奖励层所在层数
        let itemCount: { [itemid: string]: number[] } = {}; // 地块id:[格子数组]
        let sd = tcInfo.sd;
        for (let i = 0; i < sd.length; i++) {
            let result = sendRand.getRandArr2(geziCp, sd[i][1]);
            geziCp = result.arr;
            itemCount[sd[i][0].toString()] = result.result;
        }
        let jlcNum: number | null = null; // 奖励层所在行数 0-5
        if (jlC == cs) {
            jlcNum = sendRand.getRandArr2([0, 1, 2, 3, 4, 5], 1).result[0];
        }
        let itemCountKeys = Object.keys(itemCount);
        let mapLine: {
            id: string;
            hp: number;
            item: number[][];
            icon: string;
        }[] = [];
        let isHas = false;
        let tilesInfo101 = Gamecfg.taichuTiles.getItem("1");
        let tilesInfo301 = Gamecfg.taichuTiles.getItem("301");
        let line = 0; // 第几行
        for (let i = 0; i < gezi.length; i++) {
            line = Math.floor(i / 6) + 1;
            // 开始绘制地图
            if (i % 6 == 0 && mapLine.length > 0) {
                map.push(mapLine);
                mapLine = [];
            }
            isHas = false;
            let zuojiaInfo = Gamecfg.taichuZuojia.getItem(cs.toString(), line.toString());
            if (zuojiaInfo != null) {
                isHas = true;
                for (let id of zuojiaInfo.item) {
                    let tilesInfo = Gamecfg.taichuTiles.getItem(id.toString());
                    if (tilesInfo != null) {
                        mapLine.push({
                            id: tilesInfo.id,
                            hp: tilesInfo.hp,
                            item: tilesInfo.itme,
                            icon: tilesInfo.icon,
                        });
                    } else {
                        mapLine.push({
                            id: "",
                            hp: 0,
                            item: [],
                            icon: "",
                        });
                    }
                }
                i += 5;
            } else {
                for (let k = 0; k < itemCountKeys.length; k++) {
                    if (itemCount[itemCountKeys[k]].indexOf(i) != -1) {
                        let tilesInfo = Gamecfg.taichuTiles.getItem(itemCountKeys[k]);
                        if (tilesInfo != null) {
                            mapLine.push({
                                id: itemCountKeys[k],
                                hp: tilesInfo.hp,
                                item: tilesInfo.itme,
                                icon: tilesInfo.icon,
                            });
                            isHas = true;
                            break;
                        }
                    }
                }
            }
            if (!isHas) {
                if (cs == 1 && i < 6) {
                    if (tilesInfo101 != null) {
                        mapLine.push({
                            id: "1",
                            hp: 1,
                            item: [],
                            icon: tilesInfo101.icon,
                        });
                    }
                } else {
                    if (tilesInfo101 && map.length > 0 && map[map.length - 1][mapLine.length].hp == 0) {
                        // 如果上一层是空格 加一个木块
                        mapLine.push({
                            id: tilesInfo101.id,
                            hp: tilesInfo101.hp,
                            item: tilesInfo101.itme,
                            icon: tilesInfo101.icon,
                        });
                    } else {
                        mapLine.push({
                            id: "",
                            hp: 0,
                            item: [],
                            icon: "",
                        });
                    }
                }
            }
        }
        if (mapLine.length > 0) {
            map.push(mapLine);
        }
        if (jlcNum != null) {
            let len = tsInfo.sd.length;
            if (len != 12) {
                return map;
            }
            for (let i = 0; i < tsInfo.sd.length; i++) {
                if (i % 6 == 0 && i != 0) {
                    jlcNum += 1;
                }
                if (tilesInfo301 != null) {
                    map[jlcNum][i % 6] =
                        tsInfo.sd[i].length == 1
                            ? {
                                id: "301",
                                hp: 0,
                                item: [],
                                icon: i == 0 ? tilesInfo301.icon : "",
                            }
                            : {
                                id: "301",
                                hp: 1,
                                item: [tsInfo.sd[i]],
                                icon: i == 0 ? tilesInfo301.icon : "",
                            };
                }
            }
            // 奖励层下一层 整行不能为空
            for (let i = 0; i < 6; i++) {
                if (i % 6 == 0) {
                    jlcNum += 1;
                }
                if (map[jlcNum][i % 6].hp <= 0 && tilesInfo101 != null) {
                    // 转成石头
                    map[jlcNum][i % 6] = {
                        id: tilesInfo101.id,
                        hp: tilesInfo101.hp,
                        item: tilesInfo101.itme,
                        icon: tilesInfo101.icon,
                    };
                }
            }
        }
        return map;
    }

    /**
     * 根据玩家选的流派推荐阵容
     * @param type 玩家预选流派
     * @returns
     */
    tuijian(sevBack: Xys.SevBack, type: string) {
        //用于记录哪些位置被使用了
        let gezi: string[] = ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
        let tuijian: { [gzid: string]: string } = {};
        //先筛选出符合要求的弟子id列表
        let dzList1: any[] = []; //前排
        let dzList2: any[] = []; //中排
        let dzList3: any[] = []; //后排
        let wanbian1: any[] = []; //万变流前排
        let wanbian2: any[] = []; //万变流中排
        let wanbian3: any[] = []; //万变流后排
        let other1: any[] = []; //其他前排
        let other2: any[] = []; //其他中排
        let other3: any[] = []; //其他后排
        let actDiZiList: any = {};
        if (sevBack.actDiZiList != null && sevBack.actDiZiList.a != null) {
            actDiZiList = sevBack.actDiZiList.a;
        }
        for (let dzid in actDiZiList) {
            let cfg = Gamecfg.huobanBase.getItem(actDiZiList[dzid].id);
            if (cfg == null || cfg.show == 0) {
                continue;
            }
            //不是预选流派和万变流不符合条件
            if (cfg.liupai != type && cfg.liupai != "5") {
                if (cfg.dingwei == "1") {
                    other1.push(dzid);
                } else if (cfg.dingwei == "2") {
                    other2.push(dzid);
                } else if (cfg.dingwei == "3") {
                    other3.push(dzid);
                }
            }
            if (cfg.dingwei == "1" && cfg.liupai == type) {
                dzList1.push(dzid);
            } else if (cfg.dingwei == "2" && cfg.liupai == type) {
                dzList2.push(dzid);
            } else if (cfg.dingwei == "3" && cfg.liupai == type) {
                dzList3.push(dzid);
            } else if (cfg.dingwei == "1" && cfg.liupai == "5") {
                wanbian1.push(dzid);
            } else if (cfg.dingwei == "2" && cfg.liupai == "5") {
                wanbian2.push(dzid);
            } else if (cfg.dingwei == "3" && cfg.liupai == "5") {
                wanbian3.push(dzid);
            }
        }
        let push1 = 0; //记录前排放了几个弟子
        let push2 = 0; //记录中排放了几个弟子
        let push3 = 0; //记录后排放了几个弟子
        //选出1个前排3个中排2个后排 优先选本流派，然后选万变流，否则选所有弟子里面战力最高的
        if (dzList1.length > 0) {
            //如果是只有一个就直接进去
            if (dzList1.length == 1) {
                tuijian["1"] = dzList1[0];
                let index = gezi.indexOf("1");
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                push1 += 1;
            } else {
                let maxPower = 0;
                for (let dzid of dzList1) {
                    let power = this.ep_power_dizi(sevBack, dzid);
                    if (power > maxPower) {
                        maxPower = power;
                        tuijian["1"] = dzid;
                        let index = gezi.indexOf("1");
                        if (index > -1) {
                            gezi.splice(index, 1);
                        }
                        push1 += 1;
                    }
                }
            }
        } else if (wanbian1.length > 0 && push1 < 1) {
            //没有就遍历万变流
            //如果是只有一个就直接进去
            if (wanbian1.length == 1) {
                tuijian["1"] = wanbian1[0];
                let index = gezi.indexOf("1");
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                push1 += 1;
            } else {
                let maxPower = 0;
                for (let dzid of wanbian1) {
                    let power = this.ep_power_dizi(sevBack, dzid);
                    if (power > maxPower) {
                        maxPower = power;
                        tuijian["1"] = dzid;
                        let index = gezi.indexOf("1");
                        if (index > -1) {
                            gezi.splice(index, 1);
                        }
                        push1 += 1;
                    }
                }
            }
        }
        //放中排的
        if (dzList2.length > 0) {
            //如果是小于等于3个就直接放进去
            if (dzList2.length <= 3) {
                let xb = 4;
                for (let i = 0; i < dzList2.length; i++) {
                    tuijian[(xb + i).toString()] = dzList2[i];
                    let index = gezi.indexOf((xb + i).toString());
                    if (index > -1) {
                        gezi.splice(index, 1);
                    }
                    push2 += 1;
                }
            } else {
                let needDzid = dzList2
                    .map((dzid) => {
                        return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                    })
                    .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                    .slice(0, 3) // 选出战力最高的三个弟子
                    .map((item) => item.dzid); // 只取 dzid
                let xb = 4;
                for (let i = 0; i < 3; i++) {
                    tuijian[(xb + i).toString()] = needDzid[i];
                    let index = gezi.indexOf((xb + i).toString());
                    if (index > -1) {
                        gezi.splice(index, 1);
                    }
                    push2 += 1;
                }
            }
        } else if (wanbian2.length > 0 && push2 < 3) {
            //弟子不满足3个就遍历万变流
            let needDzid = wanbian2
                .map((dzid) => {
                    return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                })
                .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                .slice(0, 3 - push2) // 选出战力最高的需要的弟子数量
                .map((item) => item.dzid); // 只取 dzid
            let xb = 4 + push2;
            let cs = 2 - push3;
            cs = Math.min(cs, wanbian2.length);
            for (let i = 0; i < cs; i++) {
                tuijian[(xb + i).toString()] = needDzid[i];
                let index = gezi.indexOf((xb + i).toString());
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                push2 += 1;
            }
        }
        //放后排的
        if (dzList3.length > 0) {
            //如果是小于等于2个就直接放进去
            if (dzList3.length <= 2) {
                let xb = 7;
                for (let i = 0; i < dzList3.length; i++) {
                    tuijian[(xb + i).toString()] = dzList3[i];
                    let index = gezi.indexOf((xb + i).toString());
                    if (index > -1) {
                        gezi.splice(index, 1);
                    }
                    push3 += 1;
                }
            } else {
                let needDzid = dzList3
                    .map((dzid) => {
                        return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                    })
                    .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                    .slice(0, 2) // 选出战力最高的2个弟子
                    .map((item) => item.dzid); // 只取 dzid
                let xb = 7;
                for (let i = 0; i < 2; i++) {
                    tuijian[(xb + i).toString()] = needDzid[i];
                    let index = gezi.indexOf((xb + i).toString());
                    if (index > -1) {
                        gezi.splice(index, 1);
                    }
                    push3 += 1;
                }
            }
        } else if (wanbian3.length > 0 && push3 < 2) {
            //弟子不满足2个就遍历万变流
            let needDzid = wanbian3
                .map((dzid) => {
                    return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                })
                .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                .slice(0, 2 - push3) // 选出战力最高的需要的弟子数量
                .map((item) => item.dzid); // 只取 dzid
            let xb = 7 + push3;
            let cs = 2 - push3;
            cs = Math.min(cs, wanbian3.length);
            for (let i = 0; i < cs; i++) {
                tuijian[(xb + i).toString()] = needDzid[i];
                let index = gezi.indexOf((xb + i).toString());
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                push3 += 1;
            }
        }
        //如果遍历同派和万变流都没有符合的就优先从同站位最高战力里面拿
        if (push1 < 1) {
            //选择的流派和万变流都没有前排弟子就从其他前排弟子里面拿战力最高的
            let needDzid = other1
                .map((dzid) => {
                    return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                })
                .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                .slice(0, 1) // 选出战力最高的需要的弟子数量
                .map((item) => item.dzid); // 只取 dzid
            let xb = 1;
            let cs = Math.min(1, other1.length);
            for (let i = 0; i < cs; i++) {
                tuijian[(xb + i).toString()] = needDzid[i];

                let index = gezi.indexOf((xb + i).toString());
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                //把用掉的弟子剔除
                let index1 = other1.indexOf(needDzid[i]);
                if (index1 > -1) {
                    other1.splice(index, 1);
                }
            }
        }
        if (push2 < 3) {
            //选择的流派和万变流都没有前排弟子就从其他前排弟子里面拿战力最高的
            let needDzid = other2
                .map((dzid) => {
                    return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                })
                .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                .slice(0, 3 - push2) // 选出战力最高的需要的弟子数量
                .map((item) => item.dzid); // 只取 dzid
            let xb = 4 + push2;
            let cs = Math.min(3 - push2, other2.length);
            for (let i = 0; i < cs; i++) {
                tuijian[(xb + i).toString()] = needDzid[i];
                let index = gezi.indexOf((xb + i).toString());
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                //把用掉的弟子剔除
                let index1 = other2.indexOf(needDzid[i]);
                if (index1 > -1) {
                    other2.splice(index, 1);
                }
            }
        }
        if (push3 < 2) {
            //选择的流派和万变流都没有前排弟子就从其他前排弟子里面拿战力最高的
            let needDzid = other3
                .map((dzid) => {
                    return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                })
                .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                .slice(0, 2 - push3) // 选出战力最高的需要的弟子数量
                .map((item) => item.dzid); // 只取 dzid
            let xb = 7 + push3;
            let cs = Math.min(2 - push3, other3.length);
            for (let i = 0; i < cs; i++) {
                tuijian[(xb + i).toString()] = needDzid[i];
                let index = gezi.indexOf((xb + i).toString());
                if (index > -1) {
                    gezi.splice(index, 1);
                }
                //把用掉的弟子剔除
                let index1 = other3.indexOf(needDzid[i]);
                if (index1 > -1) {
                    other3.splice(index, 1);
                }
            }
        }
        //如果还是不足6个弟子就直接拿战力最高的前几个从空位开始放
        if (Object.keys(tuijian).length < 6) {
            //把其余的弟子合并
            let other: any[] = this.addArr(other1, other2);
            other = this.addArr(other, other3);
            let needDzid = other
                .map((dzid) => {
                    return { dzid, power: this.ep_power_dizi(sevBack, dzid) };
                })
                .sort((a, b) => b.power - a.power) // 按战力从大到小排序
                .slice(0, 6 - Object.keys(tuijian).length) // 选出战力最高的需要的弟子数量
                .map((item) => item.dzid); // 只取 dzid
            for (let i = 0; i < needDzid.length; i++) {
                //这个时候用掉的格子都已经删掉了，所以直接取就可以了
                tuijian[gezi[i]] = needDzid[i];
            }
        }
        return tuijian;
    }

    getSeedRand(seed: number) {
        return new SeedRand(seed);
    }
}

//输出
export let gameMethod: GameMethod = new GameMethod();

//种子随机
export class SeedRand {
    seed: number;
    constructor(seed: number) {
        this.seed = seed;
    }

    /**
     * 核心方法 输出一个小数
     */
    random(): number {
        this.seed = (this.seed * 9301 + 49297) % 233280;
        return this.seed / 233280.0;
    }
    random2(seed: number): number {
        seed = (seed * 9301 + 49297) % 233280;
        return seed / 233280.0;
    }

    /**
     * 按照范围获取一个随机数
     */
    rand(min: number, max: number): number {
        let _rd = Math.round((max - min + 1) * this.random() - 0.5) + min;
        return _rd;
    }

    /**
     * 随机排列一个数组
     */
    arrayShuffle(arr: any[]) {
        let len = arr.length;
        for (let i = 0; i < len - 1; i++) {
            let index = this.rand(0, len - i - 1);
            let temp = arr[index];
            arr[index] = arr[len - i - 1];
            arr[len - i - 1] = temp;
        }
        return arr;
    }

    /**
     * 随机获取数组元素
     */
    getRandArr<T>(_arr: T[], num: number): T[] {
        let arr = gameMethod.objCopy(_arr);
        let result = [];
        num = Math.min(num, arr.length);
        for (let i = 0; i < num; i++) {
            let ran = Math.floor(this.random() * (arr.length - i));
            result.push(arr[ran]);
            arr[ran] = arr[arr.length - i - 1];
        }
        return result;
    }
    /**
     * 随机获取数组元素 seed、_arr、num不变 随机出的数据完全一致
     */
    getRandArr2<T>(_arr: T[], num: number) {
        let arr: T[] = gameMethod.objCopy(_arr);
        let result: T[] = [];
        num = Math.min(num, arr.length);
        let seed = this.random2(this.seed);
        for (let i = 0; i < num; i++) {
            seed = this.random2(seed);
            let ran = Math.floor(seed * arr.length);
            result.push(arr[ran]);
            arr.splice(ran, 1);
        }
        return { result: result, arr: arr };
    }
}
