import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { Rank } from '../../public/rank/rank';
import { ReqTujian, ResTujian } from "../../shared/protocols/user/PtlTujian";

export default async function (call: ApiCall<ReqTujian, ResTujian>) {

    let curLv = call.conn.gud.tujianLv;

    if (!G.gc.tujian_jc[curLv + 1]) return call.error(globalThis.lng.user_8);

    let activeNum = Object.keys(call.conn.lshd.hero).length + Object.keys(call.conn.lshd.equip).length + Object.keys(call.conn.lshd.peijian).length;

    if (activeNum < G.gc.tujian_jc[curLv + 1].jindu) return call.error(globalThis.lng.user_9);

    await PlayerFun.addAttr(call, { tujianLv: curLv + 1 });

    Rank.list['tujian'].addNew({
        player: call.conn.gud,
        valArr: [curLv + 1]
    });

    call.succ({});
}