import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqUpWz, ResUpWz } from "../../shared/protocols/gonghui/PtlUpWz";

export default async function (call: ApiCall<ReqUpWz, ResUpWz>) {

    const conf = G.gc.shili_wz[call.req.type];
    const nextLv = call.conn.gud.ghwz[call.req.type] + 1;

    if (!conf) return call.error(globalThis.lng.gonghui_15);
    if (!conf[nextLv]) return call.error(globalThis.lng.gonghui_28);

    await PlayerFun.checkNeedIsMeet(call, conf[nextLv].need);
    await PlayerFun.cutNeed(call, conf[nextLv].need);

    let change = Object.assign({}, call.conn.gud.ghwz);
    change[call.req.type]++;

    await PlayerFun.addAttr(call, { ghwz: change });

    call.succ({});
}