import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqRenown, ResRenown } from "../../shared/protocols/user/PtlRenown";

export default async function (call: ApiCall<ReqRenown, ResRenown>) {

    let curRenown = call.conn.gud.renown;
    let conf = G.gc.mw_dj[curRenown + 1];

    if (!conf) return call.error(globalThis.lng.user_5);
    if (conf.lv > call.conn.gud.lv) return call.error(globalThis.lng.user_6);

    await PlayerFun.checkNeedIsMeet(call, conf.need);

    await PlayerFun.cutNeed(call, conf.need);
    await PlayerFun.addAttr(call, { renown: curRenown + 1 });

    call.succ({});
}