import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqUnLock, ResUnLock } from "../../shared/protocols/peijian/PtlUnLock";

export default async function (call: ApiCall<ReqUnLock, ResUnLock>) {
    let conf = G.gc.peijiancom.gridCond[call.req.pos];
    if (!conf || conf.need.length < 1) return call.errorCode(-1);

    let player = call.conn.gud;
    if (player.lv >= conf.lv) return call.errorCode(-3);
    if (player.peijianUnlock?.[call.req.pos] != undefined) return call.errorCode(-4);

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

    let wears = player.peijianUnlock || {};
    wears[call.req.pos] = '';

    await PlayerFun.addAttr(call, { peijianUnlock: wears });

    call.succ({});
}